net.sf.saxon.tree
Class DocumentImpl

java.lang.Object
  extended by net.sf.saxon.tree.NodeImpl
      extended by net.sf.saxon.tree.ParentNodeImpl
          extended by net.sf.saxon.tree.DocumentImpl
All Implemented Interfaces:
javax.xml.transform.Source, javax.xml.transform.SourceLocator, PullEvent, DocumentInfo, FingerprintedNode, Item, MutableDocumentInfo, MutableNodeInfo, NodeInfo, SiblingCountingNode, ValueRepresentation

public final class DocumentImpl
extends ParentNodeImpl
implements DocumentInfo, MutableDocumentInfo

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

A DocumentImpl object may either represent a real document node, or it may represent an imaginary container for a parentless element.

Author:
Michael H. Kay

Field Summary
 
Fields inherited from class net.sf.saxon.tree.ParentNodeImpl
children, sequence
 
Fields inherited from class net.sf.saxon.tree.NodeImpl
index, NODE_LETTER, parent
 
Fields inherited from interface net.sf.saxon.om.NodeInfo
ALL_NAMESPACES, EMPTY_NAMESPACE_LIST, IS_DTD_TYPE, IS_NILLED, LOCAL_NAMESPACES, NO_NAMESPACES
 
Fields inherited from interface net.sf.saxon.om.ValueRepresentation
EMPTY_VALUE_ARRAY
 
Constructor Summary
DocumentImpl()
          Create a DocumentImpl
 
Method Summary
 void copy(Receiver out, int whichNamespaces, boolean copyAnnotations, int locationId)
          Copy this node to a given outputter
 void deIndex(NodeImpl node)
          Remove a node from any indexes when it is detached from the tree
protected  void deregisterID(java.lang.String id)
          Remove the entry for a given ID (when nodes are deleted).
 void generateId(FastStringBuffer buffer)
          Get a character string that uniquely identifies this node
(package private)  AxisIterator getAllElements(int fingerprint)
          Get a list of all elements with a given name fingerprint
 java.lang.String getBaseURI()
          Get the base URI of this root node.
(package private)  int getColumnNumber(int sequence)
          Get the column number for an element.
 Configuration getConfiguration()
          Get the configuration previously set using setConfiguration
 ElementImpl getDocumentElement()
          Get the root (outermost) element.
 long getDocumentNumber()
          Get the unique document number
 DocumentInfo getDocumentRoot()
          Get the root (document) node
 int getLineNumber()
          Get the line number of this root node.
(package private)  int getLineNumber(int sequence)
          Get the line number for an element.
 NamePool getNamePool()
          Get the name pool used for the names in this document
 NodeInfo getNextSibling()
          Get next sibling - always null
 int getNodeKind()
          Return the type of node.
 DocumentImpl getPhysicalRoot()
          Get the physical root of the tree.
 NodeInfo getPreviousSibling()
          Get previous sibling - always null
 NodeInfo getRoot()
          Get the root node
 java.lang.String getSystemId()
          Get the system id of this root node
(package private)  java.lang.String getSystemId(int seq)
          Get the system id of an element in the document
 int getTypeAnnotation()
          Get the type annotation of this node, if any.
 java.lang.String[] getUnparsedEntity(java.lang.String name)
          Get the unparsed entity with a given name
 java.util.Iterator<java.lang.String> getUnparsedEntityNames()
          Get the list of unparsed entities defined in this document
 void graftLocationMap(DocumentImpl original)
          Copy the system ID and line number map from another document (used when grafting a simplified stylesheet)
 boolean isImaginary()
          Ask whether this is an imaginary document node
 Builder newBuilder()
          Get a Builder suitable for building nodes that can be attached to this document.
protected  void registerID(NodeInfo e, java.lang.String id)
          Register a unique element ID.
 void replaceStringValue(java.lang.CharSequence stringValue)
          Replace the string-value of this node
 void resetIndexes()
          This method is called before performing a batch of updates; it allows all cached data that might be invalidated by such updates to be cleared
 NodeInfo selectID(java.lang.String id, boolean getParent)
          Get the element with a given ID.
 void setBaseURI(java.lang.String uri)
          Set the base URI of this document node
 void setConfiguration(Configuration config)
          Set the Configuration that contains this document
(package private)  void setDocumentElement(ElementImpl e)
          Set the top-level element of the document (variously called the root element or the document element).
 void setImaginary(boolean imaginary)
          Set whether this is an imaginary document node
(package private)  void setLineAndColumn(int sequence, int line, int column)
          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 setSystemId(java.lang.String uri)
          Set the system id (base URI) of this node
(package private)  void setUnparsedEntity(java.lang.String name, java.lang.String uri, java.lang.String publicId)
          Set an unparsed entity URI associated with this document.
 
Methods inherited from class net.sf.saxon.tree.ParentNodeImpl
addChild, compact, enumerateChildren, getFirstChild, getLastChild, getNthChild, getNumberOfChildren, getSequenceNumber, getStringValue, getStringValueCS, hasChildNodes, insertChildren, insertChildrenAt, removeChild, replaceChildrenAt, useChildrenArray
 
Methods inherited from class net.sf.saxon.tree.NodeImpl
addAttribute, addNamespace, atomize, compareOrder, delete, equals, getAttributeValue, getColumnNumber, getDeclaredNamespaces, getDisplayName, getFingerprint, getLocalPart, getNameCode, getNextInDocument, getParent, getPrefix, getPreviousInDocument, getPublicId, getSiblingPosition, getTypedValue, getURI, insertSiblings, isDeleted, isId, isIdref, isNilled, isSameNodeInfo, iterateAxis, iterateAxis, removeAttribute, removeTypeAnnotation, rename, replace, setTypeAnnotation
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.saxon.om.NodeInfo
atomize, compareOrder, equals, getAttributeValue, getColumnNumber, getDeclaredNamespaces, getDisplayName, getFingerprint, getLocalPart, getNameCode, getParent, getPrefix, getStringValue, getURI, hasChildNodes, hashCode, isId, isIdref, isNilled, isSameNodeInfo, iterateAxis, iterateAxis
 
Methods inherited from interface net.sf.saxon.om.Item
getStringValueCS, getTypedValue
 

Constructor Detail

DocumentImpl

public DocumentImpl()
Create a DocumentImpl

Method Detail

setConfiguration

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

Parameters:
config - the Saxon configuration

getConfiguration

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

Specified by:
getConfiguration in interface NodeInfo
Overrides:
getConfiguration in class NodeImpl
Returns:
the Saxon configuration

getNamePool

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

Specified by:
getNamePool in interface NodeInfo
Overrides:
getNamePool in class NodeImpl
Returns:
the namepool

newBuilder

public Builder newBuilder()
Get a Builder suitable for building nodes that can be attached to this document.

Specified by:
newBuilder in interface MutableNodeInfo
Overrides:
newBuilder in class NodeImpl
Returns:
a new TreeBuilder

setImaginary

public void setImaginary(boolean imaginary)
Set whether this is an imaginary document node

Parameters:
imaginary - if true, this is an imaginary node - the tree is really rooted at the topmost element

isImaginary

public boolean isImaginary()
Ask whether this is an imaginary document node

Returns:
true if this is an imaginary node - the tree is really rooted at the topmost element

getDocumentNumber

public long getDocumentNumber()
Get the unique document number

Specified by:
getDocumentNumber in interface NodeInfo
Overrides:
getDocumentNumber in class NodeImpl
Returns:
the document number of the document containing this node

setDocumentElement

void setDocumentElement(ElementImpl e)
Set the top-level element of the document (variously called the root element or the document element). Note that a DocumentImpl may represent the root of a result tree fragment, in which case there is no document element.

Parameters:
e - the top-level element

graftLocationMap

public void graftLocationMap(DocumentImpl original)
Copy the system ID and line number map from another document (used when grafting a simplified stylesheet)

Parameters:
original - the document whose system ID and line number maps are to be grafted onto this tree

setSystemId

public void setSystemId(java.lang.String uri)
Set the system id (base URI) of this node

Specified by:
setSystemId in interface javax.xml.transform.Source
Overrides:
setSystemId in class NodeImpl

getSystemId

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

Specified by:
getSystemId in interface javax.xml.transform.Source
Specified by:
getSystemId in interface javax.xml.transform.SourceLocator
Specified by:
getSystemId in interface NodeInfo
Overrides:
getSystemId in class NodeImpl
Returns:
the System Identifier of the entity in the source document containing the node, or null if not known or not applicable.

setBaseURI

public void setBaseURI(java.lang.String uri)
Set the base URI of this document node

Parameters:
uri - the new base URI

getBaseURI

public java.lang.String getBaseURI()
Get the base URI of this root node.

Specified by:
getBaseURI in interface NodeInfo
Overrides:
getBaseURI in class NodeImpl
Returns:
the base URI

setSystemId

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

Parameters:
seq - the sequence number of the element
uri - the system identifier (base URI) of the element

getSystemId

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

Parameters:
seq - the sequence number of the element
Returns:
the systemId (base URI) of the element

setLineNumbering

public void setLineNumbering()
Set line numbering on


setLineAndColumn

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

Parameters:
sequence - the sequence number of the element
line - the line number of the element
column - the column number of the element

getLineNumber

int getLineNumber(int sequence)
Get the line number for an element.

Parameters:
sequence - the sequence number of the element
Returns:
the line number for an element. Return -1 if line numbering is off, or if the element was added subsequent to document creation by use of XQuery update

getColumnNumber

int getColumnNumber(int sequence)
Get the column number for an element.

Parameters:
sequence - the sequence number of the element
Returns:
the column number for an element. Return -1 if line numbering is off, or if the element was added subsequent to document creation by use of XQuery update

getLineNumber

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

Specified by:
getLineNumber in interface javax.xml.transform.SourceLocator
Specified by:
getLineNumber in interface NodeInfo
Overrides:
getLineNumber in class NodeImpl
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

getNextSibling

public final NodeInfo getNextSibling()
Get next sibling - always null

Overrides:
getNextSibling in class NodeImpl
Returns:
null

getPreviousSibling

public final NodeInfo getPreviousSibling()
Get previous sibling - always null

Overrides:
getPreviousSibling in class NodeImpl
Returns:
null

getDocumentElement

public ElementImpl getDocumentElement()
Get the root (outermost) element.

Returns:
the Element node for the outermost element of the document.

getRoot

public NodeInfo getRoot()
Get the root node

Specified by:
getRoot in interface NodeInfo
Overrides:
getRoot in class NodeImpl
Returns:
the NodeInfo representing the root of this tree

getDocumentRoot

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

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

getPhysicalRoot

public DocumentImpl getPhysicalRoot()
Get the physical root of the tree. This may be an imaginary document node: this method should be used only when control information held at the physical root is required

Overrides:
getPhysicalRoot in class NodeImpl
Returns:
the document node, which may be imaginary

generateId

public void generateId(FastStringBuffer buffer)
Get a character string that uniquely identifies this node

Specified by:
generateId in interface NodeInfo
Overrides:
generateId in class NodeImpl
Parameters:
buffer - a buffer into which will be placed a string based on the document number

getAllElements

AxisIterator getAllElements(int fingerprint)
Get a list of all elements with a given name fingerprint

Parameters:
fingerprint - the fingerprint of the required element name
Returns:
an iterator over all the elements with this name

deIndex

public void deIndex(NodeImpl node)
Remove a node from any indexes when it is detached from the tree

Parameters:
node - the node to be removed from all indexes

registerID

protected void registerID(NodeInfo e,
                          java.lang.String id)
Register a unique element ID. Does nothing if there is already an element with that ID.

Parameters:
e - The Element having a particular unique ID value
id - The unique ID value

selectID

public NodeInfo selectID(java.lang.String id,
                         boolean getParent)
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()
getParent -
Returns:
The NodeInfo for the given ID if one has been registered, otherwise null.

deregisterID

protected void deregisterID(java.lang.String id)
Remove the entry for a given ID (when nodes are deleted). Does nothing if the id value is not present in the index.

Parameters:
id - The id value

setUnparsedEntity

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

Parameters:
name - the entity name
uri - the system identifier of the unparsed entity
publicId - the public identifier of the unparsed entity

getUnparsedEntityNames

public java.util.Iterator<java.lang.String> getUnparsedEntityNames()
Get the list of unparsed entities defined in this document

Specified by:
getUnparsedEntityNames in interface DocumentInfo
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 name

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 ID if there is one, or null if not. If the entity does not exist, return null.

getTypeAnnotation

public int getTypeAnnotation()
Get the type annotation of this node, if any. By convention for a document node this is XS_ANY_TYPE if the document is validated, or XS_UNTYPED otherwise

Specified by:
getTypeAnnotation in interface NodeInfo
Overrides:
getTypeAnnotation in class NodeImpl
Returns:
the type annotation, as the integer name code of the type name

copy

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

Specified by:
copy in interface NodeInfo
Parameters:
out - the Receiver to which the node should be copied. It is the caller's responsibility to ensure that this Receiver is open before the method is called (or that it is self-opening), and that it is closed after use.
whichNamespaces - in the case of an element, controls which namespace nodes should be copied. Values are NodeInfo.NO_NAMESPACES, NodeInfo.LOCAL_NAMESPACES, NodeInfo.ALL_NAMESPACES
copyAnnotations - indicates whether the type annotations of element and attribute nodes should be copied
locationId - If non-zero, identifies the location of the instruction that requested this copy. If zero, indicates that the location information for the original node is to be copied; in this case the Receiver must be a LocationCopier
Throws:
XPathException

replaceStringValue

public void replaceStringValue(java.lang.CharSequence stringValue)
Replace the string-value of this node

Specified by:
replaceStringValue in interface MutableNodeInfo
Parameters:
stringValue - the new string value

resetIndexes

public void resetIndexes()
This method is called before performing a batch of updates; it allows all cached data that might be invalidated by such updates to be cleared

Specified by:
resetIndexes in interface MutableDocumentInfo