BEA Systems, Inc.

com.beasys.commerce.util.dom
Class NodeImpl

java.lang.Object
  |
  +--com.beasys.commerce.util.dom.DOMBase
        |
        +--com.beasys.commerce.util.dom.NodeImpl
Direct Known Subclasses:
AttrImpl, CharacterDataImpl, DocumentFragmentImpl, DocumentImpl, DocumentTypeImpl, ElementImpl, EntityImpl, EntityReferenceImpl, NotationImpl, ProcessingInstructionImpl

public abstract class NodeImpl
extends DOMBase
implements org.w3c.dom.Node

A base class implementation of the W3C's DOM Node object.

This provides support for child nodes and a parent node. Subclasses need to override the cloneNode(), getNodeType(), getNodeName(); subclasses might choose to override getAllowableChildrenTypes(), * getNodeValue(), and setNodeValue(java.lang.String). Elements should override getAttributes() to provide support for attributes.

See Also:
Serialized Form

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
NodeImpl(org.w3c.dom.Document document, org.w3c.dom.Node parent)
          Constructor.
 
Method Summary
protected  boolean allowsChildren()
          Tell if this node can generally have children.
 org.w3c.dom.Node appendChild(org.w3c.dom.Node child)
          Append a new child node to the end of children node list.
protected  org.w3c.dom.Node appendChildren(org.w3c.dom.Node node)
          Append all the children of a node to this node.
protected  void checkAllowChild(org.w3c.dom.Node child)
          Check if the node allows for adding the given child.
abstract  org.w3c.dom.Node cloneNode()
          Clone yourself, including attributes, but not children.
 org.w3c.dom.Node cloneNode(boolean deep)
          Clone this node.
protected  short[] getAllowableChildrenTypes()
          An array of the types of children Node's this node can have.
 org.w3c.dom.NamedNodeMap getAttributes()
          Return the attributes of this node.
 org.w3c.dom.NodeList getChildNodes()
          Return the children nodes of this node.
 org.w3c.dom.Node getFirstChild()
          Get the first child node.
 org.w3c.dom.Node getLastChild()
          Get the last child node.
 org.w3c.dom.Node getNextSibling()
          Get the next sibling of this node.
abstract  java.lang.String getNodeName()
          Get the node's name.
abstract  short getNodeType()
          Get the node's type.
static java.lang.String getNodeType(short type)
          Get a string version of the node type.
 java.lang.String getNodeValue()
          Get the node's value.
 org.w3c.dom.Node getParentNode()
          Get the parent node.
 org.w3c.dom.Node getPreviousSibling()
          Get the previous sibling of this node.
 boolean hasChildNodes()
          Return if this has children nodes.
 org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild)
          Insert a new child node in front of the given child node in our children node list.
protected  org.w3c.dom.Node insertChildrenBefore(org.w3c.dom.Node node, org.w3c.dom.Node refChild)
          Insert the given node's children in front of the given child node.
protected  boolean isAncestor(org.w3c.dom.Node node)
          Check if the given node is an ancestor (up the parent nodes) of us.
 org.w3c.dom.Node removeChild(org.w3c.dom.Node child)
          Remove the specified child node from children node list.
 org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild)
          Replace the specified child node with the new child node in our children node list.
 void setNodeValue(java.lang.String value)
          Set the node's value.
 void setParentNode(org.w3c.dom.Node parentNode)
          Set the parent node.
 
Methods inherited from class com.beasys.commerce.util.dom.DOMBase
checkOwnerDocument, checkReadOnly, getOwnerDocument, isReadOnly, setReadOnly
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeImpl

public NodeImpl(org.w3c.dom.Document document,
                org.w3c.dom.Node parent)
Constructor.
Parameters:
document - the document we're part of.
parent - our parent node.
Method Detail

cloneNode

public abstract org.w3c.dom.Node cloneNode()
Clone yourself, including attributes, but not children.

This is different from cloneNode(boolean); this is always a shallow clone.


getAllowableChildrenTypes

protected short[] getAllowableChildrenTypes()
An array of the types of children Node's this node can have.

Subclasses that can have children Nodes should override this method to return an array of shorts of the nodeType's it can have as children (e.g. Node.ATTR_NODE, Node.ELEMENT_NODE, etc.).

This method must return the same thing each time.

Returns:
an array of nodeTypes, or null for no children allowed.

allowsChildren

protected boolean allowsChildren()
Tell if this node can generally have children.
See Also:
getAllowableChildrenTypes()

checkAllowChild

protected void checkAllowChild(org.w3c.dom.Node child)
                        throws org.w3c.dom.DOMException
Check if the node allows for adding the given child.
Parameters:
child - the Node to add.
Throws:
org.w3c.dom.DOMException - thrown if the node doesn't allow children of child's type.
See Also:
getAllowableChildrenTypes(), isAncestor(org.w3c.dom.Node), DOMBase.checkReadOnly(), DOMBase.checkOwnerDocument(org.w3c.dom.Node)

isAncestor

protected boolean isAncestor(org.w3c.dom.Node node)
Check if the given node is an ancestor (up the parent nodes) of us.
Parameters:
node - the node to check.
Returns:
true if the node is an ancestor, false if not.

appendChild

public org.w3c.dom.Node appendChild(org.w3c.dom.Node child)
                             throws org.w3c.dom.DOMException
Append a new child node to the end of children node list.
Specified by:
appendChild in interface org.w3c.dom.Node
Parameters:
child - the new child node.
Returns:
child.
Throws:
org.w3c.dom.DOMException - thrown if the child cannot be added to this node.

appendChildren

protected org.w3c.dom.Node appendChildren(org.w3c.dom.Node node)
                                   throws org.w3c.dom.DOMException
Append all the children of a node to this node.

When adding document fragments to a node, you actually are supposed to add the children of the document fragment.

Parameters:
node - the Node.
Returns:
node.
Throws:
org.w3c.dom.DOMException - thrown if the node's children cannot be added.

insertBefore

public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild,
                                     org.w3c.dom.Node refChild)
                              throws org.w3c.dom.DOMException
Insert a new child node in front of the given child node in our children node list.
Specified by:
insertBefore in interface org.w3c.dom.Node
Parameters:
newChild - the child to add.
refChild - the child to add in front of.
Returns:
newChild.
Throws:
org.w3c.dom.DOMException - thrown if the child cannot be added to this node.

insertChildrenBefore

protected org.w3c.dom.Node insertChildrenBefore(org.w3c.dom.Node node,
                                                org.w3c.dom.Node refChild)
                                         throws org.w3c.dom.DOMException
Insert the given node's children in front of the given child node.
Parameters:
node - the node.
refChild - the child to add in front of.
Returns:
node.
Throws:
org.w3c.dom.DOMException - thrown if the children cannot be add to this node.

removeChild

public org.w3c.dom.Node removeChild(org.w3c.dom.Node child)
                             throws org.w3c.dom.DOMException
Remove the specified child node from children node list.
Specified by:
removeChild in interface org.w3c.dom.Node
Parameters:
child - the child to remove.
Returns:
child.
Throws:
org.w3c.dom.DOMException - thrown if the child cannot be removed from this node.

replaceChild

public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild,
                                     org.w3c.dom.Node oldChild)
                              throws org.w3c.dom.DOMException
Replace the specified child node with the new child node in our children node list.
Specified by:
replaceChild in interface org.w3c.dom.Node
Parameters:
newChild - the new child replacing the old child.
oldChild - the old child being replaced.
Returns:
oldChild.
Throws:
org.w3c.dom.DOMException - thrown if the child cannot be replaced.

hasChildNodes

public boolean hasChildNodes()
Return if this has children nodes.
Specified by:
hasChildNodes in interface org.w3c.dom.Node

cloneNode

public org.w3c.dom.Node cloneNode(boolean deep)
Clone this node.
Specified by:
cloneNode in interface org.w3c.dom.Node
Parameters:
deep - true to also clone the children of this node.
Returns:
the new node.
See Also:
Object.clone()

getAttributes

public org.w3c.dom.NamedNodeMap getAttributes()
Return the attributes of this node.

Element's should override to return a NamedNodeMap.

Specified by:
getAttributes in interface org.w3c.dom.Node
Returns:
null.

getChildNodes

public org.w3c.dom.NodeList getChildNodes()
Return the children nodes of this node.
Specified by:
getChildNodes in interface org.w3c.dom.Node
Returns:
the children node list.

getFirstChild

public org.w3c.dom.Node getFirstChild()
Get the first child node.
Specified by:
getFirstChild in interface org.w3c.dom.Node
Returns:
the first child node, or null if there are no children.

getLastChild

public org.w3c.dom.Node getLastChild()
Get the last child node.
Specified by:
getLastChild in interface org.w3c.dom.Node
Returns:
the first child node, or null if there are no children.

getNextSibling

public org.w3c.dom.Node getNextSibling()
Get the next sibling of this node.
Specified by:
getNextSibling in interface org.w3c.dom.Node

getPreviousSibling

public org.w3c.dom.Node getPreviousSibling()
Get the previous sibling of this node.
Specified by:
getPreviousSibling in interface org.w3c.dom.Node

getNodeType

public abstract short getNodeType()
Get the node's type.
Specified by:
getNodeType in interface org.w3c.dom.Node

getNodeName

public abstract java.lang.String getNodeName()
Get the node's name.

This value is subclass specific; see the DOM documentation for further details.

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

getNodeValue

public java.lang.String getNodeValue()
Get the node's value.

This value is subclass specific; see the DOM documentation for further details.

The method here returns null. Subclasses that have node values should override this method.

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

setNodeValue

public void setNodeValue(java.lang.String value)
Set the node's value.

The implementation of this is subclass specific; see the DOM documentation for further details.

The method here does nothing. Subclasses that have node values should override this method.

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

getParentNode

public org.w3c.dom.Node getParentNode()
Get the parent node.
Specified by:
getParentNode in interface org.w3c.dom.Node

setParentNode

public void setParentNode(org.w3c.dom.Node parentNode)
Set the parent node.
Parameters:
parentNode - the new parent node (can be null which means no longer in a tree).

getNodeType

public static java.lang.String getNodeType(short type)
Get a string version of the node type.

BEA Systems, Inc.

Copyright © 2000 BEA Systems, Inc. All Rights Reserved