1 16 19 package com.sun.org.apache.xml.internal.dtm; 20 21 22 import java.lang.reflect.InvocationTargetException ; 23 import java.lang.reflect.Method ; 24 25 import javax.xml.transform.SourceLocator ; 26 27 import com.sun.org.apache.xml.internal.res.XMLErrorResources; 28 import com.sun.org.apache.xml.internal.res.XMLMessages; 29 30 31 35 public class DTMException extends RuntimeException { 36 37 39 SourceLocator locator; 40 41 47 public SourceLocator getLocator() { 48 return locator; 49 } 50 51 57 public void setLocator(SourceLocator location) { 58 locator = location; 59 } 60 61 63 Throwable containedException; 64 65 71 public Throwable getException() { 72 return containedException; 73 } 74 75 80 public Throwable getCause() { 81 82 return ((containedException == this) 83 ? null 84 : containedException); 85 } 86 87 111 public synchronized Throwable initCause(Throwable cause) { 112 113 if ((this.containedException == null) && (cause != null)) { 114 throw new IllegalStateException (XMLMessages.createXMLMessage(XMLErrorResources.ER_CANNOT_OVERWRITE_CAUSE, null)); } 116 117 if (cause == this) { 118 throw new IllegalArgumentException ( 119 XMLMessages.createXMLMessage(XMLErrorResources.ER_SELF_CAUSATION_NOT_PERMITTED, null)); } 121 122 this.containedException = cause; 123 124 return this; 125 } 126 127 132 public DTMException(String message) { 133 134 super(message); 135 136 this.containedException = null; 137 this.locator = null; 138 } 139 140 145 public DTMException(Throwable e) { 146 147 super(e.getMessage()); 148 149 this.containedException = e; 150 this.locator = null; 151 } 152 153 163 public DTMException(String message, Throwable e) { 164 165 super(((message == null) || (message.length() == 0)) 166 ? e.getMessage() 167 : message); 168 169 this.containedException = e; 170 this.locator = null; 171 } 172 173 183 public DTMException(String message, SourceLocator locator) { 184 185 super(message); 186 187 this.containedException = null; 188 this.locator = locator; 189 } 190 191 199 public DTMException(String message, SourceLocator locator, 200 Throwable e) { 201 202 super(message); 203 204 this.containedException = e; 205 this.locator = locator; 206 } 207 208 212 public String getMessageAndLocation() { 213 214 StringBuffer sbuffer = new StringBuffer (); 215 String message = super.getMessage(); 216 217 if (null != message) { 218 sbuffer.append(message); 219 } 220 221 if (null != locator) { 222 String systemID = locator.getSystemId(); 223 int line = locator.getLineNumber(); 224 int column = locator.getColumnNumber(); 225 226 if (null != systemID) { 227 sbuffer.append("; SystemID: "); 228 sbuffer.append(systemID); 229 } 230 231 if (0 != line) { 232 sbuffer.append("; Line#: "); 233 sbuffer.append(line); 234 } 235 236 if (0 != column) { 237 sbuffer.append("; Column#: "); 238 sbuffer.append(column); 239 } 240 } 241 242 return sbuffer.toString(); 243 } 244 245 251 public String getLocationAsString() { 252 253 if (null != locator) { 254 StringBuffer sbuffer = new StringBuffer (); 255 String systemID = locator.getSystemId(); 256 int line = locator.getLineNumber(); 257 int column = locator.getColumnNumber(); 258 259 if (null != systemID) { 260 sbuffer.append("; SystemID: "); 261 sbuffer.append(systemID); 262 } 263 264 if (0 != line) { 265 sbuffer.append("; Line#: "); 266 sbuffer.append(line); 267 } 268 269 if (0 != column) { 270 sbuffer.append("; Column#: "); 271 sbuffer.append(column); 272 } 273 274 return sbuffer.toString(); 275 } else { 276 return null; 277 } 278 } 279 280 285 public void printStackTrace() { 286 printStackTrace(new java.io.PrintWriter (System.err, true)); 287 } 288 289 295 public void printStackTrace(java.io.PrintStream s) { 296 printStackTrace(new java.io.PrintWriter (s)); 297 } 298 299 305 public void printStackTrace(java.io.PrintWriter s) { 306 307 if (s == null) { 308 s = new java.io.PrintWriter (System.err, true); 309 } 310 311 try { 312 String locInfo = getLocationAsString(); 313 314 if (null != locInfo) { 315 s.println(locInfo); 316 } 317 318 super.printStackTrace(s); 319 } catch (Throwable e) {} 320 321 Throwable exception = getException(); 322 323 for (int i = 0; (i < 10) && (null != exception); i++) { 324 s.println("---------"); 325 326 try { 327 if (exception instanceof DTMException) { 328 String locInfo = 329 ((DTMException) exception) 330 .getLocationAsString(); 331 332 if (null != locInfo) { 333 s.println(locInfo); 334 } 335 } 336 337 exception.printStackTrace(s); 338 } catch (Throwable e) { 339 s.println("Could not print stack trace..."); 340 } 341 342 try { 343 Method meth = 344 ((Object ) exception).getClass().getMethod("getException", 345 null); 346 347 if (null != meth) { 348 Throwable prev = exception; 349 350 exception = (Throwable ) meth.invoke(exception, null); 351 352 if (prev == exception) { 353 break; 354 } 355 } else { 356 exception = null; 357 } 358 } catch (InvocationTargetException ite) { 359 exception = null; 360 } catch (IllegalAccessException iae) { 361 exception = null; 362 } catch (NoSuchMethodException nsme) { 363 exception = null; 364 } 365 } 366 } 367 } 368 | Popular Tags |