KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.saxon.instruct;
2 import net.sf.saxon.om.NamespaceResolver;
3 import net.sf.saxon.trace.InstructionInfo;
4 import net.sf.saxon.trace.InstructionInfoProvider;
5 import net.sf.saxon.trace.Location;
6
7 import java.io.Serializable JavaDoc;
8 import java.util.HashMap JavaDoc;
9 import java.util.Iterator JavaDoc;
10
11 /**
12 * Details about an instruction, used when reporting errors and when tracing
13 */

14
15 public final class InstructionDetails implements InstructionInfo, InstructionInfoProvider, Serializable JavaDoc {
16
17     private int constructType = Location.UNCLASSIFIED;
18     private String JavaDoc systemId = null;
19     private int lineNumber = -1;
20     private int columnNumber = -1;
21     private int objectNameCode = -1;
22     private NamespaceResolver namespaceResolver;
23     private HashMap JavaDoc properties = new HashMap JavaDoc(5);
24
25     public InstructionDetails() {}
26
27     /**
28      * Set the type of construct
29      */

30
31     public void setConstructType(int type) {
32         constructType = type;
33     }
34
35     /**
36      * Get the construct type
37      */

38     public int getConstructType() {
39         return constructType;
40     }
41
42     /**
43      * Set the namespace context for the instruction being traced. This is needed if the
44      * tracelistener wants to evaluate XPath expressions in the context of the current instruction
45      */

46
47     public void setNamespaceResolver(NamespaceResolver resolver) {
48         namespaceResolver = resolver;
49     }
50
51     /**
52      * Get the namespace resolver to supply the namespace context of the instruction
53      * that is being traced
54      */

55
56     public NamespaceResolver getNamespaceResolver() {
57         return namespaceResolver;
58     }
59
60     /**
61     * Set the URI of the module containing the instruction
62     * @param systemId the module's URI
63     */

64
65     public void setSystemId(String JavaDoc systemId) {
66         this.systemId = systemId;
67     }
68
69     /**
70     * Get the URI of the module containing the instruction
71     * @return the module's URI
72     */

73
74     public String JavaDoc getSystemId() {
75         return systemId;
76     }
77
78     /**
79     * Set the line number of the instruction within the module
80     * @param lineNumber the line number
81     */

82
83     public void setLineNumber(int lineNumber) {
84         this.lineNumber = lineNumber;
85     }
86
87     /**
88     * Get the line number of the instruction within its module
89     * @return the line number
90     */

91
92     public int getLineNumber() {
93         return lineNumber;
94     }
95
96     /**
97      * Set a name identifying the object of the expression, for example a function name, template name,
98      * variable name, key name, element name, etc. This is used only where the name is known statically.
99      */

100
101     public void setObjectNameCode(int nameCode) {
102         objectNameCode = nameCode;
103     }
104
105     /**
106      * Get a name identifying the object of the expression, for example a function name, template name,
107      * variable name, key name, element name, etc. This is used only where the name is known statically.
108      */

109
110     public int getObjectNameCode() {
111         return objectNameCode;
112     }
113
114     /**
115      * Set a named property of the instruction
116      */

117
118     public void setProperty(String JavaDoc name, Object JavaDoc value) {
119         properties.put(name, value);
120     }
121
122     /**
123      * Get a named property of the instruction
124      */

125
126     public Object JavaDoc getProperty(String JavaDoc name) {
127         return properties.get(name);
128     }
129
130     /**
131      * Get an iterator over all the properties available. The values returned by the iterator
132      * will be of type String, and each string can be supplied as input to the getProperty()
133      * method to retrieve the value of the property.
134      */

135
136     public Iterator JavaDoc getProperties() {
137         return properties.keySet().iterator();
138     }
139
140     /**
141     * Get the public ID of the module containing the instruction. This method
142     * is provided to satisfy the SourceLocator interface. However, the public ID is
143     * not maintained by Saxon, and the method always returns null
144     * @return null
145     */

146
147     public String JavaDoc getPublicId() {
148         return null;
149     }
150
151     /**
152      * Set the column number
153      */

154
155     public void setColumnNumber(int column) {
156         columnNumber = column;
157     }
158
159     /**
160     * Get the column number identifying the position of the instruction.
161     * @return -1 if column number is not known
162     */

163
164     public int getColumnNumber() {
165         return columnNumber;
166     }
167
168     /**
169      * Get a description of the instruction
170      */

171
172 // public String getDescription(NamePool pool) {
173
// switch (constructType) {
174
// case Location.INSTRUCTION:
175
// return pool.getDisplayName(instructionNameCode);
176
// case Location.LITERAL_RESULT_ELEMENT:
177
// return "element constructor <" + pool.getDisplayName(objectNameCode) + ">";
178
// case Location.LITERAL_RESULT_ATTRIBUTE:
179
// return "attribute constructor " + pool.getDisplayName(objectNameCode) + "=\"{...}\"";
180
// default:
181
// return "" + constructType;
182
// }
183
// }
184

185     /**
186      * Get the InstructionInfo details about the construct. This is to satisfy the InstructionInfoProvider
187      * interface.
188      */

189
190     public InstructionInfo getInstructionInfo() {
191         return this;
192     }
193
194     public String JavaDoc getSystemId(int locationId) {
195         return getSystemId();
196     }
197
198     public int getLineNumber(int locationId) {
199         return getLineNumber();
200     }
201 }
202
203 //
204
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
205
// you may not use this file except in compliance with the License. You may obtain a copy of the
206
// License at http://www.mozilla.org/MPL/
207
//
208
// Software distributed under the License is distributed on an "AS IS" basis,
209
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
210
// See the License for the specific language governing rights and limitations under the License.
211
//
212
// The Original Code is: all this file.
213
//
214
// The Initial Developer of the Original Code is Michael H. Kay.
215
//
216
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
217
//
218
// Contributor(s):
219
// Portions marked "e.g." are from Edwin Glaser (edwin@pannenleiter.de)
220
//
221
Popular Tags