Class BaseConfigurationBuilderProvider
- All Implemented Interfaces:
ConfigurationBuilderProvider
- Direct Known Subclasses:
CombinedConfigurationBuilderProvider
,FileExtensionConfigurationBuilderProvider
,MultiFileConfigurationBuilderProvider
A fully-functional, reflection-based implementation of the ConfigurationBuilderProvider
interface which can
deal with the default tags defining configuration sources.
An instance of this class is initialized with the names of the ConfigurationBuilder
class used by this
provider and the concrete Configuration
class. The ConfigurationBuilder
class must be derived from
BasicConfigurationBuilder
. When asked for the builder object, an instance of the builder class is created and
initialized from the bean declaration associated with the current configuration source.
ConfigurationBuilder
objects are configured using parameter objects. When declaring configuration sources in
XML it should not be necessary to define the single parameter objects. Rather, simple and complex properties are set
in the typical way of a bean declaration (i.e. as attributes of the current XML element or as child elements). This
class creates all supported parameter objects (whose names also must be provided at construction time) and takes care
that their properties are initialized according to the current bean declaration.
The use of reflection to create builder instances allows a generic implementation supporting many concrete builder
classes. Another reason for this approach is that builder classes are only loaded if actually needed. Some
specialized Configuration
implementations require specific external dependencies which should not be
mandatory for the use of CombinedConfigurationBuilder
. Because such classes are lazily loaded, an application
only has to include the dependencies it actually uses.
- Since:
- 2.0
-
Constructor Summary
ConstructorDescriptionBaseConfigurationBuilderProvider
(String bldrCls, String reloadBldrCls, String configCls, Collection<String> paramCls) Creates a new instance ofBaseConfigurationBuilderProvider
and initializes all its properties. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
configureBuilder
(BasicConfigurationBuilder<? extends Configuration> builder, ConfigurationDeclaration decl, Collection<BuilderParameters> params) Configures a newly created builder instance with its initialization parameters.protected BasicConfigurationBuilder<? extends Configuration>
createBuilder
(ConfigurationDeclaration decl, Collection<BuilderParameters> params) Creates a new, uninitialized instance of the builder class managed by this provider.protected Collection<BuilderParameters>
Creates a collection of parameter objects to be used for configuring the builder.protected String
Determines the name of the class to be used for a new builder instance.protected String
Determines the name of the configuration class produced by the builder.Gets the name of the class of the builder created by this provider.ConfigurationBuilder<? extends Configuration>
Gets the builder for the configuration source managed by this provider.Gets the name of the configuration class created by the builder produced by this provider.Gets an unmodifiable collection with the names of parameter classes supported by this provider.Gets the name of the class of the builder created by this provider if the reload flag is set.protected void
Passes all parameter objects to the parentCombinedConfigurationBuilder
so that properties already defined for the parent builder can be added.protected void
Initializes the parameter objects with data stored in the current bean declaration.protected boolean
Determines the allowFailOnInit flag for the newly created builder based on the givenConfigurationDeclaration
.
-
Constructor Details
-
BaseConfigurationBuilderProvider
public BaseConfigurationBuilderProvider(String bldrCls, String reloadBldrCls, String configCls, Collection<String> paramCls) Creates a new instance ofBaseConfigurationBuilderProvider
and initializes all its properties.- Parameters:
bldrCls
- the name of the builder class (must not be null)reloadBldrCls
- the name of a builder class to be used if reloading support is required (null if reloading is not supported)configCls
- the name of the configuration class (must not be null)paramCls
- a collection with the names of parameters classes- Throws:
IllegalArgumentException
- if a required parameter is missing
-
-
Method Details
-
configureBuilder
protected void configureBuilder(BasicConfigurationBuilder<? extends Configuration> builder, ConfigurationDeclaration decl, Collection<BuilderParameters> params) throws Exception Configures a newly created builder instance with its initialization parameters. This method is called after a new instance was created using reflection. This implementation passes the parameter objects to the builder'sconfigure()
method.- Parameters:
builder
- the builder to be initializeddecl
- the currentConfigurationDeclaration
params
- the collection with initialization parameter objects- Throws:
Exception
- if an error occurs
-
createBuilder
protected BasicConfigurationBuilder<? extends Configuration> createBuilder(ConfigurationDeclaration decl, Collection<BuilderParameters> params) throws Exception Creates a new, uninitialized instance of the builder class managed by this provider. This implementation determines the builder class to be used by delegating todetermineBuilderClass()
. It then calls the constructor expecting the configuration class, the map with properties, and theallowFailOnInit flag.- Parameters:
decl
- the currentConfigurationDeclaration
params
- initialization parameters for the new builder object- Returns:
- the newly created builder instance
- Throws:
Exception
- if an error occurs
-
createParameterObjects
Creates a collection of parameter objects to be used for configuring the builder. This method creates instances of the parameter classes passed to the constructor.- Returns:
- a collection with parameter objects for the builder
- Throws:
Exception
- if an error occurs while creating parameter objects via reflection
-
determineBuilderClass
Determines the name of the class to be used for a new builder instance. This implementation selects between the normal and the reloading builder class, based on the passed inConfigurationDeclaration
. If a reloading builder is desired, but this provider has no reloading support, an exception is thrown.- Parameters:
decl
- the currentConfigurationDeclaration
- Returns:
- the name of the builder class
- Throws:
ConfigurationException
- if the builder class cannot be determined
-
determineConfigurationClass
protected String determineConfigurationClass(ConfigurationDeclaration decl, Collection<BuilderParameters> params) throws ConfigurationException Determines the name of the configuration class produced by the builder. This method is called when obtaining the arguments for invoking the constructor of the builder class. This implementation just returns the pre-configured configuration class name. Derived classes may determine this class name dynamically based on the passed in parameters.- Parameters:
decl
- the currentConfigurationDeclaration
params
- the collection with parameter objects- Returns:
- the name of the builder's result configuration class
- Throws:
ConfigurationException
- if an error occurs
-
getBuilderClass
Gets the name of the class of the builder created by this provider.- Returns:
- the builder class
-
getConfigurationBuilder
public ConfigurationBuilder<? extends Configuration> getConfigurationBuilder(ConfigurationDeclaration decl) throws ConfigurationException Gets the builder for the configuration source managed by this provider. This method is called during processing of the combined configuration definition file. This implementation delegates to some protected methods to create a new builder instance using reflection and to configure it with parameter values defined by the passed inBeanDeclaration
.- Specified by:
getConfigurationBuilder
in interfaceConfigurationBuilderProvider
- Parameters:
decl
- the bean declaration with initialization parameters for the configuration builder- Returns:
- the
ConfigurationBuilder
object created by this provider - Throws:
ConfigurationException
- if an error occurs
-
getConfigurationClass
Gets the name of the configuration class created by the builder produced by this provider.- Returns:
- the configuration class
-
getParameterClasses
Gets an unmodifiable collection with the names of parameter classes supported by this provider.- Returns:
- the parameter classes
-
getReloadingBuilderClass
Gets the name of the class of the builder created by this provider if the reload flag is set. If this method returns null, reloading builders are not supported by this provider.- Returns:
- the reloading builder class
-
inheritParentBuilderProperties
protected void inheritParentBuilderProperties(ConfigurationDeclaration decl, Collection<BuilderParameters> params) Passes all parameter objects to the parentCombinedConfigurationBuilder
so that properties already defined for the parent builder can be added. This method is called before the parameter objects are initialized from the definition configuration. This way properties from the parent builder are inherited, but can be overridden for child configurations.- Parameters:
decl
- the currentConfigurationDeclaration
params
- the collection with (uninitialized) parameter objects
-
initializeParameterObjects
protected void initializeParameterObjects(ConfigurationDeclaration decl, Collection<BuilderParameters> params) throws Exception Initializes the parameter objects with data stored in the current bean declaration. This method is called before the newly created builder instance is configured with the parameter objects. It maps attributes of the bean declaration to properties of parameter objects. In addition, it invokes the parentCombinedConfigurationBuilder
so that the parameters object can inherit properties already defined for this builder.- Parameters:
decl
- the currentConfigurationDeclaration
params
- the collection with (uninitialized) parameter objects- Throws:
Exception
- if an error occurs
-
isAllowFailOnInit
Determines the allowFailOnInit flag for the newly created builder based on the givenConfigurationDeclaration
. Some combinations of flags in the declaration say that a configuration source is optional, but an empty instance should be created if its creation fail.- Parameters:
decl
- the currentConfigurationDeclaration
- Returns:
- the value of the allowFailOnInit flag
-