001: package org.tigris.scarab.util;
002:
003: /* ================================================================
004: * Copyright (c) 2000-2002 CollabNet. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are
008: * met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: *
017: * 3. The end-user documentation included with the redistribution, if
018: * any, must include the following acknowlegement: "This product includes
019: * software developed by Collab.Net <http://www.Collab.Net/>."
020: * Alternately, this acknowlegement may appear in the software itself, if
021: * and wherever such third-party acknowlegements normally appear.
022: *
023: * 4. The hosted project names must not be used to endorse or promote
024: * products derived from this software without prior written
025: * permission. For written permission, please contact info@collab.net.
026: *
027: * 5. Products derived from this software may not use the "Tigris" or
028: * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
029: * prior written permission of Collab.Net.
030: *
031: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
032: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
033: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
034: * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
035: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
036: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
037: * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
038: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
039: * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
040: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
041: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
042: *
043: * ====================================================================
044: *
045: * This software consists of voluntary contributions made by many
046: * individuals on behalf of Collab.Net.
047: */
048:
049: // Turbine
050: import org.tigris.scarab.tools.ScarabLocalizationTool;
051: import org.tigris.scarab.tools.localization.L10NMessage;
052: import org.tigris.scarab.tools.localization.LocalizationKey;
053: import org.tigris.scarab.tools.localization.Localizable;
054:
055: /**
056: This class extends TurbineException and does not change its
057: functionality. It should be used to mark Scarab specific
058: exceptions.
059: In order to ensure localization of Exception messages,
060: ScarabRuntimeException adds a new type of message, the L10NMessage.
061:
062: @author <a href="mailto:jmcnally@collab.net">John D. McNally</a>
063: @version $Id: ScarabRuntimeException.java 9977 2005-12-09 00:40:59Z hair $
064: */
065: public class ScarabRuntimeException extends RuntimeException //implements Localizable
066: {
067: /**
068: * The exception message in non-localized form.
069: * Further infos, see the {@link #getMessage(L10N) getmessage } methods below.
070: */
071: Localizable l10nMessage;
072:
073: /**
074: * Placeholder for a nested exception (may be null)
075: */
076: Throwable nested;
077:
078: /**
079: * Constructs a new <code>ScarabRuntimeException</code> with specified
080: * resource and no parameters.
081: * @param theKey the l10n error key.
082: */
083: public ScarabRuntimeException(LocalizationKey theKey) {
084: l10nMessage = new L10NMessage(theKey);
085: nested = null;
086: }
087:
088: /**
089: * Constructs a new <code>ScarabRuntimeException</code> with specified
090: * resource and a nested Throwable.
091: * @param theKey the l10n error key.
092: * @param aNested
093: */
094: public ScarabRuntimeException(LocalizationKey theKey,
095: Throwable aNested) {
096: super ();
097: l10nMessage = new L10NMessage(theKey, nested);
098: nested = aNested;
099: }
100:
101: /**
102: * Constructs a new <code>ScarabRuntimeException</code> with specified
103: * Localizable .
104: * @param theL10nInstance the l10n error key.
105: */
106: public ScarabRuntimeException(Localizable theL10nInstance) {
107: l10nMessage = theL10nInstance;
108: nested = null;
109: }
110:
111: /**
112: * Constructs a new <code>ScarabRuntimeException</code> with specified
113: * Localizable and a nested Throwable.
114: * @param theL10nInstance the l10n error key.
115: * @param aNested
116: */
117: public ScarabRuntimeException(Localizable theL10nInstance,
118: Throwable aNested) {
119: super ();
120: l10nMessage = theL10nInstance;
121: nested = aNested;
122: }
123:
124: /**
125: * Constructs a new <code>ScarabRuntimeException</code> with specified
126: * resource and a list of parameters.
127: * @param theL10nInstance the l10n error key.
128: * @param theParams
129: */
130: public ScarabRuntimeException(LocalizationKey theKey,
131: Object[] theParams) {
132: l10nMessage = new L10NMessage(theKey, theParams);
133: nested = null;
134: }
135:
136: /**
137: * convenience constructor: Constructs a new <code>ScarabRuntimeException</code>
138: * with specified resource and one parameter.
139: * @param theL10nInstance the l10n error key.
140: * @param p1
141: */
142: public ScarabRuntimeException(LocalizationKey theKey, Object p1) {
143: this (theKey, new Object[] { p1 });
144: }
145:
146: /**
147: * convenience constructor: Constructs a new <code>ScarabRuntimeException</code>
148: * with specified resource and two parameters.
149: * @param theL10nInstance the l10n error key.
150: * @param p1
151: * @param p2
152: */
153: public ScarabRuntimeException(LocalizationKey theKey, Object p1,
154: Object p2) {
155: this (theKey, new Object[] { p1, p2 });
156: }
157:
158: /**
159: * convenience constructor: Constructs a new <code>ScarabRuntimeException</code>
160: * with specified resource and three parameters.
161: * @param theL10nInstance the l10n error key.
162: * @param p1
163: * @param p2
164: * @param p3
165: */
166: public ScarabRuntimeException(LocalizationKey theKey, Object p1,
167: Object p2, Object p3) {
168: this (theKey, new Object[] { p1, p2, p3 });
169: }
170:
171: /**
172: * convenience constructor: Constructs a new <code>ScarabRuntimeException</code>
173: * with specified resource, nested Throwable and an aritrary set of parameters.
174: *
175: * @param theKey
176: * @param nested
177: * @param theParams
178: */
179: public ScarabRuntimeException(LocalizationKey theKey,
180: Throwable nested, Object[] theParams) {
181: this (new L10NMessage(theKey, theParams), nested);
182: }
183:
184: /**
185: * convenience constructor: Constructs a new <code>ScarabRuntimeException</code>
186: * with specified resource, nested Throwable and one parameter.
187: * @param theKey
188: * @param nested
189: * @param p1
190: */
191: public ScarabRuntimeException(LocalizationKey theKey,
192: Throwable nested, Object p1) {
193: this (new L10NMessage(theKey, p1), nested);
194: }
195:
196: /**
197: * convenience constructor: Constructs a new <code>ScarabRuntimeException</code>
198: * with specified resource, nested Throwable and two parameters.
199: * @param theKey
200: * @param nested
201: * @param p1
202: * @param p2
203: */
204: public ScarabRuntimeException(LocalizationKey theKey,
205: Throwable nested, Object p1, Object p2) {
206: this (new L10NMessage(theKey, p1, p2), nested);
207: }
208:
209: /**
210: * convenience constructor: Constructs a new <code>ScarabRuntimeException</code>
211: * with specified resource, nested Throwable and three parameters.
212: * @param theKey
213: * @param nested
214: * @param p1
215: * @param p2
216: * @param p3
217: */
218: public ScarabRuntimeException(LocalizationKey theKey,
219: Throwable nested, Object p1, Object p2, Object p3) {
220: this (new L10NMessage(theKey, p1, p2, p3), nested);
221: }
222:
223: /**
224: * return the L10NInstance, or null, if no L10N key was given.
225: * @return
226: */
227: public Localizable getL10nMessage() {
228: return l10nMessage;
229: }
230:
231: /**
232: * return the localized message by use of the
233: * given ScarabLocalizationTool. For further infos see
234: * {@link #getMessage() getMessage }
235: *
236: * @deprecated Does not follow core java patterns. Use setLocalizer(..) then getLocalizedMessage() instead.
237: *
238: * @param l10n
239: * @return
240: */
241: public String getMessage(ScarabLocalizationTool l10n) {
242: String result;
243: if (l10nMessage == null) {
244: if (nested == null) {
245: result = super .getMessage();
246: } else {
247: if (nested instanceof ScarabRuntimeException) {
248: result = ((ScarabRuntimeException) nested)
249: .getMessage(l10n);
250: } else if (nested instanceof ScarabException) {
251: result = ((ScarabException) nested)
252: .getMessage(l10n);
253: } else {
254: result = nested.getMessage();
255: }
256: }
257: } else {
258: result = l10nMessage.getMessage(l10n);
259: }
260: return result;
261: }
262:
263: /**
264: * return the localized message in english.
265: * Note: It is preferrable to use
266: * {@link #getMessage(ScarabLocalizationTool) getMessage }
267: *
268: * @return localized english text
269: */
270: public String getMessage() {
271: String result;
272: if (l10nMessage == null) {
273: if (nested == null) {
274: result = super.getMessage();
275: } else {
276: result = nested.getMessage();
277: }
278: } else {
279: result = l10nMessage.toString();
280: }
281: return result;
282: }
283:
284: }
|