KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xpath > internal > axes > ChildTestIterator


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

19 package com.sun.org.apache.xpath.internal.axes;
20
21 import com.sun.org.apache.xml.internal.dtm.Axis;
22 import com.sun.org.apache.xml.internal.dtm.DTM;
23 import com.sun.org.apache.xml.internal.dtm.DTMAxisTraverser;
24 import com.sun.org.apache.xml.internal.dtm.DTMIterator;
25 import com.sun.org.apache.xpath.internal.compiler.Compiler;
26
27 /**
28  * This class implements an optimized iterator for
29  * children patterns that have a node test, and possibly a predicate.
30  * @see com.sun.org.apache.xpath.internal.axes.BasicTestIterator
31  * @xsl.usage advanced
32  */

33 public class ChildTestIterator extends BasicTestIterator
34 {
35   /** The traverser to use to navigate over the descendants. */
36   transient protected DTMAxisTraverser m_traverser;
37   
38   /** The extended type ID, not set until setRoot. */
39 // protected int m_extendedTypeID;
40

41
42   /**
43    * Create a ChildTestIterator object.
44    *
45    * @param compiler A reference to the Compiler that contains the op map.
46    * @param opPos The position within the op map, which contains the
47    * location path expression for this itterator.
48    *
49    * @throws javax.xml.transform.TransformerException
50    */

51   ChildTestIterator(Compiler JavaDoc compiler, int opPos, int analysis)
52           throws javax.xml.transform.TransformerException JavaDoc
53   {
54     super(compiler, opPos, analysis);
55   }
56   
57   /**
58    * Create a ChildTestIterator object.
59    *
60    * @param traverser Traverser that tells how the KeyIterator is to be handled.
61    *
62    * @throws javax.xml.transform.TransformerException
63    */

64   public ChildTestIterator(DTMAxisTraverser traverser)
65   {
66
67     super(null);
68
69     m_traverser = traverser;
70   }
71
72   /**
73    * Get the next node via getNextXXX. Bottlenecked for derived class override.
74    * @return The next node on the axis, or DTM.NULL.
75    */

76   protected int getNextNode()
77   {
78     if(true /* 0 == m_extendedTypeID */)
79     {
80       m_lastFetched = (DTM.NULL == m_lastFetched)
81                    ? m_traverser.first(m_context)
82                    : m_traverser.next(m_context, m_lastFetched);
83     }
84 // else
85
// {
86
// m_lastFetched = (DTM.NULL == m_lastFetched)
87
// ? m_traverser.first(m_context, m_extendedTypeID)
88
// : m_traverser.next(m_context, m_lastFetched,
89
// m_extendedTypeID);
90
// }
91

92     return m_lastFetched;
93   }
94
95   
96   /**
97    * Get a cloned Iterator that is reset to the beginning
98    * of the query.
99    *
100    * @return A cloned NodeIterator set of the start of the query.
101    *
102    * @throws CloneNotSupportedException
103    */

104   public DTMIterator cloneWithReset() throws CloneNotSupportedException JavaDoc
105   {
106
107     ChildTestIterator clone = (ChildTestIterator) super.cloneWithReset();
108     clone.m_traverser = m_traverser;
109
110     return clone;
111   }
112   
113
114   /**
115    * Initialize the context values for this expression
116    * after it is cloned.
117    *
118    * @param execContext The XPath runtime context for this
119    * transformation.
120    */

121   public void setRoot(int context, Object JavaDoc environment)
122   {
123     super.setRoot(context, environment);
124     m_traverser = m_cdtm.getAxisTraverser(Axis.CHILD);
125     
126 // String localName = getLocalName();
127
// String namespace = getNamespace();
128
// int what = m_whatToShow;
129
// // System.out.println("what: ");
130
// // NodeTest.debugWhatToShow(what);
131
// if(DTMFilter.SHOW_ALL == what ||
132
// ((DTMFilter.SHOW_ELEMENT & what) == 0)
133
// || localName == NodeTest.WILD
134
// || namespace == NodeTest.WILD)
135
// {
136
// m_extendedTypeID = 0;
137
// }
138
// else
139
// {
140
// int type = getNodeTypeTest(what);
141
// m_extendedTypeID = m_cdtm.getExpandedTypeID(namespace, localName, type);
142
// }
143

144   }
145   
146   /**
147    * Returns the axis being iterated, if it is known.
148    *
149    * @return Axis.CHILD, etc., or -1 if the axis is not known or is of multiple
150    * types.
151    */

152   public int getAxis()
153   {
154     return com.sun.org.apache.xml.internal.dtm.Axis.CHILD;
155   }
156
157   /**
158    * Detaches the iterator from the set which it iterated over, releasing
159    * any computational resources and placing the iterator in the INVALID
160    * state. After<code>detach</code> has been invoked, calls to
161    * <code>nextNode</code> or<code>previousNode</code> will raise the
162    * exception INVALID_STATE_ERR.
163    */

164   public void detach()
165   {
166     if(m_allowDetach)
167     {
168       m_traverser = null;
169       
170       // Always call the superclass detach last!
171
super.detach();
172     }
173   }
174
175 }
176
Popular Tags