Package org.apache.commons.configuration2.builder.combined

# Class FileExtensionConfigurationBuilderProvider

java.lang.Object
org.apache.commons.configuration2.builder.combined.BaseConfigurationBuilderProvider
org.apache.commons.configuration2.builder.combined.FileExtensionConfigurationBuilderProvider

All Implemented Interfaces:
  `ConfigurationBuilderProvider`

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.

Since:
  2.0

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `FileExtensionConfigurationBuilderProvider(String bldrCls, String reloadBldrCls, String matchingConfigCls, String defConfigClass, String ext, Collection<String> paramCls)`
  Creates a new instance of `FileExtensionConfigurationBuilderProvider`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected String`
  `determineConfigurationClass(ConfigurationDeclaration decl, Collection<BuilderParameters> params)`
  Determines the name of the configuration class produced by the builder.
  `String`
  `getExtension()`
  Gets the file extension of this provider.
  `String`
  `getMatchingConfigurationClass()`
  Gets the name of the matching configuration class.

  ### Methods inherited from class org.apache.commons.configuration2.builder.combined.BaseConfigurationBuilderProvider

  `configureBuilder, createBuilder, createParameterObjects, determineBuilderClass, getBuilderClass, getConfigurationBuilder, getConfigurationClass, getParameterClasses, getReloadingBuilderClass, inheritParentBuilderProperties, initializeParameterObjects, isAllowFailOnInit`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### FileExtensionConfigurationBuilderProvider

    public FileExtensionConfigurationBuilderProvider(String bldrCls, String reloadBldrCls, String matchingConfigCls, String defConfigClass, String ext, Collection<String> paramCls)
    Creates a new instance of `FileExtensionConfigurationBuilderProvider`.
    Parameters:
      `bldrCls` - the name of the builder class
      `reloadBldrCls` - 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 needed
    Throws:
      `IllegalArgumentException` - if a required parameter is missing

- ## Method Details

  - ### determineConfigurationClass

    protected String determineConfigurationClass(ConfigurationDeclaration decl, Collection<BuilderParameters> params) throws ConfigurationException
    Determines the name of the configuration class produced by the builder. This method is called when obtaining the arguments for invoking the constructor of the builder class. This implementation just returns the pre-configured configuration class name. Derived classes may determine this class name dynamically based on the passed in parameters. This implementation tries to find a `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.
    Overrides:
      `determineConfigurationClass` in class `BaseConfigurationBuilderProvider`
    Parameters:
      `decl` - the current `ConfigurationDeclaration`
      `params` - the collection with parameter objects
    Returns:
      the name of the builder's result configuration class
    Throws:
      `ConfigurationException` - if an error occurs

  - ### getExtension

    public String getExtension()
    Gets the file extension of this provider.
    Returns:
      the file extension to match

  - ### getMatchingConfigurationClass

    public String getMatchingConfigurationClass()
    Gets the name of the matching configuration class. This class is used if the file extension matches the extension of this provider.
    Returns:
      the matching configuration class