1 16 19 package org.apache.xpath.axes; 20 21 import org.apache.xml.dtm.DTM; 22 import org.apache.xml.utils.PrefixResolver; 23 import org.apache.xpath.Expression; 24 import org.apache.xpath.ExpressionOwner; 25 import org.apache.xpath.VariableStack; 26 import org.apache.xpath.XPathVisitor; 27 import org.apache.xpath.compiler.Compiler; 28 29 32 33 public class WalkingIterator extends LocPathIterator implements ExpressionOwner 34 { 35 50 WalkingIterator( 51 Compiler compiler, int opPos, int analysis, boolean shouldLoadWalkers) 52 throws javax.xml.transform.TransformerException 53 { 54 super(compiler, opPos, analysis, shouldLoadWalkers); 55 56 int firstStepPos = compiler.getFirstChildPos(opPos); 57 58 if (shouldLoadWalkers) 59 { 60 m_firstWalker = WalkerFactory.loadWalkers(this, compiler, firstStepPos, 0); 61 m_lastUsedWalker = m_firstWalker; 62 } 63 } 64 65 71 public WalkingIterator(PrefixResolver nscontext) 72 { 73 74 super(nscontext); 75 } 76 77 78 82 public int getAnalysisBits() 83 { 84 int bits = 0; 85 if (null != m_firstWalker) 86 { 87 AxesWalker walker = m_firstWalker; 88 89 while (null != walker) 90 { 91 int bit = walker.getAnalysisBits(); 92 bits |= bit; 93 walker = walker.getNextWalker(); 94 } 95 } 96 return bits; 97 } 98 99 107 public Object clone() throws CloneNotSupportedException 108 { 109 110 WalkingIterator clone = (WalkingIterator) super.clone(); 111 112 if (null != m_firstWalker) 115 { 116 clone.m_firstWalker = m_firstWalker.cloneDeep(clone, null); 117 } 118 119 return clone; 120 } 121 122 125 public void reset() 126 { 127 128 super.reset(); 129 130 if (null != m_firstWalker) 131 { 132 m_lastUsedWalker = m_firstWalker; 133 134 m_firstWalker.setRoot(m_context); 135 } 136 137 } 138 139 146 public void setRoot(int context, Object environment) 147 { 148 149 super.setRoot(context, environment); 150 151 if(null != m_firstWalker) 152 { 153 m_firstWalker.setRoot(context); 154 m_lastUsedWalker = m_firstWalker; 155 } 156 } 157 158 165 public int nextNode() 166 { 167 if(m_foundLast) 168 return DTM.NULL; 169 170 if (-1 == m_stackFrame) 179 { 180 return returnNextNode(m_firstWalker.nextNode()); 181 } 182 else 183 { 184 VariableStack vars = m_execContext.getVarStack(); 185 186 int savedStart = vars.getStackFrame(); 188 189 vars.setStackFrame(m_stackFrame); 190 191 int n = returnNextNode(m_firstWalker.nextNode()); 192 193 vars.setStackFrame(savedStart); 195 196 return n; 197 } 198 } 199 200 201 208 public final AxesWalker getFirstWalker() 209 { 210 return m_firstWalker; 211 } 212 213 219 public final void setFirstWalker(AxesWalker walker) 220 { 221 m_firstWalker = walker; 222 } 223 224 225 231 public final void setLastUsedWalker(AxesWalker walker) 232 { 233 m_lastUsedWalker = walker; 234 } 235 236 242 public final AxesWalker getLastUsedWalker() 243 { 244 return m_lastUsedWalker; 245 } 246 247 254 public void detach() 255 { 256 if(m_allowDetach) 257 { 258 AxesWalker walker = m_firstWalker; 259 while (null != walker) 260 { 261 walker.detach(); 262 walker = walker.getNextWalker(); 263 } 264 265 m_lastUsedWalker = null; 266 267 super.detach(); 269 } 270 } 271 272 282 public void fixupVariables(java.util.Vector vars, int globalsSize) 283 { 284 m_predicateIndex = -1; 285 286 AxesWalker walker = m_firstWalker; 287 288 while (null != walker) 289 { 290 walker.fixupVariables(vars, globalsSize); 291 walker = walker.getNextWalker(); 292 } 293 } 294 295 298 public void callVisitors(ExpressionOwner owner, XPathVisitor visitor) 299 { 300 if(visitor.visitLocationPath(owner, this)) 301 { 302 if(null != m_firstWalker) 303 { 304 m_firstWalker.callVisitors(this, visitor); 305 } 306 } 307 } 308 309 310 312 protected AxesWalker m_lastUsedWalker; 313 314 316 protected AxesWalker m_firstWalker; 317 318 321 public Expression getExpression() 322 { 323 return m_firstWalker; 324 } 325 326 329 public void setExpression(Expression exp) 330 { 331 exp.exprSetParent(this); 332 m_firstWalker = (AxesWalker)exp; 333 } 334 335 338 public boolean deepEquals(Expression expr) 339 { 340 if (!super.deepEquals(expr)) 341 return false; 342 343 AxesWalker walker1 = m_firstWalker; 344 AxesWalker walker2 = ((WalkingIterator)expr).m_firstWalker; 345 while ((null != walker1) && (null != walker2)) 346 { 347 if(!walker1.deepEquals(walker2)) 348 return false; 349 walker1 = walker1.getNextWalker(); 350 walker2 = walker2.getNextWalker(); 351 } 352 353 if((null != walker1) || (null != walker2)) 354 return false; 355 356 return true; 357 } 358 359 } 360 | Popular Tags |