net.sf.saxon.tree
Class ElementWithAttributes

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

public class ElementWithAttributes
extends ElementImpl
implements NamespaceResolver

A node in the XML parse tree representing an XML element.

This class is an implementation of NodeInfo

Version:
8 August 2000: separated from ElementImpl
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
ElementWithAttributes()
           
 
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)
 AttributeCollection getAttributeList()
          Get the attribute list for this element.
 String getAttributeValue(int fingerprint)
          Get the value of a given attribute of this node
 int[] getDeclaredNamespaces(int[] buffer)
          Get all namespace undeclarations and undeclarations defined on this element.
 NodeInfo getFirstChild()
          Get the first child node of the element
 int[] getInScopeNamespaceCodes()
          Get the list of in-scope namespaces for this element as an array of namespace codes.
 NodeInfo getLastChild()
          Get the last child node of the element
 String getPrefixForURI(String uri)
          Search the NamespaceList for a given URI, returning the corresponding prefix.
 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.
 short getURICodeForPrefix(String prefix)
          Search the NamespaceList for a given prefix, returning the corresponding URI.
 String getURIForPrefix(String prefix, boolean useDefault)
          Get the namespace URI corresponding to a given prefix.
 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 ElementWithAttributes with an element name and attribute list
 Iterator iteratePrefixes()
          Get an iterator over all the prefixes declared in this namespace context.
 void setNamespaceDeclarations(int[] namespaces, int namespacesUsed)
          Set the namespace declarations for the element
 
Methods inherited from class net.sf.saxon.tree.ElementImpl
generateId, getBaseURI, getDocumentRoot, getLineNumber, getNameCode, getNodeKind, getRoot, getSystemId, setLineNumber, setNameCode, setSystemId
 
Methods inherited from class net.sf.saxon.tree.NodeImpl
atomize, compareOrder, equals, 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

ElementWithAttributes

public ElementWithAttributes()
Method Detail

initialise

public void initialise(int nameCode,
                       AttributeCollectionImpl atts,
                       NodeInfo parent,
                       String baseURI,
                       int lineNumber,
                       int sequenceNumber)
Initialise a new ElementWithAttributes with an element name and attribute list

Overrides:
initialise in class ElementImpl
Parameters:
nameCode - The element name, with namespaces resolved
atts - The attribute list, after namespace processing
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

setNamespaceDeclarations

public void setNamespaceDeclarations(int[] namespaces,
                                     int namespacesUsed)
Set the namespace declarations for the element

Parameters:
namespaces - the list of namespace codes
namespacesUsed - the number of entries in the list that are used

getURIForPrefix

public String getURIForPrefix(String prefix,
                              boolean useDefault)
Get the namespace URI corresponding to a given prefix. Return null if the prefix is not in scope.

Specified by:
getURIForPrefix in interface NamespaceResolver
Parameters:
prefix - the namespace prefix. May be the zero-length string, indicating that there is no prefix. This indicates either the default namespace or the null namespace, depending on the value of useDefault.
useDefault - true if the default namespace is to be used when the prefix is "". If false, the method returns "" when the prefix is "".
Returns:
the uri for the namespace, or null if the prefix is not in scope. The "null namespace" is represented by the pseudo-URI "".

iteratePrefixes

public Iterator iteratePrefixes()
Get an iterator over all the prefixes declared in this namespace context. This will include the default namespace (prefix="") and the XML namespace where appropriate

Specified by:
iteratePrefixes in interface NamespaceResolver

getURICodeForPrefix

public short getURICodeForPrefix(String prefix)
                          throws NamespaceException
Search the NamespaceList for a given prefix, returning the corresponding URI.

Parameters:
prefix - The prefix to be matched. To find the default namespace, supply ""
Returns:
The URI code corresponding to this namespace. If it is an unnamed default namespace, return Namespace.NULL_CODE.
Throws:
NamespaceException - if the prefix has not been declared on this NamespaceList.

getPrefixForURI

public String getPrefixForURI(String uri)
Search the NamespaceList for a given URI, returning the corresponding prefix.

Parameters:
uri - The URI to be matched.
Returns:
The prefix corresponding to this URI. If not found, return null. If there is more than one prefix matching the URI, the first one found is returned. If the URI matches the default namespace, return an empty string.

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 ElementImpl
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.


getInScopeNamespaceCodes

public int[] getInScopeNamespaceCodes()
Get the list of in-scope namespaces for this element as an array of namespace codes. (Used by LiteralResultElement)

Returns:
the list of namespaces

getAttributeList

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

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

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 class NodeImpl
Parameters:
fingerprint - The fingerprint of the attribute name
Returns:
the attribute value if it exists or null if not

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)

Specified by:
copy in interface NodeInfo
Overrides:
copy in class ElementImpl
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.