Package net.sf.saxon.tree.tiny
Class TinyTree
- java.lang.Object
-
- net.sf.saxon.om.GenericTreeInfo
-
- net.sf.saxon.tree.tiny.TinyTree
-
- All Implemented Interfaces:
javax.xml.transform.Source
,TreeInfo
,NodeVectorTree
public final class TinyTree extends GenericTreeInfo implements NodeVectorTree
A data structure to hold the contents of a tree. As the name implies, this implementation of the data model is optimized for size, and for speed of creation: it minimizes the number of Java objects used.It can be used to represent a tree that is rooted at a document node, or one that is rooted at an element node.
From Saxon 9.7, as a consequence of bug 2220, it is used only to hold a single tree, whose root is always node number zero.
-
-
Field Summary
Fields Modifier and Type Field Description byte[]
nodeKind
static int
TYPECODE_IDREF
-
Fields inherited from class net.sf.saxon.om.GenericTreeInfo
root
-
-
Constructor Summary
Constructors Constructor Description TinyTree(Configuration config, Statistics statistics)
Create a tree with a specified initial size
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
addTextNodeCopy(int depth, int existingNodeNr)
Create a new text node that is a copy of an existing text nodevoid
diagnosticDump()
Produce diagnostic print of main tree arraysstatic void
diagnosticDump(NodeInfo node)
Create diagnostic dump of the tree containing a particular node.int[]
getAlphaArray()
Get the array holding alpha informationint[]
getAttributeNameCodeArray()
Get the array used to hold the name codes of all attributesint[]
getAttributeParentArray()
Get the array used to hold the parent pointers of all attributesSimpleType[]
getAttributeTypeArray()
Get the array used to hold the type codes of all attributesjava.lang.String[]
getAttributeValueArray()
Get the array used to hold the name codes of all attributesint[]
getBetaArray()
Get the array holding beta informationLargeTextBuffer
getCharacterBuffer()
Get the character buffer used to hold all the text data of the documentint
getColumnNumber(int sequence)
Get the column number for a node.UnicodeString
getCommentBuffer()
Get the character buffer used to hold all the comment data of the documentNodeInfo
getCopiedFrom()
Declare that this tree was produced as a copy of another tree, and identify the root node of that treeint
getFingerprint(int nodeNr)
Get the fingerprint for a given node, which must be a document, element, text, comment, or processing instruction nodeint
getLineNumber(int sequence)
Get the line number for a node.java.util.Map<java.lang.String,IntSet>
getLocalNameIndex()
Get (and build if necessary) an index from local names to fingerprintsint
getNameCode(int nodeNr)
Get the nameCode for a given node, which must be a document, element, text, comment, or processing instruction nodeint[]
getNameCodeArray()
Get the array holding node name informationNamePool
getNamePool()
NamespaceBinding[]
getNamespaceBindings()
Get the array used to hold the namespace declarationsNamespaceMap[]
getNamespaceMaps()
Get the array used to hold the in-scope namespacesint[]
getNamespaceParentArray()
Get the array used to hold the parent pointers of all namespace declarationsint[]
getNextPointerArray()
Get the array holding next-sibling pointersTinyNodeImpl
getNode(int nr)
Get the node at a given position in the treeshort[]
getNodeDepthArray()
Get the array holding node depth informationint
getNodeKind(int nodeNr)
Get the node kind of a given node, which must be a document, element, text, comment, or processing instruction nodebyte[]
getNodeKindArray()
Get the array holding node kind informationint
getNumberOfAttributes()
Get the number of attributes in the treeint
getNumberOfNamespaces()
Get the number of namespace declarations in the treeint
getNumberOfNodes()
Get the number of nodes in the tree, excluding attributes and namespace nodesjava.lang.String
getPrefix(int nodeNr)
Get the prefix for a given element nodePrefixPool
getPrefixPool()
Get the prefix poolNodeInfo
getRootNode()
Get the NodeInfo object representing the root of the tree (not necessarily a document node)SchemaType
getSchemaType(int nodeNr)
Get the type annotation of a node.java.lang.String
getSystemId(int seq)
Get the system id of an element in the documentint
getTypeAnnotation(int nodeNr)
Get the type annotation of a node.SchemaType[]
getTypeArray()
Get the array holding node type informationAtomicSequence
getTypedValueOfAttribute(TinyAttributeImpl att, int nodeNr)
Get the typed value of an attribute node.AtomicSequence
getTypedValueOfElement(int nodeNr)
Get the type value of an element node, given only the node numberAtomicSequence
getTypedValueOfElement(TinyElementImpl element)
Get the typed value of an element node.java.lang.String[]
getUnparsedEntity(java.lang.String name)
Get the unparsed entity with a given nameID if there is one, or null if not.java.util.Iterator<java.lang.String>
getUnparsedEntityNames()
Get the list of unparsed entities defined in this documentboolean
hasXmlSpacePreserveAttribute()
Ask whether, somewhere in the tree, there is an attribute xml:space="preserve"void
indexIDElement(NodeInfo root, int nodeNr)
Index an element of type xs:IDboolean
isDefaultedAttribute(int attNr)
Ask whether an attribute results from expansion of attribute defaultsboolean
isIdAttribute(int nr)
Determine whether an attribute is an ID attribute.boolean
isIdElement(int nr)
Ask whether an element is an ID element.boolean
isIdrefAttribute(int nr)
Determine whether an attribute is an IDREF/IDREFS attribute.boolean
isIdrefElement(int nr)
Ask whether an element is an IDREF/IDREFS element.boolean
isNilled(int nodeNr)
Ask whether a given node is nilledboolean
isTopWithinEntity(int nodeNr)
boolean
isTyped()
Ask whether the document contains any nodes whose type annotation is anything other than UNTYPEDboolean
isUsesNamespaces()
Ask whether the tree contains any namespace declarationsvoid
markDefaultedAttribute(int attNr)
Mark an attribute as resulting from expansion of attribute defaultsvoid
markTopWithinEntity(int nodeNr)
NodeInfo
selectID(java.lang.String id, boolean getParent)
Get the element with a given ID.void
setConfiguration(Configuration config)
Set the Configuration that contains this documentvoid
setCopiedFrom(NodeInfo copiedFrom)
Declare that this tree was produced as a copy of another tree, and identify the root node of that treevoid
setLineNumbering()
Set line numbering onvoid
setNilled(int nodeNr)
Set an element node to be marked as nilledvoid
showSize()
Output a statistical summary to System.err-
Methods inherited from class net.sf.saxon.om.GenericTreeInfo
getConfiguration, getDocumentNumber, getDurability, getPublicId, getSpaceStrippingRule, getSystemId, getUserData, isMutable, isStreamed, setDocumentNumber, setDurability, setRootNode, setSpaceStrippingRule, setSystemId, setUserData
-
-
-
-
Field Detail
-
nodeKind
public byte[] nodeKind
-
TYPECODE_IDREF
public static final int TYPECODE_IDREF
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TinyTree
public TinyTree(Configuration config, Statistics statistics)
Create a tree with a specified initial size- Parameters:
config
- the Saxon configurationstatistics
- the size parameters for the tree
-
-
Method Detail
-
setConfiguration
public void setConfiguration(Configuration config)
Set the Configuration that contains this document- Overrides:
setConfiguration
in classGenericTreeInfo
- Parameters:
config
- the Saxon configuration
-
getPrefixPool
public PrefixPool getPrefixPool()
Get the prefix pool- Returns:
- the prefix pool
-
setCopiedFrom
public void setCopiedFrom(NodeInfo copiedFrom)
Declare that this tree was produced as a copy of another tree, and identify the root node of that tree- Parameters:
copiedFrom
- the root of the tree from which this one was copied
-
getCopiedFrom
public NodeInfo getCopiedFrom()
Declare that this tree was produced as a copy of another tree, and identify the root node of that tree- Returns:
- the root of the tree from which this one was copied, or null if this does not apply
-
addTextNodeCopy
public int addTextNodeCopy(int depth, int existingNodeNr)
Create a new text node that is a copy of an existing text node- Parameters:
depth
- the depth of the new nodeexistingNodeNr
- the node to be copied- Returns:
- the node number of the new node
-
getTypeAnnotation
public int getTypeAnnotation(int nodeNr)
Get the type annotation of a node. Applies only to document, element, text, processing instruction, and comment nodes.- Parameters:
nodeNr
- the node whose type annotation is required- Returns:
- the fingerprint of the type annotation for elements and attributes, otherwise undefined.
-
getSchemaType
public SchemaType getSchemaType(int nodeNr)
Get the type annotation of a node. Applies only to document, element, text, processing instruction, and comment nodes.- Parameters:
nodeNr
- the node whose type annotation is required- Returns:
- the fingerprint of the type annotation for elements and attributes, otherwise undefined.
-
getTypedValueOfElement
public AtomicSequence getTypedValueOfElement(TinyElementImpl element) throws XPathException
Get the typed value of an element node.- Parameters:
element
- the element node- Returns:
- the typed value of the node (a Value whose items are AtomicValue instances)
- Throws:
XPathException
- if a dynamic error occurs, for example if the node is an element annotated with a type that has element-only content
-
getTypedValueOfElement
public AtomicSequence getTypedValueOfElement(int nodeNr) throws XPathException
Get the type value of an element node, given only the node number- Parameters:
nodeNr
- the node number of the element node- Returns:
- the typed value of the node
- Throws:
XPathException
- if the eement has no typed value
-
getTypedValueOfAttribute
public AtomicSequence getTypedValueOfAttribute(TinyAttributeImpl att, int nodeNr) throws XPathException
Get the typed value of an attribute node. This method avoids materializing the attribute node if possible, but uses the attribute node supplied if it already exists.- Parameters:
att
- the attribute node if available. If null is supplied, the attribute node will be materialized only if it is needed.nodeNr
- the node number of the attribute node- Returns:
- the typed value of the node
- Throws:
XPathException
- if an error is found
-
getNodeKind
public int getNodeKind(int nodeNr)
Get the node kind of a given node, which must be a document, element, text, comment, or processing instruction node- Specified by:
getNodeKind
in interfaceNodeVectorTree
- Parameters:
nodeNr
- the node number- Returns:
- the node kind
-
getNameCode
public int getNameCode(int nodeNr)
Get the nameCode for a given node, which must be a document, element, text, comment, or processing instruction node- Parameters:
nodeNr
- the node number- Returns:
- the name code
-
getFingerprint
public int getFingerprint(int nodeNr)
Get the fingerprint for a given node, which must be a document, element, text, comment, or processing instruction node- Specified by:
getFingerprint
in interfaceNodeVectorTree
- Parameters:
nodeNr
- the node number- Returns:
- the name code
-
getPrefix
public java.lang.String getPrefix(int nodeNr)
Get the prefix for a given element node- Parameters:
nodeNr
- the node number- Returns:
- the prefix. Return "" for an unprefixed element node. Result is undefined for a non-element node.
-
markDefaultedAttribute
public void markDefaultedAttribute(int attNr)
Mark an attribute as resulting from expansion of attribute defaults- Parameters:
attNr
- the attribute number
-
isDefaultedAttribute
public boolean isDefaultedAttribute(int attNr)
Ask whether an attribute results from expansion of attribute defaults- Parameters:
attNr
- the attribute number- Returns:
- true if this attribute resulted from expansion of default or fixed values defined
in a schema. Note that this property will only be set if both the configuration properties
FeatureKeys.EXPAND_ATTRIBUTE_DEFAULTS
andFeatureKeys.MARK_DEFAULTED_ATTRIBUTES
are set.
-
indexIDElement
public void indexIDElement(NodeInfo root, int nodeNr)
Index an element of type xs:ID- Parameters:
root
- the root node of the documentnodeNr
- the element of type xs:ID
-
hasXmlSpacePreserveAttribute
public boolean hasXmlSpacePreserveAttribute()
Ask whether, somewhere in the tree, there is an attribute xml:space="preserve"- Returns:
- true if some element in the tree has an xml:space attribute with the value preserve
-
getNode
public final TinyNodeImpl getNode(int nr)
Get the node at a given position in the tree- Specified by:
getNode
in interfaceNodeVectorTree
- Parameters:
nr
- the node number- Returns:
- the node at the given position
-
isIdAttribute
public boolean isIdAttribute(int nr)
Determine whether an attribute is an ID attribute. (The represents the is-id property in the data model)- Parameters:
nr
- the node number of the attribute- Returns:
- true if this is an ID attribute
-
isIdrefAttribute
public boolean isIdrefAttribute(int nr)
Determine whether an attribute is an IDREF/IDREFS attribute. (The represents the is-idref property in the data model)- Parameters:
nr
- the node number of the attribute- Returns:
- true if this is an IDREF/IDREFS attribute
-
isIdElement
public boolean isIdElement(int nr)
Ask whether an element is an ID element. (The represents the is-id property in the data model)- Parameters:
nr
- the element node whose is-id property is required- Returns:
- true if the node has the is-id property
-
isIdrefElement
public boolean isIdrefElement(int nr)
Ask whether an element is an IDREF/IDREFS element. (The represents the is-idref property in the data model)- Parameters:
nr
- the element node whose is-idref property is required- Returns:
- true if the node has the is-idref property
-
getSystemId
public java.lang.String getSystemId(int seq)
Get the system id of an element in the document- Parameters:
seq
- the node number of the element node- Returns:
- the system id (base URI) of the element
-
getRootNode
public NodeInfo getRootNode()
Description copied from class:GenericTreeInfo
Get the NodeInfo object representing the root of the tree (not necessarily a document node)- Specified by:
getRootNode
in interfaceTreeInfo
- Overrides:
getRootNode
in classGenericTreeInfo
- Returns:
- the root node
-
setLineNumbering
public void setLineNumbering()
Set line numbering on
-
getLineNumber
public int getLineNumber(int sequence)
Get the line number for a node.- Parameters:
sequence
- the node number- Returns:
- the line number of the node. Return -1 if line numbering is off.
-
getColumnNumber
public int getColumnNumber(int sequence)
Get the column number for a node.- Parameters:
sequence
- the node number- Returns:
- the line number of the node. Return -1 if line numbering is off.
-
setNilled
public void setNilled(int nodeNr)
Set an element node to be marked as nilled- Parameters:
nodeNr
- the node number to be marked as nilled
-
isNilled
public boolean isNilled(int nodeNr)
Ask whether a given node is nilled- Parameters:
nodeNr
- the node in question (which must be an element node)- Returns:
- true if the node has the nilled property
-
selectID
public NodeInfo selectID(java.lang.String id, boolean getParent)
Get the element with a given ID.- Specified by:
selectID
in interfaceTreeInfo
- Overrides:
selectID
in classGenericTreeInfo
- Parameters:
id
- The unique ID of the required element, previously registered using registerID()getParent
- true if the required element is the parent of the element of type ID- Returns:
- The NodeInfo (always an Element) for the given ID if one has been registered, otherwise null.
-
getUnparsedEntityNames
public java.util.Iterator<java.lang.String> getUnparsedEntityNames()
Get the list of unparsed entities defined in this document- Specified by:
getUnparsedEntityNames
in interfaceTreeInfo
- Overrides:
getUnparsedEntityNames
in classGenericTreeInfo
- Returns:
- an Iterator, whose items are of type String, containing the names of all unparsed entities defined in this document. If there are no unparsed entities or if the information is not available then an empty iterator is returned
-
getUnparsedEntity
public java.lang.String[] getUnparsedEntity(java.lang.String name)
Get the unparsed entity with a given nameID if there is one, or null if not. If the entity does not exist, return null.- Specified by:
getUnparsedEntity
in interfaceTreeInfo
- Overrides:
getUnparsedEntity
in classGenericTreeInfo
- Parameters:
name
- the name of the entity- Returns:
- if the entity exists, return an array of two Strings, the first holding the system ID of the entity, the second holding the public
-
getNamePool
public NamePool getNamePool()
- Specified by:
getNamePool
in interfaceNodeVectorTree
-
markTopWithinEntity
public void markTopWithinEntity(int nodeNr)
-
isTopWithinEntity
public boolean isTopWithinEntity(int nodeNr)
-
diagnosticDump
public void diagnosticDump()
Produce diagnostic print of main tree arrays
-
diagnosticDump
public static void diagnosticDump(NodeInfo node)
Create diagnostic dump of the tree containing a particular node. Designed to be called as an extension function for diagnostics.- Parameters:
node
- the node in question
-
showSize
public void showSize()
Output a statistical summary to System.err
-
isTyped
public boolean isTyped()
Ask whether the document contains any nodes whose type annotation is anything other than UNTYPED- Specified by:
isTyped
in interfaceNodeVectorTree
- Specified by:
isTyped
in interfaceTreeInfo
- Returns:
- true if the document contains elements whose type is other than UNTYPED
-
getNumberOfNodes
public int getNumberOfNodes()
Get the number of nodes in the tree, excluding attributes and namespace nodes- Returns:
- the number of nodes.
-
getNumberOfAttributes
public int getNumberOfAttributes()
Get the number of attributes in the tree- Returns:
- the number of attributes
-
getNumberOfNamespaces
public int getNumberOfNamespaces()
Get the number of namespace declarations in the tree- Returns:
- the number of namespace declarations
-
getNodeKindArray
public byte[] getNodeKindArray()
Get the array holding node kind information- Specified by:
getNodeKindArray
in interfaceNodeVectorTree
- Returns:
- an array of bytes, byte N is the node kind of node number N
-
getNodeDepthArray
public short[] getNodeDepthArray()
Get the array holding node depth information- Returns:
- an array of shorts, byte N is the node depth of node number N
-
getNameCodeArray
public int[] getNameCodeArray()
Get the array holding node name information- Specified by:
getNameCodeArray
in interfaceNodeVectorTree
- Returns:
- an array of integers, integer N is the name code of node number N
-
getTypeArray
public SchemaType[] getTypeArray()
Get the array holding node type information- Returns:
- an array of integers, integer N is the type code of node number N
-
getNextPointerArray
public int[] getNextPointerArray()
Get the array holding next-sibling pointers- Returns:
- an array of integers, integer N is the next-sibling pointer for node number N
-
getAlphaArray
public int[] getAlphaArray()
Get the array holding alpha information- Returns:
- an array of integers, whose meaning depends on the node kind. For elements it is a pointer to the first attribute, for text, comment, and processing instruction nodes it is a pointer to the content
-
getBetaArray
public int[] getBetaArray()
Get the array holding beta information- Returns:
- an array of integers, whose meaning depends on the node kind. For elements it is a pointer to the first namespace declaration
-
getCharacterBuffer
public LargeTextBuffer getCharacterBuffer()
Get the character buffer used to hold all the text data of the document- Returns:
- the character buffer
-
getCommentBuffer
public UnicodeString getCommentBuffer()
Get the character buffer used to hold all the comment data of the document- Returns:
- the character buffer used for comments
-
getAttributeNameCodeArray
public int[] getAttributeNameCodeArray()
Get the array used to hold the name codes of all attributes- Returns:
- an integer array; the Nth integer holds the attribute name code of attribute N
-
getAttributeTypeArray
public SimpleType[] getAttributeTypeArray()
Get the array used to hold the type codes of all attributes- Returns:
- an integer array; the Nth integer holds the attribute type code of attribute N
-
getAttributeParentArray
public int[] getAttributeParentArray()
Get the array used to hold the parent pointers of all attributes- Returns:
- an integer array; the Nth integer holds the pointer to the parent element of attribute N
-
getAttributeValueArray
public java.lang.String[] getAttributeValueArray()
Get the array used to hold the name codes of all attributes- Returns:
- an array of strings; the Nth string holds the string value of attribute N
-
getNamespaceBindings
public NamespaceBinding[] getNamespaceBindings()
Get the array used to hold the namespace declarations- Returns:
- an array of namespace bindings
-
getNamespaceMaps
public NamespaceMap[] getNamespaceMaps()
Get the array used to hold the in-scope namespaces- Returns:
- an array of namespace bindings
-
getNamespaceParentArray
public int[] getNamespaceParentArray()
Get the array used to hold the parent pointers of all namespace declarations- Returns:
- an integer array; the Nth integer holds the pointer to the parent element of namespace N
-
isUsesNamespaces
public boolean isUsesNamespaces()
Ask whether the tree contains any namespace declarations- Returns:
- true if there is a namespace declaration (other than the XML namespace) anywhere in the tree
-
getLocalNameIndex
public java.util.Map<java.lang.String,IntSet> getLocalNameIndex()
Get (and build if necessary) an index from local names to fingerprints- Returns:
- a Map whose keys are local names and whose values are sets of fingerprints (usually singleton sets!) of names with that local name. The index is for element names only.
-
-