net.sf.saxon.tree.linked
Class DocumentImpl

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

public final class DocumentImpl
extends NodeImpl
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.linked.NodeImpl
NODE_LETTER
 
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
protected  void addChild(NodeImpl node, int index)
          Add a child node to this node.
 void compact(int size)
          Compact the space used by this node
 void copy(Receiver out, int copyOptions, 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(String id)
          Remove the entry for a given ID (when nodes are deleted).
protected  AxisIterator enumerateChildren(NodeTest test)
          Get an enumeration of the children of this node
 void generateId(FastStringBuffer buffer)
          Get a character string that uniquely identifies this node
 String getBaseURI()
          Get the base URI of this root node.
 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
 NodeInfo getFirstChild()
          Get the first child node of the element
 NodeInfo getLastChild()
          Get the last child node of the element
 int getLineNumber()
          Get the line number of this root node.
 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.
protected  NodeImpl getNthChild(int n)
          Get the nth child node of the element (numbering from 0)
 int getNumberOfChildren()
          Determine how many children the node has
 DocumentImpl getPhysicalRoot()
          Get the physical root of the tree.
 NodeInfo getPreviousSibling()
          Get previous sibling - always null
protected  int getRawSequenceNumber()
           
 NodeInfo getRoot()
          Get the root node
protected  long getSequenceNumber()
          Get the node sequence number (in document order).
 String getStringValue()
          Return the string-value of the node, that is, the concatenation of the character content of all descendent elements and text nodes.
 CharSequence getStringValueCS()
          Get the value of the item as a CharSequence.
 String getSystemId()
          Get the system id of this root node
 int getTypeAnnotation()
          Get the type annotation of this node, if any.
 String[] getUnparsedEntity(String name)
          Get the unparsed entity with a given name
 Iterator<String> getUnparsedEntityNames()
          Get the list of unparsed entities defined in this document
 Object getUserData(String key)
          Get user data held in the document node.
 void graftLocationMap(DocumentImpl original)
          Copy the system ID and line number map from another document (used when grafting a simplified stylesheet)
 boolean hasChildNodes()
          Determine if the node has any children.
 void insertChildren(NodeInfo[] source, boolean atStart, boolean inherit)
          Insert a sequence of nodes as children of this node.
protected  void insertChildrenAt(NodeInfo[] source, int index, boolean inherit)
          Insert children before or after a given existing child
 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, String id)
          Register a unique element ID.
protected  void removeChild(NodeImpl child)
          Remove a given child
protected  void replaceChildrenAt(NodeInfo[] source, int index, boolean inherit)
          Replace child at a given index by new children
 void replaceStringValue(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(String id, boolean getParent)
          Get the element with a given ID.
 void setBaseURI(String uri)
          Set the base URI of this document node
protected  void setChildren(Object children)
          Set the children of this node
 void setConfiguration(Configuration config)
          Set the Configuration that contains this document
 void setImaginary(boolean imaginary)
          Set whether this is an imaginary document node
 void setLineNumbering()
          Set line numbering on
protected  void setRawSequenceNumber(int seq)
           
 void setSystemId(String uri)
          Set the system id (base URI) of this node
 void setUserData(String key, Object value)
          Set user data on the document node.
 
Methods inherited from class net.sf.saxon.tree.linked.NodeImpl
addAttribute, addNamespace, atomize, compareOrder, delete, equals, getAttributeValue, getColumnNumber, getDeclaredNamespaces, getDisplayName, getFingerprint, getLocalPart, getNameCode, getNextInDocument, getParent, getPrefix, getPreviousInDocument, getPublicId, getRawParent, getSiblingPosition, getTypedValue, getURI, insertSiblings, isDeleted, isId, isIdref, isNilled, isSameNodeInfo, iterateAxis, iterateAxis, removeAttribute, removeTypeAnnotation, rename, replace, setRawParent, setSiblingPosition, 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

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(String uri)
Set the system id (base URI) of this node

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

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 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(String uri)
Set the base URI of this document node

Parameters:
uri - the new base URI

getBaseURI

public 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

setLineNumbering

public void setLineNumbering()
Set line numbering on


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

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,
                          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(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(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

getUnparsedEntityNames

public Iterator<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 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:
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 copyOptions,
                 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.
copyOptions - a selection of the options defined in CopyOptions
locationId - If non-zero, identifies the location of the instruction that requested this copy. If zero, indicates that the location information
Throws:
XPathException

replaceStringValue

public void replaceStringValue(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

setUserData

public void setUserData(String key,
                        Object value)
Set user data on the document node. The user data can be retrieved subsequently using getUserData(java.lang.String)

Specified by:
setUserData in interface DocumentInfo
Parameters:
key - A string giving the name of the property to be set. Clients are responsible for choosing a key that is likely to be unique. Must not be null. Keys used internally by Saxon are prefixed "saxon:".
value - The value to be set for the property. May be null, which effectively removes the existing value for the property.

getUserData

public Object getUserData(String key)
Get user data held in the document node. This retrieves properties previously set using setUserData(java.lang.String, java.lang.Object)

Specified by:
getUserData in interface DocumentInfo
Parameters:
key - A string giving the name of the property to be retrieved.
Returns:
the value of the property, or null if the property has not been defined.

getSequenceNumber

protected final long getSequenceNumber()
Get the node sequence number (in document order). Sequence numbers are monotonic but not consecutive. In the current implementation, parent nodes (elements and document nodes) have a zero least-significant word, while namespaces, attributes, text nodes, comments, and PIs have the top word the same as their owner and the bottom half reflecting their relative position. For nodes added by XQUery Update, the sequence number is -1L

Overrides:
getSequenceNumber in class NodeImpl
Returns:
the sequence number if there is one, or -1L otherwise.

getRawSequenceNumber

protected final int getRawSequenceNumber()

setRawSequenceNumber

protected final void setRawSequenceNumber(int seq)

setChildren

protected final void setChildren(Object children)
Set the children of this node

Parameters:
children - null if there are no children, a single NodeInfo if there is one child, an array of NodeInfo if there are multiple children

hasChildNodes

public final boolean hasChildNodes()
Determine if the node has any children.

Specified by:
hasChildNodes in interface NodeInfo
Overrides:
hasChildNodes in class NodeImpl
Returns:
true if the node has any children, false if the node has no children.

getNumberOfChildren

public final int getNumberOfChildren()
Determine how many children the node has

Returns:
the number of children of this parent node

enumerateChildren

protected final AxisIterator enumerateChildren(NodeTest test)
Get an enumeration of the children of this node

Parameters:
test - A NodeTest to be satisfied by the child nodes, or null if all child node are to be returned
Returns:
an iterator over the children of this node

getFirstChild

public final NodeInfo getFirstChild()
Get the first child node of the element

Overrides:
getFirstChild in class NodeImpl
Returns:
the first child node of the required type, or null if there are no children

getLastChild

public final NodeInfo getLastChild()
Get the last child node of the element

Overrides:
getLastChild in class NodeImpl
Returns:
the last child of the element, or null if there are no children

getNthChild

protected final NodeImpl getNthChild(int n)
Get the nth child node of the element (numbering from 0)

Parameters:
n - identifies the required child
Returns:
the last child of the element, or null if there is no n'th child

removeChild

protected void removeChild(NodeImpl child)
Remove a given child

Parameters:
child - the child to be removed

getStringValue

public String getStringValue()
Return the string-value of the node, that is, the concatenation of the character content of all descendent elements and text nodes.

Returns:
the accumulated character content of the element, including descendant elements.
See Also:
Item.getStringValueCS()

getStringValueCS

public CharSequence getStringValueCS()
Description copied from class: NodeImpl
Get the value of the item as a CharSequence. This is in some cases more efficient than the version of the method that returns a String.

Specified by:
getStringValueCS in interface Item
Specified by:
getStringValueCS in interface ValueRepresentation
Overrides:
getStringValueCS in class NodeImpl
Returns:
the string value of the item
See Also:
Item.getStringValue()

addChild

protected void addChild(NodeImpl node,
                        int index)
Add a child node to this node. For system use only. Note: normalizing adjacent text nodes is the responsibility of the caller.

Parameters:
node - the node to be added as a child of this node. This must be an instance of NodeImpl. It will be modified as a result of this call (by setting its parent property and sibling position)
index - the position where the child is to be added

insertChildren

public void insertChildren(NodeInfo[] source,
                           boolean atStart,
                           boolean inherit)
Insert a sequence of nodes as children of this node.

This method takes no action unless the target node is a document node or element node. It also takes no action in respect of any supplied nodes that are not elements, text nodes, comments, or processing instructions.

The supplied nodes will form the new children. Adjacent text nodes will be merged, and zero-length text nodes removed. The supplied nodes may be modified in situ, for example to change their parent property and to add namespace bindings, or they may be copied, at the discretion of the implementation.

Specified by:
insertChildren in interface MutableNodeInfo
Overrides:
insertChildren in class NodeImpl
Parameters:
source - the nodes to be inserted. The implementation determines what implementation classes of node it will accept; this implementation will accept text, comment, and processing instruction nodes belonging to any implementation, but elements must be instances of ElementImpl. The supplied nodes will be modified in situ, for example to change their parent property and to add namespace bindings, if they are instances of ElementImpl; otherwise they will be copied. If the nodes are copied, then on return the supplied source array will contain the copy rather than the original.
atStart - true if the new nodes are to be inserted before existing children; false if they are to be inserted after existing children
inherit - true if the inserted nodes are to inherit the namespaces of their new parent; false if such namespaces are to be undeclared
Throws:
IllegalArgumentException - if the supplied nodes use a node implementation that this implementation does not accept.

insertChildrenAt

protected void insertChildrenAt(NodeInfo[] source,
                                int index,
                                boolean inherit)
Insert children before or after a given existing child

Parameters:
source - the children to be inserted. We allow any kind of text, comment, or processing instruction node, but element nodes must be instances of this NodeInfo implementation.
index - the position before which they are to be inserted: 0 indicates insertion before the first child, 1 insertion before the second child, and so on.
inherit - true if the inserted nodes are to inherit the namespaces that are in-scope for their new parent; false if such namespaces should be undeclared on the children

replaceChildrenAt

protected void replaceChildrenAt(NodeInfo[] source,
                                 int index,
                                 boolean inherit)
Replace child at a given index by new children

Parameters:
source - the children to be inserted
index - the position at which they are to be inserted: 0 indicates replacement of the first child, replacement of the second child, and so on. The effect is undefined if index is out of range
inherit - set to true if the new child elements are to inherit the in-scope namespaces of their new parent
Throws:
IllegalArgumentException - if any of the replacement nodes is not an element, text, comment, or processing instruction node

compact

public void compact(int size)
Compact the space used by this node

Parameters:
size - the number of actual children


Copyright (c) 2004-2010 Saxonica Limited. All rights reserved.