public final class Parameters extends Object
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.
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 . |
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.
|
public Parameters()
Parameters
. A new, uninitialized DefaultParametersManager
is created.public Parameters(DefaultParametersManager manager)
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.manager
- the DefaultParametersHandler
(may be null, then a new default instance is created)public DefaultParametersManager getDefaultParametersManager()
DefaultParametersManager
associated with this object.DefaultParametersManager
public <T> void registerDefaultsHandler(Class<T> paramsClass, DefaultParametersHandler<? super T> handler)
DefaultParametersHandler
object for the given parameters class. This is a convenience
method which just delegates to the associated DefaultParametersManager
.T
- the type of the parameters supported by this handlerparamsClass
- the parameters class supported by this handler (must not be null)handler
- the DefaultParametersHandler
to be registered (must not be null)IllegalArgumentException
- if a required parameter is missingDefaultParametersManager
public <T> void registerDefaultsHandler(Class<T> paramsClass, DefaultParametersHandler<? super T> handler, Class<?> startClass)
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
.T
- the type of the parameters supported by this handlerparamsClass
- 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
appliedIllegalArgumentException
- if a required parameter is missingpublic BasicBuilderParameters basic()
public FileBasedBuilderParameters fileBased()
public CombinedBuilderParameters combined()
public JndiBuilderParameters jndi()
public HierarchicalBuilderParameters hierarchical()
public XMLBuilderParameters xml()
public PropertiesBuilderParameters properties()
public MultiFileBuilderParameters multiFile()
public DatabaseBuilderParameters database()
public INIBuilderParameters ini()
Copyright © 2001–2022 The Apache Software Foundation. All rights reserved.