Class XMLConfiguration

java.lang.Object
org.apache.empire.xml.XMLConfiguration

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.
 
  • Field Details

    • VAR_BEGIN

      protected final String 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

      public XMLConfiguration(String varIndicator)
      Constructor allowing to specify a variable prefix (e.g. $ or #)
      Parameters:
      varIndicator - the variable prefix
  • Method Details

    • init

      public void init(String filename, boolean fromResource)
      Initialize the configuration.
      Parameters:
      filename - the file
      fromResource - will read from the classpath if true
    • getRootNode

      public Element getRootNode()
      returns the configuration root element or null if init() has not been called.
      Returns:
      the configuration root element
    • readConfiguration

      protected void readConfiguration(String fileName, boolean fromResource)
      Reads the configuration file and parses the XML Configuration.
    • readProperties

      public void readProperties(Object bean, String... propertiesNodeNames)
      reads all properties from a given properties node and applies them to the given bean
      Parameters:
      bean - the bean to which to apply the configuration
      propertiesNodeNames - the name of the properties node below the root element
    • readProperties

      public void readProperties(Object bean, Element propertiesNode)
      reads all properties from a given properties node and applies them to the given bean
      Parameters:
      bean - the bean to which to apply the configuration
      propertiesNode - the properties node
    • isProperty

      protected boolean isProperty(Element item)
      Checks if the element is a property
      Parameters:
      item - the xml element
      Returns:
      true if the element is a property
    • setPropertyValue

      protected void setPropertyValue(Object bean, Element item)
      Sets the property value of an XML Element
      Parameters:
      bean - the java bean containing the property
      item - 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 object
      name - the name of the property
      value - the value
      Throws:
      IllegalAccessException
      InvocationTargetException
      NoSuchMethodException
    • resolveValue

      protected Object resolveValue(Class<?> valueType, String value)
      Resolves a property value by replacing variables and type conversion
      Parameters:
      valueType - the destination type
      value - the config value
      Returns:
      the property value
    • resolveVariable

      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
      Parameters:
      var - the variable name
      defaultValue - the default value or null
      Returns:
      the variable value
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • appendConfigProperties

      protected void appendConfigProperties(Class<?> clazz, Object object, StringBuilder b, boolean appendClassInfo)