KickJava   Java API By Example, From Geeks To Geeks.

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


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

14
15     public String JavaDoc getName() {
16         return "function-available";
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         if (argument[0] instanceof Value) {
37             return evaluate(null);
38         }
39         return this;
40     }
41
42     /**
43     * Evaluate the function in a boolean context
44     */

45
46     public boolean evaluateAsBoolean(Context c) throws XPathException {
47         String JavaDoc qname = argument[0].evaluateAsString(c);
48         return getStaticContext().isFunctionAvailable(qname);
49     }
50
51
52     /**
53     * Evaluate in a general context
54     */

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

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

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