1 22 package org.jboss.mq; 23 24 import java.io.PrintWriter ; 25 import java.io.PrintStream ; 26 27 import javax.jms.JMSException ; 28 29 import org.jboss.util.NestedThrowable; 30 import org.jboss.util.NestedException; 31 32 40 public class SpyJMSException extends JMSException implements NestedThrowable 41 { 42 43 static final long serialVersionUID = 5216406958161784593L; 44 45 46 protected Throwable nested; 47 48 55 public static void rethrowAsJMSException(String message, Throwable t) throws JMSException 56 { 57 throw getAsJMSException(message, t); 58 } 59 60 67 public static JMSException getAsJMSException(String message, Throwable t) 68 { 69 if (t instanceof JMSException ) 70 return (JMSException ) t; 71 else 72 return new SpyJMSException(message, t); 73 } 74 75 80 public SpyJMSException(final String msg) 81 { 82 super(msg); 83 this.nested = null; 84 } 85 86 93 public SpyJMSException(final String msg, final String code) 94 { 95 super(msg, code); 96 this.nested = null; 97 } 98 99 106 public SpyJMSException(final String msg, final Throwable nested) 107 { 108 super(msg); 109 this.nested = nested; 110 NestedThrowable.Util.checkNested(this, nested); 111 } 112 113 118 public SpyJMSException(final Throwable nested) 119 { 120 this(nested.getMessage(), nested); 121 } 122 123 public void setLinkedException(final Exception e) 124 { 125 this.nested = e; 126 } 127 128 public Exception getLinkedException() 129 { 130 if (nested == null) 133 return this; 134 if (nested instanceof Exception ) 135 return (Exception ) nested; 136 return new NestedException(nested); 137 } 138 139 public Throwable getNested() 140 { 141 return nested; 142 } 143 144 public Throwable getCause() 145 { 146 return nested; 147 } 148 149 public String getMessage() 150 { 151 return NestedThrowable.Util.getMessage(super.getMessage(), nested); 152 } 153 154 public void printStackTrace(final PrintStream stream) 155 { 156 if (nested == null || NestedThrowable.PARENT_TRACE_ENABLED) 157 super.printStackTrace(stream); 158 NestedThrowable.Util.print(nested, stream); 159 } 160 161 public void printStackTrace(final PrintWriter writer) 162 { 163 if (nested == null || NestedThrowable.PARENT_TRACE_ENABLED) 164 super.printStackTrace(writer); 165 NestedThrowable.Util.print(nested, writer); 166 } 167 168 public void printStackTrace() 169 { 170 printStackTrace(System.err); 171 } 172 } | Popular Tags |