|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.configuration.ConfigurationXMLDocument
A helper class that supports XML-like processing for configuration objects.
This class provides a set of methods that all have something to do with
treating a Configuration
object as a XML document. So a
configuration can be transformed into a Document
(either
dom4j or w3c), saved as an XML file or passed to Digester.
Implementation note: This class is not thread safe.
Field Summary | |
protected static java.lang.String |
ATTR_NAME
Constant for the name attribute. |
protected static java.lang.String |
ATTR_VALUE
Constant for the value attribute. |
private Configuration |
configuration
Stores the configuration object this object operates on. |
protected static java.lang.String |
ELEM_CLASS
Constant for the class element. |
protected static java.lang.String |
ELEM_PROPERTY
Constant for the property element. |
Constructor Summary | |
ConfigurationXMLDocument(Configuration config)
Creates a new instance of ConfigurationXMLDocument
and sets the configuration object to be processed. |
Method Summary | |
java.lang.Object |
callDigester(java.lang.String prefix)
Creates and initializes an object specified in the configuration using Digester. |
private Configuration |
configForKey(java.lang.String key)
Helper method for constructing a subset if necessary. |
protected org.apache.commons.digester.Digester |
createDefaultDigester(java.lang.String prefix)
Creates the default Digester instance for the given prefix. |
ConfigurationXMLReader |
createXMLReader()
Returns a XMLReader object for the actual configuration
object. |
static ConfigurationXMLReader |
createXMLReader(Configuration config)
Returns a XMLReader object for the specified configuration
object. |
ConfigurationXMLReader |
createXMLReader(java.lang.String prefix)
Returns a ConfigurationXMLReader object for the subset
configuration specified by the given prefix. |
Configuration |
getConfiguration()
Returns the Configuration object for this document. |
protected org.apache.commons.digester.Digester |
getDefaultDigester(java.lang.String prefix)
Returns a default Digester instance. |
org.dom4j.Document |
getDocument()
Transforms the wrapped configuration into a dom4j document. |
org.dom4j.Document |
getDocument(java.lang.String prefix)
Transforms the wrapped configuration into a dom4j document. |
org.dom4j.Document |
getDocument(java.lang.String prefix,
java.lang.String rootName)
Transforms the wrapped configuration into a dom4j document. |
org.w3c.dom.Document |
getW3cDocument()
Transforms the wrapped configuration into a w3c document. |
org.w3c.dom.Document |
getW3cDocument(java.lang.String prefix)
Transforms the wrapped configuration into a w3c document. |
org.w3c.dom.Document |
getW3cDocument(java.lang.String prefix,
java.lang.String rootName)
Transforms the wrapped configuration into a w3c document. |
void |
setConfiguration(Configuration configuration)
Sets the Configuration object this document operates on. |
protected void |
setupDefaultDigester(org.apache.commons.digester.Digester digester)
Initializes the default digester instance used for simple object creation. |
(package private) static org.w3c.dom.Document |
toW3cDocument(org.dom4j.Document doc)
Converts a dom4j document into a w3c document. |
void |
write(java.io.Writer out)
Writes the wrapped configuration to the given writer. |
void |
write(java.io.Writer out,
boolean pretty)
Writes the wrapped configuration to the given writer. |
void |
write(java.io.Writer out,
java.lang.String prefix)
Writes a configuration (or parts of it) to the given writer. |
void |
write(java.io.Writer out,
java.lang.String prefix,
boolean pretty)
Writes a configuration (or parts of it) to the given writer. |
void |
write(java.io.Writer out,
java.lang.String prefix,
java.lang.String root)
Writes a configuration (or parts of it) to the given writer. |
void |
write(java.io.Writer out,
java.lang.String prefix,
java.lang.String root,
boolean pretty)
Writes a configuration (or parts of it) to the given writer. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final java.lang.String ELEM_CLASS
protected static final java.lang.String ELEM_PROPERTY
protected static final java.lang.String ATTR_NAME
protected static final java.lang.String ATTR_VALUE
private Configuration configuration
Constructor Detail |
public ConfigurationXMLDocument(Configuration config)
ConfigurationXMLDocument
and sets the configuration object to be processed.
config
- the configuration objectMethod Detail |
public Configuration getConfiguration()
Configuration
object for this document.
Configuration
objectpublic void setConfiguration(Configuration configuration)
Configuration
object this document operates on.
configuration
- the Configuration
objectpublic static ConfigurationXMLReader createXMLReader(Configuration config)
XMLReader
object for the specified configuration
object. This reader can then be used to perform XML-like processing on
the configuration.
config
- the configuration object
public ConfigurationXMLReader createXMLReader()
XMLReader
object for the actual configuration
object.
public ConfigurationXMLReader createXMLReader(java.lang.String prefix)
ConfigurationXMLReader
object for the subset
configuration specified by the given prefix. If no properties are found
under this prefix, a NoSuchElementException
exception will be thrown.
prefix
- the prefix of the configuration keys that belong to the
subset; can be null, then the whole configuration is affected
public org.dom4j.Document getDocument(java.lang.String prefix, java.lang.String rootName) throws org.dom4j.DocumentException
prefix
- a prefix for the keys to process; can be null,
then all keys in the configuration will be added to the documentrootName
- the name of the root element in the document; can be
null, then a default name will be used
org.dom4j.DocumentException
- if an error occurspublic org.dom4j.Document getDocument(java.lang.String prefix) throws org.dom4j.DocumentException
prefix
- a prefix for the keys to process; can be null,
then all keys in the configuration will be added to the document
org.dom4j.DocumentException
- if an error occurspublic org.dom4j.Document getDocument() throws org.dom4j.DocumentException
org.dom4j.DocumentException
- if an error occurspublic org.w3c.dom.Document getW3cDocument(java.lang.String prefix, java.lang.String rootName) throws org.dom4j.DocumentException
prefix
- a prefix for the keys to process; can be null,
then all keys in the configuration will be added to the documentrootName
- the name of the root element in the document; can be
null, then a default name will be used
org.dom4j.DocumentException
- if an error occurspublic org.w3c.dom.Document getW3cDocument(java.lang.String prefix) throws org.dom4j.DocumentException
prefix
- a prefix for the keys to process; can be null,
then all keys in the configuration will be added to the document
org.dom4j.DocumentException
- if an error occurspublic org.w3c.dom.Document getW3cDocument() throws org.dom4j.DocumentException
org.dom4j.DocumentException
- if an error occursstatic org.w3c.dom.Document toW3cDocument(org.dom4j.Document doc) throws org.dom4j.DocumentException
doc
- the dom4j document
org.dom4j.DocumentException
- if an error occursprivate Configuration configForKey(java.lang.String key)
key
- the key
public java.lang.Object callDigester(java.lang.String prefix) throws java.io.IOException, org.xml.sax.SAXException
Creates and initializes an object specified in the configuration using Digester.
This method first constructs a subset configuration with the keys starting with the given prefix. It then transforms this subset into a XML document and let that be processed by Digester. The result of this processing is returned.
The method is intended to be used for creating simple objects that are specified somewhere in the configuration in a standard way. The following fragment shows how a configuration file must look like to be understood by the default Digester rule set used by this method:
... <class name="mypackage.MyClass"/> <args> <property name="myFirstProperty" value="myFirstValue"/> <property name="MySecondProperty" value="mySecondValue"/> ... </args> ...
prefix
- the prefix of the keys that are passed to Digester; can
be null, then the whole configuration will be processed
java.io.IOException
- if an IOException occurs
org.xml.sax.SAXException
- if a SAXException occursprotected org.apache.commons.digester.Digester getDefaultDigester(java.lang.String prefix)
prefix
- the prefix of the keys to be processed; can be
null, then the whole configuration is meant
protected org.apache.commons.digester.Digester createDefaultDigester(java.lang.String prefix)
getDefaultDigester()
.
prefix
- the prefix of the keys to be processed; can be
null, then the whole configuration is meant
protected void setupDefaultDigester(org.apache.commons.digester.Digester digester)
callDigester()
methods.
digester
- the digester instance to be initializedpublic void write(java.io.Writer out, java.lang.String prefix, java.lang.String root, boolean pretty) throws java.io.IOException, org.dom4j.DocumentException
out
- the output writerprefix
- the prefix of the subset to write; if null, the
whole configuration is writtenroot
- the name of the root element of the resulting document;
null for a default namepretty
- flag for the pretty print mode
java.io.IOException
- if an IO error occurs
org.dom4j.DocumentException
- if there is an error during processingpublic void write(java.io.Writer out, java.lang.String prefix, java.lang.String root) throws java.io.IOException, org.dom4j.DocumentException
out
- the output writerprefix
- the prefix of the subset to write; if null, the
whole configuration is writtenroot
- the name of the root element of the resulting document;
null for a default name
java.io.IOException
- if an IO error occurs
org.dom4j.DocumentException
- if there is an error during processingpublic void write(java.io.Writer out, java.lang.String prefix, boolean pretty) throws java.io.IOException, org.dom4j.DocumentException
out
- the output writerprefix
- the prefix of the subset to write; if null, the
whole configuration is writtenpretty
- flag for the pretty print mode
java.io.IOException
- if an IO error occurs
org.dom4j.DocumentException
- if there is an error during processingpublic void write(java.io.Writer out, java.lang.String prefix) throws java.io.IOException, org.dom4j.DocumentException
out
- the output writerprefix
- the prefix of the subset to write; if null, the
whole configuration is written
java.io.IOException
- if an IO error occurs
org.dom4j.DocumentException
- if there is an error during processingpublic void write(java.io.Writer out, boolean pretty) throws java.io.IOException, org.dom4j.DocumentException
out
- the output writerpretty
- flag for the pretty print mode
java.io.IOException
- if an IO error occurs
org.dom4j.DocumentException
- if there is an error during processingpublic void write(java.io.Writer out) throws java.io.IOException, org.dom4j.DocumentException
out
- the output writer
java.io.IOException
- if an IO error occurs
org.dom4j.DocumentException
- if there is an error during processing
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |