KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

22
23     public int getDataType() {
24         return Value.NODESET;
25     }
26
27     /**
28     * Determine, in the case of an expression whose data type is Value.NODESET,
29     * whether all the nodes in the node-set are guaranteed to come from the same
30     * document as the context node. Used for optimization.
31     */

32     
33     public boolean isContextDocumentNodeSet() {
34         return true;
35     }
36
37     /**
38     * Simplify and validate.
39     */

40
41     public Expression simplify() throws XPathException {
42         checkArgumentCount(0, 0);
43         return this;
44     }
45
46     /**
47     * Evaluate the function in a node-set context
48     */

49
50     public NodeSetValue evaluateAsNodeSet(Context c) throws XPathException {
51         return new SingletonNodeSet(c.getCurrentNodeInfo());
52     }
53
54     /**
55     * Evaluate in a general context
56     */

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

65
66     public int getDependencies() {
67        return Context.CURRENT_NODE;
68     }
69
70     /**
71     * Reduce the dependencies
72     */

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