ptolemy.backtrack.xmlparser
Class ConfigXmlTree

java.lang.Object
  extended by ptolemy.backtrack.xmlparser.ConfigXmlTree
All Implemented Interfaces:
java.lang.Cloneable

public class ConfigXmlTree
extends java.lang.Object
implements java.lang.Cloneable

Tree representation of XML starting from an element.

Since:
Ptolemy II 5.1
Version:
$Id: ConfigXmlTree.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Thomas Feng
Accepted Rating:
Red (tfeng)
Proposed Rating:
Red (tfeng)

Field Summary
private  java.util.Hashtable<java.lang.String,java.lang.String> _attributes
          The hash table of attributes from their names to their values.
private  java.util.Vector<ConfigXmlTree> _children
          The list of children.
private  java.lang.String _elementName
          The name of this XML element.
private  java.util.Iterator<ConfigXmlTree> _iterator
          The iterator used to iterate the children of this node.
private  ConfigXmlTree _parent
          The parent of this node. null if this node is the root node of the XML document.
 
Constructor Summary
ConfigXmlTree(java.lang.String elementName)
          Construct a node in the tree with no child.
 
Method Summary
protected  void _dump(int indent, java.io.PrintStream stream)
          Print the content of the sub-tree starting from this node to the given output stream in a text format.
private  void _dumpString(int indent, java.lang.String s, java.io.PrintStream stream)
          Print a string to the given output stream in a text format.
protected  void _setElementName(java.lang.String elementName)
          Set the name of this XML element.
protected  void _setParent(ConfigXmlTree parent)
          Set the parent of this XML node.
 void addChild(ConfigXmlTree child)
          Add a child to this node.
 java.lang.Object clone()
          Clone the sub-tree starting from this node, and return the clone result.
 void dump(java.io.PrintStream stream)
          Print the content of the sub-tree starting from this node to the given output stream in a text format.
 java.lang.String getAttribute(java.lang.String name)
          Get the value of the attribute with the given name.
 java.util.Enumeration<java.lang.String> getAttributeNames()
          Get the names of all the attributes of this XML element.
 java.lang.String getElementName()
          Get the name of this XML element.
 ConfigXmlTree getParent()
          Get the parent of this node.
 boolean hasAttribute(java.lang.String name)
          Test whether this node has an attribute with the given name.
 boolean hasMoreChildren()
          Test whether there are more children to traverse.
 boolean isLeaf()
          Test whether this node is a leaf in the XML tree.
 ConfigXmlTree nextChild()
          Return the next child to be traversed.
 void setAttribute(java.lang.String name, java.lang.String value)
          Set the value of the attribute with the given name.
 void startTraverseChildren()
          Start traversing the children of this node by initializing the internal iterator.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_attributes

private java.util.Hashtable<java.lang.String,java.lang.String> _attributes
The hash table of attributes from their names to their values.


_children

private java.util.Vector<ConfigXmlTree> _children
The list of children.


_elementName

private java.lang.String _elementName
The name of this XML element.


_iterator

private java.util.Iterator<ConfigXmlTree> _iterator
The iterator used to iterate the children of this node.


_parent

private ConfigXmlTree _parent
The parent of this node. null if this node is the root node of the XML document.

Constructor Detail

ConfigXmlTree

public ConfigXmlTree(java.lang.String elementName)
Construct a node in the tree with no child.

Parameters:
elementName - The XML element name of the node.
Method Detail

addChild

public void addChild(ConfigXmlTree child)
Add a child to this node. This child will be added after the existing children.

Parameters:
child - The child to be added.

clone

public java.lang.Object clone()
Clone the sub-tree starting from this node, and return the clone result.

Overrides:
clone in class java.lang.Object
Returns:
A clone of the sub-tree.

dump

public void dump(java.io.PrintStream stream)
Print the content of the sub-tree starting from this node to the given output stream in a text format.

Parameters:
stream - The stream to be printed to.

getAttribute

public java.lang.String getAttribute(java.lang.String name)
Get the value of the attribute with the given name.

Parameters:
name - The attribute name.
Returns:
The value of the attribute, or null if not found.
See Also:
setAttribute(String, String)

getAttributeNames

public java.util.Enumeration<java.lang.String> getAttributeNames()
Get the names of all the attributes of this XML element.

Returns:
The enumeration of attribute names.

getElementName

public java.lang.String getElementName()
Get the name of this XML element.

Returns:
The element name.

getParent

public ConfigXmlTree getParent()
Get the parent of this node.

Returns:
The parent, or null.

hasAttribute

public boolean hasAttribute(java.lang.String name)
Test whether this node has an attribute with the given name.

Parameters:
name - The attribute name.
Returns:
true if this node has an attribute with the name; false, otherwise.

hasMoreChildren

public boolean hasMoreChildren()
Test whether there are more children to traverse.

Returns:
true if there are more children to traverse; false, otherwise.
See Also:
nextChild(), startTraverseChildren()

isLeaf

public boolean isLeaf()
Test whether this node is a leaf in the XML tree.

Returns:
true if this node is a leaf; false, otherwise.

nextChild

public ConfigXmlTree nextChild()
Return the next child to be traversed.

Returns:
The next child.
See Also:
hasMoreChildren(), startTraverseChildren()

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.String value)
Set the value of the attribute with the given name. Create the attribute if it does not exist yet.

Parameters:
name - The attribute name.
value - The attribute value.
See Also:
getAttribute(String)

startTraverseChildren

public void startTraverseChildren()
Start traversing the children of this node by initializing the internal iterator.

See Also:
hasMoreChildren(), nextChild()

_dump

protected void _dump(int indent,
                     java.io.PrintStream stream)
Print the content of the sub-tree starting from this node to the given output stream in a text format. The sub-tree is indented with the specified amount.

Parameters:
indent - The amount of indentation.
stream - The stream to be printed to.

_setElementName

protected void _setElementName(java.lang.String elementName)
Set the name of this XML element.

Parameters:
elementName - The element name.

_setParent

protected void _setParent(ConfigXmlTree parent)
Set the parent of this XML node. This method does not update the parent's children list. To add this node to be one of the parent's children, use addChild(ConfigXmlTree) of the parent.

Parameters:
parent - The parent node.

_dumpString

private void _dumpString(int indent,
                         java.lang.String s,
                         java.io.PrintStream stream)
Print a string to the given output stream in a text format. The string is indented with the specified amount.

Parameters:
indent - The amount of indentation.
s - The string to be printed.
stream - The stream to be printed to.