KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > util > ScarabRuntimeException


1 package org.tigris.scarab.util;
2
3 /* ================================================================
4  * Copyright (c) 2000-2002 CollabNet. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowlegement: "This product includes
19  * software developed by Collab.Net <http://www.Collab.Net/>."
20  * Alternately, this acknowlegement may appear in the software itself, if
21  * and wherever such third-party acknowlegements normally appear.
22  *
23  * 4. The hosted project names must not be used to endorse or promote
24  * products derived from this software without prior written
25  * permission. For written permission, please contact info@collab.net.
26  *
27  * 5. Products derived from this software may not use the "Tigris" or
28  * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
29  * prior written permission of Collab.Net.
30  *
31  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
32  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34  * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
35  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
37  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
39  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  * ====================================================================
44  *
45  * This software consists of voluntary contributions made by many
46  * individuals on behalf of Collab.Net.
47  */

48
49 // Turbine
50
import org.tigris.scarab.tools.ScarabLocalizationTool;
51 import org.tigris.scarab.tools.localization.L10NMessage;
52 import org.tigris.scarab.tools.localization.LocalizationKey;
53 import org.tigris.scarab.tools.localization.Localizable;
54
55 /**
56     This class extends TurbineException and does not change its
57     functionality. It should be used to mark Scarab specific
58     exceptions.
59     In order to ensure localization of Exception messages,
60     ScarabRuntimeException adds a new type of message, the L10NMessage.
61     
62     @author <a HREF="mailto:jmcnally@collab.net">John D. McNally</a>
63     @version $Id: ScarabRuntimeException.java 9285 2004-12-02 21:32:50Z dabbous $
64 */

65 public class ScarabRuntimeException extends RuntimeException JavaDoc implements Localizable
66 {
67     /**
68      * The exception message in non-localized form.
69      * Further infos, see the {@link #getMessage(L10N) getmessage } methods below.
70      */

71     Localizable l10nMessage;
72     
73     /**
74      * Placeholder for a nested exception (may be null)
75      */

76     Throwable JavaDoc nested;
77
78     /**
79      * Constructs a new <code>ScarabRuntimeException</code> with specified
80      * resource and no parameters.
81      * @param theKey the l10n error key.
82      */

83     public ScarabRuntimeException(LocalizationKey theKey)
84     {
85          l10nMessage = new L10NMessage(theKey);
86          nested = null;
87     }
88
89     /**
90      * Constructs a new <code>ScarabRuntimeException</code> with specified
91      * resource and a nested Throwable.
92      * @param theKey the l10n error key.
93      * @param aNested
94      */

95     public ScarabRuntimeException(LocalizationKey theKey, Throwable JavaDoc aNested)
96     {
97         super();
98         l10nMessage = new L10NMessage(theKey, nested);
99         nested = aNested;
100     }
101
102
103     /**
104      * Constructs a new <code>ScarabRuntimeException</code> with specified
105      * Localizable .
106      * @param theL10nInstance the l10n error key.
107      */

108     public ScarabRuntimeException(Localizable theL10nInstance)
109     {
110          l10nMessage = theL10nInstance;
111          nested = null;
112     }
113  
114     /**
115      * Constructs a new <code>ScarabRuntimeException</code> with specified
116      * Localizable and a nested Throwable.
117      * @param theL10nInstance the l10n error key.
118      * @param aNested
119      */

120     public ScarabRuntimeException(Localizable theL10nInstance, Throwable JavaDoc aNested)
121     {
122         super();
123         l10nMessage = theL10nInstance;
124         nested = aNested;
125     }
126
127     
128     /**
129      * Constructs a new <code>ScarabRuntimeException</code> with specified
130      * resource and a list of parameters.
131      * @param theL10nInstance the l10n error key.
132      * @param theParams
133      */

134     public ScarabRuntimeException (LocalizationKey theKey, Object JavaDoc[] theParams)
135     {
136         l10nMessage = new L10NMessage(theKey, theParams);
137         nested = null;
138     }
139  
140     /**
141      * convenience constructor: Constructs a new <code>ScarabRuntimeException</code>
142      * with specified resource and one parameter.
143      * @param theL10nInstance the l10n error key.
144      * @param p1
145      */

146     public ScarabRuntimeException (LocalizationKey theKey, Object JavaDoc p1)
147     {
148         this(theKey, new Object JavaDoc[] {p1});
149     }
150  
151     /**
152      * convenience constructor: Constructs a new <code>ScarabRuntimeException</code>
153      * with specified resource and two parameters.
154      * @param theL10nInstance the l10n error key.
155      * @param p1
156      * @param p2
157      */

158     public ScarabRuntimeException (LocalizationKey theKey, Object JavaDoc p1, Object JavaDoc p2)
159     {
160         this(theKey, new Object JavaDoc[] {p1, p2});
161     }
162  
163     /**
164      * convenience constructor: Constructs a new <code>ScarabRuntimeException</code>
165      * with specified resource and three parameters.
166      * @param theL10nInstance the l10n error key.
167      * @param p1
168      * @param p2
169      * @param p3
170      */

171     public ScarabRuntimeException (LocalizationKey theKey, Object JavaDoc p1, Object JavaDoc p2, Object JavaDoc p3)
172     {
173         this(theKey, new Object JavaDoc[] {p1, p2, p3});
174     }
175   
176
177     /**
178      * convenience constructor: Constructs a new <code>ScarabRuntimeException</code>
179      * with specified resource, nested Throwable and an aritrary set of parameters.
180      *
181      * @param theKey
182      * @param nested
183      * @param theParams
184      */

185     public ScarabRuntimeException (LocalizationKey theKey, Throwable JavaDoc nested, Object JavaDoc[] theParams)
186     {
187         this(new L10NMessage(theKey, theParams),nested);
188     }
189
190     /**
191      * convenience constructor: Constructs a new <code>ScarabRuntimeException</code>
192      * with specified resource, nested Throwable and one parameter.
193      * @param theKey
194      * @param nested
195      * @param p1
196      */

197     public ScarabRuntimeException (LocalizationKey theKey, Throwable JavaDoc nested, Object JavaDoc p1)
198     {
199         this(new L10NMessage(theKey, p1),nested);
200     }
201
202     /**
203      * convenience constructor: Constructs a new <code>ScarabRuntimeException</code>
204      * with specified resource, nested Throwable and two parameters.
205      * @param theKey
206      * @param nested
207      * @param p1
208      * @param p2
209      */

210     public ScarabRuntimeException (LocalizationKey theKey, Throwable JavaDoc nested, Object JavaDoc p1, Object JavaDoc p2)
211     {
212         this(new L10NMessage(theKey, p1, p2),nested);
213     }
214
215     /**
216      * convenience constructor: Constructs a new <code>ScarabRuntimeException</code>
217      * with specified resource, nested Throwable and three parameters.
218      * @param theKey
219      * @param nested
220      * @param p1
221      * @param p2
222      * @param p3
223      */

224     public ScarabRuntimeException (LocalizationKey theKey, Throwable JavaDoc nested, Object JavaDoc p1, Object JavaDoc p2, Object JavaDoc p3)
225     {
226         this(new L10NMessage(theKey, p1, p2, p3),nested);
227     }
228
229     /**
230      * return the L10NInstance, or null, if no L10N key was given.
231      * @return
232      */

233     public Localizable getL10nMessage()
234     {
235         return l10nMessage;
236     }
237     
238     /**
239      * return the localized message by use of the
240      * given ScarabLocalizationTool. For further infos see
241      * {@link #getMessage() getMessage }
242      *
243      * @param l10n
244      * @return
245      */

246     public String JavaDoc getMessage(ScarabLocalizationTool l10n)
247     {
248         String JavaDoc result;
249         if (l10nMessage == null)
250         {
251             if (nested == null)
252             {
253                 result = super.getMessage();
254             }
255             else
256             {
257                 if ( nested instanceof ScarabRuntimeException )
258                 {
259                     result = ((ScarabRuntimeException)nested).getMessage(l10n);
260                 }
261                 else if ( nested instanceof ScarabException )
262                 {
263                     result = ((ScarabException)nested).getMessage(l10n);
264                 }
265                 else
266                 {
267                     result = nested.getMessage();
268                 }
269             }
270         }
271         else
272         {
273             result = l10nMessage.getMessage(l10n);
274         }
275         return result;
276     }
277  
278     /**
279      * return the localized message in english.
280      * Note: It is preferrable to use
281      * {@link #getMessage(ScarabLocalizationTool) getMessage }
282      *
283      * @return localized english text
284      */

285     public String JavaDoc getMessage()
286     {
287         String JavaDoc result;
288         if (l10nMessage == null)
289         {
290             if (nested == null)
291             {
292                 result = super.getMessage();
293             }
294             else
295             {
296                 result = nested.getMessage();
297             }
298         }
299         else
300         {
301             result = l10nMessage.toString();
302         }
303         return result;
304     }
305
306 }
307
Popular Tags