Package org.apache.commons.configuration
Class DefaultConfigurationBuilder.ConfigurationProvider
- java.lang.Object
-
- org.apache.commons.configuration.beanutils.DefaultBeanFactory
-
- org.apache.commons.configuration.DefaultConfigurationBuilder.ConfigurationProvider
-
- All Implemented Interfaces:
BeanFactory
- Direct Known Subclasses:
DefaultConfigurationBuilder.FileConfigurationProvider
- Enclosing class:
- DefaultConfigurationBuilder
public static class DefaultConfigurationBuilder.ConfigurationProvider extends DefaultBeanFactory
A base class for creating and initializing configuration sources.
Concrete sub classes of this base class are responsible for creating specific
Configuration
objects for the tags in the configuration definition file. The configuration factory will parse the definition file and try to find a matchingConfigurationProvider
for each encountered tag. This provider is then asked to create a correspondingConfiguration
object. It is up to a concrete implementation how this object is created and initialized.Note that at the moment only configuration classes derived from
AbstractConfiguration
are supported.
-
-
Field Summary
-
Fields inherited from class org.apache.commons.configuration.beanutils.DefaultBeanFactory
INSTANCE
-
-
Constructor Summary
Constructors Constructor Description ConfigurationProvider()
Creates a new uninitialized instance ofConfigurationProvider
.ConfigurationProvider(java.lang.Class<?> configClass)
Creates a new instance ofConfigurationProvider
and sets the class of the configuration created by this provider.ConfigurationProvider(java.lang.String configClassName)
Creates a new instance ofConfigurationProvider
and sets the name of the class of the configuration created by this provider.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Class<?>
fetchConfigurationClass()
Returns the configuration class supported by this provider.AbstractConfiguration
getConfiguration(DefaultConfigurationBuilder.ConfigurationDeclaration decl)
Returns the configuration.java.lang.Class<?>
getConfigurationClass()
Returns the class of the configuration returned by this provider.java.lang.String
getConfigurationClassName()
Returns the name of the configuration class returned by this provider.AbstractConfiguration
getEmptyConfiguration(DefaultConfigurationBuilder.ConfigurationDeclaration decl)
Returns an uninitialized configuration of the represented type.protected java.lang.Class<?>
loadClass(java.lang.String className)
Loads the class with the specified name dynamically.void
setConfigurationClass(java.lang.Class<?> configurationClass)
Sets the class of the configuration returned by this provider.void
setConfigurationClassName(java.lang.String configurationClassName)
Sets the name of the configuration class returned by this provider.-
Methods inherited from class org.apache.commons.configuration.beanutils.DefaultBeanFactory
createBean, createBeanInstance, getDefaultBeanClass, initBeanInstance
-
-
-
-
Constructor Detail
-
ConfigurationProvider
public ConfigurationProvider()
Creates a new uninitialized instance ofConfigurationProvider
.
-
ConfigurationProvider
public ConfigurationProvider(java.lang.Class<?> configClass)
Creates a new instance ofConfigurationProvider
and sets the class of the configuration created by this provider.- Parameters:
configClass
- the configuration class
-
ConfigurationProvider
public ConfigurationProvider(java.lang.String configClassName)
Creates a new instance ofConfigurationProvider
and sets the name of the class of the configuration created by this provider.- Parameters:
configClassName
- the name of the configuration class- Since:
- 1.4
-
-
Method Detail
-
getConfigurationClass
public java.lang.Class<?> getConfigurationClass()
Returns the class of the configuration returned by this provider.- Returns:
- the class of the provided configuration
-
setConfigurationClass
public void setConfigurationClass(java.lang.Class<?> configurationClass)
Sets the class of the configuration returned by this provider.- Parameters:
configurationClass
- the configuration class
-
getConfigurationClassName
public java.lang.String getConfigurationClassName()
Returns the name of the configuration class returned by this provider.- Returns:
- the configuration class name
- Since:
- 1.4
-
setConfigurationClassName
public void setConfigurationClassName(java.lang.String configurationClassName)
Sets the name of the configuration class returned by this provider.- Parameters:
configurationClassName
- the name of the configuration class- Since:
- 1.4
-
getConfiguration
public AbstractConfiguration getConfiguration(DefaultConfigurationBuilder.ConfigurationDeclaration decl) throws java.lang.Exception
Returns the configuration. This method is called to fetch the configuration from the provider. This implementation will call the inheritedcreateBean()
method to create a new instance of the configuration class.- Parameters:
decl
- the bean declaration with initialization parameters for the configuration- Returns:
- the new configuration object
- Throws:
java.lang.Exception
- if an error occurs
-
getEmptyConfiguration
public AbstractConfiguration getEmptyConfiguration(DefaultConfigurationBuilder.ConfigurationDeclaration decl) throws java.lang.Exception
Returns an uninitialized configuration of the represented type. This method will be called for optional configurations when thegetConfiguration()
method caused an error and theforceCreate
attribute is set. A concrete sub class can here try to create an uninitialized, empty configuration, which may be possible if the error was created during initialization. This base implementation just returns null.- Parameters:
decl
- the bean declaration with initialization parameters for the configuration- Returns:
- the new configuration object
- Throws:
java.lang.Exception
- if an error occurs- Since:
- 1.4
-
fetchConfigurationClass
protected java.lang.Class<?> fetchConfigurationClass() throws java.lang.Exception
Returns the configuration class supported by this provider. If a class object was set, it is returned. Otherwise the method tries to resolve the class name.- Returns:
- the class of the configuration to be created
- Throws:
java.lang.Exception
- Since:
- 1.4
-
loadClass
protected java.lang.Class<?> loadClass(java.lang.String className) throws java.lang.ClassNotFoundException
Loads the class with the specified name dynamically. If the class's name is null, null will also be returned.- Parameters:
className
- the name of the class to be loaded- Returns:
- the class object
- Throws:
java.lang.ClassNotFoundException
- if class loading fails- Since:
- 1.4
-
-