1 22 package org.jboss.mq; 23 24 import java.io.PrintStream ; 25 import java.io.PrintWriter ; 26 27 import javax.transaction.xa.XAException ; 28 29 import org.jboss.util.NestedException; 30 import org.jboss.util.NestedThrowable; 31 32 38 public class SpyXAException extends XAException implements NestedThrowable 39 { 40 41 static final long serialVersionUID = 7814140228056884098L; 42 43 44 protected Throwable nested; 45 46 54 public static XAException rethrowAsXAException(String message, Throwable t) throws XAException 55 { 56 throw getAsXAException(message, t); 57 } 58 59 66 public static XAException getAsXAException(String message, Throwable t) 67 { 68 if (t instanceof XAException ) 69 return (XAException ) t; 70 else 71 { 72 SpyXAException e = new SpyXAException(message, t); 73 e.errorCode = XAException.XAER_RMERR; 74 return e; 75 } 76 } 77 78 81 public SpyXAException() 82 { 83 super(); 84 this.nested = null; 85 } 86 87 92 public SpyXAException(final String msg) 93 { 94 super(msg); 95 this.nested = null; 96 } 97 98 104 public SpyXAException(final int code) 105 { 106 super(code); 107 this.nested = null; 108 } 109 110 115 public SpyXAException(Throwable t) 116 { 117 super(); 118 this.nested = t; 119 } 120 121 127 public SpyXAException(final String msg, Throwable t) 128 { 129 super(msg); 130 this.nested = t; 131 } 132 133 140 public SpyXAException(final int code, Throwable t) 141 { 142 super(code); 143 this.nested = t; 144 } 145 146 public Throwable getNested() 147 { 148 return nested; 149 } 150 151 public Throwable getCause() 152 { 153 return nested; 154 } 155 156 public void setLinkedException(final Exception e) 157 { 158 this.nested = e; 159 } 160 161 public Exception getLinkedException() 162 { 163 if (nested == null) 168 return this; 169 if (nested instanceof Exception ) 170 { 171 return (Exception ) nested; 172 } 173 return new NestedException(nested); 174 } 175 176 public String getMessage() 177 { 178 return NestedThrowable.Util.getMessage(super.getMessage(), nested); 179 } 180 181 public void printStackTrace(final PrintStream stream) 182 { 183 if (nested == null || NestedThrowable.PARENT_TRACE_ENABLED) 184 { 185 super.printStackTrace(stream); 186 } 187 NestedThrowable.Util.print(nested, stream); 188 } 189 190 public void printStackTrace(final PrintWriter writer) 191 { 192 if (nested == null || NestedThrowable.PARENT_TRACE_ENABLED) 193 { 194 super.printStackTrace(writer); 195 } 196 NestedThrowable.Util.print(nested, writer); 197 } 198 199 public void printStackTrace() 200 { 201 printStackTrace(System.err); 202 } 203 } | Popular Tags |