|
Java example source code file (DTMIterator.java)
The DTMIterator.java Java example source code/* * reserved comment block * DO NOT REMOVE OR ALTER! */ /* * Copyright 1999-2004 The Apache Software Foundation. * * Licensed 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,v 1.2.4.1 2005/09/15 08:14:54 suresh_emailid Exp $ */ package com.sun.org.apache.xml.internal.dtm; /** * <code>DTMIterators are used to step through a (possibly * filtered) set of nodes. Their API is modeled largely after the DOM * NodeIterator. * * <p>A DTMIterator is a somewhat unusual type of iterator, in that it * can serve both single node iteration and random access.</p> * * <p>The DTMIterator's traversal semantics, i.e. how it walks the tree, * are specified when it is created, possibly and probably by an XPath * <a href="http://www.w3.org/TR/xpath#NT-LocationPath>LocationPath or * a <a href="http://www.w3.org/TR/xpath#NT-UnionExpr">UnionExpr. * * <p>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.</p> * * <p>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.</p> * * <p>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 <code>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 <code>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: * <ul> * <li>a node (the context node... same value as "root" defined below) * <li>a pair of non-zero positive integers (the context position and the context size) * <li>a set of variable bindings * <li>a function library * <li>the set of namespace declarations in scope for the expression. * <ul> * * <p>At this time the exact implementation of this environment is application * dependent. Probably a proper interface will be created fairly soon.</p> * */ public void setRoot(int nodeHandle, Object environment); /** * Reset the iterator to the start. After resetting, the next node returned * will be the root node -- or, if that's filtered out, the first node * within the root's subtree which is _not_ skipped by the filters. */ public void reset(); /** * This attribute determines which node types are presented via the * iterator. The available set of constants is defined above. * Nodes not accepted by * <code>whatToShow will be skipped, but their children may still * be considered. * * @return one of the SHOW_XXX constants, or several ORed together. */ public int getWhatToShow(); /** * <p>The value of this flag determines whether the children of entity * reference nodes are visible to the iterator. If false, they and * their descendants will be rejected. Note that this rejection takes * precedence over <code>whatToShow and the filter. * * <p> To produce a view of the document that has entity references * expanded and does not expose the entity reference node itself, use * the <code>whatToShow flags to hide the entity reference node * and set <code>expandEntityReferences to true when creating the * iterator. To produce a view of the document that has entity reference * nodes but no entity expansion, use the <code>whatToShow flags * to show the entity reference node and set * <code>expandEntityReferences to false. * * <p>NOTE: In Xalan's use of DTM we will generally have fully expanded * entity references when the document tree was built, and thus this * flag will have no effect.</p> * * @return true if entity references will be expanded. */ public boolean getExpandEntityReferences(); /** * Returns the next node in the set and advances the position of the * iterator in the set. After a <code>DTMIterator has setRoot called, * the first call to <code>nextNode() returns that root or (if it * is rejected by the filters) the first node within its subtree which is * not filtered out. * @return The next node handle in the set being iterated over, or * <code>DTM.NULL if there are no more members in that set. */ public int nextNode(); /** * Returns the previous node in the set and moves the position of the * <code>DTMIterator backwards in the set. * @return The previous node handle in the set being iterated over, * or <code>DTM.NULL if there are no more members in that set. */ public int previousNode(); /** * Detaches the <code>DTMIterator from the set which it iterated * over, releasing any computational resources and placing the iterator * in the INVALID state. After <code>detach has been invoked, * calls to <code>nextNode or Other Java examples (source code examples)Here is a short list of links related to this Java DTMIterator.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.