1 16 19 package org.apache.xpath.axes; 20 21 import org.apache.xpath.Expression; 22 import org.apache.xpath.ExpressionOwner; 23 import org.apache.xpath.XPathVisitor; 24 import org.apache.xpath.functions.FuncLast; 25 import org.apache.xpath.functions.FuncPosition; 26 import org.apache.xpath.functions.Function; 27 import org.apache.xpath.objects.XNumber; 28 import org.apache.xpath.operations.Div; 29 import org.apache.xpath.operations.Minus; 30 import org.apache.xpath.operations.Mod; 31 import org.apache.xpath.operations.Mult; 32 import org.apache.xpath.operations.Plus; 33 import org.apache.xpath.operations.Quo; 34 import org.apache.xpath.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 org.apache.xpath.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 |