|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.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 String |
ATTR_NAME
Constant for the name attribute. |
protected static String |
ATTR_VALUE
Constant for the value attribute. |
protected static String |
ELEM_CLASS
Constant for the class element. |
protected static 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 | |
Object |
callDigester(String prefix)
Creates and initializes an object specified in the configuration using Digester. |
protected Digester |
createDefaultDigester(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(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 Digester |
getDefaultDigester(String prefix)
Returns a default Digester instance. |
Document |
getDocument()
Transforms the wrapped configuration into a dom4j document. |
Document |
getDocument(String prefix)
Transforms the wrapped configuration into a dom4j document. |
Document |
getDocument(String prefix,
String rootName)
Transforms the wrapped configuration into a dom4j document. |
Document |
getW3cDocument()
Transforms the wrapped configuration into a w3c document. |
Document |
getW3cDocument(String prefix)
Transforms the wrapped configuration into a w3c document. |
Document |
getW3cDocument(String prefix,
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(Digester digester)
Initializes the default digester instance used for simple object creation. |
void |
write(Writer out)
Writes the wrapped configuration to the given writer. |
void |
write(Writer out,
boolean pretty)
Writes the wrapped configuration to the given writer. |
void |
write(Writer out,
String prefix)
Writes a configuration (or parts of it) to the given writer. |
void |
write(Writer out,
String prefix,
boolean pretty)
Writes a configuration (or parts of it) to the given writer. |
void |
write(Writer out,
String prefix,
String root)
Writes a configuration (or parts of it) to the given writer. |
void |
write(Writer out,
String prefix,
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 String ELEM_CLASS
protected static final String ELEM_PROPERTY
protected static final String ATTR_NAME
protected static final String ATTR_VALUE
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(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 Document getDocument(String prefix, String rootName) throws 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
DocumentException
- if an error occurspublic Document getDocument(String prefix) throws DocumentException
prefix
- a prefix for the keys to process; can be null,
then all keys in the configuration will be added to the document
DocumentException
- if an error occurspublic Document getDocument() throws DocumentException
DocumentException
- if an error occurspublic Document getW3cDocument(String prefix, String rootName) throws 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
DocumentException
- if an error occurspublic Document getW3cDocument(String prefix) throws DocumentException
prefix
- a prefix for the keys to process; can be null,
then all keys in the configuration will be added to the document
DocumentException
- if an error occurspublic Document getW3cDocument() throws DocumentException
DocumentException
- if an error occurspublic Object callDigester(String prefix) throws IOException, 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
IOException
- if an IOException occurs
SAXException
- if a SAXException occursprotected Digester getDefaultDigester(String prefix)
prefix
- the prefix of the keys to be processed; can be
null, then the whole configuration is meant
protected Digester createDefaultDigester(String prefix)
getDefaultDigester()
.
prefix
- the prefix of the keys to be processed; can be
null, then the whole configuration is meant
protected void setupDefaultDigester(Digester digester)
callDigester()
methods.
digester
- the digester instance to be initializedpublic void write(Writer out, String prefix, String root, boolean pretty) throws IOException, 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
IOException
- if an IO error occurs
DocumentException
- if there is an error during processingpublic void write(Writer out, String prefix, String root) throws IOException, 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
IOException
- if an IO error occurs
DocumentException
- if there is an error during processingpublic void write(Writer out, String prefix, boolean pretty) throws IOException, 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
IOException
- if an IO error occurs
DocumentException
- if there is an error during processingpublic void write(Writer out, String prefix) throws IOException, DocumentException
out
- the output writerprefix
- the prefix of the subset to write; if null, the
whole configuration is written
IOException
- if an IO error occurs
DocumentException
- if there is an error during processingpublic void write(Writer out, boolean pretty) throws IOException, DocumentException
out
- the output writerpretty
- flag for the pretty print mode
IOException
- if an IO error occurs
DocumentException
- if there is an error during processingpublic void write(Writer out) throws IOException, DocumentException
out
- the output writer
IOException
- if an IO error occurs
DocumentException
- if there is an error during processing
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |