public class Configurations
extends java.lang.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 PropertiesConfiguration
object 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 Configurations the 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 Parameters instance can be passed in. Otherwise, a
default instance is created. In any case, the Parameters instance
associated with a Configurations object can be used to define default
settings for the configurations to be created.
DefaultParametersManager| Constructor | Description |
|---|---|
Configurations() |
Creates a new
Configurations instance with default settings. |
Configurations(Parameters params) |
Creates a new instance of
Configurations and initializes it with
the specified Parameters object. |
| Modifier and Type | Method | Description |
|---|---|---|
CombinedConfiguration |
combined(java.io.File file) |
Creates a
CombinedConfiguration instance from the content of the
given file. |
CombinedConfiguration |
combined(java.lang.String path) |
Creates a
CombinedConfiguration instance from the content of the
file identified by the given path. |
CombinedConfiguration |
combined(java.net.URL url) |
Creates a
CombinedConfiguration instance from the content of the
given URL. |
CombinedConfigurationBuilder |
combinedBuilder(java.io.File file) |
Creates a builder for a
CombinedConfiguration and initializes it
with the given file to be loaded. |
CombinedConfigurationBuilder |
combinedBuilder(java.lang.String path) |
Creates a builder for a
CombinedConfiguration and initializes it
with the given path to the file to be loaded. |
CombinedConfigurationBuilder |
combinedBuilder(java.net.URL url) |
Creates a builder for a
CombinedConfiguration and initializes it
with the given URL to be loaded. |
<T extends FileBasedConfiguration> |
fileBased(java.lang.Class<T> configClass,
java.io.File file) |
Creates an instance of the specified file-based configuration class from
the content of the given file.
|
<T extends FileBasedConfiguration> |
fileBased(java.lang.Class<T> configClass,
java.lang.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> |
fileBased(java.lang.Class<T> configClass,
java.net.URL url) |
Creates an instance of the specified file-based configuration class from
the content of the given URL.
|
<T extends FileBasedConfiguration> |
fileBasedBuilder(java.lang.Class<T> configClass,
java.io.File file) |
Creates a
FileBasedConfigurationBuilder for the specified
configuration class and initializes it with the file to be loaded. |
<T extends FileBasedConfiguration> |
fileBasedBuilder(java.lang.Class<T> configClass,
java.lang.String path) |
Creates a
FileBasedConfigurationBuilder for the specified
configuration class and initializes it with the path to the file to be
loaded. |
<T extends FileBasedConfiguration> |
fileBasedBuilder(java.lang.Class<T> configClass,
java.net.URL url) |
Creates a
FileBasedConfigurationBuilder for the specified
configuration class and initializes it with the URL to the file to be
loaded. |
Parameters |
getParameters() |
Returns the
Parameters instance associated with this object. |
INIConfiguration |
ini(java.io.File file) |
Creates a
INIConfiguration instance from the content of the given
file. |
INIConfiguration |
ini(java.lang.String path) |
Creates a
INIConfiguration instance from the content of the file
identified by the given path. |
INIConfiguration |
ini(java.net.URL url) |
Creates a
INIConfiguration instance from the content of the given
URL. |
FileBasedConfigurationBuilder<INIConfiguration> |
iniBuilder(java.io.File file) |
Creates a builder for a
INIConfiguration and initializes it with
the given file to be loaded. |
FileBasedConfigurationBuilder<INIConfiguration> |
iniBuilder(java.lang.String path) |
Creates a builder for a
INIConfiguration and initializes it with
the file file identified by the given path. |
FileBasedConfigurationBuilder<INIConfiguration> |
iniBuilder(java.net.URL url) |
Creates a builder for a
INIConfiguration and initializes it with
the given URL to be loaded. |
PropertiesConfiguration |
properties(java.io.File file) |
Creates a
PropertiesConfiguration instance from the content of
the given file. |
PropertiesConfiguration |
properties(java.lang.String path) |
Creates a
PropertiesConfiguration instance from the content of
the file identified by the given path. |
PropertiesConfiguration |
properties(java.net.URL url) |
Creates a
PropertiesConfiguration instance from the content of
the given URL. |
FileBasedConfigurationBuilder<PropertiesConfiguration> |
propertiesBuilder(java.io.File file) |
Creates a builder for a
PropertiesConfiguration and initializes
it with the given file to be loaded. |
FileBasedConfigurationBuilder<PropertiesConfiguration> |
propertiesBuilder(java.lang.String path) |
Creates a builder for a
PropertiesConfiguration and initializes
it with the given path to the file to be loaded. |
FileBasedConfigurationBuilder<PropertiesConfiguration> |
propertiesBuilder(java.net.URL url) |
Creates a builder for a
PropertiesConfiguration and initializes
it with the given URL to be loaded. |
XMLConfiguration |
xml(java.io.File file) |
Creates a
XMLConfiguration instance from the content of the given
file. |
XMLConfiguration |
xml(java.lang.String path) |
Creates a
XMLConfiguration instance from the content of the file
identified by the given path. |
XMLConfiguration |
xml(java.net.URL url) |
Creates a
XMLConfiguration instance from the content of the given
URL. |
FileBasedConfigurationBuilder<XMLConfiguration> |
xmlBuilder(java.io.File file) |
Creates a builder for a
XMLConfiguration and initializes it with
the given file to be loaded. |
FileBasedConfigurationBuilder<XMLConfiguration> |
xmlBuilder(java.lang.String path) |
Creates a builder for a
XMLConfiguration and initializes it with
the given path to the file to be loaded. |
FileBasedConfigurationBuilder<XMLConfiguration> |
xmlBuilder(java.net.URL url) |
Creates a builder for a
XMLConfiguration and initializes it with
the given URL to be loaded. |
public Configurations()
Configurations instance with default settings.public Configurations(Parameters params)
Configurations and initializes it with
the specified Parameters object.params - the Parameters (may be null, then a default
instance is created)public Parameters getParameters()
Parameters instance associated with this object.Parameters objectpublic <T extends FileBasedConfiguration> FileBasedConfigurationBuilder<T> fileBasedBuilder(java.lang.Class<T> configClass, java.io.File file)
FileBasedConfigurationBuilder for the specified
configuration class and initializes it with the file to be loaded.T - the type of the configuration to be constructedconfigClass - the configuration classfile - the file to be loadedFileBasedConfigurationBuilderpublic <T extends FileBasedConfiguration> FileBasedConfigurationBuilder<T> fileBasedBuilder(java.lang.Class<T> configClass, java.net.URL url)
FileBasedConfigurationBuilder for the specified
configuration class and initializes it with the URL to the file to be
loaded.T - the type of the configuration to be constructedconfigClass - the configuration classurl - the URL to be loadedFileBasedConfigurationBuilderpublic <T extends FileBasedConfiguration> FileBasedConfigurationBuilder<T> fileBasedBuilder(java.lang.Class<T> configClass, java.lang.String path)
FileBasedConfigurationBuilder for the specified
configuration class and initializes it with the path to the file to be
loaded.T - the type of the configuration to be constructedconfigClass - the configuration classpath - the path to the file to be loadedFileBasedConfigurationBuilderpublic <T extends FileBasedConfiguration> T fileBased(java.lang.Class<T> configClass, java.io.File file) throws ConfigurationException
T - the type of the configuration to be constructedconfigClass - the configuration classfile - the file to be loadedFileBasedConfiguration object initialized from this
fileConfigurationException - if an error occurred when loading the
configurationpublic <T extends FileBasedConfiguration> T fileBased(java.lang.Class<T> configClass, java.net.URL url) throws ConfigurationException
T - the type of the configuration to be constructedconfigClass - the configuration classurl - the URL to be loadedFileBasedConfiguration object initialized from this
fileConfigurationException - if an error occurred when loading the
configurationpublic <T extends FileBasedConfiguration> T fileBased(java.lang.Class<T> configClass, java.lang.String path) throws ConfigurationException
T - the type of the configuration to be constructedconfigClass - the configuration classpath - the path to the file to be loadedFileBasedConfiguration object initialized from this
fileConfigurationException - if an error occurred when loading the
configurationpublic FileBasedConfigurationBuilder<PropertiesConfiguration> propertiesBuilder(java.io.File file)
PropertiesConfiguration and initializes
it with the given file to be loaded.file - the file to be loadedFileBasedConfigurationBuilderpublic FileBasedConfigurationBuilder<PropertiesConfiguration> propertiesBuilder(java.net.URL url)
PropertiesConfiguration and initializes
it with the given URL to be loaded.url - the URL to be loadedFileBasedConfigurationBuilderpublic FileBasedConfigurationBuilder<PropertiesConfiguration> propertiesBuilder(java.lang.String path)
PropertiesConfiguration and initializes
it with the given path to the file to be loaded.path - the path to the file to be loadedFileBasedConfigurationBuilderpublic PropertiesConfiguration properties(java.io.File file) throws ConfigurationException
PropertiesConfiguration instance 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).file - the file to be loadedPropertiesConfiguration object initialized from this
fileConfigurationException - if an error occurred when loading the
configurationpublic PropertiesConfiguration properties(java.net.URL url) throws ConfigurationException
PropertiesConfiguration instance 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).url - the URL to be loadedPropertiesConfiguration object initialized from this
URLConfigurationException - if an error occurred when loading the
configurationpublic PropertiesConfiguration properties(java.lang.String path) throws ConfigurationException
PropertiesConfiguration instance 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).path - the path to the file to be loadedPropertiesConfiguration object initialized from this
pathConfigurationException - if an error occurred when loading the
configurationpublic FileBasedConfigurationBuilder<XMLConfiguration> xmlBuilder(java.io.File file)
XMLConfiguration and initializes it with
the given file to be loaded.file - the file to be loadedFileBasedConfigurationBuilderpublic FileBasedConfigurationBuilder<XMLConfiguration> xmlBuilder(java.net.URL url)
XMLConfiguration and initializes it with
the given URL to be loaded.url - the URL to be loadedFileBasedConfigurationBuilderpublic FileBasedConfigurationBuilder<XMLConfiguration> xmlBuilder(java.lang.String path)
XMLConfiguration and initializes it with
the given path to the file to be loaded.path - the path to the file to be loadedFileBasedConfigurationBuilderpublic XMLConfiguration xml(java.io.File file) throws ConfigurationException
XMLConfiguration instance 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).file - the file to be loadedXMLConfiguration object initialized from this fileConfigurationException - if an error occurred when loading the
configurationpublic XMLConfiguration xml(java.net.URL url) throws ConfigurationException
XMLConfiguration instance 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).url - the URL to be loadedXMLConfiguration object initialized from this fileConfigurationException - if an error occurred when loading the
configurationpublic XMLConfiguration xml(java.lang.String path) throws ConfigurationException
XMLConfiguration instance 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).path - the path to the file to be loadedXMLConfiguration object initialized from this fileConfigurationException - if an error occurred when loading the
configurationpublic FileBasedConfigurationBuilder<INIConfiguration> iniBuilder(java.io.File file)
INIConfiguration and initializes it with
the given file to be loaded.file - the file to be loadedFileBasedConfigurationBuilderpublic FileBasedConfigurationBuilder<INIConfiguration> iniBuilder(java.net.URL url)
INIConfiguration and initializes it with
the given URL to be loaded.url - the URL to be loadedFileBasedConfigurationBuilderpublic FileBasedConfigurationBuilder<INIConfiguration> iniBuilder(java.lang.String path)
INIConfiguration and initializes it with
the file file identified by the given path.path - the path to the file to be loadedFileBasedConfigurationBuilderpublic INIConfiguration ini(java.io.File file) throws ConfigurationException
INIConfiguration instance 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).file - the file to be loadedINIConfiguration object initialized from this fileConfigurationException - if an error occurred when loading the
configurationpublic INIConfiguration ini(java.net.URL url) throws ConfigurationException
INIConfiguration instance 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).url - the URL to be loadedINIConfiguration object initialized from this fileConfigurationException - if an error occurred when loading the
configurationpublic INIConfiguration ini(java.lang.String path) throws ConfigurationException
INIConfiguration instance 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).path - the path to the file to be loadedINIConfiguration object initialized from this fileConfigurationException - if an error occurred when loading the
configurationpublic CombinedConfigurationBuilder combinedBuilder(java.io.File file)
CombinedConfiguration and initializes it
with the given file to be loaded.file - the file to be loadedCombinedConfigurationBuilderpublic CombinedConfigurationBuilder combinedBuilder(java.net.URL url)
CombinedConfiguration and initializes it
with the given URL to be loaded.url - the URL to be loadedCombinedConfigurationBuilderpublic CombinedConfigurationBuilder combinedBuilder(java.lang.String path)
CombinedConfiguration and initializes it
with the given path to the file to be loaded.path - the path to the file to be loadedCombinedConfigurationBuilderpublic CombinedConfiguration combined(java.io.File file) throws ConfigurationException
CombinedConfiguration instance 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).file - the file to be loadedCombinedConfiguration object initialized from this fileConfigurationException - if an error occurred when loading the
configurationpublic CombinedConfiguration combined(java.net.URL url) throws ConfigurationException
CombinedConfiguration instance 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).url - the URL to be loadedCombinedConfiguration object initialized from this URLConfigurationException - if an error occurred when loading the
configurationpublic CombinedConfiguration combined(java.lang.String path) throws ConfigurationException
CombinedConfiguration instance 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).path - the path to the file to be loadedCombinedConfiguration object initialized from this URLConfigurationException - if an error occurred when loading the
configurationCopyright © 2001–2018. All rights reserved.