Debian Codegraph @

net/sf/saxon/expr/flwor/TraceClausePull.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.Controller;
11 import net.sf.saxon.expr.XPathContext;
12 import net.sf.saxon.trans.XPathException;
13
14 /**
15 * This class represents the tuple stream delivered as the output of a trace clause in a
16 * FLWOR expression. It does not change the values of any variables in the tuple stream,
17 * but merely informs the TraceListener whenever a new tuple is requested.
18 */
19 public class TraceClausePull extends TuplePull {
20
21 private TuplePull base;
22 private Clause baseClause;
23 private TraceClause traceClause;
24
25 public TraceClausePull(TuplePull base, TraceClause traceClause, Clause baseClause) {
26 this.base = base;
27 this.traceClause = traceClause;
28 this.baseClause = baseClause;
29 }
30
31 /**
32 * Move on to the next tuple. Before returning, this method must set all the variables corresponding
33 * to the "returned" tuple in the local stack frame associated with the context object
34 *
35 * @param context the dynamic evaluation context
36 * @return true if another tuple has been generated; false if the tuple stream is exhausted. If the
37 * method returns false, the values of the local variables corresponding to this tuple stream
38 * are undefined.
39 */
40 @Override
41 public boolean nextTuple(XPathContext context) throws XPathException {
42 Controller controller = context.getController();
43 if (controller.isTracing()) {
44 ClauseInfo baseInfo = new ClauseInfo(baseClause);
45 baseInfo.setNamespaceResolver(traceClause.getNamespaceResolver());
46 controller.getTraceListener().enter(baseInfo, context);
47 boolean b = base.nextTuple(context);
48 controller.getTraceListener().leave(baseInfo);
49 return b;
50 } else {
51 return base.nextTuple(context);
52 }
53
54 }
55
56 /**
57 * Close the tuple stream, indicating that although not all tuples have been read,
58 * no further tuples are required and resources can be released
59 */
60 @Override
61 public void close() {
62 base.close();
63 }
64 }
65