Class DefaultConfigurationBuilder.FileConfigurationProvider
java.lang.Object
org.apache.commons.configuration.beanutils.DefaultBeanFactory
org.apache.commons.configuration.DefaultConfigurationBuilder.ConfigurationProvider
org.apache.commons.configuration.DefaultConfigurationBuilder.FileConfigurationProvider
- All Implemented Interfaces:
BeanFactory
- Direct Known Subclasses:
DefaultConfigurationBuilder.XMLConfigurationProvider
- Enclosing class:
DefaultConfigurationBuilder
public static class DefaultConfigurationBuilder.FileConfigurationProvider
extends DefaultConfigurationBuilder.ConfigurationProvider
A specialized provider implementation that deals with file based
configurations. Ensures that the base path is correctly set and that the
load() method gets called.
- Since:
- 1.3
- Version:
- $Id: DefaultConfigurationBuilder.java 1366930 2012-07-29 20:05:36Z oheger $
- Author:
- Commons Configuration team
-
Field Summary
Fields inherited from class DefaultBeanFactory
INSTANCE -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance ofFileConfigurationProvider.FileConfigurationProvider(Class<?> configClass) Creates a new instance ofFileConfigurationProviderand sets the configuration class.FileConfigurationProvider(String configClassName) Creates a new instance ofFileConfigurationProviderand sets the configuration class name. -
Method Summary
Modifier and TypeMethodDescriptionCreates the configuration.Returns an uninitialized file configuration.protected voidinitBeanInstance(Object bean, BeanDeclaration data) Initializes the bean instance.Methods inherited from class DefaultConfigurationBuilder.ConfigurationProvider
fetchConfigurationClass, getConfigurationClass, getConfigurationClassName, loadClass, setConfigurationClass, setConfigurationClassNameMethods inherited from class DefaultBeanFactory
createBean, createBeanInstance, getDefaultBeanClass
-
Constructor Details
-
FileConfigurationProvider
public FileConfigurationProvider()Creates a new instance ofFileConfigurationProvider. -
FileConfigurationProvider
Creates a new instance ofFileConfigurationProviderand sets the configuration class.- Parameters:
configClass- the class for the configurations to be created
-
FileConfigurationProvider
Creates a new instance ofFileConfigurationProviderand sets the configuration class name.- Parameters:
configClassName- the name of the configuration to be created- Since:
- 1.4
-
-
Method Details
-
getConfiguration
public AbstractConfiguration getConfiguration(DefaultConfigurationBuilder.ConfigurationDeclaration decl) throws Exception Creates the configuration. After thatload()will be called. If this configuration is marked as optional, exceptions will be ignored.- Overrides:
getConfigurationin classDefaultConfigurationBuilder.ConfigurationProvider- Parameters:
decl- the declaration- Returns:
- the new configuration
- Throws:
Exception- if an error occurs
-
getEmptyConfiguration
public AbstractConfiguration getEmptyConfiguration(DefaultConfigurationBuilder.ConfigurationDeclaration decl) throws Exception Returns an uninitialized file configuration. This method will be called for optional configurations when thegetConfiguration()method caused an error and theforceCreateattribute is set. It will create the configuration of the represented type, but theload()method won't be called. This way non-existing configuration files can be handled gracefully: If loading a the file fails, an empty configuration will be created that is already configured with the correct file name.- Overrides:
getEmptyConfigurationin classDefaultConfigurationBuilder.ConfigurationProvider- 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
-
initBeanInstance
Initializes the bean instance. Ensures that the file configuration's base path will be initialized with the base path of the factory so that relative path names can be correctly resolved.- Overrides:
initBeanInstancein classDefaultBeanFactory- Parameters:
bean- the bean to be initializeddata- the declaration- Throws:
Exception- if an error occurs
-