KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > util > OpenEJBErrorHandler


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: OpenEJBErrorHandler.java 1921 2005-06-19 22:40:34Z jlaskowski $
44  */

45 package org.openejb.util;
46
47 import java.io.ByteArrayOutputStream JavaDoc;
48 import java.io.PrintWriter JavaDoc;
49
50 import org.openejb.OpenEJBException;
51
52
53 public class OpenEJBErrorHandler {
54
55     private static Logger _logger = Logger.getInstance( "OpenEJB", "org.openejb.util.resources" );
56     private static Messages _messages = new Messages( "org.openejb.util.resources" );
57
58     /**
59      * This method is only intended for situations where an unknown error
60      * or exception may occur and have fatal results.
61      *
62      * Example use:
63      * <pre>
64      * public ContainerSystem build() throws AssemblerException{
65      * try{
66      * return (org.openejb.ContainerSystem)assembleContainerSystem(config);
67      * }catch(AssemblerException ae){
68      * // AssemblerExceptions contain useful information and are debbugable.
69      * // Let the exception pass through to the top and be logged.
70      * throw ae;
71      * }catch(Exception e){
72      * // General Exceptions at this level are too generic and difficult to debug.
73      * // These exceptions are considered unknown bugs and are fatal.
74      * OpenEJBErrorHandler.handleUnknownError(e, "Assembler");
75      * }
76      * }
77      * </pre>
78      *
79      * Creates and logs an OpenEJBException with the following message:
80      *
81      * "FATAL ERROR: Unknown error in {0}. Please send the following stack trace and this message to openejb-bugs@exolab.org :\n {1}"}
82      * {0} is the part of the system that the error occurred.
83      *
84      * @param error the unknown Throwable that occurred.
85      * @param systemLocation replaces {0} in the error message.
86      */

87     public static void handleUnknownError(Throwable JavaDoc error, String JavaDoc systemLocation){
88
89         // Collect the stack trace {
90
ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
91         PrintWriter JavaDoc pw = new PrintWriter JavaDoc(baos);
92         error.printStackTrace(pw);
93         pw.flush();
94         pw.close();
95         // }
96

97         _logger.i18n.error("ge0001", systemLocation, new String JavaDoc(baos.toByteArray()));
98
99         /*
100          * An error broadcasting system is under development.
101          * At this point an appropriate error would be broadcast to all listeners.
102          */

103     }
104
105     /**
106      * Creates and throws an OpenEJBException with the following message:
107      *
108      * "The required properties object needed by {0} is null ."
109      * {1} is the part of the system that needs the properties object.
110      *
111      * @param systemLocation replaces {0} in the error message.
112      */

113     public static void propertiesObjectIsNull(String JavaDoc systemLocation) throws OpenEJBException{
114
115         throw new OpenEJBException( _messages.format( "ge0002", systemLocation ) );
116     }
117
118     /**
119      * Creates and throws an OpenEJBException with the following message:
120      *
121      * "Properties file '{0}' for {1} not found."
122      * {0} is the properties file name
123      * {1} is the part of the system that needs the properties file.
124      *
125      * @param propertyfileName replaces {0} in the error message.
126      * @param systemLocation replaces {1} in the error message.
127      */

128     public static void propertyFileNotFound(String JavaDoc propertyfileName, String JavaDoc systemLocation) throws OpenEJBException{
129
130         throw new OpenEJBException( _messages.format( "ge0003", propertyfileName, systemLocation ) );
131     }
132
133     /**
134      * Creates and throws an OpenEJBException with the following message:
135      *
136      * "Environment entry '{0}' not found in {1}."
137      * {0} is the property name
138      * {1} is the properties file name.
139      *
140      * @param propertyName replaces {0} in the error message.
141      * @param propertyfileName replaces {1} in the error message.
142      */

143     public static void propertyNotFound(String JavaDoc propertyName, String JavaDoc propertyfileName) throws OpenEJBException{
144
145         throw new OpenEJBException( _messages.format( "ge0004", propertyName, propertyfileName ) );
146     }
147
148     /**
149      * Creates and throws an OpenEJBException with the following message:
150      *
151      * "Environment entry '{0}' contains illegal value {1}."
152      * {0} is the property name
153      * {1} is the illegal value.
154      *
155      * @param propertyName replaces {0} in the error message.
156      * @param value replaces {1} in the error message.
157      */

158     public static void propertyValueIsIllegal(String JavaDoc propertyName, String JavaDoc value) throws OpenEJBException{
159
160         throw new OpenEJBException( _messages.format( "ge0005", propertyName, value ) );
161     }
162
163     /**
164      * Creates and throws an OpenEJBException with the following message:
165      *
166      * "Environment entry '{0}' contains illegal value {1}. {2}"
167      * {0} is the property name
168      * {1} is the illegal value.
169      * {2} an additional message.
170      *
171      * @param propertyName replaces {0} in the error message.
172      * @param value replaces {1} in the error message.
173      * @param message replaces {2} in the error message.
174      */

175     public static void propertyValueIsIllegal(String JavaDoc propertyName, String JavaDoc value, String JavaDoc message) throws OpenEJBException{
176
177         throw new OpenEJBException( _messages.format( "ge0006", propertyName, value, message ) );
178     }
179
180     /**
181      * Creates and throws an OpenEJBException with the following message:
182      *
183      * "The {0} cannot find and load the class '{1}'."
184      * {0} part of the system that needs the class
185      * {1} class that cannot be found.
186      *
187      * @param systemLocation replaces {0} in the error message.
188      * @param className replaces {1} in the error message.
189      */

190     public static void classNotFound(String JavaDoc systemLocation, String JavaDoc className) throws OpenEJBException{
191
192         throw new OpenEJBException( _messages.format( "ge0007", systemLocation, className ) );
193     }
194
195     /**
196      * Creates and throws an OpenEJBException with the following message:
197      *
198      * "The {0} cannot instaniate the class '{1}', the class or initializer is not accessible."
199      * {0} part of the system that needs the class
200      * {1} class that cannot be accessed.
201      *
202      * @param systemLocation replaces {0} in the error message.
203      * @param className replaces {1} in the error message.
204      */

205     public static void classNotAccessible(String JavaDoc systemLocation, String JavaDoc className) throws OpenEJBException{
206
207         throw new OpenEJBException( _messages.format( "ge0008", systemLocation, className ) );
208     }
209
210     /**
211      * Creates and throws an OpenEJBException with the following message:
212      *
213      * "The {0} cannot instaniate the class '{1}', the class may be abstract or an interface."
214      * {0} part of the system that needs the class
215      * {1} class that cannot be accessed.
216      *
217      * @param systemLocation replaces {0} in the error message.
218      * @param className replaces {1} in the error message.
219      */

220     public static void classNotIntantiateable(String JavaDoc systemLocation, String JavaDoc className) throws OpenEJBException{
221
222         throw new OpenEJBException( _messages.format( "ge0009", systemLocation, className ) );
223     }
224
225     /**
226      * Creates and throws an OpenEJBException with the following message:
227      *
228      * "The {0} cannot instaniate the class {1}: Recieved exception {2}: {3}"
229      * {0} part of the system that needs the class
230      * {1} class that cannot be accessed.
231      * {2} name of caught exception
232      * {3} message from caught exception
233      *
234      * @param systemLocation replaces {0} in the error message.
235      * @param className replaces {1} in the error message.
236      * @param exceptionClassName replaces {2} in the error message.
237      * @param message replaces {3} in the error message.
238      */

239     public static void classNotIntantiateableForUnknownReason(String JavaDoc systemLocation, String JavaDoc className, String JavaDoc exceptionClassName, String JavaDoc message) throws OpenEJBException{
240
241         throw new OpenEJBException( _messages.format( "ge0011", systemLocation, className, exceptionClassName, message ) );
242     }
243
244     /**
245      * Creates and throws an OpenEJBException with the following message:
246      *
247      * "The {0} cannot instaniate the class {1} loaded from codebase {2}: Recieved exception {3}: {4}"
248      * {0} part of the system that needs the class
249      * {1} class that cannot be accessed.
250      * {2} codebase the class was loaded from
251      * {3} name of caught exception
252      * {4} message from caught exception
253      *
254      * @param systemLocation replaces {0} in the error message.
255      * @param className replaces {1} in the error message.
256      * @param codebase replaces {2} in the error message.
257      * @param exceptionClassName replaces {3} in the error message.
258      * @param message replaces {4} in the error message.
259      */

260     public static void classNotIntantiateableFromCodebaseForUnknownReason(String JavaDoc systemLocation, String JavaDoc className, String JavaDoc codebase, String JavaDoc exceptionClassName, String JavaDoc message)
261     throws OpenEJBException
262     {
263         throw new OpenEJBException( _messages.format( "ge0012", systemLocation, className, codebase, exceptionClassName, message ) );
264     }
265
266     /**
267      * The {0} cannot locate the class {1}, the codebase '{2}' cannot
268      * be accessed. Received message: {3}"
269      *
270      * @param systemLocation
271      * replaces {0} in the error message.
272      * @param className replaces {1} in the error message.
273      * @param codebase replaces {2} in the error message.
274      *
275      * @param e e.getMessage() replaces {3} in the error message.
276      *
277      * @exception OpenEJBException
278      */

279     public static void classCodebaseNotFound(String JavaDoc systemLocation, String JavaDoc className, String JavaDoc codebase, Exception JavaDoc e) throws OpenEJBException{
280
281         throw new OpenEJBException( _messages.format( "ge0010", systemLocation, className, codebase, e.getMessage() ) );
282     }
283
284     /**
285      * Creates and throws an OpenEJBException with the following message:
286      *
287      * "Error in XML configuration file. Received {0} from the parser
288      * stating '{1}' at line {2} column {3}."},
289      * {0} the type of message.
290      * {1} the error message from the parser.
291      * {2} the line number.
292      * {3} the column number.
293      *
294      * @param messageType replaces {0} in the error message.
295      * @param message replaces {1} in the error message.
296      * @param line replaces {2} in the error message.
297      * @param column replaces {3} in the error message.
298      */

299     public static void configurationParsingError(String JavaDoc messageType, String JavaDoc message, String JavaDoc line, String JavaDoc column){
300
301         _logger.i18n.error( "as0001", messageType, message, line, column );
302         /*
303          * An error broadcasting system is under development.
304          * At this point an appropriate error would be broadcast to all listeners.
305          */

306     }
307
308 }
309
Popular Tags