KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xml > dtm > DTMAxisTraverser


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: DTMAxisTraverser.java,v 1.4 2004/02/16 23:03:44 minchau Exp $
18  */

19 package org.apache.xml.dtm;
20
21 /**
22  * A class that implements traverses DTMAxisTraverser interface can traverse
23  * a set of nodes, usually as defined by an XPath axis. It is different from
24  * an iterator, because it does not need to hold state, and, in fact, must not
25  * hold any iteration-based state. It is meant to be implemented as an inner
26  * class of a DTM, and returned by the getAxisTraverser(final int axis)
27  * function.
28  *
29  * <p>A DTMAxisTraverser can probably not traverse a reverse axis in
30  * document order.</p>
31  *
32  * <p>Typical usage:</p>
33  * <pre><code>
34  * for(int nodeHandle=myTraverser.first(myContext);
35  * nodeHandle!=DTM.NULL;
36  * nodeHandle=myTraverser.next(myContext,nodeHandle))
37  * { ... processing for node indicated by nodeHandle goes here ... }
38  * </code></pre>
39  *
40  * @author Scott Boag
41  */

42 public abstract class DTMAxisTraverser
43 {
44
45   /**
46    * By the nature of the stateless traversal, the context node can not be
47    * returned or the iteration will go into an infinate loop. So to traverse
48    * an axis, the first function must be used to get the first node.
49    *
50    * <p>This method needs to be overloaded only by those axis that process
51    * the self node. <\p>
52    *
53    * @param context The context node of this traversal. This is the point
54    * that the traversal starts from.
55    * @return the first node in the traversal.
56    */

57   public int first(int context)
58   {
59     return next(context, context);
60   }
61
62   /**
63    * By the nature of the stateless traversal, the context node can not be
64    * returned or the iteration will go into an infinate loop. So to traverse
65    * an axis, the first function must be used to get the first node.
66    *
67    * <p>This method needs to be overloaded only by those axis that process
68    * the self node. <\p>
69    *
70    * @param context The context node of this traversal. This is the point
71    * of origin for the traversal -- its "root node" or starting point.
72    * @param extendedTypeID The extended type ID that must match.
73    *
74    * @return the first node in the traversal.
75    */

76   public int first(int context, int extendedTypeID)
77   {
78     return next(context, context, extendedTypeID);
79   }
80
81   /**
82    * Traverse to the next node after the current node.
83    *
84    * @param context The context node of this traversal. This is the point
85    * of origin for the traversal -- its "root node" or starting point.
86    * @param current The current node of the traversal. This is the last known
87    * location in the traversal, typically the node-handle returned by the
88    * previous traversal step. For the first traversal step, context
89    * should be set equal to current. Note that in order to test whether
90    * context is in the set, you must use the first() method instead.
91    *
92    * @return the next node in the iteration, or DTM.NULL.
93    * @see first(int)
94    */

95   public abstract int next(int context, int current);
96
97   /**
98    * Traverse to the next node after the current node that is matched
99    * by the extended type ID.
100    *
101    * @param context The context node of this traversal. This is the point
102    * of origin for the traversal -- its "root node" or starting point.
103    * @param current The current node of the traversal. This is the last known
104    * location in the traversal, typically the node-handle returned by the
105    * previous traversal step. For the first traversal step, context
106    * should be set equal to current. Note that in order to test whether
107    * context is in the set, you must use the first() method instead.
108    * @param extendedTypeID The extended type ID that must match.
109    *
110    * @return the next node in the iteration, or DTM.NULL.
111    * @see first(int,int)
112    */

113   public abstract int next(int context, int current, int extendedTypeID);
114 }
115
Popular Tags