Class Configurations
- java.lang.Object
-
- org.apache.commons.configuration2.builder.fluent.Configurations
-
public class Configurations extends Object
A convenience class which simplifies the creation of standard configurations and their builders.Complex initializations of configuration builders can be done in a pretty straight-forward way by making use of the provided fluent API. However, if only default settings are used (and maybe a configuration file to be loaded has to be specified), this approach tends to become a bit verbose. This class was introduced to simplify the creation of configuration objects in such cases. It offers a bunch of methods which allow the creation of some standard configuration classes with default settings passing in only a minimum required parameters.
An an example consider the creation of a
PropertiesConfigurationobject from a file. Using a builder, code like the following one would have to be written:Parameters params = new Parameters(); FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class) .configure(params.fileBased().setFile(new File("config.properties"))); PropertiesConfiguration config = builder.getConfiguration();With a convenience method of
Configurationsthe same can be achieved with the following:Configurations configurations = new Configurations(); PropertiesConfiguration config = configurations.properties(new File("config.properties"));There are similar methods for constructing builder objects from which configurations can then be obtained.
This class is thread-safe. A single instance can be created by an application and used in a central way to create configuration objects. When an instance is created a
Parametersinstance can be passed in. Otherwise, a default instance is created. In any case, theParametersinstance associated with aConfigurationsobject can be used to define default settings for the configurations to be created.- Since:
- 2.0
- See Also:
DefaultParametersManager
-
-
Constructor Summary
Constructors Constructor Description Configurations()Creates a newConfigurationsinstance with default settings.Configurations(Parameters params)Creates a new instance ofConfigurationsand initializes it with the specifiedParametersobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CombinedConfigurationcombined(File file)Creates aCombinedConfigurationinstance from the content of the given file.CombinedConfigurationcombined(String path)Creates aCombinedConfigurationinstance from the content of the file identified by the given path.CombinedConfigurationcombined(URL url)Creates aCombinedConfigurationinstance from the content of the given URL.CombinedConfigurationBuildercombinedBuilder(File file)Creates a builder for aCombinedConfigurationand initializes it with the given file to be loaded.CombinedConfigurationBuildercombinedBuilder(String path)Creates a builder for aCombinedConfigurationand initializes it with the given path to the file to be loaded.CombinedConfigurationBuildercombinedBuilder(URL url)Creates a builder for aCombinedConfigurationand initializes it with the given URL to be loaded.<T extends FileBasedConfiguration>
TfileBased(Class<T> configClass, File file)Creates an instance of the specified file-based configuration class from the content of the given file.<T extends FileBasedConfiguration>
TfileBased(Class<T> configClass, String path)Creates an instance of the specified file-based configuration class from the content of the file identified by the given path.<T extends FileBasedConfiguration>
TfileBased(Class<T> configClass, URL url)Creates an instance of the specified file-based configuration class from the content of the given URL.<T extends FileBasedConfiguration>
FileBasedConfigurationBuilder<T>fileBasedBuilder(Class<T> configClass, File file)Creates aFileBasedConfigurationBuilderfor the specified configuration class and initializes it with the file to be loaded.<T extends FileBasedConfiguration>
FileBasedConfigurationBuilder<T>fileBasedBuilder(Class<T> configClass, String path)Creates aFileBasedConfigurationBuilderfor the specified configuration class and initializes it with the path to the file to be loaded.<T extends FileBasedConfiguration>
FileBasedConfigurationBuilder<T>fileBasedBuilder(Class<T> configClass, URL url)Creates aFileBasedConfigurationBuilderfor the specified configuration class and initializes it with the URL to the file to be loaded.ParametersgetParameters()Gets theParametersinstance associated with this object.INIConfigurationini(File file)Creates aINIConfigurationinstance from the content of the given file.INIConfigurationini(String path)Creates aINIConfigurationinstance from the content of the file identified by the given path.INIConfigurationini(URL url)Creates aINIConfigurationinstance from the content of the given URL.FileBasedConfigurationBuilder<INIConfiguration>iniBuilder(File file)Creates a builder for aINIConfigurationand initializes it with the given file to be loaded.FileBasedConfigurationBuilder<INIConfiguration>iniBuilder(String path)Creates a builder for aINIConfigurationand initializes it with the file file identified by the given path.FileBasedConfigurationBuilder<INIConfiguration>iniBuilder(URL url)Creates a builder for aINIConfigurationand initializes it with the given URL to be loaded.PropertiesConfigurationproperties(File file)Creates aPropertiesConfigurationinstance from the content of the given file.PropertiesConfigurationproperties(String path)Creates aPropertiesConfigurationinstance from the content of the file identified by the given path.PropertiesConfigurationproperties(URL url)Creates aPropertiesConfigurationinstance from the content of the given URL.FileBasedConfigurationBuilder<PropertiesConfiguration>propertiesBuilder()Creates a builder for aPropertiesConfiguration.FileBasedConfigurationBuilder<PropertiesConfiguration>propertiesBuilder(File file)Creates a builder for aPropertiesConfigurationand initializes it with the given file to be loaded.FileBasedConfigurationBuilder<PropertiesConfiguration>propertiesBuilder(String path)Creates a builder for aPropertiesConfigurationand initializes it with the given path to the file to be loaded.FileBasedConfigurationBuilder<PropertiesConfiguration>propertiesBuilder(URL url)Creates a builder for aPropertiesConfigurationand initializes it with the given URL to be loaded.FileBasedConfigurationBuilder<PropertiesConfiguration>propertiesBuilder(PropertiesBuilderParameters parameters)Creates a builder for aPropertiesConfigurationand initializes it with the given parameters to be loaded.XMLConfigurationxml(File file)Creates aXMLConfigurationinstance from the content of the given file.XMLConfigurationxml(String path)Creates aXMLConfigurationinstance from the content of the file identified by the given path.XMLConfigurationxml(URL url)Creates aXMLConfigurationinstance from the content of the given URL.FileBasedConfigurationBuilder<XMLConfiguration>xmlBuilder(File file)Creates a builder for aXMLConfigurationand initializes it with the given file to be loaded.FileBasedConfigurationBuilder<XMLConfiguration>xmlBuilder(String path)Creates a builder for aXMLConfigurationand initializes it with the given path to the file to be loaded.FileBasedConfigurationBuilder<XMLConfiguration>xmlBuilder(URL url)Creates a builder for aXMLConfigurationand initializes it with the given URL to be loaded.
-
-
-
Constructor Detail
-
Configurations
public Configurations()
Creates a newConfigurationsinstance with default settings.
-
Configurations
public Configurations(Parameters params)
Creates a new instance ofConfigurationsand initializes it with the specifiedParametersobject.- Parameters:
params- theParameters(may be null, then a default instance is created)
-
-
Method Detail
-
getParameters
public Parameters getParameters()
Gets theParametersinstance associated with this object.- Returns:
- the associated
Parametersobject
-
fileBasedBuilder
public <T extends FileBasedConfiguration> FileBasedConfigurationBuilder<T> fileBasedBuilder(Class<T> configClass, File file)
Creates aFileBasedConfigurationBuilderfor the specified configuration class and initializes it with the file to be loaded.- Type Parameters:
T- the type of the configuration to be constructed- Parameters:
configClass- the configuration classfile- the file to be loaded- Returns:
- the new
FileBasedConfigurationBuilder
-
fileBasedBuilder
public <T extends FileBasedConfiguration> FileBasedConfigurationBuilder<T> fileBasedBuilder(Class<T> configClass, URL url)
Creates aFileBasedConfigurationBuilderfor the specified configuration class and initializes it with the URL to the file to be loaded.- Type Parameters:
T- the type of the configuration to be constructed- Parameters:
configClass- the configuration classurl- the URL to be loaded- Returns:
- the new
FileBasedConfigurationBuilder
-
fileBasedBuilder
public <T extends FileBasedConfiguration> FileBasedConfigurationBuilder<T> fileBasedBuilder(Class<T> configClass, String path)
Creates aFileBasedConfigurationBuilderfor the specified configuration class and initializes it with the path to the file to be loaded.- Type Parameters:
T- the type of the configuration to be constructed- Parameters:
configClass- the configuration classpath- the path to the file to be loaded- Returns:
- the new
FileBasedConfigurationBuilder
-
fileBased
public <T extends FileBasedConfiguration> T fileBased(Class<T> configClass, File file) throws ConfigurationException
Creates an instance of the specified file-based configuration class from the content of the given file. This is a convenience method which can be used if no builder is needed for managing the configuration object. (Although, behind the scenes a builder is created).- Type Parameters:
T- the type of the configuration to be constructed- Parameters:
configClass- the configuration classfile- the file to be loaded- Returns:
- a
FileBasedConfigurationobject initialized from this file - Throws:
ConfigurationException- if an error occurred when loading the configuration
-
fileBased
public <T extends FileBasedConfiguration> T fileBased(Class<T> configClass, URL url) throws ConfigurationException
Creates an instance of the specified file-based configuration class from the content of the given URL. This is a convenience method which can be used if no builder is needed for managing the configuration object. (Although, behind the scenes a builder is created).- Type Parameters:
T- the type of the configuration to be constructed- Parameters:
configClass- the configuration classurl- the URL to be loaded- Returns:
- a
FileBasedConfigurationobject initialized from this file - Throws:
ConfigurationException- if an error occurred when loading the configuration
-
fileBased
public <T extends FileBasedConfiguration> T fileBased(Class<T> configClass, String path) throws ConfigurationException
Creates an instance of the specified file-based configuration class from the content of the file identified by the given path. This is a convenience method which can be used if no builder is needed for managing the configuration object. (Although, behind the scenes a builder is created).- Type Parameters:
T- the type of the configuration to be constructed- Parameters:
configClass- the configuration classpath- the path to the file to be loaded- Returns:
- a
FileBasedConfigurationobject initialized from this file - Throws:
ConfigurationException- if an error occurred when loading the configuration
-
propertiesBuilder
public FileBasedConfigurationBuilder<PropertiesConfiguration> propertiesBuilder()
Creates a builder for aPropertiesConfiguration.- Returns:
- the newly created
FileBasedConfigurationBuilder - Since:
- 2.6
-
propertiesBuilder
public FileBasedConfigurationBuilder<PropertiesConfiguration> propertiesBuilder(File file)
Creates a builder for aPropertiesConfigurationand initializes it with the given file to be loaded.- Parameters:
file- the file to be loaded- Returns:
- the newly created
FileBasedConfigurationBuilder
-
propertiesBuilder
public FileBasedConfigurationBuilder<PropertiesConfiguration> propertiesBuilder(PropertiesBuilderParameters parameters)
Creates a builder for aPropertiesConfigurationand initializes it with the given parameters to be loaded.- Parameters:
parameters- the parameters to be loaded- Returns:
- the newly created
FileBasedConfigurationBuilder - Since:
- 2.6
-
propertiesBuilder
public FileBasedConfigurationBuilder<PropertiesConfiguration> propertiesBuilder(URL url)
Creates a builder for aPropertiesConfigurationand initializes it with the given URL to be loaded.- Parameters:
url- the URL to be loaded- Returns:
- the newly created
FileBasedConfigurationBuilder
-
propertiesBuilder
public FileBasedConfigurationBuilder<PropertiesConfiguration> propertiesBuilder(String path)
Creates a builder for aPropertiesConfigurationand initializes it with the given path to the file to be loaded.- Parameters:
path- the path to the file to be loaded- Returns:
- the newly created
FileBasedConfigurationBuilder
-
properties
public PropertiesConfiguration properties(File file) throws ConfigurationException
Creates aPropertiesConfigurationinstance from the content of the given file. This is a convenience method which can be used if no builder is needed for managing the configuration object. (Although, behind the scenes a builder is created).- Parameters:
file- the file to be loaded- Returns:
- a
PropertiesConfigurationobject initialized from this file - Throws:
ConfigurationException- if an error occurred when loading the configuration
-
properties
public PropertiesConfiguration properties(URL url) throws ConfigurationException
Creates aPropertiesConfigurationinstance from the content of the given URL. This is a convenience method which can be used if no builder is needed for managing the configuration object. (Although, behind the scenes a builder is created).- Parameters:
url- the URL to be loaded- Returns:
- a
PropertiesConfigurationobject initialized from this URL - Throws:
ConfigurationException- if an error occurred when loading the configuration
-
properties
public PropertiesConfiguration properties(String path) throws ConfigurationException
Creates aPropertiesConfigurationinstance from the content of the file identified by the given path. This is a convenience method which can be used if no builder is needed for managing the configuration object. (Although, behind the scenes a builder is created).- Parameters:
path- the path to the file to be loaded- Returns:
- a
PropertiesConfigurationobject initialized from this path - Throws:
ConfigurationException- if an error occurred when loading the configuration
-
xmlBuilder
public FileBasedConfigurationBuilder<XMLConfiguration> xmlBuilder(File file)
Creates a builder for aXMLConfigurationand initializes it with the given file to be loaded.- Parameters:
file- the file to be loaded- Returns:
- the newly created
FileBasedConfigurationBuilder
-
xmlBuilder
public FileBasedConfigurationBuilder<XMLConfiguration> xmlBuilder(URL url)
Creates a builder for aXMLConfigurationand initializes it with the given URL to be loaded.- Parameters:
url- the URL to be loaded- Returns:
- the newly created
FileBasedConfigurationBuilder
-
xmlBuilder
public FileBasedConfigurationBuilder<XMLConfiguration> xmlBuilder(String path)
Creates a builder for aXMLConfigurationand initializes it with the given path to the file to be loaded.- Parameters:
path- the path to the file to be loaded- Returns:
- the newly created
FileBasedConfigurationBuilder
-
xml
public XMLConfiguration xml(File file) throws ConfigurationException
Creates aXMLConfigurationinstance from the content of the given file. This is a convenience method which can be used if no builder is needed for managing the configuration object. (Although, behind the scenes a builder is created).- Parameters:
file- the file to be loaded- Returns:
- a
XMLConfigurationobject initialized from this file - Throws:
ConfigurationException- if an error occurred when loading the configuration
-
xml
public XMLConfiguration xml(URL url) throws ConfigurationException
Creates aXMLConfigurationinstance from the content of the given URL. This is a convenience method which can be used if no builder is needed for managing the configuration object. (Although, behind the scenes a builder is created).- Parameters:
url- the URL to be loaded- Returns:
- a
XMLConfigurationobject initialized from this file - Throws:
ConfigurationException- if an error occurred when loading the configuration
-
xml
public XMLConfiguration xml(String path) throws ConfigurationException
Creates aXMLConfigurationinstance from the content of the file identified by the given path. This is a convenience method which can be used if no builder is needed for managing the configuration object. (Although, behind the scenes a builder is created).- Parameters:
path- the path to the file to be loaded- Returns:
- a
XMLConfigurationobject initialized from this file - Throws:
ConfigurationException- if an error occurred when loading the configuration
-
iniBuilder
public FileBasedConfigurationBuilder<INIConfiguration> iniBuilder(File file)
Creates a builder for aINIConfigurationand initializes it with the given file to be loaded.- Parameters:
file- the file to be loaded- Returns:
- the newly created
FileBasedConfigurationBuilder
-
iniBuilder
public FileBasedConfigurationBuilder<INIConfiguration> iniBuilder(URL url)
Creates a builder for aINIConfigurationand initializes it with the given URL to be loaded.- Parameters:
url- the URL to be loaded- Returns:
- the newly created
FileBasedConfigurationBuilder
-
iniBuilder
public FileBasedConfigurationBuilder<INIConfiguration> iniBuilder(String path)
Creates a builder for aINIConfigurationand initializes it with the file file identified by the given path.- Parameters:
path- the path to the file to be loaded- Returns:
- the newly created
FileBasedConfigurationBuilder
-
ini
public INIConfiguration ini(File file) throws ConfigurationException
Creates aINIConfigurationinstance from the content of the given file. This is a convenience method which can be used if no builder is needed for managing the configuration object. (Although, behind the scenes a builder is created).- Parameters:
file- the file to be loaded- Returns:
- a
INIConfigurationobject initialized from this file - Throws:
ConfigurationException- if an error occurred when loading the configuration
-
ini
public INIConfiguration ini(URL url) throws ConfigurationException
Creates aINIConfigurationinstance from the content of the given URL. This is a convenience method which can be used if no builder is needed for managing the configuration object. (Although, behind the scenes a builder is created).- Parameters:
url- the URL to be loaded- Returns:
- a
INIConfigurationobject initialized from this file - Throws:
ConfigurationException- if an error occurred when loading the configuration
-
ini
public INIConfiguration ini(String path) throws ConfigurationException
Creates aINIConfigurationinstance from the content of the file identified by the given path. This is a convenience method which can be used if no builder is needed for managing the configuration object. (Although, behind the scenes a builder is created).- Parameters:
path- the path to the file to be loaded- Returns:
- a
INIConfigurationobject initialized from this file - Throws:
ConfigurationException- if an error occurred when loading the configuration
-
combinedBuilder
public CombinedConfigurationBuilder combinedBuilder(File file)
Creates a builder for aCombinedConfigurationand initializes it with the given file to be loaded.- Parameters:
file- the file to be loaded- Returns:
- the newly created
CombinedConfigurationBuilder
-
combinedBuilder
public CombinedConfigurationBuilder combinedBuilder(URL url)
Creates a builder for aCombinedConfigurationand initializes it with the given URL to be loaded.- Parameters:
url- the URL to be loaded- Returns:
- the newly created
CombinedConfigurationBuilder
-
combinedBuilder
public CombinedConfigurationBuilder combinedBuilder(String path)
Creates a builder for aCombinedConfigurationand initializes it with the given path to the file to be loaded.- Parameters:
path- the path to the file to be loaded- Returns:
- the newly created
CombinedConfigurationBuilder
-
combined
public CombinedConfiguration combined(File file) throws ConfigurationException
Creates aCombinedConfigurationinstance from the content of the given file. This is a convenience method which can be used if no builder is needed for managing the configuration object. (Although, behind the scenes a builder is created).- Parameters:
file- the file to be loaded- Returns:
- a
CombinedConfigurationobject initialized from this file - Throws:
ConfigurationException- if an error occurred when loading the configuration
-
combined
public CombinedConfiguration combined(URL url) throws ConfigurationException
Creates aCombinedConfigurationinstance from the content of the given URL. This is a convenience method which can be used if no builder is needed for managing the configuration object. (Although, behind the scenes a builder is created).- Parameters:
url- the URL to be loaded- Returns:
- a
CombinedConfigurationobject initialized from this URL - Throws:
ConfigurationException- if an error occurred when loading the configuration
-
combined
public CombinedConfiguration combined(String path) throws ConfigurationException
Creates aCombinedConfigurationinstance from the content of the file identified by the given path. This is a convenience method which can be used if no builder is needed for managing the configuration object. (Although, behind the scenes a builder is created).- Parameters:
path- the path to the file to be loaded- Returns:
- a
CombinedConfigurationobject initialized from this URL - Throws:
ConfigurationException- if an error occurred when loading the configuration
-
-