net.sf.saxon.tinytree

Class TinyTree

public final class TinyTree extends 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
protected int[]alpha
protected int[]attCode
protected int[]attParent
protected int[]attTypeCode
protected CharSequence[]attValue
protected int[]beta
protected LargeStringBuffercharBuffer
protected FastStringBuffercommentBuffer
protected short[]depth
protected intdocumentNumber
protected int[]nameCode
protected int[]namespaceCode
protected int[]namespaceParent
protected int[]next
byte[]nodeKind
protected intnumberOfAttributes
protected intnumberOfNamespaces
protected intnumberOfNodes
protected int[]prior
protected int[]typeCodeArray
protected booleanusesNamespaces
Constructor Summary
TinyTree()
TinyTree(int nodes, int attributes, int namespaces, int characters)
Method Summary
voidaddAttribute(NodeInfo root, int parent, int nameCode, int typeCode, CharSequence attValue)
voidaddDocumentNode(TinyDocumentImpl doc)
Add a document node to the tree.
voidaddNamespace(int parent, int nscode)
Add a namespace node to the current element
intaddNode(short kind, int depth, int alpha, int beta, int nameCode)
Add a node to the tree
voidappendChars(CharSequence chars)
protected voidcondense()
Condense the tree: release unused memory.
voiddiagnosticDump()
Produce diagnostic print of main tree arrays
voidensurePriorIndex()
On demand, make an index for quick access to preceding-sibling nodes
int[]getAlphaArray()
intgetAttributeAnnotation(int nr)
Get the type annotation of an attribute node.
int[]getAttributeNameCodeArray()
TinyAttributeImplgetAttributeNode(int nr)
Make a (transient) attribute node from the array of attributes
int[]getAttributeParentArray()
int[]getAttributeTypeCodeArray()
CharSequence[]getAttributeValueArray()
int[]getBetaArray()
CharSequencegetCharacterBuffer()
CharSequencegetCommentBuffer()
ConfigurationgetConfiguration()
Get the configuration previously set using setConfiguration
intgetDocumentNumber()
Get the document number (actually, the tree number)
intgetLineNumber(int sequence)
Get the line number for an element.
intgetNameCode(int nodeNr)
Get the nameCode for a given node, which must be a document, element, text, comment, or processing instruction node
int[]getNameCodeArray()
NamePoolgetNamePool()
Get the name pool used for the names in this document
int[]getNamespaceCodeArray()
int[]getNamespaceParentArray()
int[]getNextPointerArray()
TinyNodeImplgetNode(int nr)
short[]getNodeDepthArray()
intgetNodeKind(int nodeNr)
Get the node kind of a given node, which must be a document, element, text, comment, or processing instruction node
byte[]getNodeKindArray()
intgetNumberOfAttributes()
intgetNumberOfNamespaces()
intgetNumberOfNodes()
Get the number of nodes in the tree, excluding attributes and namespace nodes
intgetRootNode(int nodeNr)
Get the root node for a given node
StringgetSystemId(int seq)
Get the system id of an element in the document
intgetTypeAnnotation(int nodeNr)
Get the type annotation of a node.
int[]getTypeCodeArray()
UntypedAtomicValuegetUntypedAtomicValue(int nodeNr)
Get the typed value of a node whose type is known to be untypedAtomic.
voidindexIDElement(NodeInfo root, int nodeNr, NameChecker checker)
Index an element of type xs:ID
booleanisIdref(int nr)
Determine whether an attribute is an IDREF/IDREFS attribute.
booleanisIDCode(int typeCode)
Test whether a type annotation code represents the type xs:ID or one of its subtypes
booleanisNilled(int nodeNr)
Determine whether a given node is nilled
voidsetConfiguration(Configuration config)
Set the Configuration that contains this document
voidsetElementAnnotation(int nodeNr, int typeCode)
Set the type annotation of an element node
voidsetLineNumber(int sequence, int line)
Set the line number for an element.
voidsetLineNumbering()
Set line numbering on
voidsetSystemId(int seq, String uri)
Set the system id of an element in the document.
voidshowSize()

Field Detail

alpha

protected int[] alpha

attCode

protected int[] attCode

attParent

protected int[] attParent

attTypeCode

protected int[] attTypeCode

attValue

protected CharSequence[] attValue

beta

protected int[] beta

charBuffer

protected LargeStringBuffer charBuffer

commentBuffer

protected FastStringBuffer commentBuffer

depth

protected short[] depth

documentNumber

protected int documentNumber

nameCode

protected int[] nameCode

namespaceCode

protected int[] namespaceCode

namespaceParent

protected int[] namespaceParent

protected int[] next

nodeKind

public byte[] nodeKind

numberOfAttributes

protected int numberOfAttributes

numberOfNamespaces

protected int numberOfNamespaces

numberOfNodes

protected int numberOfNodes

prior

protected int[] prior

typeCodeArray

protected int[] typeCodeArray

usesNamespaces

protected boolean usesNamespaces

Constructor Detail

TinyTree

public TinyTree()

TinyTree

public TinyTree(int nodes, int attributes, int namespaces, int characters)

Method Detail

addAttribute

void addAttribute(NodeInfo root, int parent, int nameCode, int typeCode, CharSequence attValue)

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.

addNamespace

void addNamespace(int parent, int nscode)
Add a namespace node to the current element

Parameters: parent the node number of the element nscode namespace code identifying the prefix and uri

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 tree alpha Pointer to attributes or text beta Pointer to namespaces or text nameCode The name of the node

Returns: the node number of the node that was added

appendChars

void appendChars(CharSequence chars)

condense

protected 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.

diagnosticDump

public void diagnosticDump()
Produce diagnostic print of main tree arrays

ensurePriorIndex

void ensurePriorIndex()
On demand, make an index for quick access to preceding-sibling nodes

getAlphaArray

public int[] getAlphaArray()

getAttributeAnnotation

int getAttributeAnnotation(int nr)
Get the type annotation of an attribute node. The bit 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

getAttributeNameCodeArray

public int[] getAttributeNameCodeArray()

getAttributeNode

TinyAttributeImpl getAttributeNode(int nr)
Make a (transient) attribute node from the array of attributes

getAttributeParentArray

public int[] getAttributeParentArray()

getAttributeTypeCodeArray

public int[] getAttributeTypeCodeArray()

getAttributeValueArray

public CharSequence[] getAttributeValueArray()

getBetaArray

public int[] getBetaArray()

getCharacterBuffer

public CharSequence getCharacterBuffer()

getCommentBuffer

public CharSequence getCommentBuffer()

getConfiguration

public Configuration getConfiguration()
Get the configuration previously set using setConfiguration

getDocumentNumber

public int getDocumentNumber()
Get the document number (actually, the tree number)

getLineNumber

int getLineNumber(int sequence)
Get the line number for an element. Return -1 if line numbering is off.

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

getNameCodeArray

public int[] getNameCodeArray()

getNamePool

public NamePool getNamePool()
Get the name pool used for the names in this document

getNamespaceCodeArray

public int[] getNamespaceCodeArray()

getNamespaceParentArray

public int[] getNamespaceParentArray()

getNextPointerArray

public int[] getNextPointerArray()

getNode

public TinyNodeImpl getNode(int nr)

getNodeDepthArray

public short[] getNodeDepthArray()

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

getNodeKindArray

public byte[] getNodeKindArray()

getNumberOfAttributes

public int getNumberOfAttributes()

getNumberOfNamespaces

public int getNumberOfNamespaces()

getNumberOfNodes

public int getNumberOfNodes()
Get the number of nodes in the tree, excluding attributes and namespace nodes

Returns: the number of nodes.

getRootNode

int getRootNode(int nodeNr)
Get the root node for a given node

getSystemId

String getSystemId(int seq)
Get the system id of an element in the document

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: -1 if the annotation is xdt:untyped or if the node is not an element.

getTypeCodeArray

public int[] getTypeCodeArray()

getUntypedAtomicValue

UntypedAtomicValue getUntypedAtomicValue(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.

indexIDElement

public void indexIDElement(NodeInfo root, int nodeNr, NameChecker checker)
Index an element of type xs:ID

isIdref

boolean isIdref(int nr)
Determine whether an attribute is an IDREF/IDREFS attribute. (The represents the is-IDREF property in the data model

isIDCode

public boolean isIDCode(int typeCode)
Test whether a type annotation code represents the type xs:ID or one of its subtypes

isNilled

public boolean isNilled(int nodeNr)
Determine whether a given node is nilled

setConfiguration

public void setConfiguration(Configuration config)
Set the Configuration that contains this document

setElementAnnotation

void setElementAnnotation(int nodeNr, int typeCode)
Set the type annotation of an element node

setLineNumber

void setLineNumber(int sequence, int line)
Set the line number for an element. Ignored if line numbering is off.

setLineNumbering

public void setLineNumbering()
Set line numbering on

setSystemId

void setSystemId(int seq, 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 number uri the system ID

showSize

public void showSize()