Debian Codegraph @

net/sf/saxon/expr/flwor/ForClausePush.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.expr.flwor;
9
10 import net.sf.saxon.expr.XPathContext;
11 import net.sf.saxon.om.Item;
12 import net.sf.saxon.om.SequenceIterator;
13 import net.sf.saxon.trans.XPathException;
14 import net.sf.saxon.value.Int64Value;
15
16 /**
17 * This class implements the changes to the tuple stream effected by a "for" clause in a FLWOR expression
18 */
19 public class ForClausePush extends TuplePush {
20
21 protected TuplePush destination;
22 protected ForClause forClause;
23
24 public ForClausePush(TuplePush destination, ForClause forClause) {
25 this.destination = destination;
26 this.forClause = forClause;
27 }
28
29 /*
30 * Process the next tuple.
31 */
32 @Override
33 public void processTuple(XPathContext context) throws XPathException {
34 SequenceIterator iter = forClause.getSequence().iterate(context);
35 int pos = 0;
36 Item next;
37 while ((next = iter.next()) != null) {
38 context.setLocalVariable(forClause.getRangeVariable().getLocalSlotNumber(), next);
39 if (forClause.getPositionVariable() != null) {
40 context.setLocalVariable(
41 forClause.getPositionVariable().getLocalSlotNumber(),
42 new Int64Value(++pos));
43 }
44 destination.processTuple(context);
45 }
46 }
47
48 /*
49 * Close the tuple stream
50 */
51 @Override
52 public void close() throws XPathException {
53 destination.close();
54 }
55 }
56