public class FileExtensionConfigurationBuilderProvider extends BaseConfigurationBuilderProvider
A specialized implementation of ConfigurationBuilderProvider
which determines the name of the result
configuration class based on the extension of the file to load.
This class works analogously to its base class BaseConfigurationBuilderProvider
; especially, the resulting
builder is created based on reflection. It extends the super class's functionality by a specific mechanism for
determining the resulting configuration class: At construction time two configuration class names and a file
extension are passed in. If a file name is provided in the builder's initialization parameters and this file name has
the specified extension, then the first configuration class name is used; otherwise the default configuration class
name is selected.
There are some tags for CombinedConfigurationProvider
which can produce different results depending on the
configuration files they have to load. This class can be used to implement this feature in a generic way.
Constructor and Description |
---|
FileExtensionConfigurationBuilderProvider(String bldrCls,
String reloadBldrCls,
String matchingConfigCls,
String defConfigClass,
String ext,
Collection<String> paramCls)
Creates a new instance of
FileExtensionConfigurationBuilderProvider . |
Modifier and Type | Method and Description |
---|---|
protected String |
determineConfigurationClass(ConfigurationDeclaration decl,
Collection<BuilderParameters> params)
Determines the name of the configuration class produced by the builder.
|
String |
getExtension()
Returns the file extension of this provider.
|
String |
getMatchingConfigurationClass()
Returns the name of the matching configuration class.
|
configureBuilder, createBuilder, createParameterObjects, determineBuilderClass, getBuilderClass, getConfigurationBuilder, getConfigurationClass, getParameterClasses, getReloadingBuilderClass, inheritParentBuilderProperties, initializeParameterObjects, isAllowFailOnInit
public FileExtensionConfigurationBuilderProvider(String bldrCls, String reloadBldrCls, String matchingConfigCls, String defConfigClass, String ext, Collection<String> paramCls)
FileExtensionConfigurationBuilderProvider
.bldrCls
- the name of the builder classreloadBldrCls
- the name of a builder class to be used if reloading support is required (null if
reloading is not supported)matchingConfigCls
- the name of the configuration class to be used if the provided file extension matches (must
not be null)defConfigClass
- the name of the configuration class to be used if the provided file extension does not match
(must not be null)ext
- the file extension to select the configuration class (must not be null)paramCls
- a collection with the names of parameters classes; an instance of a parameters object with basic
properties is created automatically and does not need to be contained in this list; the collection can be
null if no additional parameter objects are neededIllegalArgumentException
- if a required parameter is missingpublic String getMatchingConfigurationClass()
public String getExtension()
protected String determineConfigurationClass(ConfigurationDeclaration decl, Collection<BuilderParameters> params) throws ConfigurationException
FileBasedBuilderParametersImpl
object in the parameter
objects. If one is found, the extension of the file name is obtained and compared against the stored file extension.
In case of a match, the matching configuration class is selected, otherwise the default one.determineConfigurationClass
in class BaseConfigurationBuilderProvider
decl
- the current ConfigurationDeclaration
params
- the collection with parameter objectsConfigurationException
- if an error occursCopyright © 2001–2022 The Apache Software Foundation. All rights reserved.