1:
37:
38: package ;
39:
40: import ;
41:
42: import ;
43: import ;
44:
45:
50: public class TransformerException
51: extends Exception
52: {
53: private static final long serialVersionUID = 975798773772956428L;
54:
55:
56: private SourceLocator locator;
57: private Throwable containedException;
58:
59:
62: public TransformerException(String msg)
63: {
64: this(msg, null, null);
65: }
66:
67:
70: public TransformerException(Throwable cause)
71: {
72: this(cause.getMessage(), null, cause);
73: }
74:
75:
78: public TransformerException(String msg, Throwable cause)
79: {
80: this(msg, null, cause);
81: }
82:
83:
86: public TransformerException(String msg, SourceLocator locator)
87: {
88: this(msg, locator, null);
89: }
90:
91:
94: public TransformerException(String msg, SourceLocator locator,
95: Throwable cause)
96: {
97: super(msg);
98: this.locator = locator;
99: if (cause != null)
100: {
101: initCause(cause);
102: this.containedException = cause;
103: }
104: }
105:
106:
109: public SourceLocator getLocator()
110: {
111: return locator;
112: }
113:
114:
117: public void setLocator(SourceLocator location)
118: {
119: locator = location;
120: }
121:
122:
125: public Throwable getException()
126: {
127: return containedException;
128: }
129:
130:
133: public Throwable getCause()
134: {
135: return containedException;
136: }
137:
138:
149: public Throwable initCause(Throwable cause)
150: {
151: if (this.containedException != null)
152: {
153: throw new IllegalStateException();
154: }
155: if (cause == this)
156: {
157: throw new IllegalArgumentException();
158: }
159: this.containedException = cause;
160: return this;
161: }
162:
163:
166: public String getMessageAndLocation()
167: {
168: return (locator == null) ? getMessage() :
169: getMessage() + ": " + getLocationAsString();
170: }
171:
172:
175: public String getLocationAsString()
176: {
177: if (locator == null)
178: {
179: return null;
180: }
181: String publicId = locator.getPublicId();
182: String systemId = locator.getSystemId();
183: int lineNumber = locator.getLineNumber();
184: int columnNumber = locator.getColumnNumber();
185: CPStringBuilder buffer = new CPStringBuilder ();
186: if (publicId != null)
187: {
188: buffer.append ("publicId=");
189: buffer.append (publicId);
190: }
191: if (systemId != null)
192: {
193: if (buffer.length() > 0)
194: {
195: buffer.append(' ');
196: }
197: buffer.append ("systemId=");
198: buffer.append (systemId);
199: }
200: if (lineNumber != -1)
201: {
202: if (buffer.length() > 0)
203: {
204: buffer.append(' ');
205: }
206: buffer.append ("lineNumber=");
207: buffer.append (lineNumber);
208: }
209: if (columnNumber != -1)
210: {
211: if (buffer.length() > 0)
212: {
213: buffer.append(' ');
214: }
215: buffer.append ("columnNumber=");
216: buffer.append (columnNumber);
217: }
218: return buffer.toString();
219: }
220:
221: public void printStackTrace()
222: {
223: printStackTrace(System.out);
224: }
225:
226: public void printStackTrace(PrintStream s)
227: {
228: super.printStackTrace(s);
229: if (containedException != null)
230: {
231: s.print("caused by ");
232: containedException.printStackTrace(s);
233: }
234: }
235:
236: public void printStackTrace(PrintWriter s)
237: {
238: super.printStackTrace(s);
239: if (containedException != null)
240: {
241: s.print("caused by ");
242: containedException.printStackTrace(s);
243: }
244: }
245:
246: }