1 22 package org.jboss.resource; 23 24 import java.io.PrintWriter ; 25 import java.io.PrintStream ; 26 import java.lang.reflect.UndeclaredThrowableException ; 27 28 import javax.resource.ResourceException ; 29 30 import org.jboss.util.NestedThrowable; 31 32 42 public class JBossResourceException 43 extends ResourceException 44 implements NestedThrowable 45 { 46 47 private static final long serialVersionUID = 6614203184612359692L; 48 49 56 public static void rethrowAsResourceException(String message, Throwable t) throws ResourceException 57 { 58 if (t instanceof ResourceException ) 59 throw (ResourceException ) t; 60 else 61 throw new JBossResourceException(message, t); 62 } 63 64 70 public JBossResourceException(final String msg) 71 { 72 super(msg); 73 } 74 75 82 public JBossResourceException(final String msg, final String code) 83 { 84 super(msg, code); 85 } 86 87 95 public JBossResourceException(final String msg, final String code, final Throwable linked) 96 { 97 super(msg, code); 98 setLinkedException(process(linked)); 99 } 100 101 108 public JBossResourceException(final String msg, final Throwable linked) 109 { 110 super(msg); 111 setLinkedException(process(linked)); 112 } 113 114 120 public JBossResourceException(final Throwable linked) 121 { 122 this(linked.getMessage(), linked); 123 } 124 125 130 public Throwable getNested() 131 { 132 return getLinkedException(); 133 } 134 135 142 public Throwable getCause() 143 { 144 return getLinkedException(); 145 } 146 147 152 public String getMessage() 153 { 154 return NestedThrowable.Util.getMessage(super.getMessage(), getLinkedException()); 155 } 156 157 163 public void printStackTrace(final PrintStream stream) 164 { 165 Exception linked = getLinkedException(); 166 if (linked == null || NestedThrowable.PARENT_TRACE_ENABLED) 167 { 168 super.printStackTrace(stream); 169 } 170 NestedThrowable.Util.print(linked, stream); 171 } 172 173 179 public void printStackTrace(final PrintWriter writer) 180 { 181 Exception linked = getLinkedException(); 182 if (linked == null || NestedThrowable.PARENT_TRACE_ENABLED) 183 { 184 super.printStackTrace(writer); 185 } 186 NestedThrowable.Util.print(linked, writer); 187 } 188 189 193 public void printStackTrace() 194 { 195 printStackTrace(System.err); 196 } 197 198 private Exception process(Throwable t) 199 { 200 if (t instanceof Exception ) 201 { 202 return (Exception )t; 203 } return new UndeclaredThrowableException (t); 205 } 206 } 207 | Popular Tags |