net.sf.saxon.tinytree
Class TinyDocumentImpl

java.lang.Object
  extended by net.sf.saxon.om.AbstractNode
      extended by net.sf.saxon.tinytree.TinyNodeImpl
          extended by net.sf.saxon.tinytree.TinyParentNodeImpl
              extended by net.sf.saxon.tinytree.TinyDocumentImpl
All Implemented Interfaces:
DOMLocator, Source, SourceLocator, DocumentInfo, Item, NodeInfo, Document, Node

public final class TinyDocumentImpl
extends TinyParentNodeImpl
implements DocumentInfo, Document

A node in the XML parse tree representing the Document itself (or equivalently, the root node of the Document).

Version:
26 April 1999
Author:
Field Summary
protected  int[] alpha
           
protected  int[] attCode
           
protected  int[] attParent
           
protected  CharSequence[] attValue
           
protected  int[] beta
           
protected  char[] charBuffer
           
protected  int charBufferLength
           
protected  StringBuffer commentBuffer
           
protected  short[] depth
           
protected  int[] nameCode
           
protected  int[] namespaceCode
           
protected  int[] namespaceParent
           
protected  int[] next
           
protected  byte[] nodeKind
           
protected  int numberOfAttributes
           
protected  int numberOfNamespaces
           
protected  int numberOfNodes
           
protected  int[] prior
           
protected  int rootNode
           
 
Fields inherited from class net.sf.saxon.tinytree.TinyNodeImpl
document, nodeNr, parent
 
Fields inherited from class net.sf.saxon.om.AbstractNode
NODE_LETTER
 
Fields inherited from interface net.sf.saxon.om.NodeInfo
ALL_NAMESPACES, LOCAL_NAMESPACES, NO_NAMESPACES
 
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
Constructor Summary
TinyDocumentImpl()
           
TinyDocumentImpl(int nodes, int attributes, int namespaces, int characters)
           
 
Method Summary
protected  void addAttribute(int parent0, int code0, int type0, CharSequence value0)
           
protected  void addNamespace(int parent, int nscode)
           
protected  int addNode(short kind, int depth0, int alpha0, int beta0, int nameCode0)
          Add a node to the document
protected  void appendChars(CharSequence chars)
           
 void condense()
          Condense the tree: release unused memory.
 void copy(Receiver out, int whichNamespaces, boolean copyAnnotations)
          Copy this node to a given outputter
 void diagnosticDump()
          Produce diagnostic print of main tree arrays
protected  void ensureAttributeCapacity()
           
protected  void ensureNamespaceCapacity()
           
protected  void ensureNodeCapacity()
           
protected  void ensurePriorIndex()
          On demand, make an index for quick access to preceding-sibling nodes
 String generateId()
          Get a character string that uniquely identifies this node
protected  AxisIterator getAllElements(int fingerprint)
          Get a list of all elements with a given name.
protected  int getAttributeAnnotation(int nr)
          Get the type annotation of an attribute node.
protected  TinyAttributeImpl getAttributeNode(int nr)
          Make a (transient) attribute node from the array of attributes
 String getBaseURI()
          Get the base URI of this root node.
 int getDocumentNumber()
          Get the unique document number
 DocumentInfo getDocumentRoot()
          Get the root (document) node
protected  int getElementAnnotation(int nodeNr)
          Get the type annotation of an element node.
 int getLineNumber()
          Get the line number of this root node.
protected  int getLineNumber(int sequence)
          Get the line number for an element.
 NamePool getNamePool()
          Get the name pool used for the names in this document
protected  TinyNamespaceImpl getNamespaceNode(int nr)
          Make a (transient) namespace node from the array of namespace declarations
 TinyNodeImpl getNode(int nr)
           
 int getNodeKind()
          Return the type of node.
 NodeInfo getParent()
          Find the parent node of this node.
 NodeInfo getRoot()
          Get the root node
 long getSequenceNumber()
          Get the node sequence number (in document order).
 String getSystemId()
          Get the system id of this root node
protected  String getSystemId(int seq)
          Get the system id of an element in the document
 String[] getUnparsedEntity(String name)
          Get the unparsed entity with a given nameID if there is one, or null if not.
protected  UntypedAtomicValue getUntypedAtomicValue(int nodeNr)
          Get the typed value of a node.
protected  boolean isUsingNamespaces()
          determine whether this document uses namespaces
 NodeInfo selectID(String id)
          Get the element with a given ID.
protected  void setElementAnnotation(int nodeNr, int typeCode)
          Set the type annotation of an element node
protected  void setLineNumber(int sequence, int line)
          Set the line number for an element.
 void setLineNumbering()
          Set line numbering on
 void setNamePool(NamePool pool)
          Set the name pool used for all names in this document
 void setRootNode(NodeInfo root)
          Set the root node.
protected  void setSystemId(int seq, String uri)
          Set the system id of an element in the document
 void setSystemId(String uri)
          Set the system id of this node
protected  void setUnparsedEntity(String name, String uri, String publicId)
          Set an unparsed entity URI associated with this document.
 void showSize()
           
 
Methods inherited from class net.sf.saxon.tinytree.TinyParentNodeImpl
getStringValue, hasChildNodes
 
Methods inherited from class net.sf.saxon.tinytree.TinyNodeImpl
compareOrder, getAttributeValue, getDisplayName, getFingerprint, getLocalPart, getNameCode, getOriginatingNode, getPrefix, getURI, hasAttributes, isSameNode, iterateAxis, iterateAxis, outputNamespaceNodes, setParentNode
 
Methods inherited from class net.sf.saxon.om.AbstractNode
appendChild, appendData, cloneNode, createAttribute, createAttributeNS, createCDATASection, createComment, createDocumentFragment, createElement, createElementNS, createEntityReference, createProcessingInstruction, createTextNode, deleteData, disallowUpdate, getAttribute, getAttributeNode, getAttributeNodeNS, getAttributeNS, getAttributes, getChildNodes, getColumnNumber, getData, getDoctype, getDocumentElement, getElementById, getElementsByTagName, getElementsByTagNameNS, getFirstChild, getImplementation, getLastChild, getLength, getLocalName, getName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getOwnerElement, getParentNode, getPreviousSibling, getPublicId, getSpecified, getTagName, getTypeAnnotation, getTypedValue, getValue, hasAttribute, hasAttributeNS, importNode, insertBefore, insertData, isSupported, normalize, removeAttribute, removeAttributeNode, removeAttributeNS, removeChild, replaceChild, replaceData, setAttributeNode, setAttributeNodeNS, setAttributeNS, setData, setNodeValue, setPrefix, setValue, splitText, substringData, supports
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.saxon.om.NodeInfo
compareOrder, getAttributeValue, getDisplayName, getFingerprint, getLocalPart, getNameCode, getStringValue, getTypeAnnotation, getURI, hasChildNodes, isSameNode, iterateAxis, iterateAxis, outputNamespaceNodes
 
Methods inherited from interface net.sf.saxon.om.Item
getTypedValue
 
Methods inherited from interface org.w3c.dom.Document
adoptNode, createAttribute, createAttributeNS, createCDATASection, createComment, createDocumentFragment, createElement, createElementNS, createEntityReference, createProcessingInstruction, createTextNode, getDoctype, getDocumentElement, getDocumentURI, getDomConfig, getElementById, getElementsByTagName, getElementsByTagNameNS, getImplementation, getInputEncoding, getStrictErrorChecking, getXmlEncoding, getXmlStandalone, getXmlVersion, importNode, normalizeDocument, renameNode, setDocumentURI, setStrictErrorChecking, setXmlStandalone, setXmlVersion
 
Methods inherited from interface org.w3c.dom.Node
appendChild, cloneNode, compareDocumentPosition, getAttributes, getChildNodes, getFeature, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData
 

Field Detail

rootNode

protected int rootNode

charBuffer

protected char[] charBuffer

charBufferLength

protected int charBufferLength

commentBuffer

protected StringBuffer commentBuffer

numberOfNodes

protected int numberOfNodes

nodeKind

protected 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

numberOfAttributes

protected int numberOfAttributes

attParent

protected int[] attParent

attCode

protected int[] attCode

attValue

protected CharSequence[] attValue

numberOfNamespaces

protected int numberOfNamespaces

namespaceParent

protected int[] namespaceParent

namespaceCode

protected int[] namespaceCode
Constructor Detail

TinyDocumentImpl

public TinyDocumentImpl()

TinyDocumentImpl

public TinyDocumentImpl(int nodes,
                        int attributes,
                        int namespaces,
                        int characters)
Method Detail

setNamePool

public void setNamePool(NamePool pool)
Set the name pool used for all names in this document

Specified by:
setNamePool in interface DocumentInfo
Parameters:
pool - The name pool to be used

getNamePool

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

Specified by:
getNamePool in interface DocumentInfo
Specified by:
getNamePool in interface NodeInfo
Overrides:
getNamePool in class TinyNodeImpl
Returns:
the NamePool

getDocumentNumber

public int getDocumentNumber()
Get the unique document number

Specified by:
getDocumentNumber in interface DocumentInfo
Specified by:
getDocumentNumber in interface NodeInfo
Overrides:
getDocumentNumber in class TinyNodeImpl
Returns:
the unique number identifying this document within the name pool

ensureNodeCapacity

protected void ensureNodeCapacity()

ensureAttributeCapacity

protected void ensureAttributeCapacity()

ensureNamespaceCapacity

protected void ensureNamespaceCapacity()

setRootNode

public void setRootNode(NodeInfo root)
Set the root node. Parentless elements are implemented using a full tree structure containing a document node, but the document node is not regarded as part of the tree


addNode

protected int addNode(short kind,
                      int depth0,
                      int alpha0,
                      int beta0,
                      int nameCode0)
Add a node to the document

Parameters:
kind - The kind of the node
depth0 - The depth in the tree
alpha0 - Pointer to attributes or text
beta0 - Pointer to namespaces or text
nameCode0 - The name of the node
Returns:
the node number of the node that was added

appendChars

protected void appendChars(CharSequence chars)

condense

public 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

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


getElementAnnotation

protected int getElementAnnotation(int nodeNr)
Get the type annotation of an element node. Type.UNTYPED_ANY if there is no type annotation


ensurePriorIndex

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


addAttribute

protected void addAttribute(int parent0,
                            int code0,
                            int type0,
                            CharSequence value0)

addNamespace

protected void addNamespace(int parent,
                            int nscode)

getNode

public TinyNodeImpl getNode(int nr)

getUntypedAtomicValue

protected UntypedAtomicValue getUntypedAtomicValue(int nodeNr)
Get the typed value of a node. 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.


getSequenceNumber

public long getSequenceNumber()
Get the node sequence number (in document order). Sequence numbers are monotonic but not consecutive.

Overrides:
getSequenceNumber in class TinyNodeImpl

getAttributeNode

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


getAttributeAnnotation

protected int getAttributeAnnotation(int nr)
Get the type annotation of an attribute node.

Returns:
Type.UNTYPED_ATOMIC if there is no annotation

isUsingNamespaces

protected boolean isUsingNamespaces()
determine whether this document uses namespaces


getNamespaceNode

protected TinyNamespaceImpl getNamespaceNode(int nr)
Make a (transient) namespace node from the array of namespace declarations


setSystemId

public void setSystemId(String uri)
Set the system id of this node

Specified by:
setSystemId in interface Source
Overrides:
setSystemId in class TinyNodeImpl

getSystemId

public String getSystemId()
Get the system id of this root node

Specified by:
getSystemId in interface Source
Specified by:
getSystemId in interface SourceLocator
Specified by:
getSystemId in interface NodeInfo
Overrides:
getSystemId in class TinyNodeImpl
Returns:
the System Identifier of the entity in the source document containing the node, or null if not known. Note this is not the same as the base URI: the base URI can be modified by xml:base, but the system ID cannot.

getBaseURI

public String getBaseURI()
Get the base URI of this root node. For a root node the base URI is the same as the System ID.

Specified by:
getBaseURI in interface NodeInfo
Specified by:
getBaseURI in interface Node
Overrides:
getBaseURI in class TinyNodeImpl
Returns:
the base URI of the node

setSystemId

protected void setSystemId(int seq,
                           String uri)
Set the system id of an element in the document


getSystemId

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


setLineNumbering

public void setLineNumbering()
Set line numbering on


setLineNumber

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


getLineNumber

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


getLineNumber

public int getLineNumber()
Get the line number of this root node.

Specified by:
getLineNumber in interface SourceLocator
Specified by:
getLineNumber in interface NodeInfo
Overrides:
getLineNumber in class TinyNodeImpl
Returns:
0 always

getNodeKind

public final int getNodeKind()
Return the type of node.

Specified by:
getNodeKind in interface NodeInfo
Returns:
Type.DOCUMENT (always)
See Also:
Type

getParent

public NodeInfo getParent()
Find the parent node of this node.

Specified by:
getParent in interface NodeInfo
Overrides:
getParent in class TinyNodeImpl
Returns:
The Node object describing the containing element or root node.

getRoot

public NodeInfo getRoot()
Get the root node

Specified by:
getRoot in interface NodeInfo
Overrides:
getRoot in class TinyNodeImpl
Returns:
the NodeInfo that is the root of the tree - not necessarily a document node

getDocumentRoot

public DocumentInfo getDocumentRoot()
Get the root (document) node

Specified by:
getDocumentRoot in interface NodeInfo
Overrides:
getDocumentRoot in class TinyNodeImpl
Returns:
the DocumentInfo representing the document node, or null if the root of the tree is not a document node

generateId

public String generateId()
Get a character string that uniquely identifies this node

Specified by:
generateId in interface NodeInfo
Overrides:
generateId in class TinyNodeImpl
Returns:
an identifier based on the document number

getAllElements

protected AxisIterator getAllElements(int fingerprint)
Get a list of all elements with a given name. This is implemented as a memo function: the first time it is called for a particular element type, it remembers the result for next time.


selectID

public NodeInfo selectID(String id)
Get the element with a given ID.

Specified by:
selectID in interface DocumentInfo
Parameters:
id - The unique ID of the required element, previously registered using registerID()
Returns:
The NodeInfo (always an Element) for the given ID if one has been registered, otherwise null.

setUnparsedEntity

protected void setUnparsedEntity(String name,
                                 String uri,
                                 String publicId)
Set an unparsed entity URI associated with this document. For system use only, while building the document.


getUnparsedEntity

public String[] getUnparsedEntity(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 interface DocumentInfo
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

copy

public void copy(Receiver out,
                 int whichNamespaces,
                 boolean copyAnnotations)
          throws TransformerException
Copy this node to a given outputter

Specified by:
copy in interface NodeInfo
Parameters:
out - the Receiver to which the node should be copied
whichNamespaces - in the case of an element, controls which namespace nodes should be copied. Values are NO_NAMESPACES, LOCAL_NAMESPACES, ALL_NAMESPACES
copyAnnotations - indicates whether the type annotations of element and attribute nodes should be copied
Throws:
TransformerException

diagnosticDump

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


showSize

public void showSize()