KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > ejb > burlap > BurlapProtocolException


1 /*
2  * Copyright (c) 1998-2000 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.ejb.burlap;
30
31 import com.caucho.util.ExceptionWrapper;
32
33 import java.io.PrintStream JavaDoc;
34 import java.io.PrintWriter JavaDoc;
35 import java.rmi.RemoteException JavaDoc;
36
37 /**
38  * Wraps the actual exception with a burlap protocol exception
39  */

40 public class BurlapProtocolException extends java.rmi.RemoteException JavaDoc
41   implements ExceptionWrapper {
42   private Throwable JavaDoc rootCause;
43
44   /**
45    * Null constructor for beans
46    */

47   public BurlapProtocolException()
48   {
49   }
50   /**
51    * Create a basic BurlapProtocolException with a message.
52    *
53    * @param msg the exception message.
54    */

55   public BurlapProtocolException(String JavaDoc msg)
56   {
57     super(msg);
58   }
59
60   /**
61    * Create a BurlapProtocolException wrapping a root exception.
62    *
63    * @param rootCause the underlying wrapped exception.
64    */

65   public BurlapProtocolException(Throwable JavaDoc rootCause)
66   {
67     super(rootCause.getMessage());
68
69     this.rootCause = rootCause;
70   }
71
72   /**
73    * Creates an BurlapProtocol from a throwable.
74    */

75   public static BurlapProtocolException create(Throwable JavaDoc rootCause)
76   {
77     if (rootCause instanceof BurlapProtocolException)
78       return ((BurlapProtocolException) rootCause);
79     else
80       return new BurlapProtocolException(rootCause);
81   }
82
83   /**
84    * Creates a runtime from a throwable.
85    */

86   public static RemoteException JavaDoc createRemote(Throwable JavaDoc rootCause)
87   {
88     if (rootCause instanceof RemoteException JavaDoc)
89       return ((RemoteException JavaDoc) rootCause);
90     else
91       return new BurlapProtocolException(rootCause);
92   }
93
94   /**
95    * Returns the root exception if it exists.
96    *
97    * @return the underlying wrapped exception.
98    */

99   public Throwable JavaDoc getRootCause()
100   {
101     return rootCause;
102   }
103
104   /**
105    * Returns the appropriate exception message.
106    */

107   public String JavaDoc getMessage()
108   {
109     if (rootCause != null)
110       return rootCause.getMessage();
111     else
112       return super.getMessage();
113   }
114
115   /**
116    * Prints the stack trace, preferring the root cause if it exists.
117    */

118   public void printStackTrace()
119   {
120     if (rootCause != null)
121       rootCause.printStackTrace();
122     else
123       super.printStackTrace();
124   }
125
126   /**
127    * Prints the stack trace, preferring the root cause if it exists.
128    */

129   public void printStackTrace(PrintStream JavaDoc os)
130   {
131     if (rootCause != null)
132       rootCause.printStackTrace(os);
133     else
134       super.printStackTrace(os);
135   }
136
137   /**
138    * Prints the stack trace, preferring the root cause if it exists.
139    */

140   public void printStackTrace(PrintWriter JavaDoc os)
141   {
142     if (rootCause != null)
143       rootCause.printStackTrace(os);
144     else
145       super.printStackTrace(os);
146   }
147
148   /**
149    * Print the exception as a string.
150    */

151   public String JavaDoc toString()
152   {
153     if (rootCause == null)
154       return super.toString();
155     else
156       return getClass().getName() + ": " + rootCause;
157   }
158 }
159
160
Popular Tags