EAF 7.6 Util

org.enhydra.xml
Class NodeImpl

java.lang.Object
  extended by org.enhydra.xml.NodeImpl
All Implemented Interfaces:
org.w3c.dom.Node, org.w3c.dom.NodeList
Direct Known Subclasses:
AttrImpl, CharacterDataImpl, ElementImpl

public class NodeImpl
extends java.lang.Object
implements org.w3c.dom.Node, org.w3c.dom.NodeList

Version:
1.0
Author:
Tweety A class representing a node in a meta-data tree, which implements the

Namespaces are ignored in this implementation. The terms "tag name" and "node name" are always considered to be synonymous.


Field Summary
protected  NodeImpl firstChild
          The first (leftmost) child node of this node, or null if this node is a leaf node.
protected  NodeImpl lastChild
          The last (rightmost) child node of this node, or null if this node is a leaf node.
protected  NodeImpl nextSibling
          The next (right) sibling node of this node, or null if this node is its parent's last child node.
protected  java.lang.String nodeName
          The name (tag) of the node as a String.
protected  java.lang.String nodeValue
          The value of the node as a String.
protected  int numChildren
          The number of child nodes.
protected  org.w3c.dom.Document ownerDocument
          Owner document.
protected  NodeImpl parent
          The parent node of this node, or null if this node forms the root of its own tree.
protected  NodeImpl previousSibling
          The previous (left) sibling node of this node, or null if this node is its parent's first child node.
protected  short type
          The type of the node as a short.
 
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
Constructor Summary
NodeImpl()
          Constructs an empty NodeImpl.
NodeImpl(org.w3c.dom.Document ownerDoc, java.lang.String name)
          Constructs a NodeImpl from the given document owner and node name.
NodeImpl(org.w3c.dom.Document ownerDoc, java.lang.String nodeName, short type)
          Constructs an NodeImpl from a given document owner, node name and node type.
NodeImpl(org.w3c.dom.Document ownerDoc, java.lang.String nodeName, short type, java.lang.String value)
          Constructs an NodeImpl from a given document owner, node name, node type and node value.
NodeImpl(org.w3c.dom.Node node)
          Constructs an NodeImpl from a given node (creates the children subtree too), as a Node
NodeImpl(org.w3c.dom.Node node, boolean deep)
          Constructs an NodeImpl from a given node, as a Node, and deep as boolean.
NodeImpl(NodeImpl node)
          Constructs a NodeImpl from the given node, without creating entire children subtree.
 
Method Summary
 org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild)
          Adds the node newChild to the end of the list of children of this node.
protected  void beginToString(java.lang.StringBuffer sb, Indent indent)
          Method beginToString should be redefined in extended classes.
 org.w3c.dom.Node cloneNode(boolean deep)
          Returns a duplicate of this node.
 short compareDocumentPosition(org.w3c.dom.Node arg0)
           
protected  void endToString(java.lang.StringBuffer sb, Indent indent)
          Method endToString should be redefined in extended classes.
 org.w3c.dom.NamedNodeMap getAttributes()
          Returns all attribute nodes of this node.
 java.lang.String getBaseURI()
           
 org.w3c.dom.NodeList getChildNodes()
          Returns all child nodes of this node, or null if the node has no children.
 java.lang.Object getFeature(java.lang.String arg0, java.lang.String arg1)
           
 org.w3c.dom.Node getFirstChild()
          Returns the first child of this node, or null if the node has no children.
 org.w3c.dom.Node getLastChild()
          Returns the last child of this node, or null if the node has no children.
 int getLength()
          Returns number of child nodes.
 java.lang.String getLocalName()
          Equivalent to getNodeName.
 java.lang.String getNamespaceURI()
           
 org.w3c.dom.Node getNextSibling()
          Returns the next sibling of this node, or null if the node has no next sibling.
 java.lang.String getNodeName()
          Returns the name associated with this node.
 short getNodeType()
          Returns the node type.
 java.lang.String getNodeValue()
          Returns the value associated with this node.
 org.w3c.dom.Document getOwnerDocument()
          Returns null, since NodeImpls do not belong to any Document.
 org.w3c.dom.Node getParentNode()
          Returns the parent of this node.
 java.lang.String getPrefix()
          Returns null, since namespaces are not supported.
 org.w3c.dom.Node getPreviousSibling()
          Returns the previous sibling of this node, or null if this node has no previous sibling.
 java.lang.String getTextContent()
           
 java.lang.Object getUserData(java.lang.String arg0)
           
 boolean hasAttributes()
          Returns true, if this node has attributes, otherwise false.
 boolean hasChildNodes()
          Returns true if this node has child nodes.
protected  void initNodeImplChildren(org.w3c.dom.Node node)
          Creates the children subtree and adds to this node.
 org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild)
          Inserts the node newChild before the existing child node refChild.
 boolean isDefaultNamespace(java.lang.String arg0)
           
 boolean isEqualNode(org.w3c.dom.Node arg0)
           
 boolean isSameNode(org.w3c.dom.Node arg0)
           
 boolean isSupported(java.lang.String feature, java.lang.String version)
          Returns false since DOM features are not supported.
 org.w3c.dom.Node item(int index)
          Returns child node with the given index.
 java.lang.String lookupNamespaceURI(java.lang.String arg0)
           
 java.lang.String lookupPrefix(java.lang.String arg0)
           
protected  org.w3c.dom.Node newCommentInstance(org.w3c.dom.Node node)
          Creates new instance of the CommentImpl class.
protected  org.w3c.dom.Node newDefaultInstance(org.w3c.dom.Node node)
          Creates new instance of the NodeImpl class.
protected  org.w3c.dom.Node newElementInstance(org.w3c.dom.Node node)
          Creates new instance of the ElementImpl class.
protected  org.w3c.dom.Node newTextInstance(org.w3c.dom.Node node)
          Creates new instance of the TextImpl class.
 void normalize()
          Does nothing, since NodeImpls do not contain Text children.
 org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild)
          Removes the child node indicated by oldChild from the list of children, and returns it.
 org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild)
          Replaces the child node oldChild with newChild in the list of children, and returns the oldChild node.
 void setNodeValue(java.lang.String nodeValue)
          Sets the node value of this node.
 void setPrefix(java.lang.String prefix)
          Does nothing, since namespaces are not supported.
 void setTextContent(java.lang.String arg0)
           
 java.lang.Object setUserData(java.lang.String arg0, java.lang.Object arg1, org.w3c.dom.UserDataHandler arg2)
           
 java.lang.String toString()
          Returns String representation of this node.
 java.lang.String toString(java.lang.String tab)
          Returns String representation of this node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ownerDocument

protected org.w3c.dom.Document ownerDocument
Owner document.


nodeName

protected java.lang.String nodeName
The name (tag) of the node as a String.


nodeValue

protected java.lang.String nodeValue
The value of the node as a String.


type

protected short type
The type of the node as a short.


parent

protected NodeImpl parent
The parent node of this node, or null if this node forms the root of its own tree.


numChildren

protected int numChildren
The number of child nodes.


firstChild

protected NodeImpl firstChild
The first (leftmost) child node of this node, or null if this node is a leaf node.


lastChild

protected NodeImpl lastChild
The last (rightmost) child node of this node, or null if this node is a leaf node.


nextSibling

protected NodeImpl nextSibling
The next (right) sibling node of this node, or null if this node is its parent's last child node.


previousSibling

protected NodeImpl previousSibling
The previous (left) sibling node of this node, or null if this node is its parent's first child node.

Constructor Detail

NodeImpl

public NodeImpl()
Constructs an empty NodeImpl.


NodeImpl

public NodeImpl(NodeImpl node)
Constructs a NodeImpl from the given node, without creating entire children subtree.

Parameters:
node, - as a NodeImpl.

NodeImpl

public NodeImpl(org.w3c.dom.Node node)
Constructs an NodeImpl from a given node (creates the children subtree too), as a Node

Parameters:
node, - as a Node.

NodeImpl

public NodeImpl(org.w3c.dom.Node node,
                boolean deep)
Constructs an NodeImpl from a given node, as a Node, and deep as boolean.

Parameters:
node, - as a Node.
deep - if true, recursively clone the subtree under the specified node; if false, clone only the node itself.

NodeImpl

public NodeImpl(org.w3c.dom.Document ownerDoc,
                java.lang.String name)
Constructs a NodeImpl from the given document owner and node name.

Parameters:
ownerDoc - the document owner of the node, as a Document.
name - the name of the node, as a String.

NodeImpl

public NodeImpl(org.w3c.dom.Document ownerDoc,
                java.lang.String nodeName,
                short type)
Constructs an NodeImpl from a given document owner, node name and node type.

Parameters:
ownerDoc - the document owner of the node, as a Document.
nodeName - the name of the node, as a String.
type - the type of the node, as a short.

NodeImpl

public NodeImpl(org.w3c.dom.Document ownerDoc,
                java.lang.String nodeName,
                short type,
                java.lang.String value)
Constructs an NodeImpl from a given document owner, node name, node type and node value.

Parameters:
ownerDoc - the document owner of the node, as a Document.
nodeName - the name of the node, as a String.
type - the type of the node, as a short.
value - the value of the node, as a String.
Method Detail

initNodeImplChildren

protected void initNodeImplChildren(org.w3c.dom.Node node)
Creates the children subtree and adds to this node. (this part had to be splited from the constructor)

Parameters:
nodeas - a Node.

newElementInstance

protected org.w3c.dom.Node newElementInstance(org.w3c.dom.Node node)
Creates new instance of the ElementImpl class.

Parameters:
node, - as a Node.
Returns:
Node new instance of the ElementImpl class.

newTextInstance

protected org.w3c.dom.Node newTextInstance(org.w3c.dom.Node node)
Creates new instance of the TextImpl class.

Parameters:
node, - as a Node.
Returns:
Node new instance of the TextImpl class.

newCommentInstance

protected org.w3c.dom.Node newCommentInstance(org.w3c.dom.Node node)
Creates new instance of the CommentImpl class.

Parameters:
node, - as a Node.
Returns:
Node new instance of the CommentImpl class.

newDefaultInstance

protected org.w3c.dom.Node newDefaultInstance(org.w3c.dom.Node node)
Creates new instance of the NodeImpl class.

Parameters:
node, - as a Node.
Returns:
Node new instance of the NodeImpl class.

getNodeName

public java.lang.String getNodeName()
Returns the name associated with this node.

Specified by:
getNodeName in interface org.w3c.dom.Node
Returns:
the name, as a String.

getNodeValue

public java.lang.String getNodeValue()
Returns the value associated with this node.

Specified by:
getNodeValue in interface org.w3c.dom.Node
Returns:
the node value, as a String.

setNodeValue

public void setNodeValue(java.lang.String nodeValue)
Sets the node value of this node.

Specified by:
setNodeValue in interface org.w3c.dom.Node
Parameters:
nodeValue - new node value, as a String.

getNodeType

public short getNodeType()
Returns the node type.

Specified by:
getNodeType in interface org.w3c.dom.Node
Returns:
the short value node type.

getParentNode

public org.w3c.dom.Node getParentNode()
Returns the parent of this node. A null value indicates that the node is the root of its own tree. To add a node to an existing tree, use one of the insertBefore, replaceChild, or appendChild methods.

Specified by:
getParentNode in interface org.w3c.dom.Node
Returns:
the parent, as a Node.
See Also:
insertBefore(org.w3c.dom.Node, org.w3c.dom.Node), replaceChild(org.w3c.dom.Node, org.w3c.dom.Node), appendChild(org.w3c.dom.Node)

getChildNodes

public org.w3c.dom.NodeList getChildNodes()
Returns all child nodes of this node, or null if the node has no children.

Specified by:
getChildNodes in interface org.w3c.dom.Node
Returns:
all child nodes of this node, as a Node, or null.

getFirstChild

public org.w3c.dom.Node getFirstChild()
Returns the first child of this node, or null if the node has no children.

Specified by:
getFirstChild in interface org.w3c.dom.Node
Returns:
the first child, as a Node, or null

getLastChild

public org.w3c.dom.Node getLastChild()
Returns the last child of this node, or null if the node has no children.

Specified by:
getLastChild in interface org.w3c.dom.Node
Returns:
the last child, as a Node, or null.

getPreviousSibling

public org.w3c.dom.Node getPreviousSibling()
Returns the previous sibling of this node, or null if this node has no previous sibling.

Specified by:
getPreviousSibling in interface org.w3c.dom.Node
Returns:
the previous sibling, as a Node, or null.

getNextSibling

public org.w3c.dom.Node getNextSibling()
Returns the next sibling of this node, or null if the node has no next sibling.

Specified by:
getNextSibling in interface org.w3c.dom.Node
Returns:
the next sibling, as a Node, or null.

getOwnerDocument

public org.w3c.dom.Document getOwnerDocument()
Returns null, since NodeImpls do not belong to any Document.

Specified by:
getOwnerDocument in interface org.w3c.dom.Node
Returns:
document owner as Document.

insertBefore

public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild,
                                     org.w3c.dom.Node refChild)
Inserts the node newChild before the existing child node refChild. If refChild is null, insert newChild at the end of the list of children.

Specified by:
insertBefore in interface org.w3c.dom.Node
Parameters:
newChild - the Node to insert.
refChild - the reference Node.
Returns:
the node being inserted.
Throws:
java.lang.IllegalArgumentException - if newChild is null.

replaceChild

public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild,
                                     org.w3c.dom.Node oldChild)
Replaces the child node oldChild with newChild in the list of children, and returns the oldChild node.

Specified by:
replaceChild in interface org.w3c.dom.Node
Parameters:
newChild - the Node to insert.
oldChild - the Node to be replaced.
Returns:
the node replaced.
Throws:
java.lang.IllegalArgumentException - if newChild is null.

removeChild

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

Specified by:
removeChild in interface org.w3c.dom.Node
Parameters:
oldChild - the Node to be removed.
Returns:
the node removed.
Throws:
java.lang.IllegalArgumentException - if oldChild is null.

appendChild

public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild)
Adds the node newChild to the end of the list of children of this node.

Specified by:
appendChild in interface org.w3c.dom.Node
Parameters:
newChild - the Node to insert.
Returns:
the node added.
Throws:
java.lang.IllegalArgumentException - if newChild is null.

hasChildNodes

public boolean hasChildNodes()
Returns true if this node has child nodes.

Specified by:
hasChildNodes in interface org.w3c.dom.Node
Returns:
true if this node has children.

cloneNode

public org.w3c.dom.Node cloneNode(boolean deep)
Returns a duplicate of this node. The duplicate node has no parent (getParentNode returns null). If a shallow clone is being performed (deep is false), the new node will not have any children or siblings. If a deep clone is being performed, the new node will form the root of a complete cloned subtree.

Specified by:
cloneNode in interface org.w3c.dom.Node
Parameters:
deep - if true, recursively clone the subtree under the specified node; if false, clone only the node itself.
Returns:
the duplicate node.

normalize

public void normalize()
Does nothing, since NodeImpls do not contain Text children.

Specified by:
normalize in interface org.w3c.dom.Node

isSupported

public boolean isSupported(java.lang.String feature,
                           java.lang.String version)
Returns false since DOM features are not supported.

Specified by:
isSupported in interface org.w3c.dom.Node
Parameters:
feature - a String, which is ignored.
version - a String, which is ignored.
Returns:
false.

getPrefix

public java.lang.String getPrefix()
Returns null, since namespaces are not supported.

Specified by:
getPrefix in interface org.w3c.dom.Node
Returns:
null.
See Also:
setPrefix(java.lang.String)

setPrefix

public void setPrefix(java.lang.String prefix)
Does nothing, since namespaces are not supported.

Specified by:
setPrefix in interface org.w3c.dom.Node
Parameters:
prefix - a String, which is ignored.
See Also:
getPrefix()

getLocalName

public java.lang.String getLocalName()
Equivalent to getNodeName.

Specified by:
getLocalName in interface org.w3c.dom.Node
Returns:
the node name, as a String.

getAttributes

public org.w3c.dom.NamedNodeMap getAttributes()
Returns all attribute nodes of this node.

Specified by:
getAttributes in interface org.w3c.dom.Node
Returns:
all attribute nodes of this node.

hasAttributes

public boolean hasAttributes()
Returns true, if this node has attributes, otherwise false.

Specified by:
hasAttributes in interface org.w3c.dom.Node
Returns:
true if node has attributes, otherwise false..

getLength

public int getLength()
Returns number of child nodes.

Specified by:
getLength in interface org.w3c.dom.NodeList
Returns:
all number of child nodes.

item

public org.w3c.dom.Node item(int index)
Returns child node with the given index.

Specified by:
item in interface org.w3c.dom.NodeList
Returns:
child node with the given index.

toString

public java.lang.String toString()
Returns String representation of this node.

Overrides:
toString in class java.lang.Object
Returns:
String representation of this node.

toString

public java.lang.String toString(java.lang.String tab)
Returns String representation of this node.

Parameters:
tab - tab for node indentation.
Returns:
String representation of this node.

beginToString

protected void beginToString(java.lang.StringBuffer sb,
                             Indent indent)
Method beginToString should be redefined in extended classes. Each type of node has its own beginToString and endToString. This was added to support writing of the xml file. The Element type of node: it writes the beginning tag, then calls the child's toString, and then writes the ending tag.

Parameters:
sb - string buffer to add resulting string.
indent - used in formating the output.

endToString

protected void endToString(java.lang.StringBuffer sb,
                           Indent indent)
Method endToString should be redefined in extended classes. Each type of node has its own beginToString and endToString. This was added to support writing of the xml file. The Element type of node: it writes the beginning tag, then calls the child's toString, and then writes the ending tag.

Parameters:
sb - string buffer to add resulting string.
indent - used in formating the output.

getBaseURI

public java.lang.String getBaseURI()
Specified by:
getBaseURI in interface org.w3c.dom.Node

compareDocumentPosition

public short compareDocumentPosition(org.w3c.dom.Node arg0)
                              throws org.w3c.dom.DOMException
Specified by:
compareDocumentPosition in interface org.w3c.dom.Node
Throws:
org.w3c.dom.DOMException

getTextContent

public java.lang.String getTextContent()
                                throws org.w3c.dom.DOMException
Specified by:
getTextContent in interface org.w3c.dom.Node
Throws:
org.w3c.dom.DOMException

setTextContent

public void setTextContent(java.lang.String arg0)
                    throws org.w3c.dom.DOMException
Specified by:
setTextContent in interface org.w3c.dom.Node
Throws:
org.w3c.dom.DOMException

isSameNode

public boolean isSameNode(org.w3c.dom.Node arg0)
Specified by:
isSameNode in interface org.w3c.dom.Node

lookupPrefix

public java.lang.String lookupPrefix(java.lang.String arg0)
Specified by:
lookupPrefix in interface org.w3c.dom.Node

isDefaultNamespace

public boolean isDefaultNamespace(java.lang.String arg0)
Specified by:
isDefaultNamespace in interface org.w3c.dom.Node

lookupNamespaceURI

public java.lang.String lookupNamespaceURI(java.lang.String arg0)
Specified by:
lookupNamespaceURI in interface org.w3c.dom.Node

isEqualNode

public boolean isEqualNode(org.w3c.dom.Node arg0)
Specified by:
isEqualNode in interface org.w3c.dom.Node

getFeature

public java.lang.Object getFeature(java.lang.String arg0,
                                   java.lang.String arg1)
Specified by:
getFeature in interface org.w3c.dom.Node

setUserData

public java.lang.Object setUserData(java.lang.String arg0,
                                    java.lang.Object arg1,
                                    org.w3c.dom.UserDataHandler arg2)
Specified by:
setUserData in interface org.w3c.dom.Node

getUserData

public java.lang.Object getUserData(java.lang.String arg0)
Specified by:
getUserData in interface org.w3c.dom.Node

getNamespaceURI

public java.lang.String getNamespaceURI()
Specified by:
getNamespaceURI in interface org.w3c.dom.Node

EAF 7.6 Util