Class ConfigurationUtils

java.lang.Object
rs.baselib.configuration.ConfigurationUtils

public class ConfigurationUtils extends Object
Useful methods for configuration issues.
Author:
ralph
  • Constructor Details

    • ConfigurationUtils

      public ConfigurationUtils()
  • Method Details

    • load

      public static Object load(Configuration config, boolean configure)
      Loads an object from a configuration. The object is configured if it is an instance of IConfigurable. The class will be taken from attribute [@class].
      Parameters:
      config - the configuration to apply
      configure - whether the object shall be configured (if it is a IConfigurable).
      Returns:
      the object
    • load

      public static Object load(String className, Configuration config, boolean configure)
      Loads an object from a configuration. The object is configured if it is an instance of IConfigurable.
      Parameters:
      className - the name of class to be instantiated
      config - the configuration to apply
      configure - whether the object shall be configured (if it is a IConfigurable).
      Returns:
      the object
    • load

      public static <T> T load(Class<T> clazz, Configuration config, boolean configure)
      Loads an object from a configuration. The object is configured if it is an instance of IConfigurable.
      Type Parameters:
      T - the type of the object to be instantiated
      Parameters:
      clazz - the class to be instantiated
      config - the configuration to apply
      configure - whether the object shall be configured (if it is a IConfigurable).
      Returns:
      the object
    • configure

      public static void configure(IConfigurable configurable, Configuration config) throws ConfigurationException
      Configure the object accordingly.
      Parameters:
      configurable - the object to be configured
      config - the configuration to apply
      Throws:
      ConfigurationException - when a problem occurs
    • getParam

      public static String getParam(SubnodeConfiguration config, String name)
      Returns the config parameter with given value for attribute name.
      Parameters:
      config - config
      name - name of param
      Returns:
      value of param
    • getParam

      public static String getParam(HierarchicalConfiguration<ImmutableNode> config, String name)
      Returns the config parameter with given value for attribute name.
      Parameters:
      config - config
      name - name of param
      Returns:
      value of param
    • createPropertiesBuilderParams

      public static PropertiesBuilderParameters createPropertiesBuilderParams(String encoding)
      Creates the basic Properties Builder parameters
      Parameters:
      encoding - - loading character encoding
      Returns:
      basic builder params
    • getPropertiesConfiguration

      public static PropertiesConfiguration getPropertiesConfiguration(PropertiesBuilderParameters params) throws ConfigurationException
      Creates the Properties configuration object based on the given parameters.
      Parameters:
      params - - the Properties builder parameters
      Returns:
      the Properties configuration
      Throws:
      ConfigurationException - when an error occurs
    • getPropertiesConfiguration

      public static PropertiesConfiguration getPropertiesConfiguration(File file) throws ConfigurationException
      Create a Properties configuration object with UTF-8.
      Parameters:
      file - - file to load from
      Returns:
      the configuration object
      Throws:
      ConfigurationException - when an error occurs
    • getPropertiesConfiguration

      public static PropertiesConfiguration getPropertiesConfiguration(File file, String encoding) throws ConfigurationException
      Create a Properties configuration object.
      Parameters:
      file - - file to load from
      encoding - - encoding, e.g. UTF-8
      Returns:
      the configuration object
      Throws:
      ConfigurationException - when an error occurs
    • getPropertiesConfiguration

      public static PropertiesConfiguration getPropertiesConfiguration(URL url) throws ConfigurationException
      Create a Properties configuration object with UTF-8.
      Parameters:
      url - - URL to load from
      Returns:
      the configuration object
      Throws:
      ConfigurationException - when an error occurs
    • getPropertiesConfiguration

      public static PropertiesConfiguration getPropertiesConfiguration(URL url, String encoding) throws ConfigurationException
      Create a Properties configuration object.
      Parameters:
      url - - URL to load from
      encoding - - encoding, e.g. UTF-8
      Returns:
      the configuration object
      Throws:
      ConfigurationException - when an error occurs
    • createXMLBuilderParams

      public static XMLBuilderParameters createXMLBuilderParams(String encoding)
      Creates the basic XML Builder parameters
      Parameters:
      encoding - - loading character encoding
      Returns:
      basic builder params
    • getXmlConfiguration

      public static XMLConfiguration getXmlConfiguration(XMLBuilderParameters params) throws ConfigurationException
      Creates the XML configuration object based on the given parameters.
      Parameters:
      params - - the XML builder parameters
      Returns:
      the XML configuration
      Throws:
      ConfigurationException - when an error occurs
    • getXmlConfiguration

      public static XMLConfiguration getXmlConfiguration(File file) throws ConfigurationException
      Create a XML configuration object with UTF-8.
      Parameters:
      file - - file to load from
      Returns:
      the configuration object
      Throws:
      ConfigurationException - when an error occurs
    • getXmlConfiguration

      public static XMLConfiguration getXmlConfiguration(File file, String encoding) throws ConfigurationException
      Create a XML configuration object.
      Parameters:
      file - - file to load from
      encoding - - encoding, e.g. UTF-8
      Returns:
      the configuration object
      Throws:
      ConfigurationException - when an error occurs
    • getXmlConfiguration

      public static XMLConfiguration getXmlConfiguration(URL configUrl) throws ConfigurationException
      Create a XML configuration object with UTF-8.
      Parameters:
      configUrl - - URL to load from
      Returns:
      the configuration object
      Throws:
      ConfigurationException - when an error occurs
    • getXmlConfiguration

      public static XMLConfiguration getXmlConfiguration(URL configUrl, String encoding) throws ConfigurationException
      Create a XML configuration object.
      Parameters:
      configUrl - - URL to load from
      encoding - - encoding, e.g. UTF-8
      Returns:
      the configuration object
      Throws:
      ConfigurationException - when an error occurs