com.icl.saxon.tinytree
Class TinyDocumentImpl

java.lang.Object
  extended by com.icl.saxon.om.AbstractNode
      extended by com.icl.saxon.tinytree.TinyNodeImpl
          extended by com.icl.saxon.tinytree.TinyParentNodeImpl
              extended by com.icl.saxon.tinytree.TinyDocumentImpl
All Implemented Interfaces:
DocumentInfo, NodeInfo, DOMLocator, Source, SourceLocator, 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:
Michael H. Kay

Field Summary
protected  int[] attCode
           
protected  int[] attParent
           
protected  String[] attValue
           
protected  char[] charBuffer
           
protected  int charBufferLength
           
protected  StringBuffer commentBuffer
           
protected  short[] depth
           
protected  int lastLevelOneNode
           
protected  int[] length
           
protected  int[] nameCode
           
protected  int[] namespaceCode
           
protected  int[] namespaceParent
           
protected  int[] next
           
protected  byte[] nodeType
           
protected  int numberOfAttributes
           
protected  int numberOfNamespaces
           
protected  int numberOfNodes
           
protected  int[] offset
           
protected  int[] prior
           
 
Fields inherited from class com.icl.saxon.tinytree.TinyNodeImpl
document, nodeNr, parent
 
Fields inherited from class com.icl.saxon.om.AbstractNode
NODE_LETTER
 
Fields inherited from interface com.icl.saxon.om.NodeInfo
ATTRIBUTE, COMMENT, ELEMENT, NAMESPACE, NODE, NONE, NUMBER_OF_TYPES, PI, ROOT, TEXT
 
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()
           
 
Method Summary
protected  void addAttribute(int parent0, int code0, String type0, String value0)
           
protected  void addNamespace(int parent0, int nscode0)
           
protected  void addNode(short type0, int depth0, int offset0, int length0, int nameCode0)
           
 Node adoptNode(Node source)
          Attempts to adopt a node from another document to this document.
protected  void appendChars(char[] chars, int start, int length)
           
 void copy(Outputter out)
          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 within the document
protected  AxisEnumeration getAllElements(int fingerprint)
          Get a list of all elements with a given name.
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.
 DocumentInfo getDocumentRoot()
          Get the root (document) node
 String getDocumentURI()
          The location of the document or null if undefined or if the Document was created using DOMImplementation.createDocument.
 DOMConfiguration getDomConfig()
          The configuration used when Document.normalizeDocument() is invoked.
 String getInputEncoding()
          An attribute specifying the encoding used for this document at the time of the parsing.
 Hashtable getKeyIndex(KeyManager keymanager, int fingerprint)
          Get the index for a given key
 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)
           
 short getNodeType()
          Return the type of node.
 NodeInfo getParent()
          Find the parent node of this node.
 long getSequenceNumber()
          Get the node sequence number (in document order).
 boolean getStrictErrorChecking()
          An attribute specifying whether error checking is enforced or not.
 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 name
 String getXmlEncoding()
          An attribute specifying, as part of the XML declaration, the encoding of this document.
 boolean getXmlStandalone()
          An attribute specifying, as part of the XML declaration, whether this document is standalone.
 String getXmlVersion()
          An attribute specifying, as part of the XML declaration, the version number of this document.
protected  boolean isUsingNamespaces()
          determine whether this document uses namespaces
 void normalizeDocument()
          This method acts as if the document was going through a save and load cycle, putting the document in a "normal" form.
 Node renameNode(Node n, String namespaceURI, String qualifiedName)
          Rename an existing node of type ELEMENT_NODE or ATTRIBUTE_NODE.
 NodeInfo selectID(String id)
          Get the element with a given ID.
 void setDocumentURI(String documentURI)
          The location of the document or null if undefined or if the Document was created using DOMImplementation.createDocument.
 void setKeyIndex(KeyManager keymanager, int fingerprint, Hashtable keyindex)
          Set the index for a given key.
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 setStrictErrorChecking(boolean strictErrorChecking)
          An attribute specifying whether error checking is enforced or not.
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)
          Set an unparsed entity URI associated with this document.
 void setXmlStandalone(boolean xmlStandalone)
          An attribute specifying, as part of the XML declaration, whether this document is standalone.
 void setXmlVersion(String xmlVersion)
          An attribute specifying, as part of the XML declaration, the version number of this document.
protected  void truncate(int nodes)
          Truncate the tree: used in preview mode to delete an element after it has been processed
 
Methods inherited from class com.icl.saxon.tinytree.TinyParentNodeImpl
copyStringValue, getStringValue, hasChildNodes
 
Methods inherited from class com.icl.saxon.tinytree.TinyNodeImpl
compareOrder, getAttributeValue, getAttributeValue, getDisplayName, getEnumeration, getFingerprint, getLocalName, getNameCode, getOriginatingNode, getPrefix, getURI, hasAttributes, isSameNodeInfo, outputNamespaceNodes, setLineNumber, setParentNode
 
Methods inherited from class com.icl.saxon.om.AbstractNode
appendChild, appendData, cloneNode, compareDocumentPosition, 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, getFeature, getFirstChild, getImplementation, getLastChild, getLength, getName, getNamespaceURI, getNextSibling, getNodeName, getNodeValue, getOwnerDocument, getOwnerElement, getParentNode, getPreviousSibling, getPublicId, getSchemaTypeInfo, getSpecified, getTagName, getTextContent, getUserData, getValue, getWholeText, hasAttribute, hasAttributeNS, importNode, insertBefore, insertData, isDefaultNamespace, isElementContentWhitespace, isEqualNode, isId, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeAttribute, removeAttributeNode, removeAttributeNS, removeChild, replaceChild, replaceData, replaceWholeText, setAttributeNode, setAttributeNodeNS, setAttributeNS, setData, setIdAttribute, setIdAttributeNode, setIdAttributeNS, setNodeValue, setPrefix, setTextContent, setUserData, 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 com.icl.saxon.om.NodeInfo
compareOrder, copyStringValue, getAttributeValue, getAttributeValue, getDisplayName, getEnumeration, getFingerprint, getLocalName, getNameCode, getPrefix, getStringValue, getURI, hasChildNodes, isSameNodeInfo, outputNamespaceNodes
 
Methods inherited from interface org.w3c.dom.Document
createAttribute, createAttributeNS, createCDATASection, createComment, createDocumentFragment, createElement, createElementNS, createEntityReference, createProcessingInstruction, createTextNode, getDoctype, getDocumentElement, getElementById, getElementsByTagName, getElementsByTagNameNS, getImplementation, importNode
 
Methods inherited from interface org.w3c.dom.Node
appendChild, cloneNode, compareDocumentPosition, getAttributes, getChildNodes, getFeature, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, 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

charBuffer

protected char[] charBuffer

charBufferLength

protected int charBufferLength

commentBuffer

protected StringBuffer commentBuffer

numberOfNodes

protected int numberOfNodes

lastLevelOneNode

protected int lastLevelOneNode

nodeType

protected byte[] nodeType

depth

protected short[] depth

next

protected int[] next

offset

protected int[] offset

length

protected int[] length

nameCode

protected int[] nameCode

prior

protected int[] prior

numberOfAttributes

protected int numberOfAttributes

attParent

protected int[] attParent

attCode

protected int[] attCode

attValue

protected String[] attValue

numberOfNamespaces

protected int numberOfNamespaces

namespaceParent

protected int[] namespaceParent

namespaceCode

protected int[] namespaceCode
Constructor Detail

TinyDocumentImpl

public TinyDocumentImpl()
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

getNamePool

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

Specified by:
getNamePool in interface DocumentInfo

ensureNodeCapacity

protected void ensureNodeCapacity()

ensureAttributeCapacity

protected void ensureAttributeCapacity()

ensureNamespaceCapacity

protected void ensureNamespaceCapacity()

addNode

protected void addNode(short type0,
                       int depth0,
                       int offset0,
                       int length0,
                       int nameCode0)

appendChars

protected void appendChars(char[] chars,
                           int start,
                           int length)

truncate

protected void truncate(int nodes)
Truncate the tree: used in preview mode to delete an element after it has been processed


ensurePriorIndex

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


addAttribute

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

addNamespace

protected void addNamespace(int parent0,
                            int nscode0)

getNode

public TinyNodeImpl getNode(int nr)

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


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 NodeInfo
Specified by:
getSystemId in interface Source
Specified by:
getSystemId in interface SourceLocator
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

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 NodeInfo
Specified by:
getLineNumber in interface SourceLocator
Overrides:
getLineNumber in class TinyNodeImpl
Returns:
0 always

getNodeType

public final short getNodeType()
Return the type of node.

Specified by:
getNodeType in interface NodeInfo
Specified by:
getNodeType in interface Node
Returns:
NodeInfo.ROOT (always)

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.

getDocumentRoot

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

Specified by:
getDocumentRoot in interface NodeInfo
Overrides:
getDocumentRoot in class TinyNodeImpl
Returns:
the DocumentInfo representing this document

generateId

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

Specified by:
generateId in interface NodeInfo
Overrides:
generateId in class TinyNodeImpl
Returns:
the empty string

getAllElements

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

getKeyIndex

public Hashtable getKeyIndex(KeyManager keymanager,
                             int fingerprint)
Get the index for a given key

Specified by:
getKeyIndex in interface DocumentInfo
Parameters:
keymanager - The key manager managing this key
fingerprint - The fingerprint of the name of the key (unique with the key manager)
Returns:
The index, if one has been built, in the form of a Hashtable that maps the key value to a set of nodes having that key value. If no index has been built, returns null.

setKeyIndex

public void setKeyIndex(KeyManager keymanager,
                        int fingerprint,
                        Hashtable keyindex)
Set the index for a given key. The method is synchronized because the same document can be used by several stylesheets at the same time.

Specified by:
setKeyIndex in interface DocumentInfo
Parameters:
keymanager - The key manager managing this key
fingerprint - The fingerprint of the name of the key (unique with the key manager)
keyindex - the index, in the form of a Hashtable that maps the key value to a set of nodes having that key value. Or the String "under construction", indicating that the index is being built.

setUnparsedEntity

protected void setUnparsedEntity(String name,
                                 String uri)
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 name

Specified by:
getUnparsedEntity in interface DocumentInfo
Parameters:
name - the name of the entity
Returns:
the URI of the entity if there is one, or empty string if not

copy

public void copy(Outputter out)
          throws TransformerException
Copy this node to a given outputter

Specified by:
copy in interface NodeInfo
Throws:
TransformerException

diagnosticDump

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


adoptNode

public Node adoptNode(Node source)
               throws DOMException
Attempts to adopt a node from another document to this document.

Specified by:
adoptNode in interface Document
Parameters:
source - The node to move into this document.
Returns:
The adopted node, or null if this operation fails, such as when the source node comes from a different implementation.
Throws:
DOMException - NOT_SUPPORTED_ERR: Raised if the source node is of type DOCUMENT, DOCUMENT_TYPE.
NO_MODIFICATION_ALLOWED_ERR: Raised when the source node is readonly.
Since:
DOM Level 3

getDocumentURI

public String getDocumentURI()
The location of the document or null if undefined or if the Document was created using DOMImplementation.createDocument. No lexical checking is performed when setting this attribute; this could result in a null value returned when using Node.baseURI .
Beware that when the Document supports the feature "HTML" [DOM Level 2 HTML] , the href attribute of the HTML BASE element takes precedence over this attribute when computing Node.baseURI.

Specified by:
getDocumentURI in interface Document
Since:
DOM Level 3

getDomConfig

public DOMConfiguration getDomConfig()
The configuration used when Document.normalizeDocument() is invoked.

Specified by:
getDomConfig in interface Document
Since:
DOM Level 3

getInputEncoding

public String getInputEncoding()
An attribute specifying the encoding used for this document at the time of the parsing. This is null when it is not known, such as when the Document was created in memory.

Specified by:
getInputEncoding in interface Document
Since:
DOM Level 3

getStrictErrorChecking

public boolean getStrictErrorChecking()
An attribute specifying whether error checking is enforced or not. When set to false, the implementation is free to not test every possible error case normally defined on DOM operations, and not raise any DOMException on DOM operations or report errors while using Document.normalizeDocument(). In case of error, the behavior is undefined. This attribute is true by default.

Specified by:
getStrictErrorChecking in interface Document
Since:
DOM Level 3

getXmlEncoding

public String getXmlEncoding()
An attribute specifying, as part of the XML declaration, the encoding of this document. This is null when unspecified or when it is not known, such as when the Document was created in memory.

Specified by:
getXmlEncoding in interface Document
Since:
DOM Level 3

getXmlStandalone

public boolean getXmlStandalone()
An attribute specifying, as part of the XML declaration, whether this document is standalone. This is false when unspecified.

Note: No verification is done on the value when setting this attribute. Applications should use Document.normalizeDocument() with the "validate" parameter to verify if the value matches the validity constraint for standalone document declaration as defined in [XML 1.0].

Specified by:
getXmlStandalone in interface Document
Since:
DOM Level 3

getXmlVersion

public String getXmlVersion()
An attribute specifying, as part of the XML declaration, the version number of this document. If there is no declaration and if this document supports the "XML" feature, the value is "1.0".

Specified by:
getXmlVersion in interface Document
Since:
DOM Level 3

normalizeDocument

public void normalizeDocument()
This method acts as if the document was going through a save and load cycle, putting the document in a "normal" form.

Specified by:
normalizeDocument in interface Document
Since:
DOM Level 3

renameNode

public Node renameNode(Node n,
                       String namespaceURI,
                       String qualifiedName)
                throws DOMException
Rename an existing node of type ELEMENT_NODE or ATTRIBUTE_NODE.

Specified by:
renameNode in interface Document
Parameters:
n - The node to rename.
namespaceURI - The new namespace URI.
qualifiedName - The new qualified name.
Returns:
The renamed node. This is either the specified node or the new node that was created to replace the specified node.
Throws:
DOMException - NOT_SUPPORTED_ERR: Raised when the type of the specified node is neither ELEMENT_NODE nor ATTRIBUTE_NODE, or if the implementation does not support the renaming of the document element.
INVALID_CHARACTER_ERR: Raised if the new qualified name is not an XML name according to the XML version in use specified in the Document.xmlVersion attribute.
WRONG_DOCUMENT_ERR: Raised when the specified node was created from a different document than this document.
NAMESPACE_ERR: Raised if the qualifiedName is a malformed qualified name, if the qualifiedName has a prefix and the namespaceURI is null, or if the qualifiedName has a prefix that is "xml" and the namespaceURI is different from " http://www.w3.org/XML/1998/namespace" [XML Namespaces] . Also raised, when the node being renamed is an attribute, if the qualifiedName, or its prefix, is "xmlns" and the namespaceURI is different from "http://www.w3.org/2000/xmlns/".
Since:
DOM Level 3

setDocumentURI

public void setDocumentURI(String documentURI)
The location of the document or null if undefined or if the Document was created using DOMImplementation.createDocument. No lexical checking is performed when setting this attribute; this could result in a null value returned when using Node.baseURI .
Beware that when the Document supports the feature "HTML" [DOM Level 2 HTML] , the href attribute of the HTML BASE element takes precedence over this attribute when computing Node.baseURI.

Specified by:
setDocumentURI in interface Document
Since:
DOM Level 3

setStrictErrorChecking

public void setStrictErrorChecking(boolean strictErrorChecking)
An attribute specifying whether error checking is enforced or not. When set to false, the implementation is free to not test every possible error case normally defined on DOM operations, and not raise any DOMException on DOM operations or report errors while using Document.normalizeDocument(). In case of error, the behavior is undefined. This attribute is true by default.

Specified by:
setStrictErrorChecking in interface Document
Since:
DOM Level 3

setXmlStandalone

public void setXmlStandalone(boolean xmlStandalone)
                      throws DOMException
An attribute specifying, as part of the XML declaration, whether this document is standalone. This is false when unspecified.

Note: No verification is done on the value when setting this attribute. Applications should use Document.normalizeDocument() with the "validate" parameter to verify if the value matches the validity constraint for standalone document declaration as defined in [XML 1.0].

Specified by:
setXmlStandalone in interface Document
Throws:
DOMException - NOT_SUPPORTED_ERR: Raised if this document does not support the "XML" feature.
Since:
DOM Level 3

setXmlVersion

public void setXmlVersion(String xmlVersion)
                   throws DOMException
An attribute specifying, as part of the XML declaration, the version number of this document. If there is no declaration and if this document supports the "XML" feature, the value is "1.0". If this document does not support the "XML" feature, the value is always null. Changing this attribute will affect methods that check for invalid characters in XML names. Application should invoke Document.normalizeDocument() in order to check for invalid characters in the Nodes that are already part of this Document.
DOM applications may use the DOMImplementation.hasFeature(feature, version) method with parameter values "XMLVersion" and "1.0" (respectively) to determine if an implementation supports [XML 1.0]. DOM applications may use the same method with parameter values "XMLVersion" and "1.1" (respectively) to determine if an implementation supports [XML 1.1]. In both cases, in order to support XML, an implementation must also support the "XML" feature defined in this specification. Document objects supporting a version of the "XMLVersion" feature must not raise a NOT_SUPPORTED_ERR exception for the same version number when using Document.xmlVersion.

Specified by:
setXmlVersion in interface Document
Throws:
DOMException - NOT_SUPPORTED_ERR: Raised if the version is set to a value that is not supported by this Document or if this document does not support the "XML" feature.
Since:
DOM Level 3