KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > expr > IsLastExpression


1 package net.sf.saxon.expr;
2 import net.sf.saxon.om.Item;
3 import net.sf.saxon.om.NamePool;
4 import net.sf.saxon.trans.XPathException;
5 import net.sf.saxon.type.ItemType;
6 import net.sf.saxon.type.Type;
7 import net.sf.saxon.value.BooleanValue;
8
9 import java.io.PrintStream JavaDoc;
10
11
12 /**
13 * A position() eq last() expression, generated by the optimizer.
14 */

15
16 public final class IsLastExpression extends ComputedExpression {
17
18     private boolean condition;
19
20     /**
21     * Construct a condition that tests position() eq last() (if condition
22     * is true) or position() ne last() (if condition is false).
23     */

24
25     public IsLastExpression(boolean condition){
26         this.condition = condition;
27     };
28
29     public boolean getCondition() {
30         return condition;
31     }
32
33     public Expression simplify(StaticContext env) {
34         return this;
35     }
36
37     public Expression typeCheck(StaticContext env, ItemType contextItemType) {
38         return this;
39     }
40
41     public Expression optimize(Optimizer opt, StaticContext env, ItemType contextItemType) {
42         return this;
43     }
44
45     /**
46      * Determine the special properties of this expression
47      * @return {@link StaticProperty#NON_CREATIVE}.
48      */

49
50     public int computeSpecialProperties() {
51         int p = super.computeSpecialProperties();
52         return p | StaticProperty.NON_CREATIVE;
53     }
54
55     public Item evaluateItem(XPathContext c) throws XPathException {
56         return BooleanValue.get(condition==c.isAtLast());
57     }
58
59     /**
60     * Determine the data type of the expression
61     * @return Type.BOOLEAN
62     */

63
64     public ItemType getItemType() {
65         return Type.BOOLEAN_TYPE;
66     }
67
68     /**
69     * Determine the static cardinality
70     */

71
72     public int computeCardinality() {
73         return StaticProperty.EXACTLY_ONE;
74     }
75
76     /**
77     * Get the dependencies of this expression on the context
78     */

79
80     public int getIntrinsicDependencies() {
81         return StaticProperty.DEPENDS_ON_POSITION | StaticProperty.DEPENDS_ON_LAST;
82     }
83
84     /**
85     * Diagnostic print of expression structure
86     */

87
88     public void display(int level, NamePool pool, PrintStream JavaDoc out) {
89         out.println(ExpressionTool.indent(level) + (condition ? "" : "not ") + "isLast()");
90     }
91
92 }
93
94 //
95
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
96
// you may not use this file except in compliance with the License. You may obtain a copy of the
97
// License at http://www.mozilla.org/MPL/
98
//
99
// Software distributed under the License is distributed on an "AS IS" basis,
100
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
101
// See the License for the specific language governing rights and limitations under the License.
102
//
103
// The Original Code is: all this file.
104
//
105
// The Initial Developer of the Original Code is Michael H. Kay.
106
//
107
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
108
//
109
// Contributor(s): none.
110
//
111
Popular Tags