1 16 19 package org.apache.xpath.axes; 20 21 import org.apache.xml.dtm.Axis; 22 import org.apache.xml.dtm.DTM; 23 import org.apache.xml.dtm.DTMIterator; 24 import org.apache.xpath.Expression; 25 import org.apache.xpath.ExpressionOwner; 26 import org.apache.xpath.XPathContext; 27 import org.apache.xpath.XPathVisitor; 28 import org.apache.xpath.compiler.Compiler; 29 import org.apache.xpath.compiler.OpCodes; 30 import org.apache.xpath.objects.XNodeSet; 31 32 37 public class FilterExprWalker extends AxesWalker 38 { 39 40 45 public FilterExprWalker(WalkingIterator locPathIterator) 46 { 47 super(locPathIterator, Axis.FILTEREDLIST); 48 } 49 50 59 public void init(Compiler compiler, int opPos, int stepType) 60 throws javax.xml.transform.TransformerException 61 { 62 63 super.init(compiler, opPos, stepType); 64 65 switch (stepType) 67 { 68 case OpCodes.OP_FUNCTION : 69 case OpCodes.OP_EXTFUNCTION : 70 m_mustHardReset = true; 71 case OpCodes.OP_GROUP : 72 case OpCodes.OP_VARIABLE : 73 m_expr = compiler.compile(opPos); 74 m_expr.exprSetParent(this); 75 if(m_expr instanceof org.apache.xpath.operations.Variable) 77 { 78 m_canDetachNodeset = false; 80 } 81 break; 82 default : 83 m_expr = compiler.compile(opPos + 2); 84 m_expr.exprSetParent(this); 85 } 86 } 101 102 107 public void detach() 108 { 109 super.detach(); 110 if (m_canDetachNodeset) 111 { 112 m_exprObj.detach(); 113 } 114 m_exprObj = null; 115 } 116 117 123 public void setRoot(int root) 124 { 125 126 super.setRoot(root); 127 128 m_exprObj = FilterExprIteratorSimple.executeFilterExpr(root, 129 m_lpi.getXPathContext(), m_lpi.getPrefixResolver(), 130 m_lpi.getIsTopLevel(), m_lpi.m_stackFrame, m_expr); 131 132 } 133 134 141 public Object clone() throws CloneNotSupportedException 142 { 143 144 FilterExprWalker clone = (FilterExprWalker) super.clone(); 145 146 if (null != m_exprObj) 148 clone.m_exprObj = (XNodeSet) m_exprObj.clone(); 149 150 return clone; 151 } 152 153 160 public short acceptNode(int n) 161 { 162 163 try 164 { 165 if (getPredicateCount() > 0) 166 { 167 countProximityPosition(0); 168 169 if (!executePredicates(n, m_lpi.getXPathContext())) 170 return DTMIterator.FILTER_SKIP; 171 } 172 173 return DTMIterator.FILTER_ACCEPT; 174 } 175 catch (javax.xml.transform.TransformerException se) 176 { 177 throw new RuntimeException (se.getMessage()); 178 } 179 } 180 181 190 public int getNextNode() 191 { 192 193 if (null != m_exprObj) 194 { 195 int next = m_exprObj.nextNode(); 196 return next; 197 } 198 else 199 return DTM.NULL; 200 } 201 202 210 public int getLastPos(XPathContext xctxt) 211 { 212 return m_exprObj.getLength(); 213 } 214 215 217 private Expression m_expr; 218 219 220 transient private XNodeSet m_exprObj; 221 222 private boolean m_mustHardReset = false; 223 private boolean m_canDetachNodeset = true; 224 225 235 public void fixupVariables(java.util.Vector vars, int globalsSize) 236 { 237 super.fixupVariables(vars, globalsSize); 238 m_expr.fixupVariables(vars, globalsSize); 239 } 240 241 244 public Expression getInnerExpression() 245 { 246 return m_expr; 247 } 248 249 252 public void setInnerExpression(Expression expr) 253 { 254 expr.exprSetParent(this); 255 m_expr = expr; 256 } 257 258 259 263 public int getAnalysisBits() 264 { 265 if (null != m_expr && m_expr instanceof PathComponent) 266 { 267 return ((PathComponent) m_expr).getAnalysisBits(); 268 } 269 return WalkerFactory.BIT_FILTER; 270 } 271 272 279 public boolean isDocOrdered() 280 { 281 return m_exprObj.isDocOrdered(); 282 } 283 284 290 public int getAxis() 291 { 292 return m_exprObj.getAxis(); 293 } 294 295 class filterExprOwner implements ExpressionOwner 296 { 297 300 public Expression getExpression() 301 { 302 return m_expr; 303 } 304 305 308 public void setExpression(Expression exp) 309 { 310 exp.exprSetParent(FilterExprWalker.this); 311 m_expr = exp; 312 } 313 } 314 315 324 public void callPredicateVisitors(XPathVisitor visitor) 325 { 326 m_expr.callVisitors(new filterExprOwner(), visitor); 327 328 super.callPredicateVisitors(visitor); 329 } 330 331 332 335 public boolean deepEquals(Expression expr) 336 { 337 if (!super.deepEquals(expr)) 338 return false; 339 340 FilterExprWalker walker = (FilterExprWalker)expr; 341 if(!m_expr.deepEquals(walker.m_expr)) 342 return false; 343 344 return true; 345 } 346 347 348 349 } 350 | Popular Tags |