View Javadoc
1   /*
2    * reserved comment block
3    * DO NOT REMOVE OR ALTER!
4    */
5   /*
6    * Copyright 1999-2004 The Apache Software Foundation.
7    *
8    * Licensed under the Apache License, Version 2.0 (the "License");
9    * you may not use this file except in compliance with the License.
10   * You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  /*
21   * $Id: DTM.java,v 1.2.4.1 2005/09/15 08:14:51 suresh_emailid Exp $
22   */
23  package com.sun.org.apache.xml.internal.dtm;
24  
25  import javax.xml.transform.SourceLocator;
26  
27  import com.sun.org.apache.xml.internal.utils.XMLString;
28  
29  /**
30   * <code>DTM</code> is an XML document model expressed as a table
31   * rather than an object tree. It attempts to provide an interface to
32   * a parse tree that has very little object creation. (DTM
33   * implementations may also support incremental construction of the
34   * model, but that's hidden from the DTM API.)
35   *
36   * <p>Nodes in the DTM are identified by integer "handles".  A handle must
37   * be unique within a process, and carries both node identification and
38   * document identification.  It must be possible to compare two handles
39   * (and thus their nodes) for identity with "==".</p>
40   *
41   * <p>Namespace URLs, local-names, and expanded-names can all be
42   * represented by and tested as integer ID values.  An expanded name
43   * represents (and may or may not directly contain) a combination of
44   * the URL ID, and the local-name ID.  Note that the namespace URL id
45   * can be 0, which should have the meaning that the namespace is null.
46   * For consistancy, zero should not be used for a local-name index. </p>
47   *
48   * <p>Text content of a node is represented by an index and length,
49   * permitting efficient storage such as a shared FastStringBuffer.</p>
50   *
51   * <p>The model of the tree, as well as the general navigation model,
52   * is that of XPath 1.0, for the moment.  The model will eventually be
53   * adapted to match the XPath 2.0 data model, XML Schema, and
54   * InfoSet.</p>
55   *
56   * <p>DTM does _not_ directly support the W3C's Document Object
57   * Model. However, it attempts to come close enough that an
58   * implementation of DTM can be created that wraps a DOM and vice
59   * versa.</p>
60   *
61   * <p><strong>Please Note:</strong> The DTM API is still
62   * <strong>Subject To Change.</strong> This wouldn't affect most
63   * users, but might require updating some extensions.</p>
64   *
65   * <p> The largest change being contemplated is a reconsideration of
66   * the Node Handle representation.  We are still not entirely sure
67   * that an integer packed with two numeric subfields is really the
68   * best solution. It has been suggested that we move up to a Long, to
69   * permit more nodes per document without having to reduce the number
70   * of slots in the DTMManager. There's even been a proposal that we
71   * replace these integers with "cursor" objects containing the
72   * internal node id and a pointer to the actual DTM object; this might
73   * reduce the need to continuously consult the DTMManager to retrieve
74   * the latter, and might provide a useful "hook" back into normal Java
75   * heap management.  But changing this datatype would have huge impact
76   * on Xalan's internals -- especially given Java's lack of C-style
77   * typedefs -- so we won't cut over unless we're convinced the new
78   * solution really would be an improvement!</p>
79   * */
80  public interface DTM
81  {
82  
83    /**
84     * Null node handles are represented by this value.
85     */
86    public static final int NULL = -1;
87  
88    // These nodeType mnemonics and values are deliberately the same as those
89    // used by the DOM, for convenient mapping
90    //
91    // %REVIEW% Should we actually define these as initialized to,
92    // eg. org.w3c.dom.Document.ELEMENT_NODE?
93  
94    /**
95     * The node is a <code>Root</code>.
96     */
97    public static final short ROOT_NODE = 0;
98  
99    /**
100    * The node is an <code>Element</code>.
101    */
102   public static final short ELEMENT_NODE = 1;
103 
104   /**
105    * The node is an <code>Attr</code>.
106    */
107   public static final short ATTRIBUTE_NODE = 2;
108 
109   /**
110    * The node is a <code>Text</code> node.
111    */
112   public static final short TEXT_NODE = 3;
113 
114   /**
115    * The node is a <code>CDATASection</code>.
116    */
117   public static final short CDATA_SECTION_NODE = 4;
118 
119   /**
120    * The node is an <code>EntityReference</code>.
121    */
122   public static final short ENTITY_REFERENCE_NODE = 5;
123 
124   /**
125    * The node is an <code>Entity</code>.
126    */
127   public static final short ENTITY_NODE = 6;
128 
129   /**
130    * The node is a <code>ProcessingInstruction</code>.
131    */
132   public static final short PROCESSING_INSTRUCTION_NODE = 7;
133 
134   /**
135    * The node is a <code>Comment</code>.
136    */
137   public static final short COMMENT_NODE = 8;
138 
139   /**
140    * The node is a <code>Document</code>.
141    */
142   public static final short DOCUMENT_NODE = 9;
143 
144   /**
145    * The node is a <code>DocumentType</code>.
146    */
147   public static final short DOCUMENT_TYPE_NODE = 10;
148 
149   /**
150    * The node is a <code>DocumentFragment</code>.
151    */
152   public static final short DOCUMENT_FRAGMENT_NODE = 11;
153 
154   /**
155    * The node is a <code>Notation</code>.
156    */
157   public static final short NOTATION_NODE = 12;
158 
159   /**
160    * The node is a <code>namespace node</code>. Note that this is not
161    * currently a node type defined by the DOM API.
162    */
163   public static final short NAMESPACE_NODE = 13;
164 
165   /**
166    * The number of valid nodetypes.
167    */
168   public static final short  NTYPES = 14;
169 
170   // ========= DTM Implementation Control Functions. ==============
171   // %TBD% RETIRED -- do via setFeature if needed. Remove from impls.
172   // public void setParseBlockSize(int blockSizeSuggestion);
173 
174   /**
175    * Set an implementation dependent feature.
176    * <p>
177    * %REVIEW% Do we really expect to set features on DTMs?
178    *
179    * @param featureId A feature URL.
180    * @param state true if this feature should be on, false otherwise.
181    */
182   public void setFeature(String featureId, boolean state);
183 
184   /**
185    * Set a run time property for this DTM instance.
186    *
187    * @param property a <code>String</code> value
188    * @param value an <code>Object</code> value
189    */
190   public void setProperty(String property, Object value);
191 
192   // ========= Document Navigation Functions =========
193 
194   /**
195    * This returns a stateless "traverser", that can navigate over an
196    * XPath axis, though not in document order.
197    *
198    * @param axis One of Axes.ANCESTORORSELF, etc.
199    *
200    * @return A DTMAxisIterator, or null if the givin axis isn't supported.
201    */
202   public DTMAxisTraverser getAxisTraverser(final int axis);
203 
204   /**
205    * This is a shortcut to the iterators that implement
206    * XPath axes.
207    * Returns a bare-bones iterator that must be initialized
208    * with a start node (using iterator.setStartNode()).
209    *
210    * @param axis One of Axes.ANCESTORORSELF, etc.
211    *
212    * @return A DTMAxisIterator, or null if the givin axis isn't supported.
213    */
214   public DTMAxisIterator getAxisIterator(final int axis);
215 
216   /**
217    * Get an iterator that can navigate over an XPath Axis, predicated by
218    * the extended type ID.
219    *
220    * @param axis
221    * @param type An extended type ID.
222    *
223    * @return A DTMAxisIterator, or null if the givin axis isn't supported.
224    */
225   public DTMAxisIterator getTypedAxisIterator(final int axis, final int type);
226 
227   /**
228    * Given a node handle, test if it has child nodes.
229    * <p> %REVIEW% This is obviously useful at the DOM layer, where it
230    * would permit testing this without having to create a proxy
231    * node. It's less useful in the DTM API, where
232    * (dtm.getFirstChild(nodeHandle)!=DTM.NULL) is just as fast and
233    * almost as self-evident. But it's a convenience, and eases porting
234    * of DOM code to DTM.  </p>
235    *
236    * @param nodeHandle int Handle of the node.
237    * @return int true if the given node has child nodes.
238    */
239   public boolean hasChildNodes(int nodeHandle);
240 
241   /**
242    * Given a node handle, get the handle of the node's first child.
243    *
244    * @param nodeHandle int Handle of the node.
245    * @return int DTM node-number of first child,
246    * or DTM.NULL to indicate none exists.
247    */
248   public int getFirstChild(int nodeHandle);
249 
250   /**
251    * Given a node handle, get the handle of the node's last child.
252    *
253    * @param nodeHandle int Handle of the node.
254    * @return int Node-number of last child,
255    * or DTM.NULL to indicate none exists.
256    */
257   public int getLastChild(int nodeHandle);
258 
259   /**
260    * Retrieves an attribute node by local name and namespace URI
261    *
262    * %TBD% Note that we currently have no way to support
263    * the DOM's old getAttribute() call, which accesses only the qname.
264    *
265    * @param elementHandle Handle of the node upon which to look up this attribute.
266    * @param namespaceURI The namespace URI of the attribute to
267    *   retrieve, or null.
268    * @param name The local name of the attribute to
269    *   retrieve.
270    * @return The attribute node handle with the specified name (
271    *   <code>nodeName</code>) or <code>DTM.NULL</code> if there is no such
272    *   attribute.
273    */
274   public int getAttributeNode(int elementHandle, String namespaceURI,
275                               String name);
276 
277   /**
278    * Given a node handle, get the index of the node's first attribute.
279    *
280    * @param nodeHandle int Handle of the node.
281    * @return Handle of first attribute, or DTM.NULL to indicate none exists.
282    */
283   public int getFirstAttribute(int nodeHandle);
284 
285   /**
286    * Given a node handle, get the index of the node's first namespace node.
287    *
288    * @param nodeHandle handle to node, which should probably be an element
289    *                   node, but need not be.
290    *
291    * @param inScope true if all namespaces in scope should be
292    *                   returned, false if only the node's own
293    *                   namespace declarations should be returned.
294    * @return handle of first namespace,
295    * or DTM.NULL to indicate none exists.
296    */
297   public int getFirstNamespaceNode(int nodeHandle, boolean inScope);
298 
299   /**
300    * Given a node handle, advance to its next sibling.
301    * @param nodeHandle int Handle of the node.
302    * @return int Node-number of next sibling,
303    * or DTM.NULL to indicate none exists.
304    */
305   public int getNextSibling(int nodeHandle);
306 
307   /**
308    * Given a node handle, find its preceeding sibling.
309    * WARNING: DTM implementations may be asymmetric; in some,
310    * this operation has been resolved by search, and is relatively expensive.
311    *
312    * @param nodeHandle the id of the node.
313    * @return int Node-number of the previous sib,
314    * or DTM.NULL to indicate none exists.
315    */
316   public int getPreviousSibling(int nodeHandle);
317 
318   /**
319    * Given a node handle, advance to the next attribute. If an
320    * element, we advance to its first attribute; if an attr, we advance to
321    * the next attr of the same element.
322    *
323    * @param nodeHandle int Handle of the node.
324    * @return int DTM node-number of the resolved attr,
325    * or DTM.NULL to indicate none exists.
326    */
327   public int getNextAttribute(int nodeHandle);
328 
329   /**
330    * Given a namespace handle, advance to the next namespace in the same scope
331    * (local or local-plus-inherited, as selected by getFirstNamespaceNode)
332    *
333    * @param baseHandle handle to original node from where the first child
334    * was relative to (needed to return nodes in document order).
335    * @param namespaceHandle handle to node which must be of type
336    * NAMESPACE_NODE.
337    * NEEDSDOC @param inScope
338    * @return handle of next namespace,
339    * or DTM.NULL to indicate none exists.
340    */
341   public int getNextNamespaceNode(int baseHandle, int namespaceHandle,
342                                   boolean inScope);
343 
344   /**
345    * Given a node handle, find its parent node.
346    *
347    * @param nodeHandle the id of the node.
348    * @return int Node handle of parent,
349    * or DTM.NULL to indicate none exists.
350    */
351   public int getParent(int nodeHandle);
352 
353   /**
354    * Given a DTM which contains only a single document,
355    * find the Node Handle of the  Document node. Note
356    * that if the DTM is configured so it can contain multiple
357    * documents, this call will return the Document currently
358    * under construction -- but may return null if it's between
359    * documents. Generally, you should use getOwnerDocument(nodeHandle)
360    * or getDocumentRoot(nodeHandle) instead.
361    *
362    * @return int Node handle of document, or DTM.NULL if a shared DTM
363    * can not tell us which Document is currently active.
364    */
365   public int getDocument();
366 
367   /**
368    * Given a node handle, find the owning document node. This version mimics
369    * the behavior of the DOM call by the same name.
370    *
371    * @param nodeHandle the id of the node.
372    * @return int Node handle of owning document, or DTM.NULL if the node was
373    * a Document.
374    * @see #getDocumentRoot(int nodeHandle)
375    */
376   public int getOwnerDocument(int nodeHandle);
377 
378   /**
379    * Given a node handle, find the owning document node.
380    *
381    * @param nodeHandle the id of the node.
382    * @return int Node handle of owning document, or the node itself if it was
383    * a Document. (Note difference from DOM, where getOwnerDocument returns
384    * null for the Document node.)
385    * @see #getOwnerDocument(int nodeHandle)
386    */
387   public int getDocumentRoot(int nodeHandle);
388 
389   /**
390    * Get the string-value of a node as a String object
391    * (see http://www.w3.org/TR/xpath#data-model
392    * for the definition of a node's string-value).
393    *
394    * @param nodeHandle The node ID.
395    *
396    * @return A string object that represents the string-value of the given node.
397    */
398   public XMLString getStringValue(int nodeHandle);
399 
400   /**
401    * Get number of character array chunks in
402    * the string-value of a node.
403    * (see http://www.w3.org/TR/xpath#data-model
404    * for the definition of a node's string-value).
405    * Note that a single text node may have multiple text chunks.
406    *
407    * @param nodeHandle The node ID.
408    *
409    * @return number of character array chunks in
410    *         the string-value of a node.
411    */
412   public int getStringValueChunkCount(int nodeHandle);
413 
414   /**
415    * Get a character array chunk in the string-value of a node.
416    * (see http://www.w3.org/TR/xpath#data-model
417    * for the definition of a node's string-value).
418    * Note that a single text node may have multiple text chunks.
419    *
420    * @param nodeHandle The node ID.
421    * @param chunkIndex Which chunk to get.
422    * @param startAndLen  A two-integer array which, upon return, WILL
423    * BE FILLED with values representing the chunk's start position
424    * within the returned character buffer and the length of the chunk.
425    * @return The character array buffer within which the chunk occurs,
426    * setting startAndLen's contents as a side-effect.
427    */
428   public char[] getStringValueChunk(int nodeHandle, int chunkIndex,
429                                     int[] startAndLen);
430 
431   /**
432    * Given a node handle, return an ID that represents the node's expanded name.
433    *
434    * @param nodeHandle The handle to the node in question.
435    *
436    * @return the expanded-name id of the node.
437    */
438   public int getExpandedTypeID(int nodeHandle);
439 
440   /**
441    * Given an expanded name, return an ID.  If the expanded-name does not
442    * exist in the internal tables, the entry will be created, and the ID will
443    * be returned.  Any additional nodes that are created that have this
444    * expanded name will use this ID.
445    *
446    * NEEDSDOC @param namespace
447    * NEEDSDOC @param localName
448    * NEEDSDOC @param type
449    *
450    * @return the expanded-name id of the node.
451    */
452   public int getExpandedTypeID(String namespace, String localName, int type);
453 
454   /**
455    * Given an expanded-name ID, return the local name part.
456    *
457    * @param ExpandedNameID an ID that represents an expanded-name.
458    * @return String Local name of this node.
459    */
460   public String getLocalNameFromExpandedNameID(int ExpandedNameID);
461 
462   /**
463    * Given an expanded-name ID, return the namespace URI part.
464    *
465    * @param ExpandedNameID an ID that represents an expanded-name.
466    * @return String URI value of this node's namespace, or null if no
467    * namespace was resolved.
468    */
469   public String getNamespaceFromExpandedNameID(int ExpandedNameID);
470 
471   /**
472    * Given a node handle, return its DOM-style node name. This will
473    * include names such as #text or #document.
474    *
475    * @param nodeHandle the id of the node.
476    * @return String Name of this node, which may be an empty string.
477    * %REVIEW% Document when empty string is possible...
478    */
479   public String getNodeName(int nodeHandle);
480 
481   /**
482    * Given a node handle, return the XPath node name.  This should be
483    * the name as described by the XPath data model, NOT the DOM-style
484    * name.
485    *
486    * @param nodeHandle the id of the node.
487    * @return String Name of this node.
488    */
489   public String getNodeNameX(int nodeHandle);
490 
491   /**
492    * Given a node handle, return its DOM-style localname.
493    * (As defined in Namespaces, this is the portion of the name after the
494    * prefix, if present, or the whole node name if no prefix exists)
495    *
496    * @param nodeHandle the id of the node.
497    * @return String Local name of this node.
498    */
499   public String getLocalName(int nodeHandle);
500 
501   /**
502    * Given a namespace handle, return the prefix that the namespace decl is
503    * mapping.
504    * Given a node handle, return the prefix used to map to the namespace.
505    * (As defined in Namespaces, this is the portion of the name before any
506    * colon character).
507    *
508    * <p> %REVIEW% Are you sure you want "" for no prefix?  </p>
509    *
510    * @param nodeHandle the id of the node.
511    * @return String prefix of this node's name, or "" if no explicit
512    * namespace prefix was given.
513    */
514   public String getPrefix(int nodeHandle);
515 
516   /**
517    * Given a node handle, return its DOM-style namespace URI
518    * (As defined in Namespaces, this is the declared URI which this node's
519    * prefix -- or default in lieu thereof -- was mapped to.)
520    * @param nodeHandle the id of the node.
521    * @return String URI value of this node's namespace, or null if no
522    * namespace was resolved.
523    */
524   public String getNamespaceURI(int nodeHandle);
525 
526   /**
527    * Given a node handle, return its node value. This is mostly
528    * as defined by the DOM, but may ignore some conveniences.
529    * <p>
530    * @param nodeHandle The node id.
531    * @return String Value of this node, or null if not
532    * meaningful for this node type.
533    */
534   public String getNodeValue(int nodeHandle);
535 
536   /**
537    * Given a node handle, return its DOM-style node type.
538    *
539    * <p>%REVIEW% Generally, returning short is false economy. Return int?</p>
540    *
541    * @param nodeHandle The node id.
542    * @return int Node type, as per the DOM's Node._NODE constants.
543    */
544   public short getNodeType(int nodeHandle);
545 
546   /**
547    * Get the depth level of this node in the tree (equals 1 for
548    * a parentless node).
549    *
550    * @param nodeHandle The node id.
551    * @return the number of ancestors, plus one
552    * @xsl.usage internal
553    */
554   public short getLevel(int nodeHandle);
555 
556   // ============== Document query functions ==============
557 
558   /**
559    * Tests whether DTM DOM implementation implements a specific feature and
560    * that feature is supported by this node.
561    * @param feature The name of the feature to test.
562    * @param version This is the version number of the feature to test.
563    *   If the version is not
564    *   specified, supporting any version of the feature will cause the
565    *   method to return <code>true</code>.
566    * @return Returns <code>true</code> if the specified feature is
567    *   supported on this node, <code>false</code> otherwise.
568    */
569   public boolean isSupported(String feature, String version);
570 
571   /**
572    * Return the base URI of the document entity. If it is not known
573    * (because the document was parsed from a socket connection or from
574    * standard input, for example), the value of this property is unknown.
575    *
576    * @return the document base URI String object or null if unknown.
577    */
578   public String getDocumentBaseURI();
579 
580   /**
581    * Set the base URI of the document entity.
582    *
583    * @param baseURI the document base URI String object or null if unknown.
584    */
585   public void setDocumentBaseURI(String baseURI);
586 
587   /**
588    * Return the system identifier of the document entity. If
589    * it is not known, the value of this property is null.
590    *
591    * @param nodeHandle The node id, which can be any valid node handle.
592    * @return the system identifier String object or null if unknown.
593    */
594   public String getDocumentSystemIdentifier(int nodeHandle);
595 
596   /**
597    * Return the name of the character encoding scheme
598    *        in which the document entity is expressed.
599    *
600    * @param nodeHandle The node id, which can be any valid node handle.
601    * @return the document encoding String object.
602    */
603   public String getDocumentEncoding(int nodeHandle);
604 
605   /**
606    * Return an indication of the standalone status of the document,
607    *        either "yes" or "no". This property is derived from the optional
608    *        standalone document declaration in the XML declaration at the
609    *        beginning of the document entity, and has no value if there is no
610    *        standalone document declaration.
611    *
612    * @param nodeHandle The node id, which can be any valid node handle.
613    * @return the document standalone String object, either "yes", "no", or null.
614    */
615   public String getDocumentStandalone(int nodeHandle);
616 
617   /**
618    * Return a string representing the XML version of the document. This
619    * property is derived from the XML declaration optionally present at the
620    * beginning of the document entity, and has no value if there is no XML
621    * declaration.
622    *
623    * @param documentHandle the document handle
624    * @return the document version String object
625    */
626   public String getDocumentVersion(int documentHandle);
627 
628   /**
629    * Return an indication of
630    * whether the processor has read the complete DTD. Its value is a
631    * boolean. If it is false, then certain properties (indicated in their
632    * descriptions below) may be unknown. If it is true, those properties
633    * are never unknown.
634    *
635    * @return <code>true</code> if all declarations were processed;
636    *         <code>false</code> otherwise.
637    */
638   public boolean getDocumentAllDeclarationsProcessed();
639 
640   /**
641    *   A document type declaration information item has the following properties:
642    *
643    *     1. [system identifier] The system identifier of the external subset, if
644    *        it exists. Otherwise this property has no value.
645    *
646    * @return the system identifier String object, or null if there is none.
647    */
648   public String getDocumentTypeDeclarationSystemIdentifier();
649 
650   /**
651    * Return the public identifier of the external subset,
652    * normalized as described in 4.2.2 External Entities [XML]. If there is
653    * no external subset or if it has no public identifier, this property
654    * has no value.
655    *
656    * @return the public identifier String object, or null if there is none.
657    */
658   public String getDocumentTypeDeclarationPublicIdentifier();
659 
660   /**
661    * Returns the <code>Element</code> whose <code>ID</code> is given by
662    * <code>elementId</code>. If no such element exists, returns
663    * <code>DTM.NULL</code>. Behavior is not defined if more than one element
664    * has this <code>ID</code>. Attributes (including those
665    * with the name "ID") are not of type ID unless so defined by DTD/Schema
666    * information available to the DTM implementation.
667    * Implementations that do not know whether attributes are of type ID or
668    * not are expected to return <code>DTM.NULL</code>.
669    *
670    * <p>%REVIEW% Presumably IDs are still scoped to a single document,
671    * and this operation searches only within a single document, right?
672    * Wouldn't want collisions between DTMs in the same process.</p>
673    *
674    * @param elementId The unique <code>id</code> value for an element.
675    * @return The handle of the matching element.
676    */
677   public int getElementById(String elementId);
678 
679   /**
680    * The getUnparsedEntityURI function returns the URI of the unparsed
681    * entity with the specified name in the same document as the context
682    * node (see [3.3 Unparsed Entities]). It returns the empty string if
683    * there is no such entity.
684    * <p>
685    * XML processors may choose to use the System Identifier (if one
686    * is provided) to resolve the entity, rather than the URI in the
687    * Public Identifier. The details are dependent on the processor, and
688    * we would have to support some form of plug-in resolver to handle
689    * this properly. Currently, we simply return the System Identifier if
690    * present, and hope that it a usable URI or that our caller can
691    * map it to one.
692    * %REVIEW% Resolve Public Identifiers... or consider changing function name.
693    * <p>
694    * If we find a relative URI
695    * reference, XML expects it to be resolved in terms of the base URI
696    * of the document. The DOM doesn't do that for us, and it isn't
697    * entirely clear whether that should be done here; currently that's
698    * pushed up to a higher level of our application. (Note that DOM Level
699    * 1 didn't store the document's base URI.)
700    * %REVIEW% Consider resolving Relative URIs.
701    * <p>
702    * (The DOM's statement that "An XML processor may choose to
703    * completely expand entities before the structure model is passed
704    * to the DOM" refers only to parsed entities, not unparsed, and hence
705    * doesn't affect this function.)
706    *
707    * @param name A string containing the Entity Name of the unparsed
708    * entity.
709    *
710    * @return String containing the URI of the Unparsed Entity, or an
711    * empty string if no such entity exists.
712    */
713   public String getUnparsedEntityURI(String name);
714 
715   // ============== Boolean methods ================
716 
717   /**
718    * Return true if the xsl:strip-space or xsl:preserve-space was processed
719    * during construction of the document contained in this DTM.
720    *
721    * NEEDSDOC ($objectName$) @return
722    */
723   public boolean supportsPreStripping();
724 
725   /**
726    * Figure out whether nodeHandle2 should be considered as being later
727    * in the document than nodeHandle1, in Document Order as defined
728    * by the XPath model. This may not agree with the ordering defined
729    * by other XML applications.
730    * <p>
731    * There are some cases where ordering isn't defined, and neither are
732    * the results of this function -- though we'll generally return true.
733    * <p>
734    * %REVIEW% Make sure this does the right thing with attribute nodes!!!
735    * <p>
736    * %REVIEW% Consider renaming for clarity. Perhaps isDocumentOrder(a,b)?
737    *
738    * @param firstNodeHandle DOM Node to perform position comparison on.
739    * @param secondNodeHandle DOM Node to perform position comparison on.
740    *
741    * @return false if secondNode comes before firstNode, otherwise return true.
742    * You can think of this as
743    * <code>(firstNode.documentOrderPosition &lt;= secondNode.documentOrderPosition)</code>.
744    */
745   public boolean isNodeAfter(int firstNodeHandle, int secondNodeHandle);
746 
747   /**
748    * 2. [element content whitespace] A boolean indicating whether a
749    * text node represents white space appearing within element content
750    * (see [XML], 2.10 "White Space Handling").  Note that validating
751    * XML processors are required by XML 1.0 to provide this
752    * information... but that DOM Level 2 did not support it, since it
753    * depends on knowledge of the DTD which DOM2 could not guarantee
754    * would be available.
755    * <p>
756    * If there is no declaration for the containing element, an XML
757    * processor must assume that the whitespace could be meaningful and
758    * return false. If no declaration has been read, but the [all
759    * declarations processed] property of the document information item
760    * is false (so there may be an unread declaration), then the value
761    * of this property is indeterminate for white space characters and
762    * should probably be reported as false. It is always false for text
763    * nodes that contain anything other than (or in addition to) white
764    * space.
765    * <p>
766    * Note too that it always returns false for non-Text nodes.
767    * <p>
768    * %REVIEW% Joe wants to rename this isWhitespaceInElementContent() for clarity
769    *
770    * @param nodeHandle the node ID.
771    * @return <code>true</code> if the node definitely represents whitespace in
772    * element content; <code>false</code> otherwise.
773    */
774   public boolean isCharacterElementContentWhitespace(int nodeHandle);
775 
776   /**
777    *    10. [all declarations processed] This property is not strictly speaking
778    *        part of the infoset of the document. Rather it is an indication of
779    *        whether the processor has read the complete DTD. Its value is a
780    *        boolean. If it is false, then certain properties (indicated in their
781    *        descriptions below) may be unknown. If it is true, those properties
782    *        are never unknown.
783    *
784    * @param documentHandle A node handle that must identify a document.
785    * @return <code>true</code> if all declarations were processed;
786    *         <code>false</code> otherwise.
787    */
788   public boolean isDocumentAllDeclarationsProcessed(int documentHandle);
789 
790   /**
791    *     5. [specified] A flag indicating whether this attribute was actually
792    *        specified in the start-tag of its element, or was defaulted from the
793    *        DTD (or schema).
794    *
795    * @param attributeHandle The attribute handle
796    * @return <code>true</code> if the attribute was specified;
797    *         <code>false</code> if it was defaulted or the handle doesn't
798    *            refer to an attribute node.
799    */
800   public boolean isAttributeSpecified(int attributeHandle);
801 
802   // ========== Direct SAX Dispatch, for optimization purposes ========
803 
804   /**
805    * Directly call the
806    * characters method on the passed ContentHandler for the
807    * string-value of the given node (see http://www.w3.org/TR/xpath#data-model
808    * for the definition of a node's string-value). Multiple calls to the
809    * ContentHandler's characters methods may well occur for a single call to
810    * this method.
811    *
812    * @param nodeHandle The node ID.
813    * @param ch A non-null reference to a ContentHandler.
814    * @param normalize true if the content should be normalized according to
815    * the rules for the XPath
816    * <a href="http://www.w3.org/TR/xpath#function-normalize-space">normalize-space</a>
817    * function.
818    *
819    * @throws org.xml.sax.SAXException
820    */
821   public void dispatchCharactersEvents(
822     int nodeHandle, org.xml.sax.ContentHandler ch, boolean normalize)
823       throws org.xml.sax.SAXException;
824 
825   /**
826    * Directly create SAX parser events representing the XML content of
827    * a DTM subtree. This is a "serialize" operation.
828    *
829    * @param nodeHandle The node ID.
830    * @param ch A non-null reference to a ContentHandler.
831    *
832    * @throws org.xml.sax.SAXException
833    */
834   public void dispatchToEvents(int nodeHandle, org.xml.sax.ContentHandler ch)
835     throws org.xml.sax.SAXException;
836 
837   /**
838    * Return an DOM node for the given node.
839    *
840    * @param nodeHandle The node ID.
841    *
842    * @return A node representation of the DTM node.
843    */
844   public org.w3c.dom.Node getNode(int nodeHandle);
845 
846   // ==== Construction methods (may not be supported by some implementations!) =====
847   // %REVIEW% What response occurs if not supported?
848 
849   /**
850    * @return true iff we're building this model incrementally (eg
851    * we're partnered with a CoroutineParser) and thus require that the
852    * transformation and the parse run simultaneously. Guidance to the
853    * DTMManager.
854    */
855   public boolean needsTwoThreads();
856 
857   // %REVIEW% Do these appends make any sense, should we support a
858   // wider set of methods (like the "append" methods in the
859   // current DTMDocumentImpl draft), or should we just support SAX
860   // listener interfaces?  Should it be a separate interface to
861   // make that distinction explicit?
862 
863   /**
864    * Return this DTM's content handler, if it has one.
865    *
866    * @return null if this model doesn't respond to SAX events.
867    */
868   public org.xml.sax.ContentHandler getContentHandler();
869 
870   /**
871    * Return this DTM's lexical handler, if it has one.
872    *
873    * %REVIEW% Should this return null if constrution already done/begun?
874    *
875    * @return null if this model doesn't respond to lexical SAX events.
876    */
877   public org.xml.sax.ext.LexicalHandler getLexicalHandler();
878 
879   /**
880    * Return this DTM's EntityResolver, if it has one.
881    *
882    * @return null if this model doesn't respond to SAX entity ref events.
883    */
884   public org.xml.sax.EntityResolver getEntityResolver();
885 
886   /**
887    * Return this DTM's DTDHandler, if it has one.
888    *
889    * @return null if this model doesn't respond to SAX dtd events.
890    */
891   public org.xml.sax.DTDHandler getDTDHandler();
892 
893   /**
894    * Return this DTM's ErrorHandler, if it has one.
895    *
896    * @return null if this model doesn't respond to SAX error events.
897    */
898   public org.xml.sax.ErrorHandler getErrorHandler();
899 
900   /**
901    * Return this DTM's DeclHandler, if it has one.
902    *
903    * @return null if this model doesn't respond to SAX Decl events.
904    */
905   public org.xml.sax.ext.DeclHandler getDeclHandler();
906 
907   /**
908    * Append a child to "the end of the document". Please note that
909    * the node is always cloned in a base DTM, since our basic behavior
910    * is immutable so nodes can't be removed from their previous
911    * location.
912    *
913    * <p> %REVIEW%  DTM maintains an insertion cursor which
914    * performs a depth-first tree walk as nodes come in, and this operation
915    * is really equivalent to:
916    *    insertionCursor.appendChild(document.importNode(newChild)))
917    * where the insert point is the last element that was appended (or
918    * the last one popped back to by an end-element operation).</p>
919    *
920    * @param newChild Must be a valid new node handle.
921    * @param clone true if the child should be cloned into the document.
922    * @param cloneDepth if the clone argument is true, specifies that the
923    *                   clone should include all it's children.
924    */
925   public void appendChild(int newChild, boolean clone, boolean cloneDepth);
926 
927   /**
928    * Append a text node child that will be constructed from a string,
929    * to the end of the document. Behavior is otherwise like appendChild().
930    *
931    * @param str Non-null reference to a string.
932    */
933   public void appendTextChild(String str);
934 
935   /**
936    * Get the location of a node in the source document.
937    *
938    * @param node an <code>int</code> value
939    * @return a <code>SourceLocator</code> value or null if no location
940    * is available
941    */
942   public SourceLocator getSourceLocatorFor(int node);
943 
944   /**
945    * As the DTM is registered with the DTMManager, this method
946    * will be called. This will give the DTM implementation a
947    * chance to initialize any subsystems that are required to
948    * build the DTM
949    */
950   public void documentRegistration();
951 
952   /**
953    * As documents are released from the DTMManager, the DTM implementation
954    * will be notified of the event. This will allow the DTM implementation
955    * to shutdown any subsystem activity that may of been assoiated with
956    * the active DTM Implementation.
957    */
958 
959    public void documentRelease();
960 
961    /**
962     * Migrate a DTM built with an old DTMManager to a new DTMManager.
963     * After the migration, the new DTMManager will treat the DTM as
964     * one that is built by itself.
965     * This is used to support DTM sharing between multiple transformations.
966     * @param manager the DTMManager
967     */
968    public void migrateTo(DTMManager manager);
969 }