KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > functions > BooleanFn


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 * This class supports the XPath functions boolean(), not(), true(), and false()
12 */

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     /**
23      * Static analysis: prevent sorting of the argument
24      */

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     /**
35     * Evaluate the function
36     */

37
38     public Item evaluateItem(XPathContext context) throws XPathException {
39         return BooleanValue.get(effectiveBooleanValue(context));
40     }
41
42     /**
43     * Evaluate the effective boolean value
44     */

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 JavaDoc("Unknown boolean operation");
58         }
59     }
60
61
62 }
63
64 //
65
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
66
// you may not use this file except in compliance with the License. You may obtain a copy of the
67
// License at http://www.mozilla.org/MPL/
68
//
69
// Software distributed under the License is distributed on an "AS IS" basis,
70
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
71
// See the License for the specific language governing rights and limitations under the License.
72
//
73
// The Original Code is: all this file.
74
//
75
// The Initial Developer of the Original Code is Michael H. Kay.
76
//
77
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
78
//
79
// Contributor(s): none.
80
//
81
Popular Tags