1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package com.finalist.util.genelv.exceptions;
19
20 import javax.ejb.EJBException;
21 import java.io.*;
22
23 /***
24 * This exception is thrown for all problems that occur in the EJB
25 * Container code of the application. This class defines a few
26 * typical error types to help the developer find the error
27 * cause.
28 */
29 public class WrappedEJBException extends EJBException
30 implements java.io.Serializable {
31
32
33 public final static String EJB_FINDER = "genelv.ejb.finder";
34 public final static String UNSPECIFIED = "genelv.unspecified";
35 public final static String EJB_JNDI = "genelv.ejb.jndi";
36 public final static String JDBC = "genelv.jdbc";
37 public final static String EJB_CREATE = "genelv.ejb.create";
38 public final static String REMOTE = "genelv.remote";
39
40 /*** The real error which occured */
41 private Throwable wrappedEjbException;
42
43 /*** The errorCode of the real error */
44 private String errorCode;
45
46
47 /*** Creates new WrappedEJBException
48 * @param message Information of real exception */
49 public WrappedEJBException(String message) {
50 super(message);
51 this.errorCode = ExceptionUtil.determineErrorCode(null);
52 }
53
54
55 /*** Creates new WrappedEJBException
56 * @param e Exception to wrap */
57 public WrappedEJBException(Throwable e) {
58 super(e.getMessage());
59 this.wrappedEjbException = e;
60 this.errorCode = ExceptionUtil.determineErrorCode(e);
61 }
62
63
64 /*** Get the ApplicationResource (action) error key indicating the cause of the (wrapped EJB) exception. */
65 public String getErrorCode() {
66 if (errorCode == null) {
67 return UNSPECIFIED;
68 }
69 else {
70 return errorCode;
71 }
72 }
73
74
75 /*** Set the ApplicationResource (action) error key indicating the cause of the (wrapped EJB) exception. */
76 public void setErrorCode(String errorCode) {
77 this.errorCode = errorCode;
78 }
79
80
81 /*** Return a string version of the stack trace if the wrapped ejb exception is not null,
82 * a static message string indicating the absence of a stacktrace. */
83 public String getWrappedStackTrace() {
84 if (this.wrappedEjbException == null)
85 return this.getClass().getName() + "::No stack trace available: wrapped EJB exception is null";
86 else {
87 StringWriter sw = new StringWriter();
88 PrintWriter pw = new PrintWriter(sw);
89 this.wrappedEjbException.printStackTrace(pw);
90 pw.flush();
91 return sw.toString();
92 }
93 }
94 }