Package org.apache.empire.xml
Class XMLConfiguration
java.lang.Object
org.apache.empire.xml.XMLConfiguration
This class manages the configuration of a Java Bean by an xml configuration file. It also supports configuration of Log4J.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Stringprotected final charprotected final char -
Constructor Summary
ConstructorsConstructorDescriptionStandard Constructor without variable supportXMLConfiguration(String varIndicator) Constructor allowing to specify a variable prefix (e.g. $ or #) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappendConfigProperties(Class<?> clazz, Object object, StringBuilder b, boolean appendClassInfo) returns the configuration root element or null if init() has not been called.voidInitialize the configuration.protected booleanisProperty(Element item) Checks if the element is a propertyprotected voidreadConfiguration(String fileName, boolean fromResource) Reads the configuration file and parses the XML Configuration.voidreadProperties(Object bean, String... propertiesNodeNames) reads all properties from a given properties node and applies them to the given beanvoidreadProperties(Object bean, Element propertiesNode) reads all properties from a given properties node and applies them to the given beanprotected ObjectresolveValue(Class<?> valueType, String value) Resolves a property value by replacing variables and type conversionprotected StringresolveVariable(String var, String defaultValue) Returns the value for a given variable If a variable value cannot be resolved the function should return the default valueprotected voidsetPropertyValue(Object bean, String name, Object value) Sets a property valueprotected voidsetPropertyValue(Object bean, Element item) Sets the property value of an XML ElementtoString()
-
Field Details
-
VAR_BEGIN
-
VAR_END
protected final char VAR_END -
VAR_DEFAULT
protected final char VAR_DEFAULT
-
-
Constructor Details
-
XMLConfiguration
public XMLConfiguration()Standard Constructor without variable support -
XMLConfiguration
Constructor allowing to specify a variable prefix (e.g. $ or #)- Parameters:
varIndicator- the variable prefix
-
-
Method Details
-
init
Initialize the configuration.- Parameters:
filename- the filefromResource- will read from the classpath if true
-
getRootNode
returns the configuration root element or null if init() has not been called.- Returns:
- the configuration root element
-
readConfiguration
Reads the configuration file and parses the XML Configuration. -
readProperties
reads all properties from a given properties node and applies them to the given bean- Parameters:
bean- the bean to which to apply the configurationpropertiesNodeNames- the name of the properties node below the root element
-
readProperties
reads all properties from a given properties node and applies them to the given bean- Parameters:
bean- the bean to which to apply the configurationpropertiesNode- the properties node
-
isProperty
Checks if the element is a property- Parameters:
item- the xml element- Returns:
- true if the element is a property
-
setPropertyValue
Sets the property value of an XML Element- Parameters:
bean- the java bean containing the propertyitem- the configuration node
-
setPropertyValue
protected void setPropertyValue(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException Sets a property value- Parameters:
bean- the name of the objectname- the name of the propertyvalue- the value- Throws:
IllegalAccessExceptionInvocationTargetExceptionNoSuchMethodException
-
resolveValue
Resolves a property value by replacing variables and type conversion- Parameters:
valueType- the destination typevalue- the config value- Returns:
- the property value
-
resolveVariable
Returns the value for a given variable If a variable value cannot be resolved the function should return the default value- Parameters:
var- the variable namedefaultValue- the default value or null- Returns:
- the variable value
-
toString
-
appendConfigProperties
protected void appendConfigProperties(Class<?> clazz, Object object, StringBuilder b, boolean appendClassInfo)
-