19f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/* 29f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one 39f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or more contributor license agreements. See the NOTICE file 49f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed with this work for additional information 59f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * regarding copyright ownership. The ASF licenses this file 69f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to you under the Apache License, Version 2.0 (the "License"); 79f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * you may not use this file except in compliance with the License. 89f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * You may obtain a copy of the License at 99f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Unless required by applicable law or agreed to in writing, software 139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS, 149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * See the License for the specific language governing permissions and 169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * limitations under the License. 179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/* 199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * $Id: DTMIterator.java 468653 2006-10-28 07:07:05Z minchau $ 209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpackage org.apache.xml.dtm; 229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/** 249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>DTMIterators</code> are used to step through a (possibly 269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * filtered) set of nodes. Their API is modeled largely after the DOM 279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * NodeIterator. 289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>A DTMIterator is a somewhat unusual type of iterator, in that it 309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * can serve both single node iteration and random access.</p> 319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>The DTMIterator's traversal semantics, i.e. how it walks the tree, 339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * are specified when it is created, possibly and probably by an XPath 349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <a href="http://www.w3.org/TR/xpath#NT-LocationPath>LocationPath</a> or 359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * a <a href="http://www.w3.org/TR/xpath#NT-UnionExpr">UnionExpr</a>.</p> 369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>A DTMIterator is meant to be created once as a master static object, and 389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * then cloned many times for runtime use. Or the master object itself may 399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * be used for simpler use cases.</p> 409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>At this time, we do not expect DTMIterator to emulate 429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * NodeIterator's "maintain relative position" semantics under 439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * document mutation. It's likely to respond more like the 449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * TreeWalker's "current node" semantics. However, since the base DTM 459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * is immutable, this issue currently makes no practical 469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * difference.</p> 479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>State: In progress!!</p> */ 499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpublic interface DTMIterator 509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson{ 519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Constants returned by acceptNode, borrowed from the DOM Traversal chapter 539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // %REVIEW% Should we explicitly initialize them from, eg, 549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // org.w3c.dom.traversal.NodeFilter.FILTER_ACCEPT? 559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Accept the node. 589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public static final short FILTER_ACCEPT = 1; 609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Reject the node. Same behavior as FILTER_SKIP. (In the DOM these 639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * differ when applied to a TreeWalker but have the same result when 649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * applied to a NodeIterator). 659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public static final short FILTER_REJECT = 2; 679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Skip this single node. 709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public static final short FILTER_SKIP = 3; 729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get an instance of a DTM that "owns" a node handle. Since a node 759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * iterator may be passed without a DTMManager, this allows the 769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * caller to easily get the DTM using just the iterator. 779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param nodeHandle the nodeHandle. 799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return a non-null DTM reference. 819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public DTM getDTM(int nodeHandle); 839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get an instance of the DTMManager. Since a node 869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * iterator may be passed without a DTMManager, this allows the 879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * caller to easily get the DTMManager using just the iterator. 889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return a non-null DTMManager reference. 909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public DTMManager getDTMManager(); 929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The root node of the <code>DTMIterator</code>, as specified when it 959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * was created. Note the root node is not the root node of the 969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * document tree, but the context node from where the iteration 979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * begins and ends. 989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return nodeHandle int Handle of the context node. 1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int getRoot(); 1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Reset the root node of the <code>DTMIterator</code>, overriding 1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the value specified when it was created. Note the root node is 1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * not the root node of the document tree, but the context node from 1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * where the iteration begins. 1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param nodeHandle int Handle of the context node. 1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param environment The environment object. 1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The environment in which this iterator operates, which should provide: 1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <ul> 1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <li>a node (the context node... same value as "root" defined below) </li> 1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <li>a pair of non-zero positive integers (the context position and the context size) </li> 1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <li>a set of variable bindings </li> 1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <li>a function library </li> 1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <li>the set of namespace declarations in scope for the expression.</li> 1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <ul> 1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>At this time the exact implementation of this environment is application 1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * dependent. Probably a proper interface will be created fairly soon.</p> 1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void setRoot(int nodeHandle, Object environment); 1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Reset the iterator to the start. After resetting, the next node returned 1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * will be the root node -- or, if that's filtered out, the first node 1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * within the root's subtree which is _not_ skipped by the filters. 1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void reset(); 1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This attribute determines which node types are presented via the 1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * iterator. The available set of constants is defined above. 1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Nodes not accepted by 1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>whatToShow</code> will be skipped, but their children may still 1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * be considered. 1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return one of the SHOW_XXX constants, or several ORed together. 1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int getWhatToShow(); 1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>The value of this flag determines whether the children of entity 1469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * reference nodes are visible to the iterator. If false, they and 1479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * their descendants will be rejected. Note that this rejection takes 1489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * precedence over <code>whatToShow</code> and the filter. </p> 1499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p> To produce a view of the document that has entity references 1519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * expanded and does not expose the entity reference node itself, use 1529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the <code>whatToShow</code> flags to hide the entity reference node 1539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * and set <code>expandEntityReferences</code> to true when creating the 1549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * iterator. To produce a view of the document that has entity reference 1559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * nodes but no entity expansion, use the <code>whatToShow</code> flags 1569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to show the entity reference node and set 1579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>expandEntityReferences</code> to false.</p> 1589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>NOTE: In Xalan's use of DTM we will generally have fully expanded 1609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * entity references when the document tree was built, and thus this 1619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * flag will have no effect.</p> 1629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return true if entity references will be expanded. */ 1649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean getExpandEntityReferences(); 1659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Returns the next node in the set and advances the position of the 1689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * iterator in the set. After a <code>DTMIterator</code> has setRoot called, 1699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the first call to <code>nextNode()</code> returns that root or (if it 1709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * is rejected by the filters) the first node within its subtree which is 1719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * not filtered out. 1729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The next node handle in the set being iterated over, or 1739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>DTM.NULL</code> if there are no more members in that set. 1749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int nextNode(); 1769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Returns the previous node in the set and moves the position of the 1799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>DTMIterator</code> backwards in the set. 1809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The previous node handle in the set being iterated over, 1819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or <code>DTM.NULL</code> if there are no more members in that set. 1829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int previousNode(); 1849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Detaches the <code>DTMIterator</code> from the set which it iterated 1879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * over, releasing any computational resources and placing the iterator 1889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * in the INVALID state. After <code>detach</code> has been invoked, 1899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * calls to <code>nextNode</code> or <code>previousNode</code> will 1909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * raise a runtime exception. 1919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void detach(); 1939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Specify if it's OK for detach to release the iterator for reuse. 1969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param allowRelease true if it is OK for detach to release this iterator 1989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * for pooling. 1999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void allowDetachToRelease(boolean allowRelease); 2019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get the current node in the iterator. Note that this differs from 2049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the DOM's NodeIterator, where the current position lies between two 2059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * nodes (as part of the maintain-relative-position semantic). 2069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The current node handle, or -1. 2089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int getCurrentNode(); 2109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Tells if this NodeSetDTM is "fresh", in other words, if 2139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the first nextNode() that is called will return the 2149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * first node in the set. 2159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return true if the iteration of this list has not yet begun. 2179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean isFresh(); 2199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //========= Random Access ========== 2219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * If setShouldCacheNodes(true) is called, then nodes will 2249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * be cached, enabling random access, and giving the ability to do 2259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * sorts and the like. They are not cached by default. 2269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * %REVIEW% Shouldn't the other random-access methods throw an exception 2289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * if they're called on a DTMIterator with this flag set false? 2299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param b true if the nodes should be cached. 2319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void setShouldCacheNodes(boolean b); 2339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Tells if this iterator can have nodes added to it or set via 2369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the <code>setItem(int node, int index)</code> method. 2379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return True if the nodelist can be mutated. 2399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean isMutable(); 2419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** Get the current position within the cached list, which is one 2439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * less than the next nextNode() call will retrieve. i.e. if you 2449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * call getCurrentPos() and the return is 0, the next fetch will 2459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * take place at index 1. 2469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The position of the iteration. 2489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int getCurrentPos(); 2509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * If an index is requested, NodeSetDTM will call this method 2539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to run the iterator to the index. By default this sets 2549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * m_next to the index. If the index argument is -1, this 2559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * signals that the iterator should be run to the end and 2569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * completely fill the cache. 2579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param index The index to run to, or -1 if the iterator should be run 2599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to the end. 2609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void runTo(int index); 2629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Set the current position in the node set. 2659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param i Must be a valid index. 2679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void setCurrentPos(int i); 2699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Returns the <code>node handle</code> of an item in the collection. If 2729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>index</code> is greater than or equal to the number of nodes in 2739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the list, this returns <code>null</code>. 2749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param index of the item. 2769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The node handle at the <code>index</code>th position in the 2779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>DTMIterator</code>, or <code>-1</code> if that is not a valid 2789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * index. 2799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int item(int index); 2819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Sets the node at the specified index of this vector to be the 2849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * specified node. The previous component at that position is discarded. 2859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>The index must be a value greater than or equal to 0 and less 2879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * than the current size of the vector. 2889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The iterator must be in cached mode.</p> 2899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>Meant to be used for sorted iterators.</p> 2919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param node Node to set 2939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param index Index of where to set the node 2949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void setItem(int node, int index); 2969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The number of nodes in the list. The range of valid child node indices 2999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * is 0 to <code>length-1</code> inclusive. Note that this requires running 3009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the iterator to completion, and presumably filling the cache. 3019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The number of nodes in the list. 3039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int getLength(); 3059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //=========== Cloning operations. ============ 3079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get a cloned Iterator that is reset to the start of the iteration. 3109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return A clone of this iteration that has been reset. 3129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws CloneNotSupportedException 3149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public DTMIterator cloneWithReset() throws CloneNotSupportedException; 3169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Get a clone of this iterator, but don't reset the iteration in the 3199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * process, so that it may be used from the current position. 3209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return A clone of this object. 3229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @throws CloneNotSupportedException 3249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Object clone() throws CloneNotSupportedException; 3269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Returns true if all the nodes in the iteration well be returned in document 3299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * order. 3309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return true if all the nodes in the iteration well be returned in document 3329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * order. 3339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean isDocOrdered(); 3359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Returns the axis being iterated, if it is known. 3389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return Axis.CHILD, etc., or -1 if the axis is not known or is of multiple 3409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * types. 3419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int getAxis(); 3439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson} 345