KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.apache.torque.TorqueException;
50 import org.tigris.scarab.tools.ScarabLocalizationTool;
51 import org.tigris.scarab.tools.localization.Localizable;
52
53 /**
54  * A TorqueException ready for internationalization [in the Scarab L10N framework].
55  *
56  * @version $Id: ScarabLocalizedTorqueException.java 9088 2004-05-01 19:10:51Z dabbous $
57  * @author <a HREF="mailto:dabbous@saxess.com">Hussayn Dabbous</a>
58  */

59 public class ScarabLocalizedTorqueException extends TorqueException implements Localizable
60 {
61     private final Throwable JavaDoc throwable;
62
63     // may be null
64
private ScarabLocalizationTool localizer;
65     
66     /**
67      * Constructs a TorqueException wrapper for a given throwable.
68      * The wrapper is simply a container with no special
69      * functionality.
70      * @param e
71      */

72     public ScarabLocalizedTorqueException(final Throwable JavaDoc t)
73     {
74         throwable = t;
75         localizer = null;
76     }
77
78     /**
79      * Set the localizer to be used in later calls to {@link #getLocalizedMessage()}
80      * @param theLocalizer the localizer (may be <code>null</code>)
81      */

82      public void setLocalizer(final ScarabLocalizationTool theLocalizer)
83      {
84         localizer = theLocalizer;
85      }
86     
87     /**
88      * Delegator for the wrapped exceptions getMessage() method.
89      * @return the wrapped exception's message
90      */

91     public String JavaDoc getMessage()
92     {
93         return throwable.getMessage();
94     }
95
96
97     /**
98      * Localize this exception using the wrapped throwable.
99      * return the localized message, else return the message string
100      * of the wrapped throwable.
101      * @param l10n
102      * @return
103      */

104     public String JavaDoc getMessage(final ScarabLocalizationTool l10n)
105     {
106         return l10n.getMessage(throwable);
107     }
108
109     /**
110      * Return the localized message for that throwable, if a localizer
111      * was defined using {@link #setLocalizer(ScarabLocalizationTool)}
112      * @return the localized message.
113      */

114     public String JavaDoc getLocalizedMessage()
115     {
116         if (localizer != null)
117         {
118             return getMessage(localizer);
119         }
120         else
121         {
122             return super.getLocalizedMessage();
123         }
124     }
125 }
126
Popular Tags