1 package net.sf.saxon.sort; 2 3 import net.sf.saxon.expr.*; 4 import net.sf.saxon.om.Item; 5 import net.sf.saxon.om.NamePool; 6 import net.sf.saxon.trans.XPathException; 7 import net.sf.saxon.type.ExternalObjectType; 8 import net.sf.saxon.type.ItemType; 9 import net.sf.saxon.value.ObjectValue; 10 import net.sf.saxon.value.Value; 11 12 import java.io.PrintStream ; 13 import java.util.Arrays ; 14 import java.util.Iterator ; 15 16 24 public class TupleExpression extends ComputedExpression { 25 26 Expression[] components; 27 28 public TupleExpression(int width) { 29 components = new Expression[width]; 30 } 31 32 public void setExpression(int i, Expression exp) { 33 components[i] = exp; 34 adoptChildExpression(components[i]); 35 } 36 37 public Expression simplify(StaticContext env) throws XPathException { 38 for (int i=0; i<components.length; i++) { 39 components[i] = components[i].simplify(env); 40 adoptChildExpression(components[i]); 41 } 42 return this; 43 } 44 45 public Expression promote(PromotionOffer offer) throws XPathException { 46 for (int i=0; i<components.length; i++) { 47 components[i] = doPromotion(components[i], offer); 48 adoptChildExpression(components[i]); 49 } 50 return this; 51 } 52 53 public ItemType getItemType() { 54 return new ExternalObjectType(Object .class); 55 } 56 57 public Expression typeCheck(StaticContext env, ItemType contextItemType) throws XPathException { 58 for (int i=0; i<components.length; i++) { 59 components[i] = components[i].typeCheck(env, contextItemType); 60 adoptChildExpression(components[i]); 61 } 62 return this; 63 } 64 65 82 83 public Expression optimize(Optimizer opt, StaticContext env, ItemType contextItemType) throws XPathException { 84 for (int i=0; i<components.length; i++) { 85 components[i] = components[i].optimize(opt, env, contextItemType); 86 adoptChildExpression(components[i]); 87 } 88 return this; 89 } 90 91 public void display(int level, NamePool pool, PrintStream out) { 92 out.println(ExpressionTool.indent(level) + "Tuple"); 93 for (int i=0; i<components.length; i++) { 94 components[i].display(level+1, pool, out); 95 } 96 } 97 98 99 public Item evaluateItem(XPathContext context) throws XPathException { 100 Value[] tuple = new Value[components.length]; 101 for (int i=0; i<components.length; i++) { 102 if (i < 2) { 108 tuple[i] = ExpressionTool.eagerEvaluate(components[i], context); 109 } else { 110 tuple[i] = Value.asValue(ExpressionTool.lazyEvaluate(components[i], context, 10)); 111 } 112 } 113 return new ObjectValue(tuple); 114 } 115 116 121 122 public int computeCardinality() { 123 return StaticProperty.EXACTLY_ONE; 124 } 125 126 public int getIntrinsicDependencies() { 127 return 0; 128 } 129 130 public Iterator iterateSubExpressions() { 131 return Arrays.asList(components).iterator(); 132 } 133 134 138 } 139 140 141 | Popular Tags |