net.sf.saxon.tree
Class ElementImpl

java.lang.Object
  extended by net.sf.saxon.tree.NodeImpl
      extended by net.sf.saxon.tree.ElementImpl
All Implemented Interfaces:
Source, SourceLocator, PullEvent, FingerprintedNode, Item, NodeInfo, ValueRepresentation
Direct Known Subclasses:
ElementWithAttributes

public class ElementImpl
extends NodeImpl

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:
Michael H. Kay

Field Summary
 
Fields inherited from class net.sf.saxon.tree.NodeImpl
NODE_LETTER
 
Fields inherited from interface net.sf.saxon.om.NodeInfo
ALL_NAMESPACES, EMPTY_NAMESPACE_LIST, IS_DTD_TYPE, IS_NILLED, LOCAL_NAMESPACES, NO_NAMESPACES
 
Fields inherited from interface net.sf.saxon.om.ValueRepresentation
EMPTY_VALUE_ARRAY
 
Constructor Summary
ElementImpl()
          Construct an empty ElementImpl
 
Method Summary
 void addChild(NodeImpl node, int index)
          Add a child node to this node.
 void compact(int size)
          Compact the space used by this node
 void copy(Receiver out, int whichNamespaces, boolean copyAnnotations, int locationId)
          Copy this node to a given outputter (supporting xsl:copy-of)
 void generateId(FastStringBuffer buffer)
          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.
 int[] getDeclaredNamespaces(int[] buffer)
          Get all namespace undeclarations and undeclarations defined on this element.
 DocumentInfo getDocumentRoot()
          Get the root document node
 NodeInfo getFirstChild()
          Get the first child node of the element
 NodeInfo 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.
 NodeInfo getRoot()
          Get the root node
 String getStringValue()
          Return the string-value of the node, that is, the concatenation of the character content of all descendent elements and text nodes.
 CharSequence getStringValueCS()
          Get the value of the item as a CharSequence.
 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, AttributeCollectionImpl atts, NodeInfo parent, String baseURI, int lineNumber, int sequenceNumber)
          Initialise a new ElementImpl with an element name
 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.
 
Methods inherited from class net.sf.saxon.tree.NodeImpl
atomize, compareOrder, equals, getAttributeValue, getColumnNumber, getConfiguration, getDisplayName, getDocumentNumber, getFingerprint, getLocalPart, getNamePool, getNextInDocument, getNextSibling, getParent, getPrefix, getPreviousInDocument, getPreviousSibling, getPublicId, getTypeAnnotation, getTypedValue, getURI, hashCode, isSameNodeInfo, iterateAxis, iterateAxis
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

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

Parameters:
nameCode - the integer name code representing the element name

initialise

public void initialise(int nameCode,
                       AttributeCollectionImpl 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 Source
Specified by:
getSystemId in interface SourceLocator
Specified by:
getSystemId in interface NodeInfo
Overrides:
getSystemId in class NodeImpl
Returns:
the System Identifier of the entity in the source document containing the node, or null if not known or not applicable.

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
Returns:
the base URI of the node. This may be null if the base URI is unknown.

setLineNumber

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

Parameters:
line - the line number

getLineNumber

public int getLineNumber()
Get the line number of the node within its source document entity

Specified by:
getLineNumber in interface SourceLocator
Specified by:
getLineNumber in interface NodeInfo
Overrides:
getLineNumber in class NodeImpl
Returns:
the line number of the node in its original source document; or -1 if not available

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
Returns:
an integer name code, which may be used to obtain the actual node name from the name pool. For unnamed nodes (text nodes, comments, document nodes, and namespace nodes for the default namespace), returns -1.
See Also:
allocate, getFingerprint

generateId

public void generateId(FastStringBuffer buffer)
Get a character string that uniquely identifies this node

Specified by:
generateId in interface NodeInfo
Overrides:
generateId in class NodeImpl
Parameters:
buffer - to contain the generated ID

getDeclaredNamespaces

public int[] getDeclaredNamespaces(int[] buffer)
Get all namespace undeclarations and undeclarations defined on this element.

Specified by:
getDeclaredNamespaces in interface NodeInfo
Overrides:
getDeclaredNamespaces in class NodeImpl
Parameters:
buffer - If this is non-null, and the result array fits in this buffer, then the result may overwrite the contents of this array, to avoid the cost of allocating a new array on the heap.
Returns:
An array of integers representing the namespace declarations and undeclarations present on this element. For a node other than an element, return null. Otherwise, the returned array is a sequence of namespace codes, whose meaning may be interpreted by reference to the name pool. The top half word of each namespace code represents the prefix, the bottom half represents the URI. If the bottom half is zero, then this is a namespace undeclaration rather than a declaration. The XML namespace is never included in the list. If the supplied array is larger than required, then the first unused entry will be set to -1.

For a node other than an element, the method returns null.


getNodeKind

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

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

copy

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

Parameters:
out - The outputter
whichNamespaces - indicates which namespaces should be output: all, none, or local namespaces only (those not declared on the parent element)
copyAnnotations - indicates whether the type annotations of element and attribute nodes should be copied
locationId - If non-zero, identifies the location of the instruction that requested this copy. If zero, indicates that the location information for the original node is to be copied; in this case the Receiver must be a LocationCopier
Throws:
XPathException

hasChildNodes

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

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

getFirstChild

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

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

getLastChild

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

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

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.

Returns:
the accumulated character content of the element, including descendant elements.
See Also:
Item.getStringValueCS()

getStringValueCS

public CharSequence getStringValueCS()
Description copied from class: NodeImpl
Get the value of the item as a CharSequence. This is in some cases more efficient than the version of the method that returns a String.

Specified by:
getStringValueCS in interface Item
Specified by:
getStringValueCS in interface ValueRepresentation
Overrides:
getStringValueCS in class NodeImpl
Returns:
the string value of the item
See Also:
Item.getStringValue()

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.

Parameters:
node - the node to be added as a child of this node
index - the position where the child is to be added

compact

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

Parameters:
size - the number of actual children


Copyright (C) Michael H. Kay. All rights reserved.