public class ConfigurationFactory
extends java.lang.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
class. DefaultConfigurationBuilder
DefaultConfigurationBuilder
also has a more robust
merge algorithm for constructing combined configurations. So it is
recommended to use this class instead of ConfigurationFactory
.
Modifier and Type | Class and Description |
---|---|
static class |
ConfigurationFactory.AdditionalConfigurationData
A simple data class that holds all information about a configuration
from the
<additional> section. |
private static class |
ConfigurationFactory.CallOptionalMethodRule
A special implementation of Digester's
CallMethodRule that
is internally used for calling a file configuration's load()
method. |
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.
|
private class |
ConfigurationFactory.JNDIConfigurationFactory
A tiny inner class that allows the Configuration Factory to
let the digester construct JNDIConfiguration objects.
|
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.
|
private class |
ConfigurationFactory.SystemConfigurationFactory
A tiny inner class that allows the Configuration Factory to
let the digester construct SystemConfiguration objects.
|
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
ATTR_FILENAME
Constant for the fileName attribute.
|
private static java.lang.String |
ATTR_OPTIONAL
Constant for the optional attribute.
|
private java.lang.String |
basePath
The basePath to prefix file paths for file based property files.
|
private java.lang.String |
configurationFileName
The XML file with the details about the configuration to load
|
private java.net.URL |
configurationURL
The URL to the XML file with the details about the configuration to load.
|
private static java.lang.String |
DEF_BASE_PATH
Constant for the default base path (points to actual directory).
|
private java.lang.String |
digesterRuleNamespaceURI
The digester namespace to parse
|
private java.net.URL |
digesterRules
URL for xml digester rules file
|
private java.lang.String |
implicitBasePath
The implicit base path for included files.
|
private static org.apache.commons.logging.Log |
log
static logger
|
private static java.lang.String |
METH_LOAD
Constant for the load method.
|
private static java.lang.String |
SEC_ADDITIONAL
Constant for the additional section.
|
private static java.lang.String |
SEC_OVERRIDE
Constant for the override section.
|
private static java.lang.String |
SEC_ROOT
Constant for the root element in the info file.
|
Constructor and Description |
---|
ConfigurationFactory()
Constructor
|
ConfigurationFactory(java.lang.String configurationFileName)
Constructor with ConfigurationFile Name passed
|
Modifier and Type | Method and Description |
---|---|
private void |
configureNamespace(org.apache.commons.digester.Digester digester)
Configure the current digester to be namespace aware and to have
a Configuration object to which all of the other configurations
should be added
|
protected void |
enableDigesterSubstitutor(org.apache.commons.digester.Digester digester)
Adds a substitutor to interpolate system properties
|
java.lang.String |
getBasePath()
Returns the Base path from which this Configuration Factory operates.
|
Configuration |
getConfiguration()
Return the configuration provided by this factory.
|
java.lang.String |
getConfigurationFileName()
Returns the configurationFile.
|
java.net.URL |
getConfigurationURL()
Returns the URL of the configuration file to be loaded.
|
java.lang.String |
getDigesterRuleNamespaceURI()
Returns the digesterRuleNamespaceURI.
|
java.net.URL |
getDigesterRules()
Returns the digesterRules.
|
protected void |
initDefaultDigesterRules(org.apache.commons.digester.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(org.apache.commons.digester.Digester digester,
java.lang.String matchString,
boolean additional)
Sets up digester rules for a specified section of the configuration
info file.
|
void |
setBasePath(java.lang.String basePath)
Sets the basePath for all file references from this Configuration Factory.
|
void |
setConfigurationFileName(java.lang.String configurationFileName)
Sets the configurationFile.
|
void |
setConfigurationURL(java.net.URL url)
Sets the URL of the configuration to load.
|
void |
setDigesterRuleNamespaceURI(java.lang.String digesterRuleNamespaceURI)
Sets the digesterRuleNamespaceURI.
|
void |
setDigesterRules(java.net.URL digesterRules)
Sets the digesterRules.
|
protected void |
setupDigesterInstance(org.apache.commons.digester.Digester digester,
java.lang.String matchString,
org.apache.commons.digester.ObjectCreationFactory factory,
java.lang.String method,
boolean additional)
Sets up digester rules for a configuration to be loaded.
|
protected void |
setupUnionRules(org.apache.commons.digester.Digester digester,
java.lang.String matchString)
Sets up rules for configurations in the additional section.
|
private static final java.lang.String SEC_ROOT
private static final java.lang.String SEC_OVERRIDE
private static final java.lang.String SEC_ADDITIONAL
private static final java.lang.String ATTR_OPTIONAL
private static final java.lang.String ATTR_FILENAME
private static final java.lang.String METH_LOAD
private static final java.lang.String DEF_BASE_PATH
private static org.apache.commons.logging.Log log
private java.lang.String configurationFileName
private java.net.URL configurationURL
private java.lang.String implicitBasePath
private java.lang.String basePath
private java.net.URL digesterRules
private java.lang.String digesterRuleNamespaceURI
public ConfigurationFactory()
public ConfigurationFactory(java.lang.String configurationFileName)
configurationFileName
- The path to the configuration filepublic Configuration getConfiguration() throws ConfigurationException
ConfigurationException
- A generic exception that we had trouble during the
loading of the configuration data.public java.lang.String getConfigurationFileName()
public void setConfigurationFileName(java.lang.String configurationFileName)
configurationFileName
- The name of the configurationFile to use.public java.net.URL getConfigurationURL()
public void setConfigurationURL(java.net.URL url)
url
- the URL of the configuration to loadpublic java.net.URL getDigesterRules()
public void setDigesterRules(java.net.URL digesterRules)
digesterRules
- The digesterRules to setprotected void enableDigesterSubstitutor(org.apache.commons.digester.Digester digester)
digester
- The digester to which we add the substitutorprotected void initDefaultDigesterRules(org.apache.commons.digester.Digester digester)
<override>
and <additional>
.digester
- The digester to configureprotected void initDigesterSectionRules(org.apache.commons.digester.Digester digester, java.lang.String matchString, boolean additional)
digester
- the current digester instancematchString
- specifies the sectionadditional
- a flag if rules for the additional section are to be
addedprotected void setupDigesterInstance(org.apache.commons.digester.Digester digester, java.lang.String matchString, org.apache.commons.digester.ObjectCreationFactory factory, java.lang.String method, boolean additional)
digester
- the current digestermatchString
- the pattern to match with this rulefactory
- an ObjectCreationFactory instance to use for creating new
objectsmethod
- the name of a method to be called or null for noneadditional
- a flag if rules for the additional section are to be
addedprotected void setupUnionRules(org.apache.commons.digester.Digester digester, java.lang.String matchString)
digester
- the current digestermatchString
- the pattern to match with this rulepublic java.lang.String getDigesterRuleNamespaceURI()
public void setDigesterRuleNamespaceURI(java.lang.String digesterRuleNamespaceURI)
digesterRuleNamespaceURI
- The new digesterRuleNamespaceURI to useprivate void configureNamespace(org.apache.commons.digester.Digester digester)
digester
- The Digester to configurepublic java.lang.String getBasePath()
public void setBasePath(java.lang.String basePath)
basePath
- The new basePath to set.