public class BaseConfigurationBuilderProvider extends Object implements ConfigurationBuilderProvider
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.
Constructor and Description |
---|
BaseConfigurationBuilderProvider(String bldrCls,
String reloadBldrCls,
String configCls,
Collection<String> paramCls)
Creates a new instance of
BaseConfigurationBuilderProvider and
initializes all its properties. |
Modifier and Type | Method and Description |
---|---|
protected 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> |
createParameterObjects()
Creates a collection of parameter objects to be used for configuring the
builder.
|
protected String |
determineBuilderClass(ConfigurationDeclaration decl)
Determines the name of the class to be used for a new builder instance.
|
protected String |
determineConfigurationClass(ConfigurationDeclaration decl,
Collection<BuilderParameters> params)
Determines the name of the configuration class produced by the builder.
|
String |
getBuilderClass()
Returns the name of the class of the builder created by this provider.
|
ConfigurationBuilder<? extends Configuration> |
getConfigurationBuilder(ConfigurationDeclaration decl)
Returns the builder for the configuration source managed by this
provider.
|
String |
getConfigurationClass()
Returns the name of the configuration class created by the builder
produced by this provider.
|
Collection<String> |
getParameterClasses()
Returns an unmodifiable collection with the names of parameter classes
supported by this provider.
|
String |
getReloadingBuilderClass()
Returns the name of the class of the builder created by this provider if
the reload flag is set.
|
protected void |
inheritParentBuilderProperties(ConfigurationDeclaration decl,
Collection<BuilderParameters> params)
Passes all parameter objects to the parent
CombinedConfigurationBuilder so that properties already defined
for the parent builder can be added. |
protected void |
initializeParameterObjects(ConfigurationDeclaration decl,
Collection<BuilderParameters> params)
Initializes the parameter objects with data stored in the current bean
declaration.
|
protected boolean |
isAllowFailOnInit(ConfigurationDeclaration decl)
Determines the allowFailOnInit flag for the newly created
builder based on the given
ConfigurationDeclaration . |
public BaseConfigurationBuilderProvider(String bldrCls, String reloadBldrCls, String configCls, Collection<String> paramCls)
BaseConfigurationBuilderProvider
and
initializes all its properties.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 classesIllegalArgumentException
- if a required parameter is missingpublic String getBuilderClass()
public String getReloadingBuilderClass()
public String getConfigurationClass()
public Collection<String> getParameterClasses()
public ConfigurationBuilder<? extends Configuration> getConfigurationBuilder(ConfigurationDeclaration decl) throws ConfigurationException
BeanDeclaration
.getConfigurationBuilder
in interface ConfigurationBuilderProvider
decl
- the bean declaration with initialization parameters for the
configuration builderConfigurationBuilder
object created by this providerConfigurationException
- if an error occursprotected boolean isAllowFailOnInit(ConfigurationDeclaration decl)
ConfigurationDeclaration
. 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.decl
- the current ConfigurationDeclaration
protected Collection<BuilderParameters> createParameterObjects() throws Exception
Exception
- if an error occurs while creating parameter objects via
reflectionprotected void initializeParameterObjects(ConfigurationDeclaration decl, Collection<BuilderParameters> params) throws Exception
CombinedConfigurationBuilder
so that the
parameters object can inherit properties already defined for this
builder.decl
- the current ConfigurationDeclaration
params
- the collection with (uninitialized) parameter objectsException
- if an error occursprotected void inheritParentBuilderProperties(ConfigurationDeclaration decl, Collection<BuilderParameters> params)
CombinedConfigurationBuilder
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.decl
- the current ConfigurationDeclaration
params
- the collection with (uninitialized) parameter objectsprotected BasicConfigurationBuilder<? extends Configuration> createBuilder(ConfigurationDeclaration decl, Collection<BuilderParameters> params) throws Exception
determineBuilderClass()
. It then calls the
constructor expecting the configuration class, the map with properties,
and theallowFailOnInit flag.decl
- the current ConfigurationDeclaration
params
- initialization parameters for the new builder objectException
- if an error occursprotected void configureBuilder(BasicConfigurationBuilder<? extends Configuration> builder, ConfigurationDeclaration decl, Collection<BuilderParameters> params) throws Exception
configure()
method.builder
- the builder to be initializeddecl
- the current ConfigurationDeclaration
params
- the collection with initialization parameter objectsException
- if an error occursprotected String determineBuilderClass(ConfigurationDeclaration decl) throws ConfigurationException
ConfigurationDeclaration
. If a
reloading builder is desired, but this provider has no reloading support,
an exception is thrown.decl
- the current ConfigurationDeclaration
ConfigurationException
- if the builder class cannot be determinedprotected String determineConfigurationClass(ConfigurationDeclaration decl, Collection<BuilderParameters> params) throws ConfigurationException
decl
- the current ConfigurationDeclaration
params
- the collection with parameter objectsConfigurationException
- if an error occursCopyright © 2001–2020 The Apache Software Foundation. All rights reserved.