KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > functions > BooleanFn


1 package com.icl.saxon.functions;
2 import com.icl.saxon.*;
3 import com.icl.saxon.expr.*;
4
5 import java.util.*;
6 import java.text.*;
7
8
9
10 public class BooleanFn extends Function {
11
12     /**
13     * Function name (for diagnostics)
14     */

15
16     public String JavaDoc getName() {
17         return "boolean";
18     };
19
20     /**
21     * Determine the data type of the expression
22     * @return Value.BOOLEAN
23     */

24
25     public int getDataType() {
26         return Value.BOOLEAN;
27     }
28
29     /**
30     * Simplify and validate.
31     * This is a pure function so it can be simplified in advance if the arguments are known
32     */

33
34     public Expression simplify() throws XPathException {
35         checkArgumentCount(1, 1);
36         argument[0] = argument[0].simplify();
37         if (argument[0].getDataType()==Value.BOOLEAN) {
38             return argument[0];
39         }
40         if (argument[0] instanceof Value) {
41             return new BooleanValue(((Value)argument[0]).asBoolean());
42         }
43         return this;
44     }
45
46     /**
47     * Evaluate the function in a boolean context
48     */

49
50     public boolean evaluateAsBoolean(Context c) throws XPathException {
51         return argument[0].evaluateAsBoolean(c);
52     }
53
54     /**
55     * Evaluate in a general context
56     */

57
58     public Value evaluate(Context c) throws XPathException {
59         return new BooleanValue(evaluateAsBoolean(c));
60     }
61
62     /**
63     * Determine the dependencies
64     */

65
66     public int getDependencies() {
67         return argument[0].getDependencies();
68     }
69
70     /**
71     * Reduce the dependencies
72     */

73
74     public Expression reduce(int dep, Context c) throws XPathException {
75         BooleanFn f = new BooleanFn();
76         f.addArgument(argument[0].reduce(dep, c));
77         f.setStaticContext(getStaticContext());
78         return f.simplify();
79     }
80
81
82     
83 }
84
85 //
86
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
87
// you may not use this file except in compliance with the License. You may obtain a copy of the
88
// License at http://www.mozilla.org/MPL/
89
//
90
// Software distributed under the License is distributed on an "AS IS" basis,
91
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
92
// See the License for the specific language governing rights and limitations under the License.
93
//
94
// The Original Code is: all this file.
95
//
96
// The Initial Developer of the Original Code is
97
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
98
//
99
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
100
//
101
// Contributor(s): none.
102
//
103
Popular Tags