Class ElementImpl
- java.lang.Object
-
- net.sf.saxon.tree.linked.NodeImpl
-
- net.sf.saxon.tree.linked.ParentNodeImpl
-
- net.sf.saxon.tree.linked.ElementImpl
-
- All Implemented Interfaces:
javax.xml.transform.Source
,javax.xml.transform.SourceLocator
,ActiveSource
,GroundedValue
,Item
,MutableNodeInfo
,NamespaceResolver
,NodeInfo
,Sequence
,Location
,SteppingNode
,SiblingCountingNode
,org.xml.sax.Locator
- Direct Known Subclasses:
DataElement
,SchemaElement
,StyleElement
public class ElementImpl extends ParentNodeImpl implements NamespaceResolver
ElementImpl implements an element node in the Linked tree model. Subclasses of ElementImpl, for holding particular kinds of element, can be defined by using aNodeFactory
registered with theLinkedTreeBuilder
used to construct the tree.
-
-
Field Summary
-
Fields inherited from class net.sf.saxon.tree.linked.NodeImpl
NODE_LETTER
-
-
Constructor Summary
Constructors Constructor Description ElementImpl()
Construct an empty ElementImpl
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAttribute(NodeName nodeName, SimpleType attType, java.lang.String value, int properties, boolean inheritNamespaces)
Add an attribute to this element node.void
addNamespace(java.lang.String prefix, NamespaceUri uri)
Add a namespace node from this node.void
addNamespace(NamespaceBinding binding, boolean inherit)
Add a namespace binding (that is, a namespace node) to this element.AttributeMap
attributes()
Get the attributes of the elementprotected void
checkNotNamespaceSensitiveElement(SchemaType type)
Check whether the content of this element is namespace-sensitivevoid
copy(Receiver out, int copyOptions, Location location)
Copy this node to a given Receiver.void
delete()
Delete this node (that is, detach it from its parent)protected void
fixupInsertedNamespaces(boolean inherit)
Ensure that a child element being inserted into a tree has the right namespace declarations.void
generateId(java.lang.StringBuilder buffer)
Get a character string that uniquely identifies this nodeNamespaceMap
getAllNamespaces()
Get the namespace list for this element.java.lang.String
getAttributeValue(NamespaceUri uri, java.lang.String localName)
Get the value of a given attribute of this nodejava.lang.String
getBaseURI()
Get the base URI of this element node.int
getColumnNumber()
Get the line number of the node within its source document entityNamespaceBinding[]
getDeclaredNamespaces(NamespaceBinding[] buffer)
Get all namespace undeclarations and undeclarations defined on this element.int
getLineNumber()
Get the line number of the node within its source document entityint
getNodeKind()
Return the kind of node.NodeName
getNodeName()
Get the name of the node.NodeInfo
getRoot()
Get the root nodeSchemaType
getSchemaType()
Get the type annotationjava.lang.String
getSystemId()
Get the system ID of the entity containing this element node.NamespaceUri
getURIForPrefix(java.lang.String prefix, boolean useDefault)
Get the namespace URI corresponding to a given prefix.void
initialise(NodeName elemName, SchemaType elementType, AttributeMap atts, NodeInfo parent, int sequenceNumber)
Initialise a new ElementImpl with an element nameboolean
isId()
Determine whether this node has the is-id propertyboolean
isIdref()
Ask whether this node has the is-idref propertystatic boolean
isIdRefNode(NodeImpl node)
boolean
isInScopeNamespace(NamespaceUri uri)
Search the in-scope namespaces to see whether a given namespace is in scope.boolean
isNilled()
Determine whether the node has the is-nilled propertyjava.util.Iterator<java.lang.String>
iteratePrefixes()
Get an iterator over all the prefixes declared in this namespace context.void
removeAttribute(NodeInfo attribute)
Remove an attribute from this element nodevoid
removeNamespace(java.lang.String prefix)
Remove a namespace node from this node.void
removeTypeAnnotation()
Remove type information from this node (and its ancestors, recursively).void
rename(NodeName newName, boolean inherit)
Rename this nodevoid
replaceStringValue(UnicodeString stringValue)
Replace the string-value of this nodevoid
setAttributeInfo(int index, AttributeInfo attInfo)
Change details of an attribute of this elementvoid
setAttributes(AttributeMap atts)
Set the attribute listvoid
setLocation(java.lang.String systemId, int line, int column)
Set location information for this nodevoid
setNamespaceMap(NamespaceMap map)
void
setNilled()
Say that the element has the nilled propertyvoid
setNodeName(NodeName name)
Set the node namevoid
setSystemId(java.lang.String uri)
Set the system ID of this node.void
setTypeAnnotation(SchemaType type)
Set the type annotation on a node.-
Methods inherited from class net.sf.saxon.tree.linked.ParentNodeImpl
addChild, compact, getFirstChild, getLastChild, getNthChild, getNumberOfChildren, getRawSequenceNumber, getSequenceNumber, getUnicodeStringValue, hasChildNodes, insertChildren, insertChildrenAt, iterateChildren, removeChild, replaceChildrenAt, setChildren, setRawSequenceNumber
-
Methods inherited from class net.sf.saxon.tree.linked.NodeImpl
atomize, compareOrder, effectiveBooleanValue, equals, getConfiguration, getDisplayName, getFingerprint, getLocalPart, getNamePool, getNamespaceUri, getNextInDocument, getNextSibling, getParent, getPhysicalRoot, getPrefix, getPreviousInDocument, getPreviousSibling, getRawParent, getSiblingPosition, getSuccessorElement, getTreeInfo, hasFingerprint, hashCode, head, insertSiblings, isDeleted, iterateAxis, iterateAxis, newBuilder, replace, saveLocation, setRawParent, setSiblingPosition
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.om.GroundedValue
asIterable, concatenate, containsNode, materialize
-
Methods inherited from interface net.sf.saxon.om.Item
getLength, getStringValue, itemAt, iterate, reduce, subsequence
-
Methods inherited from interface net.sf.saxon.om.NodeInfo
asActiveSource, children, children, deliver, getAttributeValue, getGenre, getPublicId, getURI, isSameNodeInfo, isStreamed, toShortString
-
Methods inherited from interface net.sf.saxon.om.Sequence
makeRepeatable
-
-
-
-
Method Detail
-
setAttributes
public void setAttributes(AttributeMap atts)
Set the attribute list- Specified by:
setAttributes
in interfaceMutableNodeInfo
- Overrides:
setAttributes
in classNodeImpl
- Parameters:
atts
- the list of attributes of this element (not including namespace attributes)
-
setNodeName
public void setNodeName(NodeName name)
Set the node name- Parameters:
name
- the node name
-
initialise
public void initialise(NodeName elemName, SchemaType elementType, AttributeMap atts, NodeInfo parent, int sequenceNumber)
Initialise a new ElementImpl with an element name- Parameters:
elemName
- Integer representing the element name, with namespaces resolvedelementType
- the schema type of the element nodeatts
- The attribute list: always nullparent
- The parent nodesequenceNumber
- Integer identifying this element within the document
-
getNodeName
public NodeName getNodeName()
Get the name of the node. Returns null for an unnamed node- Overrides:
getNodeName
in classNodeImpl
- Returns:
- the name of the node
-
setLocation
public void setLocation(java.lang.String systemId, int line, int column)
Set location information for this node- Parameters:
systemId
- the base URIline
- the line number if knowncolumn
- the column number if known
-
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- Specified by:
setSystemId
in interfaceNodeInfo
- Specified by:
setSystemId
in interfacejavax.xml.transform.Source
- Overrides:
setSystemId
in classNodeImpl
-
getRoot
public NodeInfo getRoot()
Get the root node
-
getSystemId
public final java.lang.String getSystemId()
Get the system ID of the entity containing this element node.- Specified by:
getSystemId
in interfaceLocation
- Specified by:
getSystemId
in interfaceorg.xml.sax.Locator
- Specified by:
getSystemId
in interfaceNodeInfo
- Specified by:
getSystemId
in interfacejavax.xml.transform.Source
- Specified by:
getSystemId
in interfacejavax.xml.transform.SourceLocator
- Overrides:
getSystemId
in classNodeImpl
- Returns:
- the System Identifier of the entity in the source document containing the node, or null if not known or not applicable.
-
getBaseURI
public java.lang.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 interfaceNodeInfo
- Overrides:
getBaseURI
in classNodeImpl
- Returns:
- the base URI of the node. This may be null if the base URI is unknown, including the case where the node has no parent.
-
isNilled
public boolean isNilled()
Determine whether the node has the is-nilled property
-
setTypeAnnotation
public void setTypeAnnotation(SchemaType type)
Set the type annotation on a node. This must only be called when the caller has verified (by validation) that the node is a valid instance of the specified type. The call is ignored if the node is not an element or attribute node.- Specified by:
setTypeAnnotation
in interfaceMutableNodeInfo
- Overrides:
setTypeAnnotation
in classNodeImpl
- Parameters:
type
- the type annotation
-
setNilled
public void setNilled()
Say that the element has the nilled property
-
getSchemaType
public SchemaType getSchemaType()
Get the type annotation- Specified by:
getSchemaType
in interfaceNodeInfo
- Overrides:
getSchemaType
in classNodeImpl
- Returns:
- the type annotation of the node
-
getLineNumber
public int getLineNumber()
Get the line number of the node within its source document entity- Specified by:
getLineNumber
in interfaceLocation
- Specified by:
getLineNumber
in interfaceorg.xml.sax.Locator
- Specified by:
getLineNumber
in interfaceNodeInfo
- Specified by:
getLineNumber
in interfacejavax.xml.transform.SourceLocator
- Overrides:
getLineNumber
in classNodeImpl
- Returns:
- the line number of the node in its original source document; or -1 if not available. The default implementation returns -1.
-
getColumnNumber
public int getColumnNumber()
Get the line number of the node within its source document entity- Specified by:
getColumnNumber
in interfaceLocation
- Specified by:
getColumnNumber
in interfaceorg.xml.sax.Locator
- Specified by:
getColumnNumber
in interfaceNodeInfo
- Specified by:
getColumnNumber
in interfacejavax.xml.transform.SourceLocator
- Overrides:
getColumnNumber
in classNodeImpl
- Returns:
- the column number of the node in its original source document; or -1 if not available. The default implementation returns -1.
-
generateId
public void generateId(java.lang.StringBuilder buffer)
Get a character string that uniquely identifies this node- Specified by:
generateId
in interfaceNodeInfo
- Overrides:
generateId
in classNodeImpl
- Parameters:
buffer
- to contain the generated ID
-
getNodeKind
public final int getNodeKind()
Return the kind of node.- Specified by:
getNodeKind
in interfaceNodeInfo
- Returns:
- Type.ELEMENT
- See Also:
Type
-
attributes
public AttributeMap attributes()
Get the attributes of the element- Specified by:
attributes
in interfaceNodeInfo
- Overrides:
attributes
in classNodeImpl
- Returns:
- an attribute map containing the attributes of the element
-
copy
public void copy(Receiver out, int copyOptions, Location location) throws XPathException
Copy this node to a given Receiver.This method is primarily for internal use. It should not be considered a stable part of the Saxon API.
- Specified by:
copy
in interfaceNodeInfo
- Parameters:
out
- the Receiver to which the node should be copied. It is the caller's responsibility to ensure that this Receiver is open before the method is called (or that it is self-opening), and that it is closed after use.copyOptions
- a selection of the options defined inCopyOptions
location
- If non-null, identifies the location of the instruction that requested this copy. If zero, indicates that the location information is not available- Throws:
XPathException
- if any downstream error occurs
-
checkNotNamespaceSensitiveElement
protected void checkNotNamespaceSensitiveElement(SchemaType type) throws XPathException
Check whether the content of this element is namespace-sensitive- Parameters:
type
- the type annotation of the node- Throws:
XPathException
- if an error occurs
-
delete
public void delete()
Delete this node (that is, detach it from its parent)- Specified by:
delete
in interfaceMutableNodeInfo
- Overrides:
delete
in classNodeImpl
-
rename
public void rename(NodeName newName, boolean inherit)
Rename this node- Specified by:
rename
in interfaceMutableNodeInfo
- Overrides:
rename
in classNodeImpl
- Parameters:
newName
- the new nameinherit
- true if any new namespace binding is to be inherited
-
addNamespace
public void addNamespace(NamespaceBinding binding, boolean inherit)
Add a namespace binding (that is, a namespace node) to this element. This call has no effect if applied to a node other than an element.- Specified by:
addNamespace
in interfaceMutableNodeInfo
- Overrides:
addNamespace
in classNodeImpl
- Parameters:
binding
- The namespace binding to be added. If the target element already has a namespace binding with this (prefix, uri) pair, the call has no effect. If the target element currently has a namespace binding with this prefix and a different URI, an exception is raised.inherit
- true if the namespace is to be inherited by descendant elements
-
replaceStringValue
public void replaceStringValue(UnicodeString stringValue)
Replace the string-value of this node- Specified by:
replaceStringValue
in interfaceMutableNodeInfo
- Parameters:
stringValue
- the new string value
-
setAttributeInfo
public void setAttributeInfo(int index, AttributeInfo attInfo)
Change details of an attribute of this element- Parameters:
index
- the index position of the attribute to be changedattInfo
- new details of the attribute
-
addAttribute
public void addAttribute(NodeName nodeName, SimpleType attType, java.lang.String value, int properties, boolean inheritNamespaces)
Add an attribute to this element node.If this node is not an element, or if the supplied node is not an attribute, the method takes no action. If the element already has an attribute with this name, the method throws an exception.
This method does not perform any namespace fixup. It is the caller's responsibility to ensure that any namespace prefix used in the name of the attribute (or in its value if it has a namespace-sensitive type) is declared on this element.
- Specified by:
addAttribute
in interfaceMutableNodeInfo
- Overrides:
addAttribute
in classNodeImpl
- Parameters:
nodeName
- the name of the new attributeattType
- the type annotation of the new attributevalue
- the string value of the new attributeproperties
- properties including IS_ID and IS_IDREF propertiesinheritNamespaces
- true if any namespace used by this attribute name is to be inherited by descendant elements- Throws:
java.lang.IllegalStateException
- if the element already has an attribute with the given name.
-
removeAttribute
public void removeAttribute(NodeInfo attribute)
Remove an attribute from this element nodeIf this node is not an element, or if the specified node is not an attribute of this element, this method takes no action.
The attribute object itself becomes unusable; any attempt to use this attribute object, or any other object representing the same node, is likely to result in an exception.
- Specified by:
removeAttribute
in interfaceMutableNodeInfo
- Overrides:
removeAttribute
in classNodeImpl
- Parameters:
attribute
- the attribute node to be removed
-
removeNamespace
public void removeNamespace(java.lang.String prefix)
Remove a namespace node from this node. The namespaces of its descendant nodes are unaffected. The method has no effect on non-element nodes, nor on elements if there is no in-scope namespace with the required prefix, nor if the element name or one of its attributes uses this namespace prefix- Specified by:
removeNamespace
in interfaceMutableNodeInfo
- Parameters:
prefix
- the namespace prefix.
-
addNamespace
public void addNamespace(java.lang.String prefix, NamespaceUri uri)
Add a namespace node from this node. The namespaces of its descendant nodes are unaffected. The method has no effect on non-element nodes. If there is an existing namespace using this prefix, the method throws an exception.- Specified by:
addNamespace
in interfaceMutableNodeInfo
- Parameters:
prefix
- the namespace prefix. Empty string for the default namespace.uri
- The namespace URI.
-
removeTypeAnnotation
public void removeTypeAnnotation()
Remove type information from this node (and its ancestors, recursively). This method implements the upd:removeType() primitive defined in the XQuery Update specification- Specified by:
removeTypeAnnotation
in interfaceMutableNodeInfo
- Overrides:
removeTypeAnnotation
in classNodeImpl
-
setNamespaceMap
public void setNamespaceMap(NamespaceMap map)
-
getURIForPrefix
public NamespaceUri getURIForPrefix(java.lang.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 interfaceNamespaceResolver
- 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 java.util.Iterator<java.lang.String> 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 interfaceNamespaceResolver
- Returns:
- an iterator over all the prefixes for which a namespace binding exists, including the zero-length string to represent the null/absent prefix if it is bound
-
isInScopeNamespace
public boolean isInScopeNamespace(NamespaceUri uri)
Search the in-scope namespaces to see whether a given namespace is in scope.- Parameters:
uri
- The URI to be matched.- Returns:
- true if the namespace is in scope
-
getDeclaredNamespaces
public NamespaceBinding[] getDeclaredNamespaces(NamespaceBinding[] buffer)
Get all namespace undeclarations and undeclarations defined on this element.- Specified by:
getDeclaredNamespaces
in interfaceNodeInfo
- Overrides:
getDeclaredNamespaces
in classNodeImpl
- 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 NamespaceBinding objects representing the namespace declarations and undeclarations present on
this element. For a node other than an element, return null.
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 null.
For a node other than an element, the method returns null.
-
fixupInsertedNamespaces
protected void fixupInsertedNamespaces(boolean inherit)
Ensure that a child element being inserted into a tree has the right namespace declarations. Redundant declarations should be removed. If the child is in the null namespace but the parent has a default namespace, xmlns="" should be added. If inherit is false, namespace undeclarations should be added for all namespaces that are declared on the parent but not on the child.- Parameters:
inherit
- true if the child is to inherit the inscope namespaces of its new parent
-
getAllNamespaces
public NamespaceMap getAllNamespaces()
Get the namespace list for this element.- Specified by:
getAllNamespaces
in interfaceNodeInfo
- Overrides:
getAllNamespaces
in classNodeImpl
- Returns:
- The full set of in-scope namespaces
-
getAttributeValue
public java.lang.String getAttributeValue(NamespaceUri uri, java.lang.String localName)
Get the value of a given attribute of this node- Specified by:
getAttributeValue
in interfaceNodeInfo
- Overrides:
getAttributeValue
in classNodeImpl
- Parameters:
uri
- the namespace URI of the attribute name, orNamespaceUri.NULL
if the attribute is not in a namespacelocalName
- the local part of the attribute name- Returns:
- the attribute value if it exists or null if not
-
isId
public boolean isId()
Determine whether this node has the is-id property
-
isIdref
public boolean isIdref()
Ask whether this node has the is-idref property
-
isIdRefNode
public static boolean isIdRefNode(NodeImpl node)
-
-