org.planx.xmlstore.docnodes
Class DocNode

java.lang.Object
  extended by org.planx.xmlstore.docnodes.DocNode
All Implemented Interfaces:
Node

public class DocNode
extends Object
implements Node

DocNode is an occurrence of a Node in a document. DocNode provides the ability to locate the parent, root, and siblings of a node. A DocNode object is unique in an instance of a document with respect to the Object.equals(Object) and Object.hashCode() methods. Note, however, that if a document is created multiple times using the same root Node, the documents are considered to be distinct and each document will have its own set of DocNode objects.

Author:
Thomas Ambus

Field Summary
 
Fields inherited from interface org.planx.xmlstore.Node
CHARDATA, ELEMENT
 
Constructor Summary
DocNode(Node node)
          Create a DocNode which is the root of a document.
 
Method Summary
 int attributeCount()
          Returns the number of attributes of this node.
 int childCount()
          Returns the number of children of this node.
 DocAttribute getAttribute(int index)
          Returns the attribute with the specified index.
 String getAttribute(String attrName)
          Returns the attribute with the given name.
 String[] getAttributeNames()
          Returns the names of this Node's attributes.
 List<Attribute> getAttributes()
          Returns the attributes of this Node.
 DocNode getChild(int index)
          Returns the child with the specified index.
 List<? extends Node> getChildren()
          Returns the children of this Node.
 List<DocAttribute> getDocAttributes()
           
 List<DocNode> getDocChildren()
          Returns a list that contains the children of this node as DocNodes.
 int getIndex()
          Returns the index of this node in the parent's list of children.
 String getNodeValue()
          Returns the value of this Node.
 DocNode getParent()
          Returns the parent DocNode of this DocNode.
 int[] getPath()
          Returns an integer array containing the path from the root to this node.
 DocNode getRoot()
          Returns the root DocNode of the document that contains this DocNode.
 byte getType()
          Returns the node type of this Node.
 boolean isMutable()
          Returns true if this Node is mutable, false otherwise.
 DocNode nextSibling()
          Returns the sibling node immediately following this node.
 DocNode previousSibling()
          Returns the sibling node immediately preceding this node.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.planx.xmlstore.Node
equals, hashCode
 

Constructor Detail

DocNode

public DocNode(Node node)
Create a DocNode which is the root of a document.

Parameters:
node - the DVM Node
Method Detail

getPath

public int[] getPath()
Returns an integer array containing the path from the root to this node. The integers represent the child indexes of each node from the root to this node.


getRoot

public DocNode getRoot()
Returns the root DocNode of the document that contains this DocNode.


getParent

public DocNode getParent()
Returns the parent DocNode of this DocNode. If there is no parent, i.e. this is the root then null is returned.


getIndex

public int getIndex()
Returns the index of this node in the parent's list of children. If this node does not have a parent, i.e. this is the root, then -1 is returned.


getChild

public DocNode getChild(int index)
Returns the child with the specified index.


childCount

public int childCount()
Returns the number of children of this node.


getDocChildren

public List<DocNode> getDocChildren()
Returns a list that contains the children of this node as DocNodes.


nextSibling

public DocNode nextSibling()
Returns the sibling node immediately following this node. If there is no such node, this returns null.


previousSibling

public DocNode previousSibling()
Returns the sibling node immediately preceding this node. If there is no such node, this returns null.


attributeCount

public int attributeCount()
Returns the number of attributes of this node.


getAttribute

public DocAttribute getAttribute(int index)
Returns the attribute with the specified index. The indexing is merely for convenience, it does not imply a specific ordering of the attributes.


getDocAttributes

public List<DocAttribute> getDocAttributes()

isMutable

public boolean isMutable()
Description copied from interface: Node
Returns true if this Node is mutable, false otherwise.

Specified by:
isMutable in interface Node
Returns:
true if mutable, false if immutable.

getType

public byte getType()
Description copied from interface: Node
Returns the node type of this Node.

Specified by:
getType in interface Node
Returns:
The node type

getNodeValue

public String getNodeValue()
Description copied from interface: Node
Returns the value of this Node. When the node represents a character data node, the returned value will be the character data. When the node represents an element node, the returned value will by the tag name of the element.

Specified by:
getNodeValue in interface Node
Returns:
The node value.

getAttribute

public String getAttribute(String attrName)
Description copied from interface: Node
Returns the attribute with the given name. In case the node represents a character data node the returned value is null.

Specified by:
getAttribute in interface Node
Returns:
The attribute named by the argument.

getAttributeNames

public String[] getAttributeNames()
Description copied from interface: Node
Returns the names of this Node's attributes. If the node represents character data the returned array is empty.

Specified by:
getAttributeNames in interface Node
Returns:
The attribute names of the node.

getChildren

public List<? extends Node> getChildren()
Description copied from interface: Node
Returns the children of this Node. If the node represents character data the empty list is returned.

Specified by:
getChildren in interface Node
Returns:
An immutable list of the children of this Node.

getAttributes

public List<Attribute> getAttributes()
Description copied from interface: Node
Returns the attributes of this Node. In case the node represents character data, the empty list is returned.

Specified by:
getAttributes in interface Node
Returns:
An immutable list of the attributes of this Node.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2010. All Rights Reserved.