1 16 19 package com.sun.org.apache.xpath.internal.axes; 20 21 import com.sun.org.apache.xpath.internal.Expression; 22 import com.sun.org.apache.xpath.internal.ExpressionOwner; 23 import com.sun.org.apache.xpath.internal.XPathVisitor; 24 import com.sun.org.apache.xpath.internal.functions.FuncLast; 25 import com.sun.org.apache.xpath.internal.functions.FuncPosition; 26 import com.sun.org.apache.xpath.internal.functions.Function; 27 import com.sun.org.apache.xpath.internal.objects.XNumber; 28 import com.sun.org.apache.xpath.internal.operations.Div; 29 import com.sun.org.apache.xpath.internal.operations.Minus; 30 import com.sun.org.apache.xpath.internal.operations.Mod; 31 import com.sun.org.apache.xpath.internal.operations.Mult; 32 import com.sun.org.apache.xpath.internal.operations.Plus; 33 import com.sun.org.apache.xpath.internal.operations.Quo; 34 import com.sun.org.apache.xpath.internal.operations.Variable; 35 36 public class HasPositionalPredChecker extends XPathVisitor 37 { 38 private boolean m_hasPositionalPred = false; 39 private int m_predDepth = 0; 40 41 48 public static boolean check(LocPathIterator path) 49 { 50 HasPositionalPredChecker hppc = new HasPositionalPredChecker(); 51 path.callVisitors(null, hppc); 52 return hppc.m_hasPositionalPred; 53 } 54 55 62 public boolean visitFunction(ExpressionOwner owner, Function func) 63 { 64 if((func instanceof FuncPosition) || 65 (func instanceof FuncLast)) 66 m_hasPositionalPred = true; 67 return true; 68 } 69 70 83 93 public boolean visitPredicate(ExpressionOwner owner, Expression pred) 94 { 95 m_predDepth++; 96 97 if(m_predDepth == 1) 98 { 99 if((pred instanceof Variable) || 100 (pred instanceof XNumber) || 101 (pred instanceof Div) || 102 (pred instanceof Plus) || 103 (pred instanceof Minus) || 104 (pred instanceof Mod) || 105 (pred instanceof Quo) || 106 (pred instanceof Mult) || 107 (pred instanceof com.sun.org.apache.xpath.internal.operations.Number) || 108 (pred instanceof Function)) 109 m_hasPositionalPred = true; 110 else 111 pred.callVisitors(owner, this); 112 } 113 114 m_predDepth--; 115 116 return false; 118 } 119 120 121 } 122 123 | Popular Tags |