org.apache.commons.configuration

Class DefaultConfigurationBuilder.ConfigurationProvider

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 matching ConfigurationProvider for each encountered tag. This provider is then asked to create a corresponding Configuration 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
ClassconfigurationClass
Stores the class of the configuration to be created.
StringconfigurationClassName
Stores the name of the configuration class to be created.
Constructor Summary
ConfigurationProvider()
Creates a new uninitialized instance of ConfigurationProvider.
ConfigurationProvider(Class configClass)
Creates a new instance of ConfigurationProvider and sets the class of the configuration created by this provider.
ConfigurationProvider(String configClassName)
Creates a new instance of ConfigurationProvider and sets the name of the class of the configuration created by this provider.
Method Summary
protected ClassfetchConfigurationClass()
Returns the configuration class supported by this provider.
AbstractConfigurationgetConfiguration(DefaultConfigurationBuilder.ConfigurationDeclaration decl)
Returns the configuration.
ClassgetConfigurationClass()
Returns the class of the configuration returned by this provider.
StringgetConfigurationClassName()
Returns the name of the configuration class returned by this provider.
AbstractConfigurationgetEmptyConfiguration(DefaultConfigurationBuilder.ConfigurationDeclaration decl)
Returns an uninitialized configuration of the represented type.
protected ClassloadClass(String className)
Loads the class with the specified name dynamically.
voidsetConfigurationClass(Class configurationClass)
Sets the class of the configuration returned by this provider.
voidsetConfigurationClassName(String configurationClassName)
Sets the name of the configuration class returned by this provider.

Field Detail

configurationClass

private Class configurationClass
Stores the class of the configuration to be created.

configurationClassName

private String configurationClassName
Stores the name of the configuration class to be created.

Constructor Detail

ConfigurationProvider

public ConfigurationProvider()
Creates a new uninitialized instance of ConfigurationProvider.

ConfigurationProvider

public ConfigurationProvider(Class configClass)
Creates a new instance of ConfigurationProvider and sets the class of the configuration created by this provider.

Parameters: configClass the configuration class

ConfigurationProvider

public ConfigurationProvider(String configClassName)
Creates a new instance of ConfigurationProvider 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

fetchConfigurationClass

protected Class fetchConfigurationClass()
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

Since: 1.4

getConfiguration

public AbstractConfiguration getConfiguration(DefaultConfigurationBuilder.ConfigurationDeclaration decl)
Returns the configuration. This method is called to fetch the configuration from the provider. This implementation will call the inherited createBean() 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: Exception if an error occurs

getConfigurationClass

public Class getConfigurationClass()
Returns the class of the configuration returned by this provider.

Returns: the class of the provided configuration

getConfigurationClassName

public String getConfigurationClassName()
Returns the name of the configuration class returned by this provider.

Returns: the configuration class name

Since: 1.4

getEmptyConfiguration

public AbstractConfiguration getEmptyConfiguration(DefaultConfigurationBuilder.ConfigurationDeclaration decl)
Returns an uninitialized configuration of the represented type. This method will be called for optional configurations when the getConfiguration() method caused an error and the forceCreate 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: Exception if an error occurs

Since: 1.4

loadClass

protected Class loadClass(String className)
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: ClassNotFoundException if class loading fails

Since: 1.4

setConfigurationClass

public void setConfigurationClass(Class configurationClass)
Sets the class of the configuration returned by this provider.

Parameters: configurationClass the configuration class

setConfigurationClassName

public void setConfigurationClassName(String configurationClassName)
Sets the name of the configuration class returned by this provider.

Parameters: configurationClassName the name of the configuration class

Since: 1.4