Package net.sf.saxon.tinytree
Class TinyTree
- java.lang.Object
-
- net.sf.saxon.tinytree.TinyTree
-
public final class TinyTree extends java.lang.Object
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.
-
-
Field Summary
Fields Modifier and Type Field Description protected int[]
alpha
protected int[]
attCode
protected int[]
attParent
protected int[]
attTypeCode
protected java.lang.CharSequence[]
attValue
protected int[]
beta
protected LargeStringBuffer
charBuffer
protected FastStringBuffer
commentBuffer
protected short[]
depth
protected int
documentNumber
protected int[]
nameCode
protected int[]
namespaceCode
protected int[]
namespaceParent
protected int[]
next
byte[]
nodeKind
protected int
numberOfAttributes
protected int
numberOfNamespaces
protected int
numberOfNodes
protected int[]
prior
protected int
rootIndexUsed
protected int[]
typeCodeArray
protected boolean
usesNamespaces
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
addAttribute(NodeInfo root, int parent, int nameCode, int typeCode, java.lang.CharSequence attValue, int properties)
(package private) void
addDocumentNode(TinyDocumentImpl doc)
Add a document node to the tree.(package private) void
addNamespace(int parent, int nscode)
Add a namespace node to the current element(package private) int
addNode(short kind, int depth, int alpha, int beta, int nameCode)
Add a node to the tree(package private) void
appendChars(java.lang.CharSequence chars)
(package private) void
condense()
Condense the tree: release unused memory.void
diagnosticDump()
Produce diagnostic print of main tree arraysstatic void
diagnosticDump(NodeInfo node)
Create diagnostic dump of the tree containing a particular node.(package private) void
ensurePriorIndex()
On demand, make an index for quick access to preceding-sibling nodesint[]
getAlphaArray()
(package private) AtomicValue
getAtomizedValueOfUntypedNode(int nodeNr)
Get the typed value of a node whose type is known to be untypedAtomic.(package private) int
getAttributeAnnotation(int nr)
Get the type annotation of an attribute node.int[]
getAttributeNameCodeArray()
(package private) TinyAttributeImpl
getAttributeNode(int nr)
Make a (transient) attribute node from the array of attributesint[]
getAttributeParentArray()
int[]
getAttributeTypeCodeArray()
java.lang.CharSequence[]
getAttributeValueArray()
int[]
getBetaArray()
java.lang.CharSequence
getCharacterBuffer()
java.lang.CharSequence
getCommentBuffer()
Configuration
getConfiguration()
Get the configuration previously set using setConfigurationint
getDocumentNumber()
Get the document number (actually, the tree number)(package private) int
getLineNumber(int sequence)
Get the line number for an element.int
getNameCode(int nodeNr)
Get the nameCode for a given node, which must be a document, element, text, comment, or processing instruction nodeint[]
getNameCodeArray()
NamePool
getNamePool()
Get the name pool used for the names in this documentint[]
getNamespaceCodeArray()
int[]
getNamespaceParentArray()
int[]
getNextPointerArray()
TinyNodeImpl
getNode(int nr)
short[]
getNodeDepthArray()
int
getNodeKind(int nodeNr)
Get the node kind of a given node, which must be a document, element, text, comment, or processing instruction nodebyte[]
getNodeKindArray()
int
getNumberOfAttributes()
int
getNumberOfNamespaces()
int
getNumberOfNodes()
Get the number of nodes in the tree, excluding attributes and namespace nodes(package private) int
getRootNode(int nodeNr)
Get the root node for a given node(package private) 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.int[]
getTypeCodeArray()
void
indexIDElement(NodeInfo root, int nodeNr, NameChecker checker)
Index an element of type xs:IDboolean
isIdrefAttribute(int nr)
Determine whether an attribute is an IDREF/IDREFS attribute.boolean
isIdrefElement(int nr)
Determine whether an element is an IDREF/IDREFS element.boolean
isNilled(int nodeNr)
Determine whether a given node is nilledvoid
setConfiguration(Configuration config)
Set the Configuration that contains this document(package private) void
setElementAnnotation(int nodeNr, int typeCode)
Set the type annotation of an element node(package private) void
setLineNumber(int sequence, int line)
Set the line number for an element.void
setLineNumbering()
Set line numbering on(package private) void
setSystemId(int seq, java.lang.String uri)
Set the system id of an element in the document.void
showSize()
-
-
-
Field Detail
-
documentNumber
protected int documentNumber
-
charBuffer
protected LargeStringBuffer charBuffer
-
commentBuffer
protected FastStringBuffer commentBuffer
-
numberOfNodes
protected int numberOfNodes
-
nodeKind
public byte[] nodeKind
-
depth
protected short[] depth
-
next
protected int[] next
-
alpha
protected int[] alpha
-
beta
protected int[] beta
-
nameCode
protected int[] nameCode
-
prior
protected int[] prior
-
typeCodeArray
protected int[] typeCodeArray
-
numberOfAttributes
protected int numberOfAttributes
-
attParent
protected int[] attParent
-
attCode
protected int[] attCode
-
attValue
protected java.lang.CharSequence[] attValue
-
attTypeCode
protected int[] attTypeCode
-
numberOfNamespaces
protected int numberOfNamespaces
-
namespaceParent
protected int[] namespaceParent
-
namespaceCode
protected int[] namespaceCode
-
rootIndexUsed
protected int rootIndexUsed
-
usesNamespaces
protected boolean usesNamespaces
-
-
Method Detail
-
setConfiguration
public void setConfiguration(Configuration config)
Set the Configuration that contains this document
-
getConfiguration
public Configuration getConfiguration()
Get the configuration previously set using setConfiguration
-
getNamePool
public NamePool getNamePool()
Get the name pool used for the names in this document
-
addDocumentNode
void addDocumentNode(TinyDocumentImpl doc)
Add a document node to the tree. The data structure can contain any number of document (or element) nodes as top-level nodes. The document node is retained in the documentList list, and its offset in that list is held in the alpha array for the relevant node number.
-
addNode
int addNode(short kind, int depth, int alpha, int beta, int nameCode)
Add a node to the tree- Parameters:
kind
- The kind of the node. This must be a document, element, text, comment, or processing-instruction node (not an attribute or namespace)depth
- The depth in the treealpha
- Pointer to attributes or textbeta
- Pointer to namespaces or textnameCode
- The name of the node- Returns:
- the node number of the node that was added
-
appendChars
void appendChars(java.lang.CharSequence chars)
-
condense
void condense()
Condense the tree: release unused memory. This is done after the full tree has been built. The method makes a pragmatic judgement as to whether it is worth reclaiming space; this is only done when the constructed tree is very small compared with the space allocated.
-
setElementAnnotation
void setElementAnnotation(int nodeNr, int typeCode)
Set the type annotation of an element 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.- Returns:
- the fingerprint of the type annotation for elements and attributes, otherwise undefined.
-
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- 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
-
ensurePriorIndex
void ensurePriorIndex()
On demand, make an index for quick access to preceding-sibling nodes
-
addAttribute
void addAttribute(NodeInfo root, int parent, int nameCode, int typeCode, java.lang.CharSequence attValue, int properties)
-
indexIDElement
public void indexIDElement(NodeInfo root, int nodeNr, NameChecker checker)
Index an element of type xs:ID
-
addNamespace
void addNamespace(int parent, int nscode)
Add a namespace node to the current element- Parameters:
parent
- the node number of the elementnscode
- namespace code identifying the prefix and uri
-
getNode
public final TinyNodeImpl getNode(int nr)
-
getAtomizedValueOfUntypedNode
AtomicValue getAtomizedValueOfUntypedNode(int nodeNr)
Get the typed value of a node whose type is known to be untypedAtomic. The node must be a document, element, text, comment, or processing-instruction node, and it must have no type annotation. This method gets the typed value of a numbered node without actually instantiating the NodeInfo object, as a performance optimization.
-
getAttributeNode
TinyAttributeImpl getAttributeNode(int nr)
Make a (transient) attribute node from the array of attributes
-
getAttributeAnnotation
int getAttributeAnnotation(int nr)
Get the type annotation of an attribute node. The bitNodeInfo.IS_DTD_TYPE
(1<<30) will be set in the case of an attribute node if the type annotation is one of ID, IDREF, or IDREFS and this is derived from DTD rather than schema validation.- Returns:
- Type.UNTYPED_ATOMIC if there is no annotation
-
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)
-
isIdrefElement
public boolean isIdrefElement(int nr)
Determine whether an element is an IDREF/IDREFS element. (The represents the is-idref property in the data model)
-
setSystemId
void setSystemId(int seq, java.lang.String uri)
Set the system id of an element in the document. This identifies the external entity containing the node - this is not necessarily the same as the base URI.- Parameters:
seq
- the node numberuri
- the system ID
-
getSystemId
java.lang.String getSystemId(int seq)
Get the system id of an element in the document
-
getRootNode
int getRootNode(int nodeNr)
Get the root node for a given node
-
setLineNumbering
public void setLineNumbering()
Set line numbering on
-
setLineNumber
void setLineNumber(int sequence, int line)
Set the line number for an element. Ignored if line numbering is off.
-
getLineNumber
int getLineNumber(int sequence)
Get the line number for an element. Return -1 if line numbering is off.
-
getDocumentNumber
public int getDocumentNumber()
Get the document number (actually, the tree number)
-
isNilled
public boolean isNilled(int nodeNr)
Determine whether a given node is nilled
-
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.
-
showSize
public void showSize()
-
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()
-
getNumberOfNamespaces
public int getNumberOfNamespaces()
-
getNodeKindArray
public byte[] getNodeKindArray()
-
getNodeDepthArray
public short[] getNodeDepthArray()
-
getNameCodeArray
public int[] getNameCodeArray()
-
getTypeCodeArray
public int[] getTypeCodeArray()
-
getNextPointerArray
public int[] getNextPointerArray()
-
getAlphaArray
public int[] getAlphaArray()
-
getBetaArray
public int[] getBetaArray()
-
getCharacterBuffer
public java.lang.CharSequence getCharacterBuffer()
-
getCommentBuffer
public java.lang.CharSequence getCommentBuffer()
-
getAttributeNameCodeArray
public int[] getAttributeNameCodeArray()
-
getAttributeTypeCodeArray
public int[] getAttributeTypeCodeArray()
-
getAttributeParentArray
public int[] getAttributeParentArray()
-
getAttributeValueArray
public java.lang.CharSequence[] getAttributeValueArray()
-
getNamespaceCodeArray
public int[] getNamespaceCodeArray()
-
getNamespaceParentArray
public int[] getNamespaceParentArray()
-
-