org.apache.commons.configuration2.builder.fluent

## Class Parameters

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

    Constructors
    Constructor and Description
    `Parameters()` Creates a new instance of `Parameters`.
    `Parameters(DefaultParametersManager manager)` Creates a new instance of `Parameters` and initializes it with the given `DefaultParametersManager`.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `BasicBuilderParameters` | `basic()` Creates a new instance of a parameters object for basic configuration properties.
    `CombinedBuilderParameters` | `combined()` Creates a new instance of a parameters object for combined configuration builder properties.
    `DatabaseBuilderParameters` | `database()` Creates a new instance of a parameters object for database configurations.
    `FileBasedBuilderParameters` | `fileBased()` Creates a new instance of a parameters object for file-based configuration properties.
    `DefaultParametersManager` | `getDefaultParametersManager()` Returns the `DefaultParametersManager` associated with this object.
    `HierarchicalBuilderParameters` | `hierarchical()` Creates a new instance of a parameters object for hierarchical configurations.
    `INIBuilderParameters` | `ini()` Creates a new instance of a parameters object for INI configurations.
    `JndiBuilderParameters` | `jndi()` Creates a new instance of a parameters object for JNDI configurations.
    `MultiFileBuilderParameters` | `multiFile()` Creates a new instance of a parameters object for a builder for multiple file-based configurations.
    `PropertiesBuilderParameters` | `properties()` Creates a new instance of a parameters object for properties configurations.
    `<T> void` | `registerDefaultsHandler(Class<T> paramsClass, DefaultParametersHandler<? super T> handler)` Registers the specified `DefaultParametersHandler` object for the given parameters class.
    `<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.
    `XMLBuilderParameters` | `xml()` Creates a new instance of a parameters object for XML configurations.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Parameters

          public Parameters()

      Creates a new instance of `Parameters`. A new, uninitialized `DefaultParametersManager` is created.

    - #### Parameters

          public Parameters(DefaultParametersManager manager)

      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 Detail

    - #### getDefaultParametersManager

          public DefaultParametersManager getDefaultParametersManager()

      Returns the `DefaultParametersManager` associated with this object.
      Returns:
        the `DefaultParametersManager`

    - #### 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:
        `DefaultParametersManager`

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

    - #### basic

          public BasicBuilderParameters basic()

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

    - #### fileBased

          public FileBasedBuilderParameters fileBased()

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

    - #### combined

          public CombinedBuilderParameters combined()

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

    - #### jndi

          public JndiBuilderParameters jndi()

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

    - #### hierarchical

          public HierarchicalBuilderParameters hierarchical()

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

    - #### xml

          public XMLBuilderParameters xml()

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

    - #### properties

          public PropertiesBuilderParameters properties()

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

    - #### multiFile

          public MultiFileBuilderParameters multiFile()

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

    - #### database

          public DatabaseBuilderParameters database()

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

    - #### ini

          public INIBuilderParameters ini()

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

Copyright © 2001–2019 The Apache Software Foundation. All rights reserved.