KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dream > util > Error


1 /**
2  * Dream
3  * Copyright (C) 2003-2004 INRIA Rhone-Alpes
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact : dream@objectweb.org
20  *
21  * Initial developer(s): Vivien Quema
22  * Contributor(s):
23  */

24
25 package org.objectweb.dream.util;
26
27 import org.objectweb.util.monolog.api.BasicLevel;
28 import org.objectweb.util.monolog.api.Logger;
29
30 /**
31  * Defines some methods to handle (i.e. throw exception) errors.
32  */

33 public final class Error
34 {
35
36   private Error()
37   {
38   }
39
40   /**
41    * Handles a bug: throws an {@link InternalError}and logs a
42    * <code>ERROR</code> message.
43    *
44    * @param logger the logger to be used to log the error message.
45    */

46   public static void bug(Logger logger)
47   {
48     if (logger != null)
49     {
50       logger.log(BasicLevel.ERROR,
51           "This is a bug. Please contact dream@objectweb.org");
52     }
53     throw new InternalError JavaDoc("This is a bug. Please contact dream@objectweb.org");
54   }
55
56   /**
57    * Handles a bug: throws an {@link InternalError}and logs a
58    * <code>ERROR</code> message.
59    *
60    * @param logger the logger to be used to log the error message.
61    * @param e a throwable object.
62    */

63   public static void bug(Logger logger, Throwable JavaDoc e)
64   {
65     if (logger != null && logger.isLoggable(BasicLevel.ERROR))
66     {
67       logger.log(BasicLevel.ERROR,
68           "This is a bug. Please contact dream@objectweb.org", e);
69     }
70     else
71     {
72       e.printStackTrace();
73     }
74     throw new InternalError JavaDoc("This is a bug. Please contact dream@objectweb.org");
75   }
76
77   /**
78    * Handles an error: throws an {@link InternalError}and logs a
79    * <code>ERROR</code> message.
80    *
81    * @param message the message to display.
82    * @param logger the logger to be used to log the error message.
83    * @param e a throwable object.
84    */

85   public static void error(String JavaDoc message, Logger logger, Throwable JavaDoc e)
86   {
87     if (logger != null && logger.isLoggable(BasicLevel.ERROR))
88     {
89       logger.log(BasicLevel.ERROR, message, e);
90     }
91     else
92     {
93       e.printStackTrace();
94     }
95     throw new InternalError JavaDoc(message);
96   }
97
98   /**
99    * Handles an error: throws an {@link InternalError}and logs a
100    * <code>ERROR</code> message.
101    *
102    * @param message the message to display.
103    * @param logger the logger to be used to log the error message.
104    */

105   public static void error(String JavaDoc message, Logger logger)
106   {
107     if (logger != null)
108     {
109       logger.log(BasicLevel.ERROR, message);
110     }
111     throw new InternalError JavaDoc(message);
112   }
113
114 }
Popular Tags