001: package net.sf.saxon.expr;
002:
003: import net.sf.saxon.om.Item;
004: import net.sf.saxon.om.NamePool;
005: import net.sf.saxon.trans.XPathException;
006: import net.sf.saxon.type.ItemType;
007: import net.sf.saxon.type.Type;
008: import net.sf.saxon.type.TypeHierarchy;
009: import net.sf.saxon.value.BooleanValue;
010:
011: import java.io.PrintStream;
012:
013: /**
014: * A position() eq last() expression, generated by the optimizer.
015: */
016:
017: public final class IsLastExpression extends ComputedExpression {
018:
019: private boolean condition;
020:
021: /**
022: * Construct a condition that tests position() eq last() (if condition
023: * is true) or position() ne last() (if condition is false).
024: */
025:
026: public IsLastExpression(boolean condition) {
027: this .condition = condition;
028: };
029:
030: public boolean getCondition() {
031: return condition;
032: }
033:
034: public Expression simplify(StaticContext env) {
035: return this ;
036: }
037:
038: public Expression typeCheck(StaticContext env,
039: ItemType contextItemType) {
040: return this ;
041: }
042:
043: public Expression optimize(Optimizer opt, StaticContext env,
044: ItemType contextItemType) {
045: return this ;
046: }
047:
048: /**
049: * Determine the special properties of this expression
050: * @return {@link StaticProperty#NON_CREATIVE}.
051: */
052:
053: public int computeSpecialProperties() {
054: int p = super .computeSpecialProperties();
055: return p | StaticProperty.NON_CREATIVE;
056: }
057:
058: public Item evaluateItem(XPathContext c) throws XPathException {
059: return BooleanValue.get(condition == c.isAtLast());
060: }
061:
062: /**
063: * Determine the data type of the expression
064: * @return Type.BOOLEAN
065: * @param th
066: */
067:
068: public ItemType getItemType(TypeHierarchy th) {
069: return Type.BOOLEAN_TYPE;
070: }
071:
072: /**
073: * Determine the static cardinality
074: */
075:
076: public int computeCardinality() {
077: return StaticProperty.EXACTLY_ONE;
078: }
079:
080: /**
081: * Get the dependencies of this expression on the context
082: */
083:
084: public int getIntrinsicDependencies() {
085: return StaticProperty.DEPENDS_ON_POSITION
086: | StaticProperty.DEPENDS_ON_LAST;
087: }
088:
089: /**
090: * Diagnostic print of expression structure
091: */
092:
093: public void display(int level, NamePool pool, PrintStream out) {
094: out.println(ExpressionTool.indent(level)
095: + (condition ? "" : "not ") + "isLast()");
096: }
097:
098: }
099:
100: //
101: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
102: // you may not use this file except in compliance with the License. You may obtain a copy of the
103: // License at http://www.mozilla.org/MPL/
104: //
105: // Software distributed under the License is distributed on an "AS IS" basis,
106: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
107: // See the License for the specific language governing rights and limitations under the License.
108: //
109: // The Original Code is: all this file.
110: //
111: // The Initial Developer of the Original Code is Michael H. Kay.
112: //
113: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
114: //
115: // Contributor(s): none.
116: //
|