KickJava   Java API By Example, From Geeks To Geeks.

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


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.apache.turbine.TurbineException;
51 import org.tigris.scarab.tools.ScarabLocalizationTool;
52 import org.tigris.scarab.tools.localization.L10NMessage;
53 import org.tigris.scarab.tools.localization.LocalizationKey;
54 import org.tigris.scarab.tools.localization.Localizable;
55
56 /**
57     This class extends TurbineException and does not change its
58     functionality. It should be used to mark Scarab specific
59     exceptions.
60     In order to ensure localization of Exception messages,
61     ScarabException adds a new type of message, the L10NMessage.
62     
63     @author <a HREF="mailto:jmcnally@collab.net">John D. McNally</a>
64     @version $Id: ScarabException.java 9104 2004-05-10 21:04:51Z dabbous $
65 */

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

72     Localizable l10nMessage;
73     
74
75     /**
76      * Constructs a new <code>ScarabException</code> with specified
77      * resource and no parameters.
78      * @param theKey the l10n error key.
79      */

80     public ScarabException(LocalizationKey theKey)
81     {
82          l10nMessage = new L10NMessage(theKey);
83     }
84
85     /**
86      * Constructs a new <code>ScarabException</code> with specified
87      * resource and a nested Throwable.
88      * @param theKey the l10n error key.
89      * @param nested
90      */

91     public ScarabException(LocalizationKey theKey, Throwable JavaDoc nested)
92     {
93         super(nested);
94         l10nMessage = new L10NMessage(theKey, nested);
95     }
96
97
98     /**
99      * Constructs a new <code>ScarabException</code> with specified
100      * Localizable .
101      * @param theL10nInstance the l10n error key.
102      */

103     public ScarabException(Localizable theL10nInstance)
104     {
105          l10nMessage = theL10nInstance;
106     }
107  
108     /**
109      * Constructs a new <code>ScarabException</code> with specified
110      * Localizable and a nested Throwable.
111      * @param theL10nInstance the l10n error key.
112      * @param nested
113      */

114     public ScarabException(Localizable theL10nInstance, Throwable JavaDoc nested)
115     {
116         super(nested);
117         l10nMessage = theL10nInstance;
118     }
119
120     
121     /**
122      * Constructs a new <code>ScarabException</code> with specified
123      * resource and a list of parameters.
124      * @param theL10nInstance the l10n error key.
125      * @param theParams
126      */

127     public ScarabException (LocalizationKey theKey, Object JavaDoc[] theParams)
128     {
129         l10nMessage = new L10NMessage(theKey, theParams);
130     }
131  
132     /**
133      * convenience constructor: Constructs a new <code>ScarabException</code>
134      * with specified resource and one parameter.
135      * @param theL10nInstance the l10n error key.
136      * @param p1
137      */

138     public ScarabException (LocalizationKey theKey, Object JavaDoc p1)
139     {
140         this(theKey, new Object JavaDoc[] {p1});
141     }
142  
143     /**
144      * convenience constructor: Constructs a new <code>ScarabException</code>
145      * with specified resource and two parameters.
146      * @param theL10nInstance the l10n error key.
147      * @param p1
148      * @param p2
149      */

150     public ScarabException (LocalizationKey theKey, Object JavaDoc p1, Object JavaDoc p2)
151     {
152         this(theKey, new Object JavaDoc[] {p1, p2});
153     }
154  
155     /**
156      * convenience constructor: Constructs a new <code>ScarabException</code>
157      * with specified resource and three parameters.
158      * @param theL10nInstance the l10n error key.
159      * @param p1
160      * @param p2
161      * @param p3
162      */

163     public ScarabException (LocalizationKey theKey, Object JavaDoc p1, Object JavaDoc p2, Object JavaDoc p3)
164     {
165         this(theKey, new Object JavaDoc[] {p1, p2, p3});
166     }
167   
168
169     /**
170      * convenience constructor: Constructs a new <code>ScarabException</code>
171      * with specified resource, nested Throwable and an aritrary set of parameters.
172      *
173      * @param theKey
174      * @param nested
175      * @param theParams
176      */

177     public ScarabException (LocalizationKey theKey, Throwable JavaDoc nested, Object JavaDoc[] theParams)
178     {
179         this(new L10NMessage(theKey, theParams),nested);
180     }
181
182     /**
183      * convenience constructor: Constructs a new <code>ScarabException</code>
184      * with specified resource, nested Throwable and one parameter.
185      * @param theKey
186      * @param nested
187      * @param p1
188      */

189     public ScarabException (LocalizationKey theKey, Throwable JavaDoc nested, Object JavaDoc p1)
190     {
191         this(new L10NMessage(theKey, p1),nested);
192     }
193
194     /**
195      * convenience constructor: Constructs a new <code>ScarabException</code>
196      * with specified resource, nested Throwable and two parameters.
197      * @param theKey
198      * @param nested
199      * @param p1
200      * @param p2
201      */

202     public ScarabException (LocalizationKey theKey, Throwable JavaDoc nested, Object JavaDoc p1, Object JavaDoc p2)
203     {
204         this(new L10NMessage(theKey, p1, p2),nested);
205     }
206
207     /**
208      * convenience constructor: Constructs a new <code>ScarabException</code>
209      * with specified resource, nested Throwable and three parameters.
210      * @param theKey
211      * @param nested
212      * @param p1
213      * @param p2
214      * @param p3
215      */

216     public ScarabException (LocalizationKey theKey, Throwable JavaDoc nested, Object JavaDoc p1, Object JavaDoc p2, Object JavaDoc p3)
217     {
218         this(new L10NMessage(theKey, p1, p2, p3),nested);
219     }
220
221     /**
222      * return the L10NInstance, or null, if no L10N key was given.
223      * @return
224      */

225     public Localizable getL10nMessage()
226     {
227         return l10nMessage;
228     }
229     
230     /**
231      * return the localized message by use of the
232      * given ScarabLocalizationTool. For further infos see
233      * {@link #getMessage() getMessage }
234      *
235      * @param l10n
236      * @return
237      */

238     public String JavaDoc getMessage(ScarabLocalizationTool l10n)
239     {
240         String JavaDoc result;
241         if (l10nMessage == null)
242         {
243             result = super.getMessage();
244         }
245         else
246         {
247             result = l10nMessage.getMessage(l10n);
248         }
249         return result;
250     }
251  
252     /**
253      * return the localized message in english.
254      * Note: It is preferrable to use
255      * {@link #getMessage(ScarabLocalizationTool) getMessage }
256      * Currently it is possible, that a ScarabException
257      * contains NO L10NInstance. This is due to the deprecated
258      * constructors {@link #ScarabException() ScarabException }
259      * and {@link #ScarabException(String) ScarabException }
260      * Eventually (after these constructors have been deleted
261      * from the code base) we guarantee, that ScarabException
262      * is fully localized.
263      *
264      * @return localized english text
265      */

266     public String JavaDoc getMessage()
267     {
268         String JavaDoc result;
269         if (l10nMessage == null)
270         {
271             result = super.getMessage();
272         }
273         else
274         {
275             result = l10nMessage.toString();
276         }
277         return result;
278     }
279
280 }
281
Popular Tags