1 package net.sf.saxon.pattern; 2 3 import net.sf.saxon.expr.*; 4 import net.sf.saxon.om.*; 5 import net.sf.saxon.trans.XPathException; 6 import net.sf.saxon.type.ItemType; 7 import net.sf.saxon.type.SchemaType; 8 import net.sf.saxon.type.Type; 9 import net.sf.saxon.value.BooleanValue; 10 11 import java.io.PrintStream ; 12 import java.util.Iterator ; 13 14 28 29 public class PatternSponsor implements Expression { 30 31 private Pattern pattern; 32 33 public PatternSponsor(Pattern pattern) { 34 this.pattern = pattern; 35 } 36 37 40 41 public Pattern getPattern() { 42 return pattern; 43 } 44 45 50 51 public int getImplementationMethod() { 52 return EVALUATE_METHOD; 53 } 54 55 63 64 public Expression simplify(StaticContext env) throws XPathException { 65 pattern = pattern.simplify(env); 66 return this; 67 } 68 69 86 87 public Expression optimize(Optimizer opt, StaticContext env, ItemType contextItemType) throws XPathException { 88 return this; 89 } 90 91 114 115 public Expression typeCheck(StaticContext env, ItemType contextItemType) throws XPathException { 116 pattern = pattern.analyze(env, contextItemType); 117 return this; 118 } 119 120 136 137 public Expression promote(PromotionOffer offer) throws XPathException { 138 pattern.promote(offer); 139 return this; 140 } 141 142 149 150 public int getSpecialProperties() { 151 return 0; 152 } 153 154 166 167 public int getCardinality() { 168 return StaticProperty.EXACTLY_ONE; 169 } 170 171 183 184 public ItemType getItemType() { 185 return Type.BOOLEAN_TYPE; 186 } 187 188 200 201 public int getDependencies() { 202 return pattern.getDependencies(); 203 } 204 205 212 213 public Iterator iterateSubExpressions() { 214 return pattern.iterateSubExpressions(); 215 } 216 217 226 227 public Container getParentExpression() { 228 return pattern; 229 } 230 231 246 247 public Item evaluateItem(XPathContext context) throws XPathException { 248 return BooleanValue.get(effectiveBooleanValue(context)); 249 } 250 251 265 266 public SequenceIterator iterate(XPathContext context) throws XPathException { 267 return SingletonIterator.makeIterator(evaluateItem(context)); 268 } 269 270 281 282 public boolean effectiveBooleanValue(XPathContext context) throws XPathException { 283 Item contextItem = context.getContextItem(); 284 if (contextItem instanceof NodeInfo) { 285 return pattern.matches((NodeInfo)contextItem, context); 286 } 287 return false; 288 } 289 290 307 308 public String evaluateAsString(XPathContext context) throws XPathException { 309 return evaluateItem(context).getStringValue(); 310 } 311 312 318 319 public void process(XPathContext context) throws XPathException { 320 throw new UnsupportedOperationException ("Patterns cannot be evaluated in push mode"); 321 } 322 323 331 332 public void display(int level, NamePool pool, PrintStream out) { 333 out.println(ExpressionTool.indent(level) + "pattern " + pattern.toString()); 334 } 335 336 347 348 public void checkPermittedContents(SchemaType parentType, StaticContext env, boolean whole) throws XPathException { 349 throw new UnsupportedOperationException ("checkPermittedContents() is not applicable to a pattern"); 350 } 351 } 352 353 | Popular Tags |