286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 1999-2004 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A/*
286N/A * $Id: DTMIterator.java,v 1.2.4.1 2005/09/15 08:14:54 suresh_emailid Exp $
286N/A */
286N/Apackage com.sun.org.apache.xml.internal.dtm;
286N/A
286N/A/**
286N/A
286N/A * <code>DTMIterators</code> are used to step through a (possibly
286N/A * filtered) set of nodes. Their API is modeled largely after the DOM
286N/A * NodeIterator.
286N/A *
286N/A * <p>A DTMIterator is a somewhat unusual type of iterator, in that it
286N/A * can serve both single node iteration and random access.</p>
286N/A *
286N/A * <p>The DTMIterator's traversal semantics, i.e. how it walks the tree,
286N/A * are specified when it is created, possibly and probably by an XPath
286N/A * <a href="http://www.w3.org/TR/xpath#NT-LocationPath>LocationPath</a> or
286N/A * a <a href="http://www.w3.org/TR/xpath#NT-UnionExpr">UnionExpr</a>.</p>
286N/A *
286N/A * <p>A DTMIterator is meant to be created once as a master static object, and
286N/A * then cloned many times for runtime use. Or the master object itself may
286N/A * be used for simpler use cases.</p>
286N/A *
286N/A * <p>At this time, we do not expect DTMIterator to emulate
286N/A * NodeIterator's "maintain relative position" semantics under
286N/A * document mutation. It's likely to respond more like the
286N/A * TreeWalker's "current node" semantics. However, since the base DTM
286N/A * is immutable, this issue currently makes no practical
286N/A * difference.</p>
286N/A *
286N/A * <p>State: In progress!!</p> */
286N/Apublic interface DTMIterator
286N/A{
286N/A
286N/A // Constants returned by acceptNode, borrowed from the DOM Traversal chapter
286N/A // %REVIEW% Should we explicitly initialize them from, eg,
286N/A // org.w3c.dom.traversal.NodeFilter.FILTER_ACCEPT?
286N/A
286N/A /**
286N/A * Accept the node.
286N/A */
286N/A public static final short FILTER_ACCEPT = 1;
286N/A
286N/A /**
286N/A * Reject the node. Same behavior as FILTER_SKIP. (In the DOM these
286N/A * differ when applied to a TreeWalker but have the same result when
286N/A * applied to a NodeIterator).
286N/A */
286N/A public static final short FILTER_REJECT = 2;
286N/A
286N/A /**
286N/A * Skip this single node.
286N/A */
286N/A public static final short FILTER_SKIP = 3;
286N/A
286N/A /**
286N/A * Get an instance of a DTM that "owns" a node handle. Since a node
286N/A * iterator may be passed without a DTMManager, this allows the
286N/A * caller to easily get the DTM using just the iterator.
286N/A *
286N/A * @param nodeHandle the nodeHandle.
286N/A *
286N/A * @return a non-null DTM reference.
286N/A */
286N/A public DTM getDTM(int nodeHandle);
286N/A
286N/A /**
286N/A * Get an instance of the DTMManager. Since a node
286N/A * iterator may be passed without a DTMManager, this allows the
286N/A * caller to easily get the DTMManager using just the iterator.
286N/A *
286N/A * @return a non-null DTMManager reference.
286N/A */
286N/A public DTMManager getDTMManager();
286N/A
286N/A /**
286N/A * The root node of the <code>DTMIterator</code>, as specified when it
286N/A * was created. Note the root node is not the root node of the
286N/A * document tree, but the context node from where the iteration
286N/A * begins and ends.
286N/A *
286N/A * @return nodeHandle int Handle of the context node.
286N/A */
286N/A public int getRoot();
286N/A
286N/A /**
286N/A * Reset the root node of the <code>DTMIterator</code>, overriding
286N/A * the value specified when it was created. Note the root node is
286N/A * not the root node of the document tree, but the context node from
286N/A * where the iteration begins.
286N/A *
286N/A * @param nodeHandle int Handle of the context node.
286N/A * @param environment The environment object.
286N/A * The environment in which this iterator operates, which should provide:
286N/A * <ul>
286N/A * <li>a node (the context node... same value as "root" defined below) </li>
286N/A * <li>a pair of non-zero positive integers (the context position and the context size) </li>
286N/A * <li>a set of variable bindings </li>
286N/A * <li>a function library </li>
286N/A * <li>the set of namespace declarations in scope for the expression.</li>
286N/A * <ul>
286N/A *
286N/A * <p>At this time the exact implementation of this environment is application
286N/A * dependent. Probably a proper interface will be created fairly soon.</p>
286N/A *
286N/A */
286N/A public void setRoot(int nodeHandle, Object environment);
286N/A
286N/A /**
286N/A * Reset the iterator to the start. After resetting, the next node returned
286N/A * will be the root node -- or, if that's filtered out, the first node
286N/A * within the root's subtree which is _not_ skipped by the filters.
286N/A */
286N/A public void reset();
286N/A
286N/A /**
286N/A * This attribute determines which node types are presented via the
286N/A * iterator. The available set of constants is defined above.
286N/A * Nodes not accepted by
286N/A * <code>whatToShow</code> will be skipped, but their children may still
286N/A * be considered.
286N/A *
286N/A * @return one of the SHOW_XXX constants, or several ORed together.
286N/A */
286N/A public int getWhatToShow();
286N/A
286N/A /**
286N/A * <p>The value of this flag determines whether the children of entity
286N/A * reference nodes are visible to the iterator. If false, they and
286N/A * their descendants will be rejected. Note that this rejection takes
286N/A * precedence over <code>whatToShow</code> and the filter. </p>
286N/A *
286N/A * <p> To produce a view of the document that has entity references
286N/A * expanded and does not expose the entity reference node itself, use
286N/A * the <code>whatToShow</code> flags to hide the entity reference node
286N/A * and set <code>expandEntityReferences</code> to true when creating the
286N/A * iterator. To produce a view of the document that has entity reference
286N/A * nodes but no entity expansion, use the <code>whatToShow</code> flags
286N/A * to show the entity reference node and set
286N/A * <code>expandEntityReferences</code> to false.</p>
286N/A *
286N/A * <p>NOTE: In Xalan's use of DTM we will generally have fully expanded
286N/A * entity references when the document tree was built, and thus this
286N/A * flag will have no effect.</p>
286N/A *
286N/A * @return true if entity references will be expanded. */
286N/A public boolean getExpandEntityReferences();
286N/A
286N/A /**
286N/A * Returns the next node in the set and advances the position of the
286N/A * iterator in the set. After a <code>DTMIterator</code> has setRoot called,
286N/A * the first call to <code>nextNode()</code> returns that root or (if it
286N/A * is rejected by the filters) the first node within its subtree which is
286N/A * not filtered out.
286N/A * @return The next node handle in the set being iterated over, or
286N/A * <code>DTM.NULL</code> if there are no more members in that set.
286N/A */
286N/A public int nextNode();
286N/A
286N/A /**
286N/A * Returns the previous node in the set and moves the position of the
286N/A * <code>DTMIterator</code> backwards in the set.
286N/A * @return The previous node handle in the set being iterated over,
286N/A * or <code>DTM.NULL</code> if there are no more members in that set.
286N/A */
286N/A public int previousNode();
286N/A
286N/A /**
286N/A * Detaches the <code>DTMIterator</code> from the set which it iterated
286N/A * over, releasing any computational resources and placing the iterator
286N/A * in the INVALID state. After <code>detach</code> has been invoked,
286N/A * calls to <code>nextNode</code> or <code>previousNode</code> will
286N/A * raise a runtime exception.
286N/A */
286N/A public void detach();
286N/A
286N/A /**
286N/A * Specify if it's OK for detach to release the iterator for reuse.
286N/A *
286N/A * @param allowRelease true if it is OK for detach to release this iterator
286N/A * for pooling.
286N/A */
286N/A public void allowDetachToRelease(boolean allowRelease);
286N/A
286N/A /**
286N/A * Get the current node in the iterator. Note that this differs from
286N/A * the DOM's NodeIterator, where the current position lies between two
286N/A * nodes (as part of the maintain-relative-position semantic).
286N/A *
286N/A * @return The current node handle, or -1.
286N/A */
286N/A public int getCurrentNode();
286N/A
286N/A /**
286N/A * Tells if this NodeSetDTM is "fresh", in other words, if
286N/A * the first nextNode() that is called will return the
286N/A * first node in the set.
286N/A *
286N/A * @return true if the iteration of this list has not yet begun.
286N/A */
286N/A public boolean isFresh();
286N/A
286N/A //========= Random Access ==========
286N/A
286N/A /**
286N/A * If setShouldCacheNodes(true) is called, then nodes will
286N/A * be cached, enabling random access, and giving the ability to do
286N/A * sorts and the like. They are not cached by default.
286N/A *
286N/A * %REVIEW% Shouldn't the other random-access methods throw an exception
286N/A * if they're called on a DTMIterator with this flag set false?
286N/A *
286N/A * @param b true if the nodes should be cached.
286N/A */
286N/A public void setShouldCacheNodes(boolean b);
286N/A
286N/A /**
286N/A * Tells if this iterator can have nodes added to it or set via
286N/A * the <code>setItem(int node, int index)</code> method.
286N/A *
286N/A * @return True if the nodelist can be mutated.
286N/A */
286N/A public boolean isMutable();
286N/A
286N/A /** Get the current position within the cached list, which is one
286N/A * less than the next nextNode() call will retrieve. i.e. if you
286N/A * call getCurrentPos() and the return is 0, the next fetch will
286N/A * take place at index 1.
286N/A *
286N/A * @return The position of the iteration.
286N/A */
286N/A public int getCurrentPos();
286N/A
286N/A /**
286N/A * If an index is requested, NodeSetDTM will call this method
286N/A * to run the iterator to the index. By default this sets
286N/A * m_next to the index. If the index argument is -1, this
286N/A * signals that the iterator should be run to the end and
286N/A * completely fill the cache.
286N/A *
286N/A * @param index The index to run to, or -1 if the iterator should be run
286N/A * to the end.
286N/A */
286N/A public void runTo(int index);
286N/A
286N/A /**
286N/A * Set the current position in the node set.
286N/A *
286N/A * @param i Must be a valid index.
286N/A */
286N/A public void setCurrentPos(int i);
286N/A
286N/A /**
286N/A * Returns the <code>node handle</code> of an item in the collection. If
286N/A * <code>index</code> is greater than or equal to the number of nodes in
286N/A * the list, this returns <code>null</code>.
286N/A *
286N/A * @param index of the item.
286N/A * @return The node handle at the <code>index</code>th position in the
286N/A * <code>DTMIterator</code>, or <code>-1</code> if that is not a valid
286N/A * index.
286N/A */
286N/A public int item(int index);
286N/A
286N/A /**
286N/A * Sets the node at the specified index of this vector to be the
286N/A * specified node. The previous component at that position is discarded.
286N/A *
286N/A * <p>The index must be a value greater than or equal to 0 and less
286N/A * than the current size of the vector.
286N/A * The iterator must be in cached mode.</p>
286N/A *
286N/A * <p>Meant to be used for sorted iterators.</p>
286N/A *
286N/A * @param node Node to set
286N/A * @param index Index of where to set the node
286N/A */
286N/A public void setItem(int node, int index);
286N/A
286N/A /**
286N/A * The number of nodes in the list. The range of valid child node indices
286N/A * is 0 to <code>length-1</code> inclusive. Note that this requires running
286N/A * the iterator to completion, and presumably filling the cache.
286N/A *
286N/A * @return The number of nodes in the list.
286N/A */
286N/A public int getLength();
286N/A
286N/A //=========== Cloning operations. ============
286N/A
286N/A /**
286N/A * Get a cloned Iterator that is reset to the start of the iteration.
286N/A *
286N/A * @return A clone of this iteration that has been reset.
286N/A *
286N/A * @throws CloneNotSupportedException
286N/A */
286N/A public DTMIterator cloneWithReset() throws CloneNotSupportedException;
286N/A
286N/A /**
286N/A * Get a clone of this iterator, but don't reset the iteration in the
286N/A * process, so that it may be used from the current position.
286N/A *
286N/A * @return A clone of this object.
286N/A *
286N/A * @throws CloneNotSupportedException
286N/A */
286N/A public Object clone() throws CloneNotSupportedException;
286N/A
286N/A /**
286N/A * Returns true if all the nodes in the iteration well be returned in document
286N/A * order.
286N/A *
286N/A * @return true if all the nodes in the iteration well be returned in document
286N/A * order.
286N/A */
286N/A public boolean isDocOrdered();
286N/A
286N/A /**
286N/A * Returns the axis being iterated, if it is known.
286N/A *
286N/A * @return Axis.CHILD, etc., or -1 if the axis is not known or is of multiple
286N/A * types.
286N/A */
286N/A public int getAxis();
286N/A
286N/A}