java.lang.Object
org.apache.commons.configuration2.builder.fluent.Parameters

public final class Parameters extends Object
A convenience class for creating parameter objects for initializing configuration builder objects.

For setting initialization properties of new configuration objects, a number of specialized parameter classes exists. These classes use inheritance to organize the properties they support in a logic way. For instance, parameters for file-based configurations also support the basic properties common to all configuration implementations, parameters for XML configurations also include file-based and basic properties, etc.

When constructing a configuration builder, an easy-to-use fluent API is desired to define specific properties for the configuration to be created. However, the inheritance structure of the parameter classes makes it surprisingly difficult to provide such an API. This class comes to rescue by defining a set of methods for the creation of interface-based parameter objects offering a truly fluent API. The methods provided can be called directly when setting up a configuration builder as shown in the following example code fragment:

 Parameters params = new Parameters();
 configurationBuilder.configure(params.fileBased()
   .setThrowExceptionOnMissing(true)
   .setEncoding("UTF-8")
   .setListDelimiter('#')
   .setFileName("test.xml"));
 

Using this class it is not only possible to create new parameters objects but also to initialize the newly created objects with default values. This is via the associated DefaultParametersManager object. Such an object can be passed to the constructor, or a new (uninitialized) instance is created. There are convenience methods for interacting with the associated DefaultParametersManager, namely to register or remove DefaultParametersHandler objects. On all newly created parameters objects the handlers registered at the associated DefaultParametersHandler are automatically applied.

Implementation note: This class is thread-safe.

Since:
2.0
  • Constructor Details

    • Parameters

      public Parameters()
      Creates a new instance of Parameters. A new, uninitialized DefaultParametersManager is created.
    • Parameters

      Creates a new instance of Parameters and initializes it with the given DefaultParametersManager. Because DefaultParametersManager is thread-safe, it makes sense to share a single instance between multiple Parameters objects; that way the same initialization is performed on newly created parameters objects.
      Parameters:
      manager - the DefaultParametersHandler (may be null, then a new default instance is created)
  • Method Details

    • basic

      Creates a new instance of a parameters object for basic configuration properties.
      Returns:
      the new parameters object
    • combined

      Creates a new instance of a parameters object for combined configuration builder properties.
      Returns:
      the new parameters object
    • database

      Creates a new instance of a parameters object for database configurations.
      Returns:
      the new parameters object
    • fileBased

      Creates a new instance of a parameters object for file-based configuration properties.
      Returns:
      the new parameters object
    • getDefaultParametersManager

      Gets the DefaultParametersManager associated with this object.
      Returns:
      the DefaultParametersManager
    • hierarchical

      Creates a new instance of a parameters object for hierarchical configurations.
      Returns:
      the new parameters object
    • ini

      Creates a new instance of a parameters object for INI configurations.
      Returns:
      the new parameters object
    • jndi

      Creates a new instance of a parameters object for JNDI configurations.
      Returns:
      the new parameters object
    • multiFile

      Creates a new instance of a parameters object for a builder for multiple file-based configurations.
      Returns:
      the new parameters object
    • properties

      Creates a new instance of a parameters object for properties configurations.
      Returns:
      the new parameters object
    • registerDefaultsHandler

      public <T> void registerDefaultsHandler(Class<T> paramsClass, DefaultParametersHandler<? super T> handler)
      Registers the specified DefaultParametersHandler object for the given parameters class. This is a convenience method which just delegates to the associated DefaultParametersManager.
      Type Parameters:
      T - the type of the parameters supported by this handler
      Parameters:
      paramsClass - the parameters class supported by this handler (must not be null)
      handler - the DefaultParametersHandler to be registered (must not be null)
      Throws:
      IllegalArgumentException - if a required parameter is missing
      See Also:
    • registerDefaultsHandler

      public <T> void registerDefaultsHandler(Class<T> paramsClass, DefaultParametersHandler<? super T> handler, Class<?> startClass)
      Registers the specified DefaultParametersHandler object for the given parameters class and start class in the inheritance hierarchy. This is a convenience method which just delegates to the associated DefaultParametersManager.
      Type Parameters:
      T - the type of the parameters supported by this handler
      Parameters:
      paramsClass - the parameters class supported by this handler (must not be null)
      handler - the DefaultParametersHandler to be registered (must not be null)
      startClass - an optional start class in the hierarchy of parameter objects for which this handler should be applied
      Throws:
      IllegalArgumentException - if a required parameter is missing
    • xml

      Creates a new instance of a parameters object for XML configurations.
      Returns:
      the new parameters object