1:
37: package ;
38:
39: import ;
40: import ;
41:
42:
47: public class TransformerException
48: extends Exception
49: {
50: private static final long serialVersionUID = 975798773772956428L;
51:
52:
53: private SourceLocator locator;
54: private Throwable containedException;
55:
56:
59: public TransformerException(String msg)
60: {
61: this(msg, null, null);
62: }
63:
64:
67: public TransformerException(Throwable cause)
68: {
69: this(cause.getMessage(), null, cause);
70: }
71:
72:
75: public TransformerException(String msg, Throwable cause)
76: {
77: this(msg, null, cause);
78: }
79:
80:
83: public TransformerException(String msg, SourceLocator locator)
84: {
85: this(msg, locator, null);
86: }
87:
88:
91: public TransformerException(String msg, SourceLocator locator,
92: Throwable cause)
93: {
94: super(msg);
95: this.locator = locator;
96: if (cause != null)
97: {
98: initCause(cause);
99: this.containedException = cause;
100: }
101: }
102:
103:
106: public SourceLocator getLocator()
107: {
108: return locator;
109: }
110:
111:
114: public void setLocator(SourceLocator location)
115: {
116: locator = location;
117: }
118:
119:
122: public Throwable getException()
123: {
124: return containedException;
125: }
126:
127:
130: public Throwable getCause()
131: {
132: return containedException;
133: }
134:
135:
146: public Throwable initCause(Throwable cause)
147: {
148: if (this.containedException != null)
149: {
150: throw new IllegalStateException();
151: }
152: if (cause == this)
153: {
154: throw new IllegalArgumentException();
155: }
156: this.containedException = cause;
157: return this;
158: }
159:
160:
163: public String getMessageAndLocation()
164: {
165: return (locator == null) ? getMessage() :
166: getMessage() + ": " + getLocationAsString();
167: }
168:
169:
172: public String getLocationAsString()
173: {
174: if (locator == null)
175: {
176: return null;
177: }
178: String publicId = locator.getPublicId();
179: String systemId = locator.getSystemId();
180: int lineNumber = locator.getLineNumber();
181: int columnNumber = locator.getColumnNumber();
182: StringBuffer buffer = new StringBuffer ();
183: if (publicId != null)
184: {
185: buffer.append ("publicId=");
186: buffer.append (publicId);
187: }
188: if (systemId != null)
189: {
190: if (buffer.length() > 0)
191: {
192: buffer.append(' ');
193: }
194: buffer.append ("systemId=");
195: buffer.append (systemId);
196: }
197: if (lineNumber != -1)
198: {
199: if (buffer.length() > 0)
200: {
201: buffer.append(' ');
202: }
203: buffer.append ("lineNumber=");
204: buffer.append (lineNumber);
205: }
206: if (columnNumber != -1)
207: {
208: if (buffer.length() > 0)
209: {
210: buffer.append(' ');
211: }
212: buffer.append ("columnNumber=");
213: buffer.append (columnNumber);
214: }
215: return buffer.toString();
216: }
217:
218: public void printStackTrace()
219: {
220: printStackTrace(System.out);
221: }
222:
223: public void printStackTrace(PrintStream s)
224: {
225: super.printStackTrace(s);
226: if (containedException != null)
227: {
228: s.print("caused by ");
229: containedException.printStackTrace(s);
230: }
231: }
232:
233: public void printStackTrace(PrintWriter s)
234: {
235: super.printStackTrace(s);
236: if (containedException != null)
237: {
238: s.print("caused by ");
239: containedException.printStackTrace(s);
240: }
241: }
242:
243: }