nankin.zheng.gatem.model
Class DOMTree

java.lang.Object
  |
  +--nankin.zheng.gatem.model.DOMTree

class DOMTree
extends java.lang.Object

DOMTree supports some frequently-used operations on an org.w3c.dom.Node object. It uses org.w3c.dom.Node and org.w3c.dom.NodeList as its proxy.

NOTE: this class is planned to be replaced by Apache Jakarta Commons Digester package.

Version:
1.0 (to be deprecated), Date 2003-04-14
Author:
ZHENG Zhong

Field Summary
private  org.w3c.dom.Node root
          The root of the current subtree.
 
Constructor Summary
  DOMTree(java.io.InputStream fin)
          Constructor, read and parse an xml file to a tree.
private DOMTree(org.w3c.dom.Node node)
          Private constructor, create a DOMTree object directly by root.
 
Method Summary
 DOMTree getElement(int index, java.lang.String tagname)
          Get by index the element with the given tag name.
 int getElementCount(java.lang.String tagname)
          How many elements (of the given tag name) are there among its all direct children.
 java.lang.String getTextValue()
          Get the first text value of the node.
private  boolean isElement(org.w3c.dom.Node node, java.lang.String tagname)
          Whether the node is an element (with a given tag name).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

root

private org.w3c.dom.Node root
The root of the current subtree.

Constructor Detail

DOMTree

public DOMTree(java.io.InputStream fin)
        throws GameException
Constructor, read and parse an xml file to a tree.

Throws:
GameException - if any IO or parse error occured.

DOMTree

private DOMTree(org.w3c.dom.Node node)
         throws GameException
Private constructor, create a DOMTree object directly by root.

Throws:
GameException - if node is null.
Method Detail

isElement

private boolean isElement(org.w3c.dom.Node node,
                          java.lang.String tagname)
Whether the node is an element (with a given tag name).

Parameters:
node - node to be verified.
tagname - tag name to be verified (null means that tag name will not be verified).
Returns:
true if node is an element, having the given tag name (if tagname!=null).

getElementCount

public int getElementCount(java.lang.String tagname)
How many elements (of the given tag name) are there among its all direct children.

Parameters:
tagname - tag name of the element (null means that tag name will not be verified).
Returns:
count of elements.

getElement

public DOMTree getElement(int index,
                          java.lang.String tagname)
                   throws GameException
Get by index the element with the given tag name.

NOTE that this method will never return null.

Parameters:
index - index of elements.
tagname - tag name.
Returns:
a DOM tree whose root is the expected element.
Throws:
GameException - if index is out of bound or element is not found.

getTextValue

public java.lang.String getTextValue()
Get the first text value of the node.

Returns:
text value, and NOTE that null will never be returned.