edu.ucsb.nceas.morpho.framework
Class ConfigXML

java.lang.Object
  |
  +--edu.ucsb.nceas.morpho.framework.ConfigXML

public class ConfigXML
extends java.lang.Object

This class is designed to store configuration information in an XML file. The concept is similar to that of a Properties file except that using the XML format allows for a hierarchy of properties and repeated properties. All 'keys' are element names, while values are always stored as XML text nodes. The XML file is parsed and stored in memory as a DOM object. Note that nodes are specified by node tags rather than paths


Constructor Summary
ConfigXML(java.io.InputStream configStream)
          String passed to the creator is the XML config file name
ConfigXML(java.lang.String filename)
          String passed to the creator is the XML config file name
 
Method Summary
 void addChild(java.lang.String parentName, int i, java.lang.String childName, java.lang.String value)
          Add a child node to the specified parent
 java.util.Vector get(java.lang.String key)
          Gets the value(s) corresponding to a key string (i.e.
 java.lang.String get(java.lang.String key, int i)
          Gets the value(s) corresponding to a key string (i.e.
static java.lang.String getConfigDirectory()
          Determine the home directory in which configuration files should be located
 java.util.Hashtable getHashtable(java.lang.String parentName, java.lang.String keyName, java.lang.String valueName)
          Assume that there is some parent node which has a subset of child nodes that are repeated e.g.
 org.w3c.dom.NodeList getPathContent(java.lang.String path)
          gets the content of a tag in a given xml file with the given path
 java.util.Vector getValuesForPath(java.lang.String pathstring)
           
 boolean insert(java.lang.String key, java.lang.String value)
          Inserts another node before the first element with the name contained in 'key', otherwise appends it to the end of the config file (last element in root node)
 void print(org.w3c.dom.Node node)
          This method can 'print' any DOM subtree.
 void removeChildren(java.lang.String parentName, int i)
          removes all children of the specified parent
 void removeNode(java.lang.String nodeName, int i)
          deletes indicated node
 void save()
          Save the configuration file
 void saveDOM(org.w3c.dom.Node nd)
          This method wraps the 'print' method to send DOM back to the XML document (file) that was used to create the DOM.
 boolean set(java.lang.String key, int i, java.lang.String value)
          used to set a value corresponding to 'key'; value is changed in DOM structure in memory
protected  org.w3c.dom.Attr[] sortAttributes(org.w3c.dom.NamedNodeMap attrs)
          Returns a sorted list of attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConfigXML

public ConfigXML(java.lang.String filename)
          throws java.io.FileNotFoundException
String passed to the creator is the XML config file name
Parameters:
filename - name of XML file

ConfigXML

public ConfigXML(java.io.InputStream configStream)
          throws java.io.FileNotFoundException
String passed to the creator is the XML config file name
Parameters:
input - stream containing the XML configuration data
Method Detail

get

public java.util.Vector get(java.lang.String key)
Gets the value(s) corresponding to a key string (i.e. the value(s) for a named parameter.
Parameters:
key - 'key' is element name.
Returns:
Returns a Vector of strings because may have repeated elements

get

public java.lang.String get(java.lang.String key,
                            int i)
Gets the value(s) corresponding to a key string (i.e. the value(s) for a named parameter.
Parameters:
key - 'key' is element name.
i - zero based index of elements with the name stored in key
Returns:
String value of the ith element with name in 'key'

set

public boolean set(java.lang.String key,
                   int i,
                   java.lang.String value)
used to set a value corresponding to 'key'; value is changed in DOM structure in memory
Parameters:
key - 'key' is element name.
i - index in set of elements with 'key' name
value - new value to be inserted in ith key
Returns:
boolean true if the operation succeeded

insert

public boolean insert(java.lang.String key,
                      java.lang.String value)
Inserts another node before the first element with the name contained in 'key', otherwise appends it to the end of the config file (last element in root node)
Parameters:
key - element name which will be duplicated
value - value for new element
Returns:
boolean true if the operation succeeded

addChild

public void addChild(java.lang.String parentName,
                     int i,
                     java.lang.String childName,
                     java.lang.String value)
Add a child node to the specified parent
Parameters:
parentName - name of parent element
i - index of parent element
childName - element name of new child
value - value of new child

removeNode

public void removeNode(java.lang.String nodeName,
                       int i)
deletes indicated node
Parameters:
nodeName - node tag
i - node index

removeChildren

public void removeChildren(java.lang.String parentName,
                           int i)
removes all children of the specified parent
Parameters:
parentName - Name of parent node
i - index of parent node

getHashtable

public java.util.Hashtable getHashtable(java.lang.String parentName,
                                        java.lang.String keyName,
                                        java.lang.String valueName)
Assume that there is some parent node which has a subset of child nodes that are repeated e.g. xxx qqq yyy www ... this method will return a Hashtable of names-values of parent

save

public void save()
Save the configuration file

saveDOM

public void saveDOM(org.w3c.dom.Node nd)
This method wraps the 'print' method to send DOM back to the XML document (file) that was used to create the DOM. i.e. this method saves changes to disk
Parameters:
nd - node (usually the document root)

print

public void print(org.w3c.dom.Node node)
This method can 'print' any DOM subtree. Specifically it is set (by means of 'out') to write the in-memory DOM to the same XML file that was originally read. Action thus saves a new version of the XML doc
Parameters:
node - node usually set to the 'doc' node for complete XML file re-write

sortAttributes

protected org.w3c.dom.Attr[] sortAttributes(org.w3c.dom.NamedNodeMap attrs)
Returns a sorted list of attributes.

getValuesForPath

public java.util.Vector getValuesForPath(java.lang.String pathstring)

getPathContent

public org.w3c.dom.NodeList getPathContent(java.lang.String path)
gets the content of a tag in a given xml file with the given path
Parameters:
path - the path to get the content from

getConfigDirectory

public static java.lang.String getConfigDirectory()
Determine the home directory in which configuration files should be located


Copyright © 2000 National Center for Ecological Analysis and Synthesis. All Rights Reserved.