KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > instruct > TraceExpression


1 package net.sf.saxon.instruct;
2
3 import net.sf.saxon.expr.Expression;
4 import net.sf.saxon.om.NamespaceResolver;
5 import net.sf.saxon.trace.InstructionInfo;
6
7 import java.util.HashMap JavaDoc;
8 import java.util.Iterator JavaDoc;
9
10 /**
11  * A subclass of TraceWrapper used to trace expressions in XPath and XQuery. Unlike
12  * the TraceInstruction class, this class contains all information needed for tracing,
13  * rather than referencing a separate InstructionDetails object.
14  */

15
16 // This class is used for tracing
17
// within XPath/XQuery expressions. The TraceExpression itself holds all the information
18
// about the source needing to be traced (the InstructionInfo).
19

20 public class TraceExpression extends TraceWrapper implements InstructionInfo {
21
22     private int lineNumber = -1;
23     private int columnNumber = -1;
24     private String JavaDoc systemId = null;
25     private int objectNameCode = -1;
26     private int constructType;
27     private NamespaceResolver namespaceResolver = null;
28     private HashMap JavaDoc properties = new HashMap JavaDoc(10);
29
30     /**
31      * Create a trace expression that traces execution of a given child expression
32      * @param child the expression to be traced. This will be available to the TraceListener
33      * as the value of the "expression" property of the InstructionInfo.
34      */

35     public TraceExpression(Expression child) {
36         this.child = child;
37         setProperty("expression", child);
38     }
39
40     /**
41      * Set the line number of the expression being traced
42      * @param line
43      */

44     public void setLineNumber(int line) {
45         lineNumber = line;
46     }
47
48     /**
49      * Set the column number of the expression being traced
50      * @param column
51      */

52     public void setColumnNumber(int column) {
53         columnNumber = column;
54     }
55
56     /**
57      * Set the type of construct. This will generally be a constant
58      * in class {@link net.sf.saxon.trace.Location}
59      */

60
61     public void setConstructType(int type) {
62         constructType = type;
63     }
64
65     /**
66      * Get the construct type. This will generally be a constant
67      * in class {@link net.sf.saxon.trace.Location}
68      */

69     public int getConstructType() {
70         return constructType;
71     }
72
73     /**
74      * Set the namespace context for the instruction being traced. This is needed if the
75      * tracelistener wants to evaluate XPath expressions in the context of the current instruction
76      */

77
78     public void setNamespaceResolver(NamespaceResolver resolver) {
79         namespaceResolver = resolver;
80     }
81
82     /**
83      * Get the namespace resolver to supply the namespace context of the instruction
84      * that is being traced
85      */

86
87     public NamespaceResolver getNamespaceResolver() {
88         return namespaceResolver;
89     }
90
91     /**
92     * Set the URI of the module containing the instruction
93     * @param systemId the module's URI
94     */

95
96     public void setSystemId(String JavaDoc systemId) {
97         this.systemId = systemId;
98     }
99
100     /**
101     * Get the URI of the module containing the instruction
102     * @return the module's URI
103     */

104
105     public String JavaDoc getSystemId() {
106         return systemId;
107     }
108
109     /**
110     * Get the line number of the instruction within its module
111     * @return the line number
112     */

113
114     public int getLineNumber() {
115         return lineNumber;
116     }
117
118     /**
119      * Set a name identifying the object of the expression, for example a function name, template name,
120      * variable name, key name, element name, etc. This is used only where the name is known statically.
121      */

122
123     public void setObjectNameCode(int nameCode) {
124         objectNameCode = nameCode;
125     }
126
127     /**
128      * Get a name identifying the object of the expression, for example a function name, template name,
129      * variable name, key name, element name, etc. This is used only where the name is known statically.
130      */

131
132     public int getObjectNameCode() {
133         return objectNameCode;
134     }
135
136     /**
137      * Set a named property of the instruction/expression
138      */

139
140     public void setProperty(String JavaDoc name, Object JavaDoc value) {
141         properties.put(name, value);
142     }
143
144     /**
145      * Get a named property of the instruction/expression
146      */

147
148     public Object JavaDoc getProperty(String JavaDoc name) {
149         return properties.get(name);
150     }
151
152     /**
153      * Get an iterator over all the properties available. The values returned by the iterator
154      * will be of type String, and each string can be supplied as input to the getProperty()
155      * method to retrieve the value of the property.
156      */

157
158     public Iterator JavaDoc getProperties() {
159         return properties.keySet().iterator();
160     }
161
162
163     /**
164     * Get the column number identifying the position of the instruction. This method
165     * is provided to satisfy the SourceLocator interface. However, the column number is
166     * not maintained by Saxon, and the method always returns -1
167     * @return -1
168     */

169
170     public int getColumnNumber() {
171         return columnNumber;
172     }
173
174      /**
175      * Get the InstructionInfo details about the construct. This is to satisfy the InstructionInfoProvider
176      * interface.
177      */

178
179     public InstructionInfo getInstructionInfo() {
180         return this;
181     }
182
183     /**
184      * Get the system identifier (that is the base URI) of the static context of the expression being
185      * traced. This returns the same result as getSystemId(), it is provided to satisfy the
186      * {@link net.sf.saxon.event.LocationProvider} interface.
187      * @param locationId not used
188      * @return the URI of the module containing the expression
189      */

190     public String JavaDoc getSystemId(int locationId) {
191         return getSystemId();
192     }
193      /**
194      * Get the line number of the expression being
195      * traced. This returns the same result as getLineNumber(), it is provided to satisfy the
196      * {@link net.sf.saxon.event.LocationProvider} interface.
197      * @param locationId not used
198      * @return the line number of the expression within its module
199      */

200
201     public int getLineNumber(int locationId) {
202         return getLineNumber();
203     }
204 }
205
206 //
207
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
208
// you may not use this file except in compliance with the License. You may obtain a copy of the
209
// License at http://www.mozilla.org/MPL/
210
//
211
// Software distributed under the License is distributed on an "AS IS" basis,
212
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
213
// See the License for the specific language governing rights and limitations under the License.
214
//
215
// The Original Code is: all this file.
216
//
217
// The Initial Developer of the Original Code is Michael H. Kay
218
//
219
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
220
//
221
// Contributor(s): none.
222
//
223

224
Popular Tags