KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > OpenEJBException


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "Exolab" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of Exoffice Technologies. For written permission,
18  * please contact info@exolab.org.
19  *
20  * 4. Products derived from this Software may not be called "Exolab"
21  * nor may "Exolab" appear in their names without prior written
22  * permission of Exoffice Technologies. Exolab is a registered
23  * trademark of Exoffice Technologies.
24  *
25  * 5. Due credit should be given to the Exolab Project
26  * (http://www.exolab.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 1999 (C) Exoffice Technologies Inc. All Rights Reserved.
42  *
43  * $Id: OpenEJBException.java 1096 2004-03-26 21:41:16Z dblevins $
44  */

45 package org.openejb;
46
47 import java.io.PrintStream JavaDoc;
48 import java.io.PrintWriter JavaDoc;
49
50 /**
51  * The OpenEJBException is the standard exception thrown by all methods in all type in the
52  * Container Provider Interface (CPI). The OpenEJBException has 3 subtypes each serving a different
53  * purpose. The CPI will always thrown one of these subtype and never the OpenEJBException itself.
54  * <ul>
55  * <li><b>org.openejb.ApplicationException</b><br>
56  * This type is thrown when a normal EnterpriseBean exception is thrown. The ApplicationException's nested
57  * Exception will be either an EJB ApplicationException ( a custom exception defined by the bean developer)
58  * or a RemoteException. The org.openejb.ApplicationException must be caught and its nested exception rethrown
59  * by the bean proxy to the client. The org.openejb.ApplicationException is non-system exception; it does NOT
60  * indicate a problem with the contaienr itself.
61  * <li><b>org.openejb.InvalidateReferenceException</b><br>
62  * This type is thrown when the EnterpriseBean throws a RuntimeException or system exception that results in the
63  * eviction of the bean instance. The InvalidateReferenceException's nested exception will be a RuntimeException,
64  * which must be converted to a RemoteException or the nested exception will be a RemoteException. The
65  * Application Server must catch the InvalidateReferenceException and its nested exception rethrown by the bean proxy
66  * (if the nested exception is a RuntimeException it must first be converted to a RemoteException).
67  * After the exception is re-thrown by the bean proxy, the bean proxy must be invalidated so that all subsequent invocations by
68  * the client on that bean proxy throw a RemoteException. The proxy is made invalid. InvalidateReferenceException is non-system
69  * exception; it does NOT indicate a problem with the container itself.
70  * <li><b>org.openejb.SystemException</b><br>
71  * This type is thrown when the container has encountered an unresolvable system exception that make this Container
72  * unable to process requests. A breakdown in communication with one of the primary services or a RuntimeException
73  * thrown within the container (not by a bean) is are good examples. The org.openejb.SystemException represents a
74  * serious problem with the Container. The Container should be shut down and not used for any more processing.
75  * </ul>
76  *
77  * @author <a HREF="arkin@exoffice.com">Assaf Arkin</a>
78  * @author Brett McLaughlin
79  * @author Richard Monson-Haefel
80  * @version $Revision: 1096 $ $Date: 2004-03-26 13:41:16 -0800 (Fri, 26 Mar 2004) $
81  * @see ApplicationException
82  * @see InvalidateReferenceException
83  * @see OpenEJBException
84  * @see SystemException
85  */

86 public class OpenEJBException extends Exception JavaDoc {
87
88     /** Error code for unknown errors */
89     private String JavaDoc message = "error.unknown";
90
91     /** Stored <code>Exception</code> for root cause */
92     private Throwable JavaDoc rootCause;
93
94     /**
95      * <p>
96      * Default constructor, which simply delegates exception
97      * handling up the inheritance chain to <code>Exception</code>.
98      * </p>
99      */

100     public OpenEJBException() {
101         super();
102     }
103
104     /**
105      * <p>
106      * This constructor allows a message to be supplied indicating the source
107      * of the problem that occurred.
108      * </p>
109      *
110      * @param message <code>String</code> identifying the cause of the problem.
111      */

112     public OpenEJBException(String JavaDoc message) {
113         super( message );
114         this.message = message;
115     }
116
117     /**
118      * <p>
119      * This constructor allows a "root cause" exception to be supplied,
120      * which may later be used by the wrapping application.
121      * </p>
122      *
123      * @param rootCause <code>Throwable</code> that triggered the problem.
124      */

125     public OpenEJBException(Throwable JavaDoc rootCause) {
126         this.rootCause = rootCause;
127     }
128
129     /**
130      * This constructor allows both a message identifying the
131      * problem that occurred as well as a "root cause" exception
132      * to be supplied, which may later be used by the wrapping
133      * application.
134      *
135      * @param message <code>String</code> identifying the cause of the problem.
136      * @param rootCause <code>Throwable</code> that triggered this problem.
137      */

138     public OpenEJBException(String JavaDoc message, Throwable JavaDoc rootCause) {
139         this( message );
140         this.rootCause = rootCause;
141     }
142
143     /**
144      * <p>
145      * This returns the message for the <code>Exception</code>. If there is
146      * a root cause, the message associated with the root cause
147      * is appended.
148      * </p>
149      *
150      * @return <code>String</code> - message for this <code>Exception</code>.
151      */

152     public String JavaDoc getMessage() {
153         if (rootCause != null) {
154             return super.getMessage() + ": " + rootCause.getMessage();
155         } else {
156             return super.getMessage();
157         }
158     }
159
160     /**
161      * <p>
162      * This prints the stack trace of the <code>Exception</code>. If there is
163      * a root cause, the stack trace of the root <code>Exception</code>
164      * is printed right after.
165      * </p>
166      */

167     public void printStackTrace() {
168         super.printStackTrace();
169         if (rootCause != null) {
170             System.err.println("Root cause: ");
171             rootCause.printStackTrace();
172         }
173     }
174
175     /**
176      * <p>
177      * This prints the stack trace of the <code>Exception</code>. If there is
178      * a root cause, the stack trace of the root <code>Exception</code>
179      * is printed right after.
180      * </p>
181      *
182      * @param stream <code>PrintStream</code> to print stack trace to.
183      */

184     public void printStackTrace(PrintStream JavaDoc stream) {
185         super.printStackTrace(stream);
186         if (rootCause != null) {
187             stream.print("Root cause: ");
188             rootCause.printStackTrace(stream);
189         }
190     }
191     
192     /**
193      * <p>
194      * This prints the stack trace of the <code>Exception</code>. If there is
195      * a root cause, the stack trace of the root <code>Exception</code>
196      * is printed right after.
197      * </p>
198      *
199      * @param writer <code>PrintWriter</code> to print stack trace to.
200      */

201     public void printStackTrace(PrintWriter JavaDoc writer) {
202         super.printStackTrace(writer);
203         if (rootCause != null) {
204             writer.print("Root cause: ");
205             rootCause.printStackTrace(writer);
206         }
207     }
208
209     /**
210      * <p>
211      * This will return the root cause <code>Throwable</code>, or
212      * <code>null</code> if one does not exist.
213      * </p>
214      *
215      * @return <code>Throwable</code> - the wrapped <code>Throwable</code>.
216      */

217     public Throwable JavaDoc getRootCause() {
218         return rootCause;
219     }
220
221 }
222
Popular Tags