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.value.Cardinality; 7 8 12 13 public final class FirstItemExpression extends UnaryExpression { 14 15 19 20 public FirstItemExpression(Expression base) { 21 super(base); 22 computeStaticProperties(); 23 } 24 25 42 43 public Expression optimize(Optimizer opt, StaticContext env, ItemType contextItemType) throws XPathException { 44 operand = operand.optimize(opt, env, contextItemType); 45 if (!Cardinality.allowsMany(operand.getCardinality())) { 46 return operand; 47 } 48 return this; 49 } 50 51 54 55 public Expression promote(PromotionOffer offer) throws XPathException { 56 Expression exp = offer.accept(this); 57 if (exp != null) { 58 return exp; 59 } else { 60 if (offer.action != PromotionOffer.UNORDERED) { 61 operand = doPromotion(operand, offer); 63 } 64 return this; 65 } 66 } 67 68 71 72 public int computeCardinality() { 73 return operand.getCardinality() & ~StaticProperty.ALLOWS_MANY; 74 } 75 76 79 80 public Item evaluateItem(XPathContext context) throws XPathException { 81 return operand.iterate(context).next(); 82 } 83 84 87 88 public String displayOperator(NamePool pool) { 89 return "first item of"; 90 } 91 92 } 93 94 95 96 | Popular Tags |