| 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.om.FocusIterator; |
| 12 |
import net.sf.saxon.om.FocusTrackingIterator; |
| 13 |
import net.sf.saxon.om.Item; |
| 14 |
import net.sf.saxon.trans.XPathException; |
| 15 |
import net.sf.saxon.value.Int64Value; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
public class ForClausePull extends TuplePull { |
| 21 |
|
| 22 |
protected TuplePull base; |
| 23 |
protected ForClause forClause; |
| 24 |
protected FocusIterator currentIteration; |
| 25 |
|
| 26 |
|
| 27 |
public ForClausePull(TuplePull base, ForClause forClause) { |
| 28 |
this.base = base; |
| 29 |
this.forClause = forClause; |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
@Override |
| 42 |
public boolean nextTuple(XPathContext context) throws XPathException { |
| 43 |
while (true) { |
| 44 |
if (currentIteration == null) { |
| 45 |
if (!base.nextTuple(context)) { |
| 46 |
return false; |
| 47 |
} |
| 48 |
currentIteration = new FocusTrackingIterator(forClause.getSequence().iterate(context)); |
| 49 |
} |
| 50 |
Item next = currentIteration.next(); |
| 51 |
if (next != null) { |
| 52 |
context.setLocalVariable(forClause.getRangeVariable().getLocalSlotNumber(), next); |
| 53 |
if (forClause.getPositionVariable() != null) { |
| 54 |
context.setLocalVariable( |
| 55 |
forClause.getPositionVariable().getLocalSlotNumber(), |
| 56 |
new Int64Value(currentIteration.position())); |
| 57 |
} |
| 58 |
return true; |
| 59 |
} else { |
| 60 |
currentIteration = null; |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
@Override |
| 70 |
public void close() { |
| 71 |
base.close(); |
| 72 |
if (currentIteration != null) { |
| 73 |
currentIteration.close(); |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
|