001: package net.sf.saxon.instruct;
002:
003: import net.sf.saxon.om.NamespaceResolver;
004: import net.sf.saxon.trace.InstructionInfo;
005: import net.sf.saxon.trace.InstructionInfoProvider;
006: import net.sf.saxon.trace.Location;
007:
008: import java.io.Serializable;
009: import java.util.HashMap;
010: import java.util.Iterator;
011:
012: /**
013: * Details about an instruction, used when reporting errors and when tracing
014: */
015:
016: public final class InstructionDetails implements InstructionInfo,
017: InstructionInfoProvider, Serializable {
018:
019: private int constructType = Location.UNCLASSIFIED;
020: private String systemId = null;
021: private int lineNumber = -1;
022: private int columnNumber = -1;
023: private int objectNameCode = -1;
024: private NamespaceResolver namespaceResolver;
025: private HashMap properties = new HashMap(5);
026:
027: public InstructionDetails() {
028: }
029:
030: /**
031: * Set the type of construct
032: */
033:
034: public void setConstructType(int type) {
035: constructType = type;
036: }
037:
038: /**
039: * Get the construct type
040: */
041: public int getConstructType() {
042: return constructType;
043: }
044:
045: /**
046: * Set the namespace context for the instruction being traced. This is needed if the
047: * tracelistener wants to evaluate XPath expressions in the context of the current instruction
048: */
049:
050: public void setNamespaceResolver(NamespaceResolver resolver) {
051: namespaceResolver = resolver;
052: }
053:
054: /**
055: * Get the namespace resolver to supply the namespace context of the instruction
056: * that is being traced
057: */
058:
059: public NamespaceResolver getNamespaceResolver() {
060: return namespaceResolver;
061: }
062:
063: /**
064: * Set the URI of the module containing the instruction
065: * @param systemId the module's URI
066: */
067:
068: public void setSystemId(String systemId) {
069: this .systemId = systemId;
070: }
071:
072: /**
073: * Get the URI of the module containing the instruction
074: * @return the module's URI
075: */
076:
077: public String getSystemId() {
078: return systemId;
079: }
080:
081: /**
082: * Set the line number of the instruction within the module
083: * @param lineNumber the line number
084: */
085:
086: public void setLineNumber(int lineNumber) {
087: this .lineNumber = lineNumber;
088: }
089:
090: /**
091: * Get the line number of the instruction within its module
092: * @return the line number
093: */
094:
095: public int getLineNumber() {
096: return lineNumber;
097: }
098:
099: /**
100: * Set a name identifying the object of the expression, for example a function name, template name,
101: * variable name, key name, element name, etc. This is used only where the name is known statically.
102: */
103:
104: public void setObjectNameCode(int nameCode) {
105: objectNameCode = nameCode;
106: }
107:
108: /**
109: * Get a name identifying the object of the expression, for example a function name, template name,
110: * variable name, key name, element name, etc. This is used only where the name is known statically.
111: */
112:
113: public int getObjectNameCode() {
114: return objectNameCode;
115: }
116:
117: /**
118: * Set a named property of the instruction
119: */
120:
121: public void setProperty(String name, Object value) {
122: properties.put(name, value);
123: }
124:
125: /**
126: * Get a named property of the instruction
127: */
128:
129: public Object getProperty(String name) {
130: return properties.get(name);
131: }
132:
133: /**
134: * Get an iterator over all the properties available. The values returned by the iterator
135: * will be of type String, and each string can be supplied as input to the getProperty()
136: * method to retrieve the value of the property.
137: */
138:
139: public Iterator getProperties() {
140: return properties.keySet().iterator();
141: }
142:
143: /**
144: * Get the public ID of the module containing the instruction. This method
145: * is provided to satisfy the SourceLocator interface. However, the public ID is
146: * not maintained by Saxon, and the method always returns null
147: * @return null
148: */
149:
150: public String getPublicId() {
151: return null;
152: }
153:
154: /**
155: * Set the column number
156: */
157:
158: public void setColumnNumber(int column) {
159: columnNumber = column;
160: }
161:
162: /**
163: * Get the column number identifying the position of the instruction.
164: * @return -1 if column number is not known
165: */
166:
167: public int getColumnNumber() {
168: return columnNumber;
169: }
170:
171: /**
172: * Get a description of the instruction
173: */
174:
175: // public String getDescription(NamePool pool) {
176: // switch (constructType) {
177: // case Location.INSTRUCTION:
178: // return pool.getDisplayName(instructionNameCode);
179: // case Location.LITERAL_RESULT_ELEMENT:
180: // return "element constructor <" + pool.getDisplayName(objectNameCode) + ">";
181: // case Location.LITERAL_RESULT_ATTRIBUTE:
182: // return "attribute constructor " + pool.getDisplayName(objectNameCode) + "=\"{...}\"";
183: // default:
184: // return "" + constructType;
185: // }
186: // }
187: /**
188: * Get the InstructionInfo details about the construct. This is to satisfy the InstructionInfoProvider
189: * interface.
190: */
191:
192: public InstructionInfo getInstructionInfo() {
193: return this ;
194: }
195:
196: public String getSystemId(int locationId) {
197: return getSystemId();
198: }
199:
200: public int getLineNumber(int locationId) {
201: return getLineNumber();
202: }
203: }
204:
205: //
206: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
207: // you may not use this file except in compliance with the License. You may obtain a copy of the
208: // License at http://www.mozilla.org/MPL/
209: //
210: // Software distributed under the License is distributed on an "AS IS" basis,
211: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
212: // See the License for the specific language governing rights and limitations under the License.
213: //
214: // The Original Code is: all this file.
215: //
216: // The Initial Developer of the Original Code is Michael H. Kay.
217: //
218: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
219: //
220: // Contributor(s):
221: // Portions marked "e.g." are from Edwin Glaser (edwin@pannenleiter.de)
222: //
|