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