KickJava   Java API By Example, From Geeks To Geeks.

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


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 public class Position extends Function {
9
10     /**
11     * Function name (for diagnostics)
12     */

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

22
23     public int getDataType() {
24         return Value.NUMBER;
25     }
26
27     /**
28     * Simplify and validate.
29     */

30
31     public Expression simplify() throws XPathException {
32         checkArgumentCount(0, 0);
33         return this;
34     }
35
36     /**
37     * Evaluate the function in a numeric context
38     */

39
40     public double evaluateAsNumber(Context c) throws XPathException {
41         return (double)c.getContextPosition();
42     }
43
44     /**
45     * Evaluate in a general context
46     */

47
48     public Value evaluate(Context c) throws XPathException {
49         return new NumericValue(evaluateAsNumber(c));
50     }
51
52     /**
53     * Determine the dependencies
54     */

55
56     public int getDependencies() {
57         return Context.POSITION;
58     }
59
60     /**
61     * Reduce the dependencies
62     */

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