| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.expr.flwor; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.XPathContext; |
| 11 |
import net.sf.saxon.expr.parser.PathMap; |
| 12 |
import net.sf.saxon.expr.parser.RebindingMap; |
| 13 |
import net.sf.saxon.trace.ExpressionPresenter; |
| 14 |
import net.sf.saxon.trans.XPathException; |
| 15 |
import net.sf.saxon.tree.util.FastStringBuffer; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
public class CountClause extends Clause { |
| 21 |
|
| 22 |
private LocalVariableBinding rangeVariable; |
| 23 |
|
| 24 |
@Override |
| 25 |
public int getClauseKey() { |
| 26 |
return COUNT; |
| 27 |
} |
| 28 |
|
| 29 |
public CountClause copy(FLWORExpression flwor, RebindingMap rebindings) { |
| 30 |
CountClause c2 = new CountClause(); |
| 31 |
c2.rangeVariable = rangeVariable.copy(); |
| 32 |
c2.setPackageData(getPackageData()); |
| 33 |
c2.setLocation(getLocation()); |
| 34 |
return c2; |
| 35 |
} |
| 36 |
|
| 37 |
public void setRangeVariable(LocalVariableBinding binding) { |
| 38 |
this.rangeVariable = binding; |
| 39 |
} |
| 40 |
|
| 41 |
public LocalVariableBinding getRangeVariable() { |
| 42 |
return rangeVariable; |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
@Override |
| 51 |
public LocalVariableBinding[] getRangeVariables() { |
| 52 |
return new LocalVariableBinding[]{rangeVariable}; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
@Override |
| 65 |
public TuplePull getPullStream(TuplePull base, XPathContext context) { |
| 66 |
return new CountClausePull(base, this); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
@Override |
| 79 |
public TuplePush getPushStream(TuplePush destination, XPathContext context) { |
| 80 |
return new CountClausePush(destination, this); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
@Override |
| 89 |
public void processOperands(OperandProcessor processor) throws XPathException { |
| 90 |
|
| 91 |
} |
| 92 |
|
| 93 |
@Override |
| 94 |
public void addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet) { |
| 95 |
|
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
@Override |
| 105 |
public void explain(ExpressionPresenter out) throws XPathException { |
| 106 |
out.startElement("count"); |
| 107 |
out.emitAttribute("var", getRangeVariable().getVariableQName()); |
| 108 |
out.endElement(); |
| 109 |
} |
| 110 |
|
| 111 |
public String toString() { |
| 112 |
FastStringBuffer fsb = new FastStringBuffer(FastStringBuffer.C64); |
| 113 |
fsb.append("count $"); |
| 114 |
fsb.append(rangeVariable.getVariableQName().getDisplayName()); |
| 115 |
return fsb.toString(); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|