Class ElementImpl
- All Implemented Interfaces:
Source,SourceLocator,PullEvent,FingerprintedNode,Item<NodeInfo>,MutableNodeInfo,NamespaceResolver,NodeInfo,ValueRepresentation<NodeInfo>,SiblingCountingNode
- Direct Known Subclasses:
DataElement,StyleElement
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.linked.NodeImpl
NODE_LETTERFields inherited from interface net.sf.saxon.om.NodeInfo
ALL_NAMESPACES, IS_DTD_TYPE, IS_NILLED, LOCAL_NAMESPACES, NO_NAMESPACESFields inherited from interface net.sf.saxon.om.ValueRepresentation
EMPTY_VALUE_ARRAY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAttribute(NodeName nameCode, SimpleType attType, CharSequence value, int properties) Add an attribute to this element node.voidaddNamespace(NamespaceBinding nscode, boolean inherit) Add a namespace binding (that is, a namespace node) to this element.voidCopy this node to a given outputter (supporting xsl:copy-of)voiddelete()Delete this node (that is, detach it from its parent)protected voidfixupInsertedNamespaces(boolean inherit) Ensure that a child element being inserted into a tree has the right namespace declarations.voidgenerateId(FastStringBuffer buffer) Get a character string that uniquely identifies this nodeGet the attribute list for this element.getAttributeValue(int fingerprint) Get the value of a given attribute of this nodegetAttributeValue(String uri, String localName) Get the value of a given attribute of this nodeGet the base URI of this element node.intGet the line number of the node within its source document entitygetDeclaredNamespaces(NamespaceBinding[] buffer) Get all namespace undeclarations and undeclarations defined on this element.Get the root node, if it is a document node.intGet the line number of the node within its source document entityintGet the nameCode of the node.Get the namespace list for this element.final intReturn the kind of node.getPrefixForURI(String uri) Search the NamespaceList for a given URI, returning the corresponding prefix.getRoot()Get the root nodeGet the type annotationfinal StringGet the system ID of the entity containing this element node.intGet the fingerpint of the type annotation of this node, if anygetURIForPrefix(String prefix, boolean useDefault) Get the namespace URI corresponding to a given prefix.Get the attribute list.voidinitialise(NodeName elemName, SchemaType elementType, AttributeCollectionImpl atts, NodeInfo parent, int sequenceNumber) Initialise a new ElementImpl with an element namebooleanisId()Determine whether this node has the is-id propertybooleanisNilled()Determine whether the node has the is-nilled propertyGet an iterator over all the prefixes declared in this namespace context.voidremoveAttribute(NodeInfo attribute) Remove an attribute from this element nodevoidRemove type information from this node (and its ancestors, recursively).voidRename this nodevoidreplaceStringValue(CharSequence stringValue) Replace the string-value of this nodevoidSet the attribute listvoidsetLocation(String systemId, int line, int column) Set location information for this nodevoidsetNameCode(int nameCode) Set the name code.voidsetNamespaceDeclarations(NamespaceBinding[] namespaces, int namespacesUsed) Set the namespace declarations for the elementvoidsetNamespaceList(NamespaceBinding[] namespaces) Set the namespace listvoidsetSystemId(String uri) Set the system ID of this node.voidsetTypeAnnotation(int typeCode) Set the type annotation on a node.Methods inherited from class net.sf.saxon.tree.linked.ParentNodeImpl
addChild, compact, enumerateChildren, getFirstChild, getLastChild, getNthChild, getNumberOfChildren, getRawSequenceNumber, getSequenceNumber, getStringValue, getStringValueCS, hasChildNodes, insertChildren, insertChildrenAt, removeChild, replaceChildrenAt, setChildren, setRawSequenceNumberMethods inherited from class net.sf.saxon.tree.linked.NodeImpl
atomize, compareOrder, equals, getConfiguration, getDisplayName, getDocumentNumber, getFingerprint, getLocalPart, getNamePool, getNextInDocument, getNextSibling, getParent, getPhysicalRoot, getPrefix, getPreviousInDocument, getPreviousSibling, getPublicId, getRawParent, getSiblingPosition, getTypedValue, getURI, insertSiblings, isDeleted, isIdref, isSameNodeInfo, iterateAxis, iterateAxis, newBuilder, replace, setRawParent, setSiblingPosition
-
Constructor Details
-
ElementImpl
public ElementImpl()Construct an empty ElementImpl
-
-
Method Details
-
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
-
setAttributeList
Set the attribute list- Parameters:
atts- the list of attributes of this element (not including namespace attributes)
-
setNamespaceList
Set the namespace list- Parameters:
namespaces- an integer array of namespace codes
-
initialise
public void initialise(NodeName elemName, SchemaType elementType, AttributeCollectionImpl 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
-
setLocation
Set location information for this node- Parameters:
systemId- the base URIline- the line number if knowncolumn- the column number if known
-
setSystemId
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:
setSystemIdin interfaceSource- Overrides:
setSystemIdin classNodeImpl
-
getRoot
Get the root node -
getDocumentRoot
Get the root node, if it is a document node.- Specified by:
getDocumentRootin interfaceNodeInfo- Overrides:
getDocumentRootin classNodeImpl- Returns:
- the DocumentInfo representing the containing document. If this node is part of a tree that does not have a document node as its root, returns null.
- Since:
- 8.4
-
getSystemId
Get the system ID of the entity containing this element node.- Specified by:
getSystemIdin interfaceNodeInfo- Specified by:
getSystemIdin interfaceSource- Specified by:
getSystemIdin interfaceSourceLocator- Overrides:
getSystemIdin classNodeImpl- Returns:
- the System Identifier of the entity in the source document containing the node, or null if not known or not applicable.
-
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:
getBaseURIin interfaceNodeInfo- Overrides:
getBaseURIin 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.
-
gsetAttributeCollection
Get the attribute list. Note that if the attribute list is empty, it should not be modified, as it will be shared by other elements. Instead, set a new attribute list.- Returns:
- the list of attributes of this element (not including namespace attributes)
-
isNilled
public boolean isNilled()Determine whether the node has the is-nilled property -
setTypeAnnotation
public void setTypeAnnotation(int typeCode) 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:
setTypeAnnotationin interfaceMutableNodeInfo- Overrides:
setTypeAnnotationin classNodeImpl- Parameters:
typeCode- the type annotation (possibly including high bits set to indicate the isID, isIDREF, and isNilled properties)
-
getTypeAnnotation
public int getTypeAnnotation()Get the fingerpint of the type annotation of this node, if any- Specified by:
getTypeAnnotationin interfaceNodeInfo- Overrides:
getTypeAnnotationin classNodeImpl- Returns:
- the type annotation, as the integer name code of the type name
-
getSchemaType
Get the type annotation- Specified by:
getSchemaTypein interfaceNodeInfo- Overrides:
getSchemaTypein 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:
getLineNumberin interfaceNodeInfo- Specified by:
getLineNumberin interfaceSourceLocator- Overrides:
getLineNumberin classNodeImpl- Returns:
- the line number of the node in its original source document; or -1 if not available
-
getColumnNumber
public int getColumnNumber()Get the line number of the node within its source document entity- Specified by:
getColumnNumberin interfaceNodeInfo- Specified by:
getColumnNumberin interfaceSourceLocator- Overrides:
getColumnNumberin classNodeImpl- Returns:
- the column 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:
getNameCodein interfaceNodeInfo- Overrides:
getNameCodein classNodeImpl- 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:
-
generateId
Get a character string that uniquely identifies this node- Specified by:
generateIdin interfaceNodeInfo- Overrides:
generateIdin classNodeImpl- Parameters:
buffer- to contain the generated ID
-
getNodeKind
public final int getNodeKind()Return the kind of node.- Specified by:
getNodeKindin interfaceNodeInfo- Returns:
- Type.ELEMENT
- See Also:
-
copy
Copy this node to a given outputter (supporting xsl:copy-of)- Specified by:
copyin interfaceNodeInfo- Parameters:
out- The outputtercopyOptions-locationId- If non-zero, identifies the location of the instruction that requested this copy. If zero, indicates that the location information- Throws:
XPathException- if any downstream error occurs
-
delete
public void delete()Delete this node (that is, detach it from its parent)- Specified by:
deletein interfaceMutableNodeInfo- Overrides:
deletein classNodeImpl
-
rename
Rename this node- Specified by:
renamein interfaceMutableNodeInfo- Overrides:
renamein classNodeImpl- Parameters:
newName- the new name
-
addNamespace
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:
addNamespacein interfaceMutableNodeInfo- Overrides:
addNamespacein classNodeImpl- Parameters:
nscode- The namespace code representing the (prefix, uri) pair of 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- If true, the new namespace binding will be inherited by any children of the target element that do not already have a namespace binding for the specified prefix, recursively. If false, the new namespace binding will not be inherited.- Throws:
IllegalArgumentException- if the target element already has a namespace binding for this prefix, or if the namespace code represents a namespace undeclaration
-
replaceStringValue
Replace the string-value of this node- Specified by:
replaceStringValuein interfaceMutableNodeInfo- Parameters:
stringValue- the new string value
-
addAttribute
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:
addAttributein interfaceMutableNodeInfo- Overrides:
addAttributein classNodeImpl- Parameters:
nameCode- 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 properties- Throws:
IllegalStateException- if the element already has an attribute with the given name.
-
removeAttribute
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:
removeAttributein interfaceMutableNodeInfo- Overrides:
removeAttributein classNodeImpl- Parameters:
attribute- the attribute node to be removed
-
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:
removeTypeAnnotationin interfaceMutableNodeInfo- Overrides:
removeTypeAnnotationin classNodeImpl
-
setNamespaceDeclarations
Set the namespace declarations for the element- Parameters:
namespaces- the list of namespace codesnamespacesUsed- the number of entries in the list that are used
-
getURIForPrefix
Get the namespace URI corresponding to a given prefix. Return null if the prefix is not in scope.- Specified by:
getURIForPrefixin 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
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:
iteratePrefixesin 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
-
getPrefixForURI
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
Get all namespace undeclarations and undeclarations defined on this element.- Specified by:
getDeclaredNamespacesin interfaceNodeInfo- Overrides:
getDeclaredNamespacesin 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
-
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
-
getNamespaceList
Get the namespace list for this element.- Returns:
- The raw namespace list, as an array of name codes
-
getAttributeValue
Get the value of a given attribute of this node- Specified by:
getAttributeValuein interfaceNodeInfo- Overrides:
getAttributeValuein classNodeImpl- Parameters:
fingerprint- The fingerprint of the attribute name- Returns:
- the attribute value if it exists or null if not
-
getAttributeValue
Get the value of a given attribute of this node- Specified by:
getAttributeValuein interfaceNodeInfo- Overrides:
getAttributeValuein classNodeImpl- Parameters:
uri- the namespace URI of the attribute name, or "" if the attribute is not in a namepsacelocalName- 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
-