KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

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

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

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

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