KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xpath > axes > ChildIterator


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: ChildIterator.java,v 1.15 2004/02/17 04:32:08 minchau Exp $
18  */

19 package org.apache.xpath.axes;
20
21 import org.apache.xml.dtm.DTM;
22 import org.apache.xpath.XPathContext;
23 import org.apache.xpath.compiler.Compiler;
24
25 /**
26  * This class implements an optimized iterator for
27  * "node()" patterns, that is, any children of the
28  * context node.
29  * @see org.apache.xpath.axes.LocPathIterator
30  * @xsl.usage advanced
31  */

32 public class ChildIterator extends LocPathIterator
33 {
34
35   /**
36    * Create a ChildIterator object.
37    *
38    * @param compiler A reference to the Compiler that contains the op map.
39    * @param opPos The position within the op map, which contains the
40    * location path expression for this itterator.
41    * @param analysis Analysis bits of the entire pattern.
42    *
43    * @throws javax.xml.transform.TransformerException
44    */

45   ChildIterator(Compiler JavaDoc compiler, int opPos, int analysis)
46           throws javax.xml.transform.TransformerException JavaDoc
47   {
48     super(compiler, opPos, analysis, false);
49   }
50   
51   /**
52    * Return the first node out of the nodeset, if this expression is
53    * a nodeset expression. This is the default implementation for
54    * nodesets.
55    * <p>WARNING: Do not mutate this class from this function!</p>
56    * @param xctxt The XPath runtime context.
57    * @return the first node out of the nodeset, or DTM.NULL.
58    */

59   public int asNode(XPathContext xctxt)
60     throws javax.xml.transform.TransformerException JavaDoc
61   {
62     int current = xctxt.getCurrentNode();
63     
64     DTM dtm = xctxt.getDTM(current);
65     
66     return dtm.getFirstChild(current);
67   }
68
69   /**
70    * Returns the next node in the set and advances the position of the
71    * iterator in the set. After a NodeIterator is created, the first call
72    * to nextNode() returns the first node in the set.
73    *
74    * @return The next <code>Node</code> in the set being iterated over, or
75    * <code>null</code> if there are no more members in that set.
76    */

77   public int nextNode()
78   {
79     if(m_foundLast)
80         return DTM.NULL;
81
82     int next;
83
84     m_lastFetched = next = (DTM.NULL == m_lastFetched)
85                            ? m_cdtm.getFirstChild(m_context)
86                            : m_cdtm.getNextSibling(m_lastFetched);
87
88     // m_lastFetched = next;
89
if (DTM.NULL != next)
90     {
91       m_pos++;
92       return next;
93     }
94     else
95     {
96       m_foundLast = true;
97
98       return DTM.NULL;
99     }
100   }
101   
102   /**
103    * Returns the axis being iterated, if it is known.
104    *
105    * @return Axis.CHILD, etc., or -1 if the axis is not known or is of multiple
106    * types.
107    */

108   public int getAxis()
109   {
110     return org.apache.xml.dtm.Axis.CHILD;
111   }
112
113
114 }
115
Popular Tags