1 16 19 package com.sun.org.apache.xpath.internal.patterns; 20 21 import com.sun.org.apache.xml.internal.dtm.DTM; 22 import com.sun.org.apache.xml.internal.dtm.DTMIterator; 23 import com.sun.org.apache.xpath.internal.Expression; 24 import com.sun.org.apache.xpath.internal.ExpressionOwner; 25 import com.sun.org.apache.xpath.internal.XPathContext; 26 import com.sun.org.apache.xpath.internal.XPathVisitor; 27 import com.sun.org.apache.xpath.internal.objects.XNumber; 28 import com.sun.org.apache.xpath.internal.objects.XObject; 29 30 34 public class FunctionPattern extends StepPattern 35 { 36 37 46 public FunctionPattern(Expression expr, int axis, int predaxis) 47 { 48 49 super(0, null, null, axis, predaxis); 50 51 m_functionExpr = expr; 52 } 53 54 57 public final void calcScore() 58 { 59 60 m_score = SCORE_OTHER; 61 62 if (null == m_targetString) 63 calcTargetString(); 64 } 65 66 70 Expression m_functionExpr; 71 72 82 public void fixupVariables(java.util.Vector vars, int globalsSize) 83 { 84 super.fixupVariables(vars, globalsSize); 85 m_functionExpr.fixupVariables(vars, globalsSize); 86 } 87 88 89 102 public XObject execute(XPathContext xctxt, int context) 103 throws javax.xml.transform.TransformerException 104 { 105 106 DTMIterator nl = m_functionExpr.asIterator(xctxt, context); 107 XNumber score = SCORE_NONE; 108 109 if (null != nl) 110 { 111 int n; 112 113 while (DTM.NULL != (n = nl.nextNode())) 114 { 115 score = (n == context) ? SCORE_OTHER : SCORE_NONE; 116 117 if (score == SCORE_OTHER) 118 { 119 context = n; 120 121 break; 122 } 123 } 124 125 } 127 nl.detach(); 128 129 return score; 130 } 131 132 145 public XObject execute(XPathContext xctxt, int context, 146 DTM dtm, int expType) 147 throws javax.xml.transform.TransformerException 148 { 149 150 DTMIterator nl = m_functionExpr.asIterator(xctxt, context); 151 XNumber score = SCORE_NONE; 152 153 if (null != nl) 154 { 155 int n; 156 157 while (DTM.NULL != (n = nl.nextNode())) 158 { 159 score = (n == context) ? SCORE_OTHER : SCORE_NONE; 160 161 if (score == SCORE_OTHER) 162 { 163 context = n; 164 165 break; 166 } 167 } 168 169 nl.detach(); 170 } 171 172 return score; 173 } 174 175 188 public XObject execute(XPathContext xctxt) 189 throws javax.xml.transform.TransformerException 190 { 191 192 int context = xctxt.getCurrentNode(); 193 DTMIterator nl = m_functionExpr.asIterator(xctxt, context); 194 XNumber score = SCORE_NONE; 195 196 if (null != nl) 197 { 198 int n; 199 200 while (DTM.NULL != (n = nl.nextNode())) 201 { 202 score = (n == context) ? SCORE_OTHER : SCORE_NONE; 203 204 if (score == SCORE_OTHER) 205 { 206 context = n; 207 208 break; 209 } 210 } 211 212 nl.detach(); 213 } 214 215 return score; 216 } 217 218 class FunctionOwner implements ExpressionOwner 219 { 220 223 public Expression getExpression() 224 { 225 return m_functionExpr; 226 } 227 228 229 232 public void setExpression(Expression exp) 233 { 234 exp.exprSetParent(FunctionPattern.this); 235 m_functionExpr = exp; 236 } 237 } 238 239 242 protected void callSubtreeVisitors(XPathVisitor visitor) 243 { 244 m_functionExpr.callVisitors(new FunctionOwner(), visitor); 245 super.callSubtreeVisitors(visitor); 246 } 247 248 } 249 | Popular Tags |