Package rs.baselib.configuration
Class ConfigurationUtils
java.lang.Object
rs.baselib.configuration.ConfigurationUtils
Useful methods for configuration issues.
- Author:
- ralph
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
configure
(IConfigurable configurable, Configuration config) Configure the object accordingly.static PropertiesBuilderParameters
createPropertiesBuilderParams
(String encoding) Creates the basic Properties Builder parametersstatic XMLBuilderParameters
createXMLBuilderParams
(String encoding) Creates the basic XML Builder parametersstatic String
getParam
(HierarchicalConfiguration<ImmutableNode> config, String name) Returns the config parameter with given value for attribute name.static String
getParam
(SubnodeConfiguration config, String name) Returns the config parameter with given value for attribute name.static PropertiesConfiguration
Create a Properties configuration object with UTF-8.static PropertiesConfiguration
getPropertiesConfiguration
(File file, String encoding) Create a Properties configuration object.static PropertiesConfiguration
Create a Properties configuration object with UTF-8.static PropertiesConfiguration
getPropertiesConfiguration
(URL url, String encoding) Create a Properties configuration object.static PropertiesConfiguration
Creates the Properties configuration object based on the given parameters.static XMLConfiguration
getXmlConfiguration
(File file) Create a XML configuration object with UTF-8.static XMLConfiguration
getXmlConfiguration
(File file, String encoding) Create a XML configuration object.static XMLConfiguration
getXmlConfiguration
(URL configUrl) Create a XML configuration object with UTF-8.static XMLConfiguration
getXmlConfiguration
(URL configUrl, String encoding) Create a XML configuration object.static XMLConfiguration
Creates the XML configuration object based on the given parameters.static <T> T
load
(Class<T> clazz, Configuration config, boolean configure) Loads an object from a configuration.static Object
load
(String className, Configuration config, boolean configure) Loads an object from a configuration.static Object
load
(Configuration config, boolean configure) Loads an object from a configuration.
-
Constructor Details
-
ConfigurationUtils
public ConfigurationUtils()
-
-
Method Details
-
load
Loads an object from a configuration. The object is configured if it is an instance ofIConfigurable
. The class will be taken from attribute[@class]
.- Parameters:
config
- the configuration to applyconfigure
- whether the object shall be configured (if it is aIConfigurable
).- Returns:
- the object
-
load
Loads an object from a configuration. The object is configured if it is an instance ofIConfigurable
.- Parameters:
className
- the name of class to be instantiatedconfig
- the configuration to applyconfigure
- whether the object shall be configured (if it is aIConfigurable
).- Returns:
- the object
-
load
Loads an object from a configuration. The object is configured if it is an instance ofIConfigurable
.- Type Parameters:
T
- the type of the object to be instantiated- Parameters:
clazz
- the class to be instantiatedconfig
- the configuration to applyconfigure
- whether the object shall be configured (if it is aIConfigurable
).- Returns:
- the object
-
configure
public static void configure(IConfigurable configurable, Configuration config) throws ConfigurationException Configure the object accordingly.- Parameters:
configurable
- the object to be configuredconfig
- the configuration to apply- Throws:
ConfigurationException
- when a problem occurs
-
getParam
Returns the config parameter with given value for attribute name.- Parameters:
config
- configname
- name of param- Returns:
- value of param
-
getParam
Returns the config parameter with given value for attribute name.- Parameters:
config
- configname
- name of param- Returns:
- value of param
-
createPropertiesBuilderParams
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 fromencoding
- - 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 fromencoding
- - encoding, e.g. UTF-8- Returns:
- the configuration object
- Throws:
ConfigurationException
- when an error occurs
-
createXMLBuilderParams
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
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 fromencoding
- - encoding, e.g. UTF-8- Returns:
- the configuration object
- Throws:
ConfigurationException
- when an error occurs
-
getXmlConfiguration
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 fromencoding
- - encoding, e.g. UTF-8- Returns:
- the configuration object
- Throws:
ConfigurationException
- when an error occurs
-