Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.configuration
Class ConfigurationFactory

    java.lang.Object
      org.apache.commons.configuration.ConfigurationFactory

    public class ConfigurationFactory

extends Object

Factory class to create a CompositeConfiguration from a .xml file using Digester. By default it can handle the Configurations from commons- configuration. If you need to add your own, then you can pass in your own digester rules to use. It is also namespace aware, by providing a digesterRuleNamespaceURI.

Note: Almost all of the features provided by this class and many more are also available for the ``DefaultConfigurationBuilder`` class. `DefaultConfigurationBuilder` also has a more robust merge algorithm for constructing combined configurations. So it is recommended to use this class instead of `ConfigurationFactory`.

Version:
  $Id: ConfigurationFactory.java 524006 2007-03-30 09:33:17Z oheger $
Author:
  Eric Pugh, Henning P. Schmiedehausen, Oliver Heger

Nested Class Summary
`static class` | `ConfigurationFactory.AdditionalConfigurationData` A simple data class that holds all information about a configuration from the `<additional>` section.
`static class` | `ConfigurationFactory.ConfigurationBuilder` An internally used helper class for constructing the composite configuration object.
`class` | `ConfigurationFactory.DigesterConfigurationFactory` A base class for digester factory classes.
`class` | `ConfigurationFactory.FileConfigurationFactory` A tiny inner class that allows the Configuration Factory to let the digester construct FileConfiguration objects that already have the correct base Path set.
`class` | `ConfigurationFactory.PropertiesConfigurationFactory` A factory that returns an XMLPropertiesConfiguration for .xml files and a PropertiesConfiguration for the others.
`class` | `ConfigurationFactory.PropertyListConfigurationFactory` A factory that returns an XMLPropertyListConfiguration for .xml files and a PropertyListConfiguration for the others.

Constructor Summary
`ConfigurationFactory()` Constructor
`ConfigurationFactory(String configurationFileName)` Constructor with ConfigurationFile Name passed

Method Summary
`protected void` | `enableDigesterSubstitutor(Digester digester)` Adds a substitutor to interpolate system properties
`String` | `getBasePath()` Returns the Base path from which this Configuration Factory operates.
`Configuration` | `getConfiguration()` Return the configuration provided by this factory.
`String` | `getConfigurationFileName()` Returns the configurationFile.
`URL` | `getConfigurationURL()` Returns the URL of the configuration file to be loaded.
`String` | `getDigesterRuleNamespaceURI()` Returns the digesterRuleNamespaceURI.
`URL` | `getDigesterRules()` Returns the digesterRules.
`protected void` | `initDefaultDigesterRules(Digester digester)` Initializes the parsing rules for the default digester This allows the Configuration Factory to understand the default types: Properties, XML and JNDI.
`protected void` | `initDigesterSectionRules(Digester digester, String matchString, boolean additional)` Sets up digester rules for a specified section of the configuration info file.
`void` | `setBasePath(String basePath)` Sets the basePath for all file references from this Configuration Factory.
`void` | `setConfigurationFileName(String configurationFileName)` Sets the configurationFile.
`void` | `setConfigurationURL(URL url)` Sets the URL of the configuration to load.
`void` | `setDigesterRuleNamespaceURI(String digesterRuleNamespaceURI)` Sets the digesterRuleNamespaceURI.
`void` | `setDigesterRules(URL digesterRules)` Sets the digesterRules.
`protected void` | `setupDigesterInstance(Digester digester, String matchString, ObjectCreationFactory factory, String method, boolean additional)` Sets up digester rules for a configuration to be loaded.
`protected void` | `setupUnionRules(Digester digester, String matchString)` Sets up rules for configurations in the additional section.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ConfigurationFactory

    public ConfigurationFactory()

  Constructor

### ConfigurationFactory

    public ConfigurationFactory(String configurationFileName)

  Constructor with ConfigurationFile Name passed

  Parameters:
    `configurationFileName` - The path to the configuration file

Method Detail

### getConfiguration

    public Configuration getConfiguration()
                                   throws ConfigurationException

  Return the configuration provided by this factory. It loads the configuration file which is a XML description of the actual configurations to load. It can contain various different types of configuration, e.g. Properties, XML and JNDI.

  Returns:
    A Configuration object
  Throws:
    `ConfigurationException` - A generic exception that we had trouble during the loading of the configuration data.

### getConfigurationFileName

    public String getConfigurationFileName()

  Returns the configurationFile.

  Returns:
    The name of the configuration file. Can be null.

### setConfigurationFileName

    public void setConfigurationFileName(String configurationFileName)

  Sets the configurationFile.

  Parameters:
    `configurationFileName` - The name of the configurationFile to use.

### getConfigurationURL

    public URL getConfigurationURL()

  Returns the URL of the configuration file to be loaded.

  Returns:
    the URL of the configuration to load

### setConfigurationURL

    public void setConfigurationURL(URL url)

  Sets the URL of the configuration to load. This configuration can be either specified by a file name or by a URL.

  Parameters:
    `url` - the URL of the configuration to load

### getDigesterRules

    public URL getDigesterRules()

  Returns the digesterRules.

  Returns:
    URL

### setDigesterRules

    public void setDigesterRules(URL digesterRules)

  Sets the digesterRules.

  Parameters:
    `digesterRules` - The digesterRules to set

### enableDigesterSubstitutor

    protected void enableDigesterSubstitutor(Digester digester)

  Adds a substitutor to interpolate system properties

  Parameters:
    `digester` - The digester to which we add the substitutor

### initDefaultDigesterRules

    protected void initDefaultDigesterRules(Digester digester)

  Initializes the parsing rules for the default digester This allows the Configuration Factory to understand the default types: Properties, XML and JNDI. Two special sections are introduced: `<override>` and `<additional>`.

  Parameters:
    `digester` - The digester to configure

### initDigesterSectionRules

    protected void initDigesterSectionRules(Digester digester,
                                            String matchString,
                                            boolean additional)

  Sets up digester rules for a specified section of the configuration info file.

  Parameters:
    `digester` - the current digester instance
    `matchString` - specifies the section
    `additional` - a flag if rules for the additional section are to be added

### setupDigesterInstance

    protected void setupDigesterInstance(Digester digester,
                                         String matchString,
                                         ObjectCreationFactory factory,
                                         String method,
                                         boolean additional)

  Sets up digester rules for a configuration to be loaded.

  Parameters:
    `digester` - the current digester
    `matchString` - the pattern to match with this rule
    `factory` - an ObjectCreationFactory instance to use for creating new objects
    `method` - the name of a method to be called or null for none
    `additional` - a flag if rules for the additional section are to be added

### setupUnionRules

    protected void setupUnionRules(Digester digester,
                                   String matchString)

  Sets up rules for configurations in the additional section.

  Parameters:
    `digester` - the current digester
    `matchString` - the pattern to match with this rule

### getDigesterRuleNamespaceURI

    public String getDigesterRuleNamespaceURI()

  Returns the digesterRuleNamespaceURI.

  Returns:
    A String with the digesterRuleNamespaceURI.

### setDigesterRuleNamespaceURI

    public void setDigesterRuleNamespaceURI(String digesterRuleNamespaceURI)

  Sets the digesterRuleNamespaceURI.

  Parameters:
    `digesterRuleNamespaceURI` - The new digesterRuleNamespaceURI to use

### getBasePath

    public String getBasePath()

  Returns the Base path from which this Configuration Factory operates. This is never null. If you set the BasePath to null, then a base path according to the configuration to load is returned.

  Returns:
    The base Path of this configuration factory.

### setBasePath

    public void setBasePath(String basePath)

  Sets the basePath for all file references from this Configuration Factory. Normally a base path need not to be set because it is determined by the location of the configuration file to load. All relative pathes in this file are resolved relative to this file. Setting a base path makes sense if such relative pathes should be otherwise resolved, e.g. if the configuration file is loaded from the class path and all sub configurations it refers to are stored in a special config directory.

  Parameters:
    `basePath` - The new basePath to set.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2007 The Apache Software Foundation. All Rights Reserved.