com.icl.saxon.tree

Class NodeImpl

Implemented Interfaces:
DOMLocator, Node, NodeInfo, Source, SourceLocator
Known Direct Subclasses:
AttributeImpl, CommentImpl, NamespaceImpl, ParentNodeImpl, ProcInstImpl, TextImpl

public abstract class NodeImpl
extends AbstractNode

A node in the XML parse tree representing an XML element, character content, or attribute.

This is the top-level class in the implementation class hierarchy; it essentially contains all those methods that can be defined using other primitive methods, without direct access to data.

Author:
Michael H. Kay

Field Summary

protected static NodeInfo[]
emptyArray
protected int
index
protected ParentNodeImpl
parent

Fields inherited from class com.icl.saxon.om.AbstractNode

NODE_LETTER

Fields inherited from interface com.icl.saxon.om.NodeInfo

ATTRIBUTE, COMMENT, ELEMENT, NAMESPACE, NODE, NONE, NUMBER_OF_TYPES, PI, ROOT, TEXT

Method Summary

int
compareOrder(NodeInfo other)
Determine the relative position of this node and another node, in document order.
String
generateId()
Get a character string that uniquely identifies this node within this document (The calling code will prepend a document identifier)
String
getAttributeValue(String uri, String localName)
Find the value of a given attribute of this node.
String
getAttributeValue(int fingerprint)
Get the value of a given attribute of this node
NamedNodeMap
getAttributes()
Return a NamedNodeMap containing the attributes of this node (if it is an Element ) or null otherwise.
String
getBaseURI()
Get the base URI for the node.
NodeList
getChildNodes()
Return a NodeList that contains all children of this node.
String
getDisplayName()
Get the display name of this node.
Element
getDocumentElement()
Get the outermost element.
DocumentInfo
getDocumentRoot()
Get the root (document) node
AxisEnumeration
getEnumeration(byte axisNumber, NodeTest nodeTest)
Return an enumeration over the nodes reached by the given axis from this node
int
getFingerprint()
Get the fingerprint of the node.
Node
getFirstChild()
Get first child - default implementation used for leaf nodes
Node
getLastChild()
Get last child - default implementation used for leaf nodes
int
getLineNumber()
Get the line number of the node within its source document entity
String
getLocalName()
Get the local name of this node.
int
getNameCode()
Get the nameCode of the node.
NamePool
getNamePool()
Get the NamePool
NodeImpl
getNextInDocument(NodeImpl anchor)
Get the next node in document order
Node
getNextSibling()
Get next sibling node
Node
getOriginatingNode()
Get the node corresponding to this javax.xml.transform.dom.DOMLocator
NodeInfo
getParent()
Find the parent node of this node.
String
getPrefix()
Get the prefix part of the name of this node.
NodeImpl
getPreviousInDocument()
Get the previous node in document order
Node
getPreviousSibling()
Get the previous sibling of the node
protected long
getSequenceNumber()
Get the node sequence number (in document order).
String
getSystemId()
Get the system ID for the node.
String
getURI()
Get the URI part of the name of this node.
boolean
hasAttributes()
Returns whether this node (if it is an element) has any attributes.
boolean
hasChildNodes()
Determine whether the node has any children.
boolean
isSameNodeInfo(NodeInfo other)
Determine whether this is the same node as another node
void
outputNamespaceNodes(Outputter out, boolean includeAncestors)
Output all namespace nodes associated with this element.
void
removeNode()
Remove this node from the tree.
void
setSystemId(String uri)
Set the system ID of this node.

Methods inherited from class com.icl.saxon.om.AbstractNode

appendChild, appendData, cloneNode, compareDocumentPosition, compareOrder, copyStringValue, createAttribute, createAttributeNS, createCDATASection, createComment, createDocumentFragment, createElement, createElementNS, createEntityReference, createProcessingInstruction, createTextNode, deleteData, disallowUpdate, generateId, getAttribute, getAttributeNS, getAttributeNode, getAttributeNodeNS, getAttributeValue, getAttributeValue, getAttributes, getBaseURI, getChildNodes, getColumnNumber, getData, getDisplayName, getDoctype, getDocumentElement, getDocumentRoot, getElementById, getElementsByTagName, getElementsByTagNameNS, getEnumeration, getFeature, getFingerprint, getFirstChild, getImplementation, getLastChild, getLength, getLineNumber, getLocalName, getName, getNameCode, getNamespaceURI, getNextSibling, getNodeName, getNodeValue, getOriginatingNode, getOwnerDocument, getOwnerElement, getParent, getParentNode, getPrefix, getPreviousSibling, getPublicId, getSchemaTypeInfo, getSpecified, getSystemId, getTagName, getTextContent, getURI, getUserData, getValue, getWholeText, hasAttribute, hasAttributeNS, hasAttributes, hasChildNodes, importNode, insertBefore, insertData, isDefaultNamespace, isElementContentWhitespace, isEqualNode, isId, isSameNode, isSameNodeInfo, isSupported, lookupNamespaceURI, lookupPrefix, normalize, outputNamespaceNodes, removeAttribute, removeAttributeNS, removeAttributeNode, removeChild, replaceChild, replaceData, replaceWholeText, setAttributeNS, setAttributeNode, setAttributeNodeNS, setData, setIdAttribute, setIdAttributeNS, setIdAttributeNode, setNodeValue, setPrefix, setTextContent, setUserData, setValue, splitText, substringData, supports

Field Details

emptyArray

protected static NodeInfo[] emptyArray

index

protected int index

parent

protected ParentNodeImpl parent

Method Details

compareOrder

public final int compareOrder(NodeInfo other)
Determine the relative position of this node and another node, in document order. The other node will always be in the same document.
Specified by:
compareOrder in interface NodeInfo
Overrides:
compareOrder in interface AbstractNode
Parameters:
other - The other node, whose position is to be compared with this node
Returns:
-1 if this node precedes the other node, +1 if it follows the other node, or 0 if they are the same node. (In this case, isSameNode() will always return true, and the two nodes will produce the same result for generateId())

generateId

public String generateId()
Get a character string that uniquely identifies this node within this document (The calling code will prepend a document identifier)
Specified by:
generateId in interface NodeInfo
Overrides:
generateId in interface AbstractNode
Returns:
a string.

getAttributeValue

public String getAttributeValue(String uri,
                                String localName)
Find the value of a given attribute of this node.
This method is defined on all nodes to meet XSL requirements, but for nodes other than elements it will always return null.
Specified by:
getAttributeValue in interface NodeInfo
Overrides:
getAttributeValue in interface AbstractNode
Parameters:
uri - the namespace uri of an attribute
localName - the local name of an attribute
Returns:
the value of the attribute, if it exists, otherwise null

getAttributeValue

public String getAttributeValue(int fingerprint)
Get the value of a given attribute of this node
Specified by:
getAttributeValue in interface NodeInfo
Overrides:
getAttributeValue in interface AbstractNode
Parameters:
fingerprint - The fingerprint of the attribute name
Returns:
the attribute value if it exists or null if not

getAttributes

public NamedNodeMap getAttributes()
Return a NamedNodeMap containing the attributes of this node (if it is an Element ) or null otherwise. (DOM method)
Overrides:
getAttributes in interface AbstractNode

getBaseURI

public String getBaseURI()
Get the base URI for the node. Default implementation for child nodes.
Specified by:
getBaseURI in interface NodeInfo
Overrides:
getBaseURI in interface AbstractNode

getChildNodes

public NodeList getChildNodes()
Return a NodeList that contains all children of this node. If there are no children, this is a NodeList containing no nodes.
Overrides:
getChildNodes in interface AbstractNode

getDisplayName

public String getDisplayName()
Get the display name of this node. For elements and attributes this is [prefix:]localname. For unnamed nodes, it is an empty string.
Specified by:
getDisplayName in interface NodeInfo
Overrides:
getDisplayName in interface AbstractNode
Returns:
The display name of this node. For a node with no name, return an empty string.

getDocumentElement

public Element getDocumentElement()
Get the outermost element.
Overrides:
getDocumentElement in interface AbstractNode
Returns:
the Element node for the outermost element of the document. If the document is not well-formed, this returns the last element child of the root if there is one, otherwise null.

getDocumentRoot

public DocumentInfo getDocumentRoot()
Get the root (document) node
Specified by:
getDocumentRoot in interface NodeInfo
Overrides:
getDocumentRoot in interface AbstractNode
Returns:
the DocumentInfo representing the containing document

getEnumeration

public AxisEnumeration getEnumeration(byte axisNumber,
                                      NodeTest nodeTest)
Return an enumeration over the nodes reached by the given axis from this node
Specified by:
getEnumeration in interface NodeInfo
Overrides:
getEnumeration in interface AbstractNode
Parameters:
nodeTest - A pattern to be matched by the returned nodes
Returns:
an AxisEnumeration that scans the nodes reached by the axis in turn.

getFingerprint

public int getFingerprint()
Get the fingerprint of the node. This is used to compare whether two nodes have equivalent names. Return -1 for a node with no name.
Specified by:
getFingerprint in interface NodeInfo
Overrides:
getFingerprint in interface AbstractNode

getFirstChild

public Node getFirstChild()
Get first child - default implementation used for leaf nodes
Overrides:
getFirstChild in interface AbstractNode
Returns:
null

getLastChild

public Node getLastChild()
Get last child - default implementation used for leaf nodes
Overrides:
getLastChild in interface AbstractNode
Returns:
null

getLineNumber

public int getLineNumber()
Get the line number of the node within its source document entity
Specified by:
getLineNumber in interface NodeInfo
Overrides:
getLineNumber in interface AbstractNode

getLocalName

public String getLocalName()
Get the local name of this node.
Specified by:
getLocalName in interface NodeInfo
Overrides:
getLocalName in interface AbstractNode
Returns:
The local name of this node. For a node with no name, return an empty string.

getNameCode

public int getNameCode()
Get the nameCode of the node. This is used to locate the name in the NamePool
Specified by:
getNameCode in interface NodeInfo
Overrides:
getNameCode in interface AbstractNode

getNamePool

public NamePool getNamePool()
Get the NamePool

getNextInDocument

public NodeImpl getNextInDocument(NodeImpl anchor)
Get the next node in document order
Parameters:
Returns:
the next node in the document, or null if there is no such node

getNextSibling

public Node getNextSibling()
Get next sibling node
Overrides:
getNextSibling in interface AbstractNode
Returns:
The next sibling node of the required type. Returns null if the current node is the last child of its parent.

getOriginatingNode

public Node getOriginatingNode()
Get the node corresponding to this javax.xml.transform.dom.DOMLocator
Overrides:
getOriginatingNode in interface AbstractNode

getParent

public final NodeInfo getParent()
Find the parent node of this node.
Specified by:
getParent in interface NodeInfo
Overrides:
getParent in interface AbstractNode
Returns:
The Node object describing the containing element or root node.

getPrefix

public String getPrefix()
Get the prefix part of the name of this node. This is the name before the ":" if any.
Specified by:
getPrefix in interface NodeInfo
Overrides:
getPrefix in interface AbstractNode
Returns:
the prefix part of the name. For an unnamed node, return an empty string.

getPreviousInDocument

public NodeImpl getPreviousInDocument()
Get the previous node in document order
Returns:
the previous node in the document, or null if there is no such node

getPreviousSibling

public Node getPreviousSibling()
Get the previous sibling of the node
Overrides:
getPreviousSibling in interface AbstractNode
Returns:
The previous sibling node. Returns null if the current node is the first child of its parent.

getSequenceNumber

protected long getSequenceNumber()
Get the node sequence number (in document order). Sequence numbers are monotonic but not consecutive. In the current implementation, parent nodes (elements and roots) have a zero least-significant word, while namespaces, attributes, text nodes, comments, and PIs have the top word the same as their owner and the bottom half reflecting their relative position. This is the default implementation for child nodes.

getSystemId

public String getSystemId()
Get the system ID for the node. Default implementation for child nodes.
Specified by:
getSystemId in interface NodeInfo
Overrides:
getSystemId in interface AbstractNode

getURI

public String getURI()
Get the URI part of the name of this node. This is the URI corresponding to the prefix, or the URI of the default namespace if appropriate.
Specified by:
getURI in interface NodeInfo
Overrides:
getURI in interface AbstractNode
Returns:
The URI of the namespace of this node. For the default namespace, return an empty string. For an unnamed node, return null.

hasAttributes

public boolean hasAttributes()
Returns whether this node (if it is an element) has any attributes.
Overrides:
hasAttributes in interface AbstractNode
Returns:
true if this node has any attributes, false otherwise.
Since:
DOM Level 2

hasChildNodes

public boolean hasChildNodes()
Determine whether the node has any children.
Specified by:
hasChildNodes in interface NodeInfo
Overrides:
hasChildNodes in interface AbstractNode
Returns:
true if the node has any children, false if the node has no children.

isSameNodeInfo

public boolean isSameNodeInfo(NodeInfo other)
Determine whether this is the same node as another node
Specified by:
isSameNodeInfo in interface NodeInfo
Overrides:
isSameNodeInfo in interface AbstractNode
Returns:
true if this Node object and the supplied Node object represent the same node in the tree.

outputNamespaceNodes

public void outputNamespaceNodes(Outputter out,
                                 boolean includeAncestors)
            throws TransformerException
Output all namespace nodes associated with this element. Does nothing if the node is not an element.
Specified by:
outputNamespaceNodes in interface NodeInfo
Overrides:
outputNamespaceNodes in interface AbstractNode
Parameters:
out - The relevant outputter
includeAncestors - True if namespaces declared on ancestor elements must be output; false if it is known that these are already on the result tree

removeNode

public void removeNode()
Remove this node from the tree. For system use only. When one or more nodes have been removed, renumberChildren() must be called to adjust the numbering of remaining nodes. PRECONDITION: The node must have a parent node.

setSystemId

public void setSystemId(String uri)
Set the system ID of this node. This method is provided so that a NodeInfo implements the javax.xml.transform.Source interface, allowing a node to be used directly as the Source of a transformation