/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* * $Id: DTMIterator.java 468653 2006-10-28 07:07:05Z minchau $ */ package org.apache.xml.dtm; /** * DTMIterators are used to step through a (possibly * filtered) set of nodes. Their API is modeled largely after the DOM * NodeIterator. * *

A DTMIterator is a somewhat unusual type of iterator, in that it * can serve both single node iteration and random access.

* *

The DTMIterator's traversal semantics, i.e. how it walks the tree, * are specified when it is created, possibly and probably by an XPath * UnionExpr.

* *

A DTMIterator is meant to be created once as a master static object, and * then cloned many times for runtime use. Or the master object itself may * be used for simpler use cases.

* *

At this time, we do not expect DTMIterator to emulate * NodeIterator's "maintain relative position" semantics under * document mutation. It's likely to respond more like the * TreeWalker's "current node" semantics. However, since the base DTM * is immutable, this issue currently makes no practical * difference.

* *

State: In progress!!

*/ public interface DTMIterator { // Constants returned by acceptNode, borrowed from the DOM Traversal chapter // %REVIEW% Should we explicitly initialize them from, eg, // org.w3c.dom.traversal.NodeFilter.FILTER_ACCEPT? /** * Accept the node. */ public static final short FILTER_ACCEPT = 1; /** * Reject the node. Same behavior as FILTER_SKIP. (In the DOM these * differ when applied to a TreeWalker but have the same result when * applied to a NodeIterator). */ public static final short FILTER_REJECT = 2; /** * Skip this single node. */ public static final short FILTER_SKIP = 3; /** * Get an instance of a DTM that "owns" a node handle. Since a node * iterator may be passed without a DTMManager, this allows the * caller to easily get the DTM using just the iterator. * * @param nodeHandle the nodeHandle. * * @return a non-null DTM reference. */ public DTM getDTM(int nodeHandle); /** * Get an instance of the DTMManager. Since a node * iterator may be passed without a DTMManager, this allows the * caller to easily get the DTMManager using just the iterator. * * @return a non-null DTMManager reference. */ public DTMManager getDTMManager(); /** * The root node of the DTMIterator, as specified when it * was created. Note the root node is not the root node of the * document tree, but the context node from where the iteration * begins and ends. * * @return nodeHandle int Handle of the context node. */ public int getRoot(); /** * Reset the root node of the DTMIterator, overriding * the value specified when it was created. Note the root node is * not the root node of the document tree, but the context node from * where the iteration begins. * * @param nodeHandle int Handle of the context node. * @param environment The environment object. * The environment in which this iterator operates, which should provide: *