Package com.icl.saxon.tree
Class NodeImpl
- java.lang.Object
-
- com.icl.saxon.om.AbstractNode
-
- com.icl.saxon.tree.NodeImpl
-
- All Implemented Interfaces:
NodeInfo
,javax.xml.transform.dom.DOMLocator
,javax.xml.transform.Source
,javax.xml.transform.SourceLocator
,org.w3c.dom.Node
- Direct Known 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
Fields Modifier and Type Field Description 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 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
Constructors Constructor Description NodeImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareOrder(NodeInfo other)
Determine the relative position of this node and another node, in document order.java.lang.String
generateId()
Get a character string that uniquely identifies this node within this document (The calling code will prepend a document identifier)org.w3c.dom.NamedNodeMap
getAttributes()
Return aNamedNodeMap
containing the attributes of this node (if it is anElement
) ornull
otherwise.java.lang.String
getAttributeValue(int fingerprint)
Get the value of a given attribute of this nodejava.lang.String
getAttributeValue(java.lang.String uri, java.lang.String localName)
Find the value of a given attribute of this node.java.lang.String
getBaseURI()
Get the base URI for the node.org.w3c.dom.NodeList
getChildNodes()
Return aNodeList
that contains all children of this node.java.lang.String
getDisplayName()
Get the display name of this node.org.w3c.dom.Element
getDocumentElement()
Get the outermost element.DocumentInfo
getDocumentRoot()
Get the root (document) nodeAxisEnumeration
getEnumeration(byte axisNumber, NodeTest nodeTest)
Return an enumeration over the nodes reached by the given axis from this nodeint
getFingerprint()
Get the fingerprint of the node.org.w3c.dom.Node
getFirstChild()
Get first child - default implementation used for leaf nodesorg.w3c.dom.Node
getLastChild()
Get last child - default implementation used for leaf nodesint
getLineNumber()
Get the line number of the node within its source document entityjava.lang.String
getLocalName()
Get the local name of this node.int
getNameCode()
Get the nameCode of the node.NamePool
getNamePool()
Get the NamePoolNodeImpl
getNextInDocument(NodeImpl anchor)
Get the next node in document orderorg.w3c.dom.Node
getNextSibling()
Get next sibling nodeorg.w3c.dom.Node
getOriginatingNode()
Get the node corresponding to this javax.xml.transform.dom.DOMLocatorNodeInfo
getParent()
Find the parent node of this node.java.lang.String
getPrefix()
Get the prefix part of the name of this node.NodeImpl
getPreviousInDocument()
Get the previous node in document orderorg.w3c.dom.Node
getPreviousSibling()
Get the previous sibling of the nodeprotected long
getSequenceNumber()
Get the node sequence number (in document order).java.lang.String
getSystemId()
Get the system ID for the node.java.lang.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 nodevoid
outputNamespaceNodes(Outputter out, boolean includeAncestors)
Output all namespace nodes associated with this element.void
removeNode()
Remove this node from the tree.void
setSystemId(java.lang.String uri)
Set the system ID of this node.-
Methods inherited from class com.icl.saxon.om.AbstractNode
appendChild, appendData, cloneNode, compareDocumentPosition, copyStringValue, createAttribute, createAttributeNS, createCDATASection, createComment, createDocumentFragment, createElement, createElementNS, createEntityReference, createProcessingInstruction, createTextNode, deleteData, disallowUpdate, getAttribute, getAttributeNode, getAttributeNodeNS, getAttributeNS, getColumnNumber, getData, getDoctype, getElementById, getElementsByTagName, getElementsByTagNameNS, getFeature, getImplementation, getLength, getName, getNamespaceURI, getNodeName, getNodeValue, getOwnerDocument, getOwnerElement, getParentNode, getPublicId, getSchemaTypeInfo, getSpecified, getTagName, getTextContent, getUserData, getValue, getWholeText, hasAttribute, hasAttributeNS, importNode, insertBefore, insertData, isDefaultNamespace, isElementContentWhitespace, isEqualNode, isId, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeAttribute, removeAttributeNode, removeAttributeNS, removeChild, replaceChild, replaceData, replaceWholeText, setAttributeNode, setAttributeNodeNS, setAttributeNS, setData, setIdAttribute, setIdAttributeNode, setIdAttributeNS, setNodeValue, setPrefix, setTextContent, setUserData, setValue, splitText, substringData, supports
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.icl.saxon.om.NodeInfo
copy, getNodeType, getStringValue
-
-
-
-
Field Detail
-
emptyArray
protected static NodeInfo[] emptyArray
-
parent
protected ParentNodeImpl parent
-
index
protected int index
-
-
Method Detail
-
setSystemId
public void setSystemId(java.lang.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
-
isSameNodeInfo
public boolean isSameNodeInfo(NodeInfo other)
Determine whether this is the same node as another node- Specified by:
isSameNodeInfo
in interfaceNodeInfo
- Specified by:
isSameNodeInfo
in classAbstractNode
- Returns:
- true if this Node object and the supplied Node object represent the same node in the tree.
-
getNameCode
public int getNameCode()
Get the nameCode of the node. This is used to locate the name in the NamePool- Specified by:
getNameCode
in interfaceNodeInfo
- Specified by:
getNameCode
in classAbstractNode
- See Also:
allocate
,getFingerprint
-
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 interfaceNodeInfo
- Specified by:
getFingerprint
in classAbstractNode
-
generateId
public java.lang.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 interfaceNodeInfo
- Specified by:
generateId
in classAbstractNode
- Returns:
- a string.
-
getOriginatingNode
public org.w3c.dom.Node getOriginatingNode()
Get the node corresponding to this javax.xml.transform.dom.DOMLocator- Specified by:
getOriginatingNode
in interfacejavax.xml.transform.dom.DOMLocator
- Overrides:
getOriginatingNode
in classAbstractNode
-
getSystemId
public java.lang.String getSystemId()
Get the system ID for the node. Default implementation for child nodes.- Specified by:
getSystemId
in interfaceNodeInfo
- Specified by:
getSystemId
in interfacejavax.xml.transform.Source
- Specified by:
getSystemId
in interfacejavax.xml.transform.SourceLocator
- Specified by:
getSystemId
in classAbstractNode
- Returns:
- the System Identifier of the entity in the source document containing the node, or null if not known. Note this is not the same as the base URI: the base URI can be modified by xml:base, but the system ID cannot.
-
getBaseURI
public java.lang.String getBaseURI()
Get the base URI for the node. Default implementation for child nodes.- Specified by:
getBaseURI
in interfaceorg.w3c.dom.Node
- Specified by:
getBaseURI
in interfaceNodeInfo
- Specified by:
getBaseURI
in classAbstractNode
-
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.
-
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 interfaceNodeInfo
- Specified by:
compareOrder
in classAbstractNode
- 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())
-
getNamePool
public NamePool getNamePool()
Get the NamePool
-
getPrefix
public java.lang.String getPrefix()
Get the prefix part of the name of this node. This is the name before the ":" if any.- Specified by:
getPrefix
in interfaceorg.w3c.dom.Node
- Specified by:
getPrefix
in interfaceNodeInfo
- Specified by:
getPrefix
in classAbstractNode
- Returns:
- the prefix part of the name. For an unnamed node, return an empty string.
-
getURI
public java.lang.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 interfaceNodeInfo
- Specified by:
getURI
in classAbstractNode
- Returns:
- The URI of the namespace of this node. For the default namespace, return an empty string. For an unnamed node, return null.
-
getDisplayName
public java.lang.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 interfaceNodeInfo
- Overrides:
getDisplayName
in classAbstractNode
- Returns:
- The display name of this node. For a node with no name, return an empty string.
-
getLocalName
public java.lang.String getLocalName()
Get the local name of this node.- Specified by:
getLocalName
in interfaceorg.w3c.dom.Node
- Specified by:
getLocalName
in interfaceNodeInfo
- Specified by:
getLocalName
in classAbstractNode
- Returns:
- The local name of this node. For a node with no name, return an empty string.
-
getLineNumber
public int getLineNumber()
Get the line number of the node within its source document entity- Specified by:
getLineNumber
in interfaceNodeInfo
- Specified by:
getLineNumber
in interfacejavax.xml.transform.SourceLocator
- Overrides:
getLineNumber
in classAbstractNode
- Returns:
- the line number of the node in its original source document; or -1 if not available
-
getParent
public final NodeInfo getParent()
Find the parent node of this node.- Specified by:
getParent
in interfaceNodeInfo
- Specified by:
getParent
in classAbstractNode
- Returns:
- The Node object describing the containing element or root node.
-
getPreviousSibling
public org.w3c.dom.Node getPreviousSibling()
Get the previous sibling of the node- Specified by:
getPreviousSibling
in interfaceorg.w3c.dom.Node
- Overrides:
getPreviousSibling
in classAbstractNode
- Returns:
- The previous sibling node. Returns null if the current node is the first child of its parent.
-
getNextSibling
public org.w3c.dom.Node getNextSibling()
Get next sibling node- Specified by:
getNextSibling
in interfaceorg.w3c.dom.Node
- Overrides:
getNextSibling
in classAbstractNode
- Returns:
- The next sibling node of the required type. Returns null if the current node is the last child of its parent.
-
getFirstChild
public org.w3c.dom.Node getFirstChild()
Get first child - default implementation used for leaf nodes- Specified by:
getFirstChild
in interfaceorg.w3c.dom.Node
- Overrides:
getFirstChild
in classAbstractNode
- Returns:
- null
-
getLastChild
public org.w3c.dom.Node getLastChild()
Get last child - default implementation used for leaf nodes- Specified by:
getLastChild
in interfaceorg.w3c.dom.Node
- Overrides:
getLastChild
in classAbstractNode
- Returns:
- null
-
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 interfaceNodeInfo
- Specified by:
getEnumeration
in classAbstractNode
- Parameters:
node
- NodeInfo representing the node from which the enumeration startsnodeType
- the type(s) of node to be included, e.g. NodeInfo.ELEMENT, NodeInfo.TEXT. The value NodeInfo.NODE means include any type of node.nodeTest
- A pattern to be matched by the returned nodes- Returns:
- an AxisEnumeration that scans the nodes reached by the axis in turn.
-
hasAttributes
public boolean hasAttributes()
Returns whether this node (if it is an element) has any attributes.- Specified by:
hasAttributes
in interfaceorg.w3c.dom.Node
- Specified by:
hasAttributes
in classAbstractNode
- Returns:
true
if this node has any attributes,false
otherwise.- Since:
- DOM Level 2
-
getAttributeValue
public java.lang.String getAttributeValue(java.lang.String uri, java.lang.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 interfaceNodeInfo
- Specified by:
getAttributeValue
in classAbstractNode
- Parameters:
uri
- the namespace uri of an attributelocalName
- the local name of an attribute- Returns:
- the value of the attribute, if it exists, otherwise null
-
getAttributeValue
public java.lang.String getAttributeValue(int fingerprint)
Get the value of a given attribute of this node- Specified by:
getAttributeValue
in interfaceNodeInfo
- Specified by:
getAttributeValue
in classAbstractNode
- Parameters:
fingerprint
- The fingerprint of the attribute name- Returns:
- the attribute value if it exists or null if not
-
getDocumentElement
public org.w3c.dom.Element getDocumentElement()
Get the outermost element.- Overrides:
getDocumentElement
in classAbstractNode
- 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 interfaceNodeInfo
- Overrides:
getDocumentRoot
in classAbstractNode
- Returns:
- the DocumentInfo representing the containing document
-
getNextInDocument
public NodeImpl getNextInDocument(NodeImpl anchor)
Get the next node in document order- Parameters:
anchor
- : the scan stops when it reaches a node that is not a descendant of the specified anchor node- Returns:
- the next node in the document, or null if there is no such node
-
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
-
outputNamespaceNodes
public void outputNamespaceNodes(Outputter out, boolean includeAncestors) throws javax.xml.transform.TransformerException
Output all namespace nodes associated with this element. Does nothing if the node is not an element.- Specified by:
outputNamespaceNodes
in interfaceNodeInfo
- Overrides:
outputNamespaceNodes
in classAbstractNode
- Parameters:
out
- The relevant outputterincludeAncestors
- True if namespaces declared on ancestor elements must be output; false if it is known that these are already on the result tree- Throws:
javax.xml.transform.TransformerException
-
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.
-
getChildNodes
public org.w3c.dom.NodeList getChildNodes()
Return aNodeList
that contains all children of this node. If there are no children, this is aNodeList
containing no nodes.- Specified by:
getChildNodes
in interfaceorg.w3c.dom.Node
- Overrides:
getChildNodes
in classAbstractNode
-
getAttributes
public org.w3c.dom.NamedNodeMap getAttributes()
Return aNamedNodeMap
containing the attributes of this node (if it is anElement
) ornull
otherwise. (DOM method)- Specified by:
getAttributes
in interfaceorg.w3c.dom.Node
- Overrides:
getAttributes
in classAbstractNode
-
hasChildNodes
public boolean hasChildNodes()
Determine whether the node has any children.- Specified by:
hasChildNodes
in interfaceorg.w3c.dom.Node
- Specified by:
hasChildNodes
in interfaceNodeInfo
- Specified by:
hasChildNodes
in classAbstractNode
- Returns:
true
if the node has any children,false
if the node has no children.
-
-