net.sf.saxon.tree

Class DocumentImpl

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

Constructor Summary
DocumentImpl()
Create a DocumentImpl
Method Summary
voidcopy(Receiver out, int whichNamespaces, boolean copyAnnotations, int locationId)
Copy this node to a given outputter
voiddeIndex(NodeImpl node)
Remove a node from any indexes when it is detached from the tree
protected voidderegisterID(String id)
Remove the entry for a given ID (when nodes are deleted).
voidgenerateId(FastStringBuffer buffer)
Get a character string that uniquely identifies this node
AxisIteratorgetAllElements(int fingerprint)
Get a list of all elements with a given name fingerprint
StringgetBaseURI()
Get the base URI of this root node.
intgetColumnNumber(int sequence)
Get the column number for an element.
ConfigurationgetConfiguration()
Get the configuration previously set using setConfiguration
ElementImplgetDocumentElement()
Get the root (outermost) element.
longgetDocumentNumber()
Get the unique document number
DocumentInfogetDocumentRoot()
Get the root (document) node
intgetLineNumber(int sequence)
Get the line number for an element.
intgetLineNumber()
Get the line number of this root node.
NamePoolgetNamePool()
Get the name pool used for the names in this document
NodeInfogetNextSibling()
Get next sibling - always null
intgetNodeKind()
Return the type of node.
DocumentImplgetPhysicalRoot()
Get the physical root of the tree.
NodeInfogetPreviousSibling()
Get previous sibling - always null
NodeInfogetRoot()
Get the root node
StringgetSystemId()
Get the system id of this root node
StringgetSystemId(int seq)
Get the system id of an element in the document
intgetTypeAnnotation()
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
voidgraftLocationMap(DocumentImpl original)
Copy the system ID and line number map from another document (used when grafting a simplified stylesheet)
booleanisImaginary()
Ask whether this is an imaginary document node
BuildernewBuilder()
Get a Builder suitable for building nodes that can be attached to this document.
protected voidregisterID(NodeInfo e, String id)
Register a unique element ID.
voidreplaceStringValue(CharSequence stringValue)
Replace the string-value of this node
voidresetIndexes()
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
NodeInfoselectID(String id, boolean getParent)
Get the element with a given ID.
voidsetBaseURI(String uri)
Set the base URI of this document node
voidsetConfiguration(Configuration config)
Set the Configuration that contains this document
voidsetDocumentElement(ElementImpl e)
Set the top-level element of the document (variously called the root element or the document element).
voidsetImaginary(boolean imaginary)
Set whether this is an imaginary document node
voidsetLineAndColumn(int sequence, int line, int column)
Set the line number for an element.
voidsetLineNumbering()
Set line numbering on
voidsetSystemId(String uri)
Set the system id (base URI) of this node
voidsetSystemId(int seq, String uri)
Set the system id of an element in the document
voidsetUnparsedEntity(String name, String uri, String publicId)
Set an unparsed entity URI associated with this document.

Constructor Detail

DocumentImpl

public DocumentImpl()
Create a DocumentImpl

Method Detail

copy

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

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

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

generateId

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

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

getBaseURI

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

Returns: the base URI

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

getConfiguration

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

Returns: the Saxon configuration

getDocumentElement

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

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

getDocumentNumber

public long getDocumentNumber()
Get the unique document number

getDocumentRoot

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

Returns: the DocumentInfo representing this document

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

getLineNumber

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

Returns: 0 always

getNamePool

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

getNextSibling

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

Returns: null

getNodeKind

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

Returns: Type.DOCUMENT (always)

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

Returns: the document node, which may be imaginary

getPreviousSibling

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

Returns: null

getRoot

public NodeInfo getRoot()
Get the root node

Returns: the NodeInfo representing the root of this tree

getSystemId

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

getSystemId

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

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

Returns: the type annotation, as the integer name code of the type name

getUnparsedEntity

public String[] getUnparsedEntity(String name)
Get the unparsed entity with a given name

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.

getUnparsedEntityNames

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

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

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

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

newBuilder

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

Returns: a new TreeBuilder

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

replaceStringValue

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

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

selectID

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

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.

setBaseURI

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

Parameters: uri the new base URI

setConfiguration

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

Parameters: config the Saxon configuration

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

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

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

setLineNumbering

public void setLineNumbering()
Set line numbering on

setSystemId

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

setSystemId

void setSystemId(int seq, 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

setUnparsedEntity

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.

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