View Javadoc

1   /*   Copyright (C) 2004 Finalist IT Group
2    *
3    *   This file is part of JAG - the Java J2EE Application Generator
4    *
5    *   JAG is free software; you can redistribute it and/or modify
6    *   it under the terms of the GNU General Public License as published by
7    *   the Free Software Foundation; either version 2 of the License, or
8    *   (at your option) any later version.
9    *   JAG is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   *   GNU General Public License for more details.
13   *   You should have received a copy of the GNU General Public License
14   *   along with JAG; if not, write to the Free Software
15   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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  }