Debian Codegraph @

net/sf/saxon/expr/flwor/TraceClause.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.expr.parser.PathMap;
12 import net.sf.saxon.expr.parser.RebindingMap;
13 import net.sf.saxon.om.NamespaceResolver;
14 import net.sf.saxon.trace.ExpressionPresenter;
15 import net.sf.saxon.trans.XPathException;
16
17 /**
18 * A "trace" clause in a FLWOR expression, added by a TraceCodeInjector for diagnostic
19 * tracing, debugging, profiling or similar purposes.
20 */
21 public class TraceClause extends Clause {
22
23 private Clause target;
24 private NamespaceResolver nsResolver;
25
26 /**
27 * Create a traceClause
28 *
29 * @param target the clause whose evaluation is being traced
30 */
31
32 public TraceClause(Clause target, NamespaceResolver nsResolver) {
33 this.target = target;
34 this.nsResolver = nsResolver;
35 }
36
37 /**
38 * Get the namespace bindings from the static context of the clause
39 *
40 * @return a namespace resolver that reflects the in scope namespaces of the clause
41 */
42
43 public NamespaceResolver getNamespaceResolver() {
44 return nsResolver;
45 }
46
47 /**
48 * Set the namespace bindings from the static context of the clause
49 *
50 * @param nsResolver a namespace resolver that reflects the in scope namespaces of the clause
51 */
52
53 public void setNamespaceResolver(NamespaceResolver nsResolver) {
54 this.nsResolver = nsResolver;
55 }
56
57
58 @Override
59 public int getClauseKey() {
60 return TRACE;
61 }
62
63 public TraceClause copy(FLWORExpression flwor, RebindingMap rebindings) {
64 return new TraceClause(target, nsResolver);
65 }
66
67 /**
68 * Get a tuple stream that implements the functionality of this clause, taking its
69 * input from another tuple stream which this clause modifies
70 *
71 * @param base the input tuple stream
72 * @param context the dynamic evaluation context
73 * @return the output tuple stream
74 */
75 @Override
76 public TuplePull getPullStream(TuplePull base, XPathContext context) {
77 return new TraceClausePull(base, this, target);
78 }
79
80 /**
81 * Get a push-mode tuple stream that implements the functionality of this clause, supplying its
82 * output to another tuple stream
83 *
84 * @param destination the output tuple stream
85 * @param context the dynamic evaluation context
86 * @return the push tuple stream that implements the functionality of this clause of the FLWOR
87 * expression
88 */
89 @Override
90 public TuplePush getPushStream(TuplePush destination, XPathContext context) {
91 return new TraceClausePush(destination, this, target);
92 }
93
94 /**
95 * Process the subexpressions of this clause
96 *
97 * @param processor the expression processor used to process the subexpressions
98 */
99 @Override
100 public void processOperands(OperandProcessor processor) throws XPathException {
101 }
102
103 @Override
104 public void addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet) {
105 // no action
106 }
107
108 /**
109 * Diagnostic print of expression structure. The abstract expression tree
110 * is written to the supplied output destination.
111 *
112 * @param out the expression presenter used to display the structure
113 */
114 @Override
115 public void explain(ExpressionPresenter out) throws XPathException {
116 out.startElement("trace");
117 out.endElement();
118 }
119
120 public String toString() {
121 return "trace";
122 }
123 }
124