Class AttributeImpl
java.lang.Object
net.sf.saxon.tree.linked.NodeImpl
net.sf.saxon.tree.linked.AttributeImpl
- All Implemented Interfaces:
Source, SourceLocator, PullEvent, FingerprintedNode, Item<NodeInfo>, MutableNodeInfo, NodeInfo, ValueRepresentation<NodeInfo>, SiblingCountingNode
A node in the "linked" tree representing an attribute. Note that this is
generated only "on demand", when the attribute is selected by a path expression.
It is possible for multiple AttributeImpl objects to represent the same attribute node. The identity of an attribute node is determined by the identity of the element, and the index position of the attribute within the element. Index positions are not reused when an attribute is deleted, and are retained when an attribute is renamed.
This object no longer caches information such as the name code and string value, because these would become invalid when the element node is modified.
- Author:
- Michael H. Kay
-
Field Summary
Fields inherited from class NodeImpl
NODE_LETTERFields inherited from interface NodeInfo
ALL_NAMESPACES, IS_DTD_TYPE, IS_NILLED, LOCAL_NAMESPACES, NO_NAMESPACESFields inherited from interface ValueRepresentation
EMPTY_VALUE_ARRAY -
Constructor Summary
ConstructorsConstructorDescriptionAttributeImpl(ElementImpl element, int index) Construct an Attribute node for the n'th attribute of a given element -
Method Summary
Modifier and TypeMethodDescriptionvoidCopy this node to a given outputtervoiddelete()Delete this node (that is, detach it from its parent)voidgenerateId(FastStringBuffer buffer) Get sequential key.intGet the name code, which enables the name to be located in the name poolgetNextInDocument(NodeImpl anchor) Get the next node in document order (skipping attributes)Get next sibling - not defined for attributesfinal intReturn the type of node.Get the previous node in document order (skipping attributes)Get previous sibling - not defined for attributesGet the type annotationprotected longGet the node sequence number (in document order).Return the character value of the node.intGet the fingerprint of the type annotation of this node, if anyinthashCode()The hashCode() method obeys the contract for hashCode(): that is, if two objects are equal (represent the same node) then they must have the same hashCode()booleanTest whether this MutableNodeInfo object represents a node that has been deleted.booleanisId()Determine whether this node has the is-id propertybooleanisIdref()Determine whether this node has the is-idref propertybooleanisNilled()Determine whether the node has the is-nilled propertybooleanisSameNodeInfo(NodeInfo other) Determine whether this is the same node as another nodevoidRemove type information from this node (and its ancestors, recursively).voidRename this nodevoidReplace this node with a given sequence of nodesvoidreplaceStringValue(CharSequence stringValue) Replace the string-value of this node.voidsetTypeAnnotation(int typeCode) Set the type annotation on a node.Methods inherited from class NodeImpl
addAttribute, addNamespace, atomize, compareOrder, equals, getAttributeValue, getAttributeValue, getBaseURI, getColumnNumber, getConfiguration, getDeclaredNamespaces, getDisplayName, getDocumentNumber, getDocumentRoot, getFingerprint, getFirstChild, getLastChild, getLineNumber, getLocalPart, getNamePool, getParent, getPhysicalRoot, getPrefix, getPublicId, getRawParent, getRoot, getSiblingPosition, getStringValueCS, getSystemId, getTypedValue, getURI, hasChildNodes, insertChildren, insertSiblings, iterateAxis, iterateAxis, newBuilder, removeAttribute, setRawParent, setSiblingPosition, setSystemId
-
Constructor Details
-
AttributeImpl
Construct an Attribute node for the n'th attribute of a given element- Parameters:
element- The element containing the relevant attributeindex- The index position of the attribute starting at zero
-
-
Method Details
-
getNameCode
public int getNameCode()Get the name code, which enables the name to be located in the name pool- 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:
-
getTypeAnnotation
public int getTypeAnnotation()Get the fingerprint 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, if any
-
isId
-
isIdref
-
isNilled
-
isSameNodeInfo
Determine whether this is the same node as another node- Specified by:
isSameNodeInfoin interfaceNodeInfo- Overrides:
isSameNodeInfoin classNodeImpl- Parameters:
other- the node to be compared with this node- Returns:
- true if this Node object and the supplied Node object represent the same node in the tree.
-
hashCode
public int hashCode()The hashCode() method obeys the contract for hashCode(): that is, if two objects are equal (represent the same node) then they must have the same hashCode()- Specified by:
hashCodein interfaceNodeInfo- Overrides:
hashCodein classObject- Since:
- 8.7 Previously, the effect of the equals() and hashCode() methods was not defined. Callers should therefore be aware that third party implementations of the NodeInfo interface may not implement the correct semantics.
-
getSequenceNumber
protected 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:
getSequenceNumberin classNodeImpl- Returns:
- the sequence number if there is one, or -1L otherwise.
-
getNodeKind
public final int getNodeKind()Return the type of node.- Returns:
- Node.ATTRIBUTE
- See Also:
-
getStringValue
Return the character value of the node.- Returns:
- the attribute value
- See Also:
-
getNextSibling
Get next sibling - not defined for attributes- Overrides:
getNextSiblingin classNodeImpl- Returns:
- The next sibling node of the required type. Returns null if the current node is the last child of its parent.
-
getPreviousSibling
Get previous sibling - not defined for attributes- Overrides:
getPreviousSiblingin classNodeImpl- Returns:
- The previous sibling node. Returns null if the current node is the first child of its parent.
-
getPreviousInDocument
Get the previous node in document order (skipping attributes)- Overrides:
getPreviousInDocumentin classNodeImpl- Returns:
- the previous node in the document, or null if there is no such node
-
getNextInDocument
Get the next node in document order (skipping attributes)- Overrides:
getNextInDocumentin classNodeImpl- Parameters:
anchor- the scan stops when it reaches a node that is not a descendant of the specified anchor node- Returns:
- the next node in the document, or null if there is no such node
-
generateId
Get sequential key. Returns key of owning element with the attribute index as a suffix- Specified by:
generateIdin interfaceNodeInfo- Overrides:
generateIdin classNodeImpl- Parameters:
buffer- a buffer to which the generated ID will be written
-
copy
Copy this node to a given outputter- 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 inCopyOptionslocationId- 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
-
isDeleted
public boolean isDeleted()Test whether this MutableNodeInfo object represents a node that has been deleted. Generally, such a node is unusable, and any attempt to use it will result in an exception being thrown- Specified by:
isDeletedin interfaceMutableNodeInfo- Overrides:
isDeletedin classNodeImpl- Returns:
- true if this node has been deleted
-
replace
Replace this node with a given sequence of nodes- Specified by:
replacein interfaceMutableNodeInfo- Overrides:
replacein classNodeImpl- Parameters:
replacement- the replacement nodes (which for this version of the method must be attribute nodes - they may use any implementation of the NodeInfo interface). The target attribute node is deleted, and the replacement nodes are added to the parent element; if they have the same names as existing nodes, then the existing nodes will be overwritten.inherit- set to true if new child elements are to inherit the in-scope namespaces of their new parent. Not used when replacing attribute nodes.- Throws:
IllegalArgumentException- if any of the replacement nodes is not an attributeIllegalStateException- if this node has been deleted or has no parent node or if two of the replacement nodes have the same name
-
rename
Rename this node- Specified by:
renamein interfaceMutableNodeInfo- Overrides:
renamein classNodeImpl- Parameters:
newNameCode- the NamePool code of the new name
-
replaceStringValue
Description copied from interface:MutableNodeInfoReplace the string-value of this node. If applied to an element or document node, this causes all existing children to be deleted, and replaced with a new text node whose string value is the value supplied. The caller is responsible for checking that the value is valid, for example that comments do not contain a double hyphen; the implementation is not required to check for such conditions.- Parameters:
stringValue- the new string value
-
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
-
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)
-