public class XMLConfiguration extends Object
This class manages the configuration of a Java Bean by an xml configuration file. It also supports configuration of Log4J.
Modifier and Type | Field and Description |
---|---|
protected String |
VAR_BEGIN |
protected char |
VAR_DEFAULT |
protected char |
VAR_END |
Constructor and Description |
---|
XMLConfiguration()
Standard Constructor without variable support
|
XMLConfiguration(String varIndicator)
Constructor allowing to specify a variable prefix (e.g. $ or #)
|
Modifier and Type | Method and Description |
---|---|
protected void |
appendConfigProperties(Class<?> clazz,
Object object,
StringBuilder b,
boolean appendClassInfo) |
Element |
getRootNode()
returns the configuration root element or null if init() has not been called.
|
void |
init(String filename,
boolean fromResource)
Initialize the configuration.
|
protected boolean |
isProperty(Element item)
Checks if the element is a property
|
protected void |
readConfiguration(String fileName,
boolean fromResource)
Reads the configuration file and parses the XML Configuration.
|
void |
readProperties(Object bean,
Element propertiesNode)
reads all properties from a given properties node and applies them to the given bean
|
void |
readProperties(Object bean,
String... propertiesNodeNames)
reads all properties from a given properties node and applies them to the given bean
|
protected Object |
resolveValue(Class<?> valueType,
String value)
Resolves a property value by replacing variables and type conversion
|
protected String |
resolveVariable(String var,
String defaultValue)
Returns the value for a given variable
If a variable value cannot be resolved the function should return the default value
|
protected void |
setPropertyValue(Object bean,
Element item)
Sets the property value of an XML Element
|
protected void |
setPropertyValue(Object bean,
String name,
Object value)
Sets a property value
|
String |
toString() |
protected final String VAR_BEGIN
protected final char VAR_END
protected final char VAR_DEFAULT
public XMLConfiguration()
public XMLConfiguration(String varIndicator)
varIndicator
- the variable prefixpublic void init(String filename, boolean fromResource)
filename
- the filefromResource
- will read from the classpath if truepublic Element getRootNode()
protected void readConfiguration(String fileName, boolean fromResource)
public void readProperties(Object bean, String... propertiesNodeNames)
bean
- the bean to which to apply the configurationpropertiesNodeNames
- the name of the properties node below the root elementpublic void readProperties(Object bean, Element propertiesNode)
bean
- the bean to which to apply the configurationpropertiesNode
- the properties nodeprotected boolean isProperty(Element item)
item
- the xml elementprotected void setPropertyValue(Object bean, Element item)
bean
- the java bean containing the propertyitem
- the configuration nodeprotected void setPropertyValue(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
bean
- the name of the objectname
- the name of the propertyvalue
- the valueIllegalAccessException
InvocationTargetException
NoSuchMethodException
protected Object resolveValue(Class<?> valueType, String value)
valueType
- the destination typevalue
- the config valueprotected String resolveVariable(String var, String defaultValue)
var
- the variable namedefaultValue
- the default value or nullprotected void appendConfigProperties(Class<?> clazz, Object object, StringBuilder b, boolean appendClassInfo)
Copyright © 2008–2023 Apache Software Foundation. All rights reserved.