1 28 29 package com.caucho.xpath.pattern; 30 31 import com.caucho.xpath.Env; 32 import com.caucho.xpath.Expr; 33 import com.caucho.xpath.ExprEnvironment; 34 import com.caucho.xpath.XPathException; 35 36 import org.w3c.dom.Node ; 37 38 import java.util.Iterator ; 39 40 46 public class FromExpr extends AbstractPattern { 47 private Expr _expr; 48 49 public FromExpr(AbstractPattern parent, Expr expr) 50 { 51 super(parent); 52 53 _expr = expr; 54 } 55 56 65 public boolean match(Node node, ExprEnvironment env) 66 throws XPathException 67 { 68 NodeIterator iter = _expr.evalNodeSet(node, env); 69 70 while (iter.hasNext()) { 71 Node subnode = iter.nextNode(); 72 if (subnode == node) 73 return true; 74 } 75 76 return false; 77 } 78 79 88 public NodeIterator createNodeIterator(Node node, ExprEnvironment env, 89 AbstractPattern match) 90 throws XPathException 91 { 92 return _expr.evalNodeSet(node, env); 93 } 94 95 98 public int position(Node node, Env env, AbstractPattern pattern) 99 throws XPathException 100 { 101 Iterator iter = _expr.evalNodeSet(node, env); 102 103 int i = 1; 104 while (iter.hasNext()) { 105 if (iter.next() == node) 106 return i; 107 i++; 108 } 109 110 return 0; 111 } 112 113 116 public int count(Node node, Env env, AbstractPattern pattern) 117 throws XPathException 118 { 119 Iterator iter = _expr.evalNodeSet(node, env); 120 int count = 0; 121 122 while (iter.hasNext()) { 123 iter.next(); 124 count++; 125 } 126 127 return count; 128 } 129 130 public String toString() 131 { 132 return getPrefix() + "(" + _expr + ")"; 133 } 134 } 135 | Popular Tags |