|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.configuration.AbstractConfiguration
org.apache.commons.configuration.BaseConfiguration
org.apache.commons.configuration.BasePathConfiguration
org.apache.commons.configuration.XMLConfiguration
org.apache.commons.configuration.DOM4JConfiguration
Reads a XML configuration file.
To retrieve the value of an attribute of an element, use
X.Y.Z[@attribute]
. The '@' symbol was chosen for
consistency with XPath.
Setting property values will NOT automatically persist
changes to disk, unless autoSave=true
.
Nested Class Summary |
Nested classes inherited from class org.apache.commons.configuration.AbstractConfiguration |
AbstractConfiguration.Container, AbstractConfiguration.PropertiesTokenizer |
Field Summary | |
private static char |
ATTRIB_MARKER
|
private static java.lang.String |
ATTRIB_START_MARKER
|
private boolean |
autoSave
If true, modifications are immediately persisted. |
private org.dom4j.Document |
document
The XML document from our data source. |
private java.lang.String |
fileName
A handle to our data source. |
private static java.lang.String |
NODE_DELIMITER
For consistency with properties files. |
Fields inherited from class org.apache.commons.configuration.BasePathConfiguration |
|
Fields inherited from class org.apache.commons.configuration.BaseConfiguration |
|
Fields inherited from class org.apache.commons.configuration.AbstractConfiguration |
defaults, END_TOKEN, START_TOKEN |
Constructor Summary | |
DOM4JConfiguration()
Empty construtor. |
|
DOM4JConfiguration(java.io.File file)
Attempts to load the XML file. |
|
DOM4JConfiguration(java.lang.String resource)
Attempts to load the XML file as a resource from the classpath. |
Method Summary | |
void |
addProperty(java.lang.String name,
java.lang.Object value)
Calls super method, and also ensures the underlying Document is modified so changes are persisted when saved. |
void |
clearProperty(java.lang.String name)
Calls super method, and also ensures the underlying Document is modified so changes are persisted when saved. |
private void |
clearXmlProperty(java.lang.String name)
|
java.io.File |
getFile()
Returns the file. |
java.lang.String |
getFileName()
Returns the fileName. |
private void |
initProperties(org.dom4j.Element element,
java.lang.StringBuffer hierarchy)
Loads and initializes from the XML file. |
void |
load()
|
private void |
possiblySave()
|
private static java.io.File |
resourceURLToFile(java.lang.String resource)
|
void |
save()
|
void |
setAutoSave(boolean autoSave)
If true, changes are automatically persisted. |
void |
setFile(java.io.File file)
Sets the file. |
void |
setFileName(java.lang.String fileName)
|
void |
setProperty(java.lang.String name,
java.lang.Object value)
Calls super method, and also ensures the underlying Document is modified so changes are persisted when saved. |
private void |
setXmlProperty(java.lang.String name,
java.lang.Object value)
Sets the property value in our document tree, auto-saving if appropriate. |
Methods inherited from class org.apache.commons.configuration.BasePathConfiguration |
getBasePath, setBasePath |
Methods inherited from class org.apache.commons.configuration.BaseConfiguration |
addPropertyDirect, containsKey, getKeys, getPropertyDirect, isEmpty |
Methods inherited from class org.apache.commons.configuration.AbstractConfiguration |
getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getDouble, getDouble, getDouble, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getKeys, getList, getList, getLong, getLong, getLong, getProperties, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, interpolate, interpolateHelper, processString, subset, testBoolean |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final char ATTRIB_MARKER
private static final java.lang.String ATTRIB_START_MARKER
private static final java.lang.String NODE_DELIMITER
private java.lang.String fileName
private org.dom4j.Document document
private boolean autoSave
Constructor Detail |
public DOM4JConfiguration()
public DOM4JConfiguration(java.lang.String resource) throws java.lang.Exception
resource
- Name of the resource
java.lang.Exception
- If error reading data source.DOM4JConfiguration(File)
public DOM4JConfiguration(java.io.File file) throws java.lang.Exception
file
- File object representing the XML file.
java.lang.Exception
- If error reading data source.Method Detail |
public void load() throws java.lang.Exception
java.lang.Exception
private static java.io.File resourceURLToFile(java.lang.String resource)
private void initProperties(org.dom4j.Element element, java.lang.StringBuffer hierarchy)
element
- The element to start processing from. Callers
should supply the root element of the document.hierarchy
- public void addProperty(java.lang.String name, java.lang.Object value)
Document
is modified so changes are persisted when saved.
addProperty
in interface Configuration
addProperty
in class AbstractConfiguration
name
- value
- public void setProperty(java.lang.String name, java.lang.Object value)
Document
is modified so changes are persisted when saved.
setProperty
in interface Configuration
setProperty
in class AbstractConfiguration
name
- value
- private void setXmlProperty(java.lang.String name, java.lang.Object value)
name
- The name of the element to set a value for.value
- The value to set.public void clearProperty(java.lang.String name)
Document
is modified so changes are persisted when saved.
clearProperty
in interface Configuration
clearProperty
in class BaseConfiguration
name
- The name of the property to clear.private void clearXmlProperty(java.lang.String name)
private void possiblySave()
public void setAutoSave(boolean autoSave)
autoSave
- public void save() throws java.io.IOException
java.io.IOException
public java.io.File getFile()
public void setFile(java.io.File file)
file
- The file to setpublic void setFileName(java.lang.String fileName)
public java.lang.String getFileName()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |