KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

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

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

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