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 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.

Since:
2.0
See Also:
  • Constructor Details

    • Configurations

      public Configurations()
      Creates a new Configurations instance with default settings.
    • Configurations

      public Configurations(Parameters params)
      Creates a new instance of Configurations and initializes it with the specified Parameters object.
      Parameters:
      params - the Parameters (may be null, then a default instance is created)
  • Method Details

    • combined

      Creates a 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).
      Parameters:
      file - the file to be loaded
      Returns:
      a CombinedConfiguration object initialized from this file
      Throws:
      ConfigurationException - if an error occurred when loading the configuration
    • combined

      Creates a 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).
      Parameters:
      path - the path to the file to be loaded
      Returns:
      a CombinedConfiguration object initialized from this URL
      Throws:
      ConfigurationException - if an error occurred when loading the configuration
    • combined

      Creates a 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).
      Parameters:
      url - the URL to be loaded
      Returns:
      a CombinedConfiguration object initialized from this URL
      Throws:
      ConfigurationException - if an error occurred when loading the configuration
    • combinedBuilder

      Creates a builder for a CombinedConfiguration and initializes it with the given file to be loaded.
      Parameters:
      file - the file to be loaded
      Returns:
      the newly created CombinedConfigurationBuilder
    • combinedBuilder

      Creates a builder for a CombinedConfiguration and 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
    • combinedBuilder

      Creates a builder for a CombinedConfiguration and initializes it with the given URL to be loaded.
      Parameters:
      url - the URL to be loaded
      Returns:
      the newly created CombinedConfigurationBuilder
    • 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 class
      file - the file to be loaded
      Returns:
      a FileBasedConfiguration object 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 class
      path - the path to the file to be loaded
      Returns:
      a FileBasedConfiguration object 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 class
      url - the URL to be loaded
      Returns:
      a FileBasedConfiguration object initialized from this file
      Throws:
      ConfigurationException - if an error occurred when loading the configuration
    • fileBasedBuilder

      public <T extends FileBasedConfiguration> FileBasedConfigurationBuilder<T> fileBasedBuilder(Class<T> configClass, File file)
      Creates a FileBasedConfigurationBuilder for 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 class
      file - the file to be loaded
      Returns:
      the new FileBasedConfigurationBuilder
    • fileBasedBuilder

      public <T extends FileBasedConfiguration> FileBasedConfigurationBuilder<T> fileBasedBuilder(Class<T> configClass, String path)
      Creates a FileBasedConfigurationBuilder for 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 class
      path - the path to the file to be loaded
      Returns:
      the new FileBasedConfigurationBuilder
    • fileBasedBuilder

      public <T extends FileBasedConfiguration> FileBasedConfigurationBuilder<T> fileBasedBuilder(Class<T> configClass, URL url)
      Creates a FileBasedConfigurationBuilder for 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 class
      url - the URL to be loaded
      Returns:
      the new FileBasedConfigurationBuilder
    • getParameters

      Gets the Parameters instance associated with this object.
      Returns:
      the associated Parameters object
    • ini

      Creates a 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).
      Parameters:
      file - the file to be loaded
      Returns:
      a INIConfiguration object initialized from this file
      Throws:
      ConfigurationException - if an error occurred when loading the configuration
    • ini

      Creates a 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).
      Parameters:
      path - the path to the file to be loaded
      Returns:
      a INIConfiguration object initialized from this file
      Throws:
      ConfigurationException - if an error occurred when loading the configuration
    • ini

      Creates a 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).
      Parameters:
      url - the URL to be loaded
      Returns:
      a INIConfiguration object initialized from this file
      Throws:
      ConfigurationException - if an error occurred when loading the configuration
    • iniBuilder

      Creates a builder for a INIConfiguration and initializes it with the given file to be loaded.
      Parameters:
      file - the file to be loaded
      Returns:
      the newly created FileBasedConfigurationBuilder
    • iniBuilder

      Creates a builder for a INIConfiguration and 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
    • iniBuilder

      Creates a builder for a INIConfiguration and initializes it with the given URL to be loaded.
      Parameters:
      url - the URL to be loaded
      Returns:
      the newly created FileBasedConfigurationBuilder
    • properties

      Creates a 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).
      Parameters:
      file - the file to be loaded
      Returns:
      a PropertiesConfiguration object initialized from this file
      Throws:
      ConfigurationException - if an error occurred when loading the configuration
    • properties

      Creates a 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).
      Parameters:
      path - the path to the file to be loaded
      Returns:
      a PropertiesConfiguration object initialized from this path
      Throws:
      ConfigurationException - if an error occurred when loading the configuration
    • properties

      Creates a 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).
      Parameters:
      url - the URL to be loaded
      Returns:
      a PropertiesConfiguration object initialized from this URL
      Throws:
      ConfigurationException - if an error occurred when loading the configuration
    • propertiesBuilder

      Creates a builder for a PropertiesConfiguration.
      Returns:
      the newly created FileBasedConfigurationBuilder
      Since:
      2.6
    • propertiesBuilder

      Creates a builder for a PropertiesConfiguration and initializes it with the given file to be loaded.
      Parameters:
      file - the file to be loaded
      Returns:
      the newly created FileBasedConfigurationBuilder
    • propertiesBuilder

      Creates a builder for a PropertiesConfiguration and 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

      Creates a builder for a PropertiesConfiguration and 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
    • propertiesBuilder

      Creates a builder for a PropertiesConfiguration and initializes it with the given URL to be loaded.
      Parameters:
      url - the URL to be loaded
      Returns:
      the newly created FileBasedConfigurationBuilder
    • xml

      Creates a 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).
      Parameters:
      file - the file to be loaded
      Returns:
      a XMLConfiguration object initialized from this file
      Throws:
      ConfigurationException - if an error occurred when loading the configuration
    • xml

      Creates a 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).
      Parameters:
      path - the path to the file to be loaded
      Returns:
      a XMLConfiguration object initialized from this file
      Throws:
      ConfigurationException - if an error occurred when loading the configuration
    • xml

      Creates a 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).
      Parameters:
      url - the URL to be loaded
      Returns:
      a XMLConfiguration object initialized from this file
      Throws:
      ConfigurationException - if an error occurred when loading the configuration
    • xmlBuilder

      Creates a builder for a XMLConfiguration and initializes it with the given file to be loaded.
      Parameters:
      file - the file to be loaded
      Returns:
      the newly created FileBasedConfigurationBuilder
    • xmlBuilder

      Creates a builder for a XMLConfiguration and 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
    • xmlBuilder

      Creates a builder for a XMLConfiguration and initializes it with the given URL to be loaded.
      Parameters:
      url - the URL to be loaded
      Returns:
      the newly created FileBasedConfigurationBuilder