net.sf.saxon.tree
Class ElementImpl

java.lang.Object
  extended bynet.sf.saxon.om.AbstractNode
      extended bynet.sf.saxon.tree.NodeImpl
          extended bynet.sf.saxon.tree.ParentNodeImpl
              extended bynet.sf.saxon.tree.ElementImpl
All Implemented Interfaces:
DOMLocator, Element, Item, Node, NodeInfo, Source, SourceLocator
Direct Known Subclasses:
ElementWithAttributes

public class ElementImpl
extends ParentNodeImpl
implements Element

ElementImpl implements an element with no attributes or namespace declarations.

This class is an implementation of NodeInfo. For elements with attributes or namespace declarations, class ElementWithAttributes is used.

Author:
Field Summary
protected  int nameCode
           
protected  DocumentImpl root
           
protected  int sequence
           
 
Fields inherited from class net.sf.saxon.tree.NodeImpl
index, parent
 
Fields inherited from class net.sf.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_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
Fields inherited from interface net.sf.saxon.om.NodeInfo
ALL_NAMESPACES, LOCAL_NAMESPACES, NO_NAMESPACES
 
Constructor Summary
ElementImpl()
          Construct an empty ElementImpl
 
Method Summary
 void addChild(NodeImpl node, int index)
          Add a child node to this node.
 void addNamespaceNodes(ElementImpl owner, List list, boolean addXML)
          Make the set of all namespace nodes associated with this element.
 void compact(int size)
          Compact the space used by this node
 void copy(Receiver out, int whichNamespaces)
          Copy this node to a given outputter (supporting xsl:copy-of)
 AxisIterator enumerateChildren(NodeTest test)
          Get an enumeration of the children of this node
 String generateId()
          Get a character string that uniquely identifies this node
 AttributeCollection getAttributeList()
          Get the attribute list for this element.
 String getBaseURI()
          Get the base URI of this element node.
 DocumentInfo getDocumentRoot()
          Get the root document node
 Node getFirstChild()
          Get the first child node of the element
 Node getLastChild()
          Get the last child node of the element
 int getLineNumber()
          Get the line number of the node within its source document entity
 int getNameCode()
          Get the nameCode of the node.
 int getNodeKind()
          Return the type of node.
 String getNodeValue()
          Get the node value as defined in the DOM.
protected  NodeImpl getNthChild(int n)
          Get the nth child node of the element (numbering from 0)
 NodeInfo getRoot()
          Get the root node
protected  long getSequenceNumber()
          Get the node sequence number (in document order).
 String getStringValue()
          Return the string-value of the node, that is, the concatenation of the character content of all descendent elements and text nodes.
 String getSystemId()
          Get the system ID of the entity containing this element node.
 boolean hasChildNodes()
          Determine if the node has any children.
 void initialise(int nameCode, AttributeCollection atts, NodeInfo parent, String baseURI, int lineNumber, int sequenceNumber)
          Initialise a new ElementImpl with an element name
 void outputNamespaceNodes(Receiver out, boolean includeAncestors)
          Output all namespace nodes associated with this element.
 void setAttribute(String name, String value)
          Set the value of an attribute on the current element.
 void setLineNumber(int line)
          Set the line number of the element within its source document entity
 void setNameCode(int nameCode)
          Set the name code.
 void setSystemId(String uri)
          Set the system ID of this node.
 void useChildrenArray(NodeImpl[] array)
          Supply an array to be used for the array of children.
 
Methods inherited from class net.sf.saxon.tree.NodeImpl
compareOrder, copy, getAttributeValue, getDisplayName, getDocumentElement, getFingerprint, getLocalPart, getNamePool, getNextInDocument, getNextSibling, getOriginatingNode, getParent, getPrefix, getPreviousInDocument, getPreviousSibling, getURI, hasAttributes, isSameNode, iterateAxis, iterateAxis
 
Methods inherited from class net.sf.saxon.om.AbstractNode
appendChild, appendData, cloneNode, createAttribute, createAttributeNS, createCDATASection, createComment, createDocumentFragment, createElement, createElementNS, createEntityReference, createProcessingInstruction, createTextNode, deleteData, disallowUpdate, getAttribute, getAttributeNode, getAttributeNodeNS, getAttributeNS, getAttributes, getChildNodes, getColumnNumber, getData, getDoctype, getDocumentNumber, getElementById, getElementsByTagName, getElementsByTagNameNS, getImplementation, getLength, getLocalName, getName, getNamespaceURI, getNodeName, getNodeType, getOwnerDocument, getOwnerElement, getParentNode, getPublicId, getSpecified, getTagName, getTypeAnnotation, getTypedValue, getValue, hasAttribute, hasAttributeNS, importNode, insertBefore, insertData, isSupported, normalize, removeAttribute, removeAttributeNode, removeAttributeNS, removeChild, replaceChild, replaceData, setAttributeNode, setAttributeNodeNS, setAttributeNS, setData, setNodeValue, setPrefix, 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 org.w3c.dom.Element
getAttribute, getAttributeNode, getAttributeNodeNS, getAttributeNS, getElementsByTagName, getElementsByTagNameNS, getTagName, hasAttribute, hasAttributeNS, removeAttribute, removeAttributeNode, removeAttributeNS, setAttributeNode, setAttributeNodeNS, setAttributeNS
 
Methods inherited from interface org.w3c.dom.Node
appendChild, cloneNode, getAttributes, getChildNodes, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, hasAttributes, hasChildNodes, insertBefore, isSupported, normalize, removeChild, replaceChild, setNodeValue, setPrefix
 

Field Detail

nameCode

protected int nameCode

root

protected DocumentImpl root

sequence

protected int sequence
Constructor Detail

ElementImpl

public ElementImpl()
Construct an empty ElementImpl

Method Detail

setNameCode

public void setNameCode(int nameCode)
Set the name code. Used when creating a dummy element in the Stripper


initialise

public void initialise(int nameCode,
                       AttributeCollection atts,
                       NodeInfo parent,
                       String baseURI,
                       int lineNumber,
                       int sequenceNumber)
Initialise a new ElementImpl with an element name

Parameters:
nameCode - Integer representing the element name, with namespaces resolved
atts - The attribute list: always null
parent - The parent node
baseURI - The base URI of the new element
lineNumber - The line number of the element in the source document
sequenceNumber - Integer identifying this element within the document

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

Specified by:
setSystemId in interface Source
Overrides:
setSystemId in class NodeImpl

getRoot

public NodeInfo getRoot()
Get the root node

Specified by:
getRoot in interface NodeInfo
Overrides:
getRoot in class NodeImpl
Returns:
the NodeInfo representing the containing document

getDocumentRoot

public DocumentInfo getDocumentRoot()
Get the root document node

Specified by:
getDocumentRoot in interface NodeInfo
Overrides:
getDocumentRoot in class NodeImpl
Returns:
the DocumentInfo representing the containing document

getSystemId

public final String getSystemId()
Get the system ID of the entity containing this element node.

Specified by:
getSystemId in interface NodeInfo
Overrides:
getSystemId in class NodeImpl

getBaseURI

public String getBaseURI()
Get the base URI of this element node. This will be the same as the System ID unless xml:base has been used.

Specified by:
getBaseURI in interface NodeInfo
Overrides:
getBaseURI in class NodeImpl

setLineNumber

public void setLineNumber(int line)
Set the line number of the element within its source document entity


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 class NodeImpl

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 class NodeImpl

generateId

public String generateId()
Get a character string that uniquely identifies this node

Specified by:
generateId in interface NodeInfo
Overrides:
generateId in class NodeImpl
Returns:
a string.

addNamespaceNodes

public void addNamespaceNodes(ElementImpl owner,
                              List list,
                              boolean addXML)
Make the set of all namespace nodes associated with this element.

Parameters:
owner - The element owning these namespace nodes.
list - a List containing NamespaceImpl objects representing the namespaces in scope for this element; the method appends nodes to this List, which should initially be empty. Note that the returned list will never contain the XML namespace (to get this, the NamespaceEnumeration class adds it itself). The list WILL include an entry for the undeclaration xmlns=""; again it is the job of NamespaceEnumeration to ignore this, since it doesn't represent a true namespace node.
addXML - Add the XML namespace node to the list

outputNamespaceNodes

public void outputNamespaceNodes(Receiver out,
                                 boolean includeAncestors)
                          throws TransformerException
Output all namespace nodes associated with this element.

Specified by:
outputNamespaceNodes in interface NodeInfo
Overrides:
outputNamespaceNodes in class NodeImpl
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
Throws:
TransformerException

getNodeKind

public final int getNodeKind()
Return the type of node.

Specified by:
getNodeKind in interface NodeInfo
Returns:
Type.ELEMENT
See Also:
Type

getAttributeList

public AttributeCollection getAttributeList()
Get the attribute list for this element.

Returns:
The attribute list. This will not include any namespace attributes. The attribute names will be in expanded form, with prefixes replaced by URIs

setAttribute

public void setAttribute(String name,
                         String value)
                  throws DOMException
Set the value of an attribute on the current element.

Specified by:
setAttribute in interface Element
Throws:
DOMException - (always): the Saxon tree is immutable

copy

public void copy(Receiver out,
                 int whichNamespaces)
          throws TransformerException
Copy this node to a given outputter (supporting xsl:copy-of)

Specified by:
copy in class NodeImpl
Parameters:
out - The outputter
whichNamespaces - indicates which namespaces should be output: all, none, or local namespaces only (those not declared on the parent element)
Throws:
TransformerException

getSequenceNumber

protected final 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.

Overrides:
getSequenceNumber in class NodeImpl

hasChildNodes

public final boolean hasChildNodes()
Determine if the node has any children.

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

enumerateChildren

public final AxisIterator enumerateChildren(NodeTest test)
Get an enumeration of the children of this node

Parameters:
test - A NodeTest to be satisfied by the child nodes, or null if all child node are to be returned

getFirstChild

public final Node getFirstChild()
Get the first child node of the element

Specified by:
getFirstChild in interface Node
Overrides:
getFirstChild in class NodeImpl
Returns:
the first child node of the required type, or null if there are no children

getLastChild

public final Node getLastChild()
Get the last child node of the element

Specified by:
getLastChild in interface Node
Overrides:
getLastChild in class NodeImpl
Returns:
the last child of the element, or null if there are no children

getNthChild

protected final NodeImpl getNthChild(int n)
Get the nth child node of the element (numbering from 0)

Returns:
the last child of the element, or null if there is no n'th child

getStringValue

public String getStringValue()
Return the string-value of the node, that is, the concatenation of the character content of all descendent elements and text nodes.

Specified by:
getStringValue in interface NodeInfo
Specified by:
getStringValue in class AbstractNode
Returns:
the accumulated character content of the element, including descendant elements.

useChildrenArray

public void useChildrenArray(NodeImpl[] array)
Supply an array to be used for the array of children. For system use only.


addChild

public void addChild(NodeImpl node,
                     int index)
Add a child node to this node. For system use only. Note: normalizing adjacent text nodes is the responsibility of the caller.


compact

public void compact(int size)
Compact the space used by this node


getNodeValue

public String getNodeValue()
Get the node value as defined in the DOM. This is not the same as the XPath string-value.

Specified by:
getNodeValue in interface Node
Overrides:
getNodeValue in class AbstractNode