| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.expr.flwor; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.*; |
| 11 |
import net.sf.saxon.expr.parser.*; |
| 12 |
import net.sf.saxon.trace.ExpressionPresenter; |
| 13 |
import net.sf.saxon.trans.XPathException; |
| 14 |
import net.sf.saxon.tree.util.FastStringBuffer; |
| 15 |
import net.sf.saxon.type.ItemType; |
| 16 |
|
| 17 |
import java.util.List; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
public class WhereClause extends Clause { |
| 23 |
|
| 24 |
private Operand predicateOp; |
| 25 |
|
| 26 |
public WhereClause(FLWORExpression flwor, Expression predicate) { |
| 27 |
this.predicateOp = new Operand(flwor, predicate, OperandRole.INSPECT); |
| 28 |
} |
| 29 |
|
| 30 |
@Override |
| 31 |
public void setRepeated(boolean repeated) { |
| 32 |
super.setRepeated(repeated); |
| 33 |
if (repeated) { |
| 34 |
this.predicateOp.setOperandRole(OperandRole.REPEAT_INSPECT); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
@Override |
| 39 |
public int getClauseKey() { |
| 40 |
return WHERE; |
| 41 |
} |
| 42 |
|
| 43 |
public Expression getPredicate() { |
| 44 |
return predicateOp.getChildExpression(); |
| 45 |
} |
| 46 |
|
| 47 |
public void setPredicate(Expression predicate) { |
| 48 |
predicateOp.setChildExpression(predicate); |
| 49 |
} |
| 50 |
|
| 51 |
public WhereClause copy(FLWORExpression flwor, RebindingMap rebindings) { |
| 52 |
WhereClause w2 = new WhereClause(flwor, getPredicate().copy(rebindings)); |
| 53 |
w2.setLocation(getLocation()); |
| 54 |
w2.setPackageData(getPackageData()); |
| 55 |
return w2; |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
@Override |
| 62 |
public void typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { |
| 63 |
super.typeCheck(visitor, contextInfo); |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
@Override |
| 76 |
public TuplePull getPullStream(TuplePull base, XPathContext context) { |
| 77 |
return new WhereClausePull(base, getPredicate()); |
| 78 |
} |
| 79 |
|
| 80 |
@Override |
| 81 |
public void gatherVariableReferences(final ExpressionVisitor visitor, Binding binding, List<VariableReference> references) { |
| 82 |
ExpressionTool.gatherVariableReferences(getPredicate(), binding, references); |
| 83 |
} |
| 84 |
|
| 85 |
@Override |
| 86 |
public void refineVariableType(ExpressionVisitor visitor, List<VariableReference> references, Expression returnExpr) { |
| 87 |
final ItemType actualItemType = getPredicate().getItemType(); |
| 88 |
for (VariableReference ref : references) { |
| 89 |
ref.refineVariableType(actualItemType, getPredicate().getCardinality(), |
| 90 |
getPredicate() instanceof Literal ? ((Literal) getPredicate()).getValue() : null, |
| 91 |
getPredicate().getSpecialProperties()); |
| 92 |
ExpressionTool.resetStaticProperties(returnExpr); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
@Override |
| 106 |
public TuplePush getPushStream(TuplePush destination, XPathContext context) { |
| 107 |
return new WhereClausePush(destination, getPredicate()); |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
@Override |
| 116 |
public void processOperands(OperandProcessor processor) throws XPathException { |
| 117 |
processor.processOperand(predicateOp); |
| 118 |
} |
| 119 |
|
| 120 |
@Override |
| 121 |
public void addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet) { |
| 122 |
getPredicate().addToPathMap(pathMap, pathMapNodeSet); |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
@Override |
| 132 |
public void explain(ExpressionPresenter out) throws XPathException { |
| 133 |
out.startElement("where"); |
| 134 |
getPredicate().export(out); |
| 135 |
out.endElement(); |
| 136 |
} |
| 137 |
|
| 138 |
public String toShortString() { |
| 139 |
FastStringBuffer fsb = new FastStringBuffer(FastStringBuffer.C64); |
| 140 |
fsb.append("where "); |
| 141 |
fsb.append(getPredicate().toShortString()); |
| 142 |
return fsb.toString(); |
| 143 |
} |
| 144 |
|
| 145 |
public String toString() { |
| 146 |
FastStringBuffer fsb = new FastStringBuffer(FastStringBuffer.C64); |
| 147 |
fsb.append("where "); |
| 148 |
fsb.append(getPredicate().toString()); |
| 149 |
return fsb.toString(); |
| 150 |
} |
| 151 |
} |
| 152 |
|