1 package org.codehaus.xfire; 2 3 import java.io.PrintStream; 4 import java.io.PrintWriter; 5 6 /*** 7 * Used for internal XFire exceptions when a fault shouldn't be returned to the service invoker. 8 * 9 * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a> 10 * @since Feb 14, 2004 11 */ 12 public class XFireRuntimeException 13 extends RuntimeException 14 { 15 private Throwable cause; 16 private String message; 17 18 /*** 19 * Constructs a new xfire runtime exception with the specified detail message. 20 * 21 * @param message the detail message. 22 */ 23 public XFireRuntimeException(String message) 24 { 25 super(message); 26 this.message = message; 27 } 28 29 /*** 30 * Constructs a new xfire runtime exception with the specified detail message and cause. 31 * 32 * @param message the detail message. 33 * @param cause the cause. 34 */ 35 public XFireRuntimeException(String message, Throwable cause) 36 { 37 super(message); 38 this.message = message; 39 this.cause = cause; 40 } 41 42 43 /*** 44 * Returns the cause of this throwable or <code>null</code> if the cause is nonexistent or unknown. 45 * 46 * @return the nested cause. 47 */ 48 public Throwable getCause() 49 { 50 return (this.cause == this ? null : this.cause); 51 } 52 53 /*** 54 * Return the detail message, including the message from the {@link #getCause() nested exception} if there is one. 55 * 56 * @return the detail message. 57 */ 58 public String getMessage() 59 { 60 if (this.cause == null || this.cause == this) 61 { 62 return message; 63 } 64 else 65 { 66 return message + ". Nested exception is " + this.cause.getClass().getName() + 67 ": " + this.cause.getMessage(); 68 } 69 } 70 71 public String getActualMessage() 72 { 73 return message; 74 } 75 76 /*** 77 * Prints this throwable and its backtrace to the specified print stream. 78 * 79 * @param s <code>PrintStream</code> to use for output 80 */ 81 public void printStackTrace(PrintStream s) 82 { 83 if (this.cause == null || this.cause == this) 84 { 85 super.printStackTrace(s); 86 } 87 else 88 { 89 s.println(this); 90 this.cause.printStackTrace(s); 91 } 92 } 93 94 /*** 95 * Prints this throwable and its backtrace to the specified print writer. 96 * 97 * @param w <code>PrintWriter</code> to use for output 98 */ 99 public void printStackTrace(PrintWriter w) 100 { 101 if (this.cause == null || this.cause == this) 102 { 103 super.printStackTrace(w); 104 } 105 else 106 { 107 w.println(this); 108 this.cause.printStackTrace(w); 109 } 110 } 111 112 public void prepend(String message) 113 { 114 if(this.message != null) 115 { 116 this.message = message + ": " + this.message; 117 } 118 else 119 { 120 this.message = message; 121 } 122 } 123 124 public void setMessage(String s) 125 { 126 message = s; 127 } 128 }