org.eclipse.ercp.xml.dom
Class TreeNode

java.lang.Object
  extended by org.eclipse.ercp.xml.dom.NodeImpl
      extended by org.eclipse.ercp.xml.dom.NSNodeImpl
          extended by org.eclipse.ercp.xml.dom.TreeNode
All Implemented Interfaces:
Node, NodeList
Direct Known Subclasses:
CharacterDataImpl, DocumentImpl, ElementImpl

public abstract class TreeNode
extends NSNodeImpl

Support previous and next siblings


Field Summary
protected  TreeNode firstChild
           
protected  TreeNode lastChild
           
protected  int length
           
protected  TreeNode nextSibling
           
protected  TreeNode parentNode
           
protected  TreeNode previousSibling
           
 
Fields inherited from class org.eclipse.ercp.xml.dom.NSNodeImpl
localName, namespaceURI, prefix, qualifiedName
 
Fields inherited from class org.eclipse.ercp.xml.dom.NodeImpl
ownerDocument
 
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
Constructor Summary
TreeNode(DocumentImpl ownerDocument)
          Constructor for SiblingNode
TreeNode(DocumentImpl ownerDocument, java.lang.String qualifiedName)
           
TreeNode(DocumentImpl ownerDocument, java.lang.String namespaceURI, java.lang.String qualifiedName)
           
 
Method Summary
 Node appendChild(Node newChild)
          Adds the node newChild to the end of the list of children of this node.
protected  void getElementByTagName(java.lang.String name, NodeListImpl list)
           
 NodeList getElementsByTagName(java.lang.String name)
          Returns a NodeList of all descendant Elements with a given tag name, in the order in which they are encountered in a preorder traversal of this Element tree.
 NodeList getElementsByTagNameNS(java.lang.String namespaceURI, java.lang.String localName)
          Returns a NodeList of all the descendant Elements with a given local name and namespace URI in the order in which they are encountered in a preorder traversal of this Element tree.
 Node getFirstChild()
          The first child of this node.
 Node getLastChild()
          The last child of this node.
 int getLength()
          The number of nodes in the list.
 Node getNextSibling()
          The node immediately following this node.
 Node getParentNode()
          The parent of this node.
 Node getPreviousSibling()
          The node immediately preceding this node.
 boolean hasChildNodes()
          Returns whether this node has any children.
 Node insertBefore(Node newChild, Node refChild)
          Inserts the node newChild before the existing child node refChild.
 Node item(int index)
          Returns the indexth item in the collection.
 void normalize()
          Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes.
 Node removeChild(Node oldChild)
          Removes the child node indicated by oldChild from the list of children, and returns it.
 Node replaceChild(Node newChild, Node oldChild)
          Replaces the child node oldChild with newChild in the list of children, and returns the oldChild node.
 
Methods inherited from class org.eclipse.ercp.xml.dom.NSNodeImpl
getLocalName, getNamespaceURI, getNodeName, getPrefix, setPrefix
 
Methods inherited from class org.eclipse.ercp.xml.dom.NodeImpl
getAttributes, getChildNodes, getNodeValue, getOwnerDocument, hasAttributes, isSupported, setNodeValue, spreadOwnerDocument
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.w3c.dom.Node
cloneNode, getNodeType
 

Field Detail

nextSibling

protected TreeNode nextSibling

previousSibling

protected TreeNode previousSibling

parentNode

protected TreeNode parentNode

firstChild

protected TreeNode firstChild

lastChild

protected TreeNode lastChild

length

protected int length
Constructor Detail

TreeNode

public TreeNode(DocumentImpl ownerDocument)
Constructor for SiblingNode


TreeNode

public TreeNode(DocumentImpl ownerDocument,
                java.lang.String qualifiedName)

TreeNode

public TreeNode(DocumentImpl ownerDocument,
                java.lang.String namespaceURI,
                java.lang.String qualifiedName)
Method Detail

insertBefore

public Node insertBefore(Node newChild,
                         Node refChild)
                  throws DOMException
Inserts the node newChild before the existing child node refChild. If refChild is null, insert newChild at the end of the list of children.
If newChild is a DocumentFragment object, all of its children are inserted, in the same order, before refChild. If the newChild is already in the tree, it is first removed.

Specified by:
insertBefore in interface Node
Overrides:
insertBefore in class NodeImpl
Parameters:
newChildThe - node to insert.
refChildThe - reference node, i.e., the node before which the new node must be inserted.
Returns:
The node being inserted.
Throws:
DOMException - HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow children of the type of the newChild node, or if the node to insert is one of this node's ancestors.
WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the one that created this node.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly or if the parent of the node being inserted is readonly.
NOT_FOUND_ERR: Raised if refChild is not a child of this node.

removeChild

public Node removeChild(Node oldChild)
                 throws DOMException
Removes the child node indicated by oldChild from the list of children, and returns it.

Specified by:
removeChild in interface Node
Overrides:
removeChild in class NodeImpl
Parameters:
oldChildThe - node being removed.
Returns:
The node removed.
Throws:
DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
NOT_FOUND_ERR: Raised if oldChild is not a child of this node.

appendChild

public Node appendChild(Node newChild)
                 throws DOMException
Adds the node newChild to the end of the list of children of this node. If the newChild is already in the tree, it is first removed.

Specified by:
appendChild in interface Node
Overrides:
appendChild in class NodeImpl
Parameters:
newChildThe - node to add.If it is a DocumentFragment object, the entire contents of the document fragment are moved into the child list of this node
Returns:
The node added.
Throws:
DOMException - HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow children of the type of the newChild node, or if the node to append is one of this node's ancestors.
WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the one that created this node.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.

replaceChild

public Node replaceChild(Node newChild,
                         Node oldChild)
                  throws DOMException
Replaces the child node oldChild with newChild in the list of children, and returns the oldChild node.
If newChild is a DocumentFragment object, oldChild is replaced by all of the DocumentFragment children, which are inserted in the same order. If the newChild is already in the tree, it is first removed.

Specified by:
replaceChild in interface Node
Overrides:
replaceChild in class NodeImpl
Parameters:
newChildThe - new node to put in the child list.
oldChildThe - node being replaced in the list.
Returns:
The node replaced.
Throws:
DOMException - HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow children of the type of the newChild node, or if the node to put in is one of this node's ancestors.
WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the one that created this node.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node or the parent of the new node is readonly.
NOT_FOUND_ERR: Raised if oldChild is not a child of this node.

getFirstChild

public Node getFirstChild()
The first child of this node. If there is no such node, this returns null.

Specified by:
getFirstChild in interface Node
Overrides:
getFirstChild in class NodeImpl

getLastChild

public Node getLastChild()
The last child of this node. If there is no such node, this returns null.

Specified by:
getLastChild in interface Node
Overrides:
getLastChild in class NodeImpl

getPreviousSibling

public Node getPreviousSibling()
The node immediately preceding this node. If there is no such node, this returns null.

Specified by:
getPreviousSibling in interface Node
Overrides:
getPreviousSibling in class NodeImpl

getNextSibling

public Node getNextSibling()
The node immediately following this node. If there is no such node, this returns null.

Specified by:
getNextSibling in interface Node
Overrides:
getNextSibling in class NodeImpl

hasChildNodes

public boolean hasChildNodes()
Returns whether this node has any children.

Specified by:
hasChildNodes in interface Node
Overrides:
hasChildNodes in class NodeImpl
Returns:
true if this node has any children, false otherwise.

getLength

public int getLength()
The number of nodes in the list. The range of valid child node indices is 0 to length-1 inclusive.

Specified by:
getLength in interface NodeList
Overrides:
getLength in class NodeImpl

getParentNode

public Node getParentNode()
The parent of this node. All nodes, except Attr, Document, DocumentFragment, Entity, and Notation may have a parent. However, if a node has just been created and not yet added to the tree, or if it has been removed from the tree, this is null.

Specified by:
getParentNode in interface Node
Overrides:
getParentNode in class NodeImpl

item

public Node item(int index)
Returns the indexth item in the collection. If index is greater than or equal to the number of nodes in the list, this returns null.

Specified by:
item in interface NodeList
Overrides:
item in class NodeImpl
Parameters:
index - Index into the collection.
Returns:
The node at the indexth position in the NodeList, or null if that is not a valid index.

getElementsByTagName

public NodeList getElementsByTagName(java.lang.String name)
Returns a NodeList of all descendant Elements with a given tag name, in the order in which they are encountered in a preorder traversal of this Element tree.

Parameters:
nameThe - name of the tag to match on. The special value "*" matches all tags.
Returns:
A list of matching Element nodes.

getElementByTagName

protected void getElementByTagName(java.lang.String name,
                                   NodeListImpl list)

getElementsByTagNameNS

public NodeList getElementsByTagNameNS(java.lang.String namespaceURI,
                                       java.lang.String localName)
Returns a NodeList of all the descendant Elements with a given local name and namespace URI in the order in which they are encountered in a preorder traversal of this Element tree.
HTML-only DOM implementations do not need to implement this method.

Parameters:
namespaceURIThe - namespace URI of the elements to match on. The special value "*" matches all namespaces.
localNameThe - local name of the elements to match on. The special value "*" matches all local names.
Returns:
A new NodeList object containing all the matched Elements.
Since:
DOM Level 2

normalize

public void normalize()
Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes. This can be used to ensure that the DOM view of a document is the same as if it were saved and re-loaded, and is useful when operations (such as XPointer lookups) that depend on a particular document tree structure are to be used.In cases where the document contains CDATASections, the normalize operation alone may not be sufficient, since XPointers do not differentiate between Text nodes and CDATASection nodes.

Specified by:
normalize in interface Node
Overrides:
normalize in class NodeImpl