Class Parameters
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
ConstructorDescriptionCreates a new instance ofParameters
.Parameters
(DefaultParametersManager manager) Creates a new instance ofParameters
and initializes it with the givenDefaultParametersManager
. -
Method Summary
Modifier and TypeMethodDescriptionbasic()
Creates a new instance of a parameters object for basic configuration properties.combined()
Creates a new instance of a parameters object for combined configuration builder properties.database()
Creates a new instance of a parameters object for database configurations.Creates a new instance of a parameters object for file-based configuration properties.Gets theDefaultParametersManager
associated with this object.Creates a new instance of a parameters object for hierarchical configurations.ini()
Creates a new instance of a parameters object for INI configurations.jndi()
Creates a new instance of a parameters object for JNDI configurations.Creates a new instance of a parameters object for a builder for multiple file-based configurations.Creates a new instance of a parameters object for properties configurations.<T> void
registerDefaultsHandler
(Class<T> paramsClass, DefaultParametersHandler<? super T> handler) Registers the specifiedDefaultParametersHandler
object for the given parameters class.<T> void
registerDefaultsHandler
(Class<T> paramsClass, DefaultParametersHandler<? super T> handler, Class<?> startClass) Registers the specifiedDefaultParametersHandler
object for the given parameters class and start class in the inheritance hierarchy.xml()
Creates a new instance of a parameters object for XML configurations.
-
Constructor Details
-
Parameters
public Parameters()Creates a new instance ofParameters
. A new, uninitializedDefaultParametersManager
is created. -
Parameters
Creates a new instance ofParameters
and initializes it with the givenDefaultParametersManager
. BecauseDefaultParametersManager
is thread-safe, it makes sense to share a single instance between multipleParameters
objects; that way the same initialization is performed on newly created parameters objects.- Parameters:
manager
- theDefaultParametersHandler
(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 theDefaultParametersManager
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 specifiedDefaultParametersHandler
object for the given parameters class. This is a convenience method which just delegates to the associatedDefaultParametersManager
.- 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
- theDefaultParametersHandler
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 specifiedDefaultParametersHandler
object for the given parameters class and start class in the inheritance hierarchy. This is a convenience method which just delegates to the associatedDefaultParametersManager
.- 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
- theDefaultParametersHandler
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
-