1 package net.sf.saxon.functions; 2 import net.sf.saxon.expr.ExpressionTool; 3 import net.sf.saxon.expr.StaticContext; 4 import net.sf.saxon.expr.XPathContext; 5 import net.sf.saxon.expr.Optimizer; 6 import net.sf.saxon.om.Item; 7 import net.sf.saxon.trans.XPathException; 8 import net.sf.saxon.value.BooleanValue; 9 10 11 12 public class Existence extends SystemFunction { 13 14 public static final int EXISTS = 0; 15 public static final int EMPTY = 1; 16 17 20 21 public void checkArguments(StaticContext env) throws XPathException { 22 super.checkArguments(env); 23 Optimizer opt = env.getConfiguration().getOptimizer(); 24 argument[0] = ExpressionTool.unsorted(opt, argument[0], false); 25 } 26 27 30 31 public boolean effectiveBooleanValue(XPathContext c) throws XPathException { 32 switch (operation) { 33 case EXISTS: return argument[0].iterate(c).next() != null; 34 case EMPTY: return argument[0].iterate(c).next() == null; 35 } 36 return false; 37 } 38 39 42 43 public Item evaluateItem(XPathContext c) throws XPathException { 44 return BooleanValue.get(effectiveBooleanValue(c)); 45 } 46 47 } 48 49 | Popular Tags |