KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > expr > IsLastExpression


1 package com.icl.saxon.expr;
2 import com.icl.saxon.Context;
3
4
5 /**
6 * position()=last() expression
7 */

8
9 public final class IsLastExpression extends Expression {
10     
11     private boolean condition;
12     
13     /**
14     * Construct a condition that tests position()=last (if condition
15     * is true) or position()!=last() (if condition is false).
16     */

17
18     public IsLastExpression(boolean condition){
19         this.condition = condition;
20     };
21
22     public boolean getCondition() {
23         return condition;
24     }
25
26     public Expression simplify() {
27         return this;
28     }
29     
30     public Value evaluate(Context c) throws XPathException {
31         return new BooleanValue(evaluateAsBoolean(c));
32     }
33
34     public boolean evaluateAsBoolean(Context c) throws XPathException {
35         return condition==c.isAtLast();
36     }
37
38     /**
39     * Determine the data type of the expression
40     * @return Value.BOOLEAN
41     */

42
43     public int getDataType() {
44         return Value.BOOLEAN;
45     }
46
47     /**
48     * Get the dependencies of this expression on the context
49     */

50     
51     public int getDependencies() {
52         return Context.POSITION | Context.LAST;
53     }
54
55     /**
56     * Perform a partial evaluation of the expression, by eliminating specified dependencies
57     * on the context.
58     * @param dependencies The dependencies to be removed
59     * @param context The context to be used for the partial evaluation
60     * @return a new expression that does not have any of the specified
61     * dependencies
62     */

63
64     public Expression reduce(int dependencies, Context context) throws XPathException {
65         if (((Context.LAST | Context.POSITION) & dependencies) != 0 ) {
66             return new BooleanValue(context.isAtLast());
67         } else {
68             return this;
69         }
70     }
71
72     /**
73     * Diagnostic print of expression structure
74     */

75     
76     public void display(int level) {
77         System.err.println(indent(level) + "isLast()");
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