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 13 14 15 public class BooleanFn extends SystemFunction { 16 17 public static final int BOOLEAN = 0; 18 public static final int NOT = 1; 19 public static final int TRUE = 2; 20 public static final int FALSE = 3; 21 22 25 26 public void checkArguments(StaticContext env) throws XPathException { 27 super.checkArguments(env); 28 if (operation==BOOLEAN || operation==NOT) { 29 Optimizer opt = env.getConfiguration().getOptimizer(); 30 argument[0] = ExpressionTool.unsortedIfHomogeneous(opt, argument[0], false); 31 } 32 } 33 34 37 38 public Item evaluateItem(XPathContext context) throws XPathException { 39 return BooleanValue.get(effectiveBooleanValue(context)); 40 } 41 42 45 46 public boolean effectiveBooleanValue(XPathContext c) throws XPathException { 47 switch (operation) { 48 case BOOLEAN: 49 return argument[0].effectiveBooleanValue(c); 50 case NOT: 51 return !argument[0].effectiveBooleanValue(c); 52 case TRUE: 53 return true; 54 case FALSE: 55 return false; 56 default: 57 throw new UnsupportedOperationException ("Unknown boolean operation"); 58 } 59 } 60 61 62 } 63 64 | Popular Tags |