| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.functions; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.Callable; |
| 11 |
import net.sf.saxon.expr.Expression; |
| 12 |
import net.sf.saxon.expr.SystemFunctionCall; |
| 13 |
import net.sf.saxon.expr.XPathContext; |
| 14 |
import net.sf.saxon.expr.sort.GroupIterator; |
| 15 |
import net.sf.saxon.expr.sort.MergeInstr; |
| 16 |
import net.sf.saxon.om.Sequence; |
| 17 |
import net.sf.saxon.om.SequenceIterator; |
| 18 |
import net.sf.saxon.om.SequenceTool; |
| 19 |
import net.sf.saxon.trans.XPathException; |
| 20 |
import net.sf.saxon.value.AtomicValue; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public class CurrentMergeKey extends SystemFunction implements Callable { |
| 28 |
|
| 29 |
private MergeInstr controllingInstruction = null; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public void setControllingInstruction(MergeInstr instruction) { |
| 38 |
this.controllingInstruction = instruction; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public MergeInstr getControllingInstruction() { |
| 48 |
return controllingInstruction; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
@Override |
| 61 |
public Expression makeFunctionCall(Expression... arguments) { |
| 62 |
return new SystemFunctionCall(this, arguments) { |
| 63 |
@Override |
| 64 |
public Expression getScopingExpression() { |
| 65 |
return getControllingInstruction(); |
| 66 |
} |
| 67 |
}; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public SequenceIterator<AtomicValue> iterate(XPathContext c) throws XPathException { |
| 77 |
GroupIterator gi = c.getCurrentMergeGroupIterator(); |
| 78 |
if (gi == null) { |
| 79 |
throw new XPathException("There is no current merge key", "XTDE3510"); |
| 80 |
} |
| 81 |
return gi.getCurrentGroupingKey().iterate(); |
| 82 |
|
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
public Sequence<AtomicValue> call(XPathContext context, Sequence[] arguments) throws XPathException { |
| 95 |
return SequenceTool.toLazySequence(iterate(context)); |
| 96 |
} |
| 97 |
|
| 98 |
} |
| 99 |
|
| 100 |
|