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.utils.PrefixResolver; 24 import org.apache.xpath.Expression; 25 import org.apache.xpath.ExpressionOwner; 26 import org.apache.xpath.VariableStack; 27 import org.apache.xpath.XPathContext; 28 import org.apache.xpath.XPathVisitor; 29 import org.apache.xpath.objects.XNodeSet; 30 31 35 public class FilterExprIteratorSimple extends LocPathIterator 36 { 37 39 private Expression m_expr; 40 41 42 transient private XNodeSet m_exprObj; 43 44 private boolean m_mustHardReset = false; 45 private boolean m_canDetachNodeset = true; 46 47 54 public FilterExprIteratorSimple() 55 { 56 super(null); 57 } 58 59 66 public FilterExprIteratorSimple(Expression expr) 67 { 68 super(null); 69 m_expr = expr; 70 } 71 72 79 public void setRoot(int context, Object environment) 80 { 81 super.setRoot(context, environment); 82 m_exprObj = executeFilterExpr(context, m_execContext, getPrefixResolver(), 83 getIsTopLevel(), m_stackFrame, m_expr); 84 } 85 86 90 public static XNodeSet executeFilterExpr(int context, XPathContext xctxt, 91 PrefixResolver prefixResolver, 92 boolean isTopLevel, 93 int stackFrame, 94 Expression expr ) 95 throws org.apache.xml.utils.WrappedRuntimeException 96 { 97 PrefixResolver savedResolver = xctxt.getNamespaceContext(); 98 XNodeSet result = null; 99 100 try 101 { 102 xctxt.pushCurrentNode(context); 103 xctxt.setNamespaceContext(prefixResolver); 104 105 110 if (isTopLevel) 111 { 112 VariableStack vars = xctxt.getVarStack(); 114 115 int savedStart = vars.getStackFrame(); 117 vars.setStackFrame(stackFrame); 118 119 result = (org.apache.xpath.objects.XNodeSet) expr.execute(xctxt); 120 result.setShouldCacheNodes(true); 121 122 vars.setStackFrame(savedStart); 124 } 125 else 126 result = (org.apache.xpath.objects.XNodeSet) expr.execute(xctxt); 127 128 } 129 catch (javax.xml.transform.TransformerException se) 130 { 131 132 throw new org.apache.xml.utils.WrappedRuntimeException(se); 134 } 135 finally 136 { 137 xctxt.popCurrentNode(); 138 xctxt.setNamespaceContext(savedResolver); 139 } 140 return result; 141 } 142 143 151 public int nextNode() 152 { 153 if(m_foundLast) 154 return DTM.NULL; 155 156 int next; 157 158 if (null != m_exprObj) 159 { 160 m_lastFetched = next = m_exprObj.nextNode(); 161 } 162 else 163 m_lastFetched = next = DTM.NULL; 164 165 if (DTM.NULL != next) 167 { 168 m_pos++; 169 return next; 170 } 171 else 172 { 173 m_foundLast = true; 174 175 return DTM.NULL; 176 } 177 } 178 179 184 public void detach() 185 { 186 if(m_allowDetach) 187 { 188 super.detach(); 189 m_exprObj.detach(); 190 m_exprObj = null; 191 } 192 } 193 194 204 public void fixupVariables(java.util.Vector vars, int globalsSize) 205 { 206 super.fixupVariables(vars, globalsSize); 207 m_expr.fixupVariables(vars, globalsSize); 208 } 209 210 213 public Expression getInnerExpression() 214 { 215 return m_expr; 216 } 217 218 221 public void setInnerExpression(Expression expr) 222 { 223 expr.exprSetParent(this); 224 m_expr = expr; 225 } 226 227 231 public int getAnalysisBits() 232 { 233 if (null != m_expr && m_expr instanceof PathComponent) 234 { 235 return ((PathComponent) m_expr).getAnalysisBits(); 236 } 237 return WalkerFactory.BIT_FILTER; 238 } 239 240 247 public boolean isDocOrdered() 248 { 249 return m_exprObj.isDocOrdered(); 250 } 251 252 class filterExprOwner implements ExpressionOwner 253 { 254 257 public Expression getExpression() 258 { 259 return m_expr; 260 } 261 262 265 public void setExpression(Expression exp) 266 { 267 exp.exprSetParent(FilterExprIteratorSimple.this); 268 m_expr = exp; 269 } 270 271 } 272 273 282 public void callPredicateVisitors(XPathVisitor visitor) 283 { 284 m_expr.callVisitors(new filterExprOwner(), visitor); 285 286 super.callPredicateVisitors(visitor); 287 } 288 289 292 public boolean deepEquals(Expression expr) 293 { 294 if (!super.deepEquals(expr)) 295 return false; 296 297 FilterExprIteratorSimple fet = (FilterExprIteratorSimple) expr; 298 if (!m_expr.deepEquals(fet.m_expr)) 299 return false; 300 301 return true; 302 } 303 304 310 public int getAxis() 311 { 312 if(null != m_exprObj) 313 return m_exprObj.getAxis(); 314 else 315 return Axis.FILTEREDLIST; 316 } 317 318 319 } 320 321 | Popular Tags |