Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

hk.hku.cecid.phoenix.common.util
Class XMLProperty  view XMLProperty download XMLProperty.java

java.lang.Object
  extended byhk.hku.cecid.phoenix.common.util.Property
      extended byhk.hku.cecid.phoenix.common.util.XMLProperty

public class XMLProperty
extends Property

This is a concrete implementation of the property object for loading and saving the property content into a XML-based file. The file is assumed to be rooted by a "Property" element. And the get/set path is simplified XPath, with "/" as separator. For example, a path of "A/B/C" and value of "test" creates a tree like:

<Property>
   <A>
   <B>
     <C>test</C>
   </B>
  </A>
</Property>

Version:
$Revision: 1.9 $

Field Summary
protected  org.jdom.Document doc
          Internal variable for holding the DOM tree of the XML property object
protected  java.lang.String fileName
          Internal variable for holding the file name of the property file
 
Fields inherited from class hk.hku.cecid.phoenix.common.util.Property
cache, DEFAULT_FILENAME, PROP_HOME
 
Constructor Summary
  XMLProperty()
          Default constructor.
(package private) XMLProperty(java.lang.String fileName)
          Internal constructor.
 
Method Summary
 java.lang.String get(java.lang.String path)
          Gets the property value given the path (key).
 java.lang.String get(java.lang.String path, java.lang.String defaultValue)
          Gets the property value given the path (key).
protected  org.jdom.Element getChildElement(org.jdom.Element parent, java.lang.String token)
          Gets the child element of the specified element, with the specified node name.
 java.lang.String[] getMultiple(java.lang.String path)
          Gets the property value given the path (key).
 void reload()
          Reloads the property file.
 void save()
          Saves the property object to the same location when loading.
 void save(java.lang.String fileName)
          Saves the property object to the specified location.
 void set(java.lang.String path, java.lang.String value)
          Sets the property value of the given path (key).
 
Methods inherited from class hk.hku.cecid.phoenix.common.util.Property
getFromCache, load, load, loadFromFullPath, reload, removeFromCache, saveToCache
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fileName

protected java.lang.String fileName
Internal variable for holding the file name of the property file


doc

protected org.jdom.Document doc
Internal variable for holding the DOM tree of the XML property object

Constructor Detail

XMLProperty

XMLProperty(java.lang.String fileName)
      throws java.io.IOException
Internal constructor. Not to be called by user. This loads the content of the specified property file into memory.


XMLProperty

public XMLProperty()
Default constructor. This is for creating a brand new XML-based property object.

Method Detail

reload

public void reload()
Reloads the property file.

Overrides:
reload in class Property

getMultiple

public java.lang.String[] getMultiple(java.lang.String path)
Gets the property value given the path (key). Multiple values are referenced by the same path will be returned using a String array. Multiple values are searched only at leaf nodes.

Specified by:
getMultiple in class Property

get

public java.lang.String get(java.lang.String path)
Gets the property value given the path (key).

Specified by:
get in class Property

get

public java.lang.String get(java.lang.String path,
                            java.lang.String defaultValue)
Gets the property value given the path (key). If the property value is not found, the default value passed in is returned.

Specified by:
get in class Property

set

public void set(java.lang.String path,
                java.lang.String value)
Sets the property value of the given path (key).

Specified by:
set in class Property

save

public void save()
          throws java.io.IOException
Saves the property object to the same location when loading.

Specified by:
save in class Property

save

public void save(java.lang.String fileName)
          throws java.io.IOException
Saves the property object to the specified location.

Specified by:
save in class Property

getChildElement

protected org.jdom.Element getChildElement(org.jdom.Element parent,
                                           java.lang.String token)
Gets the child element of the specified element, with the specified node name. The node name supports getting the nth child by using node-name[n]. If there is anything wrong when parsing the node name, we will use abandon the parsing and fall back to assume the whole specified string as node name.