KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opencms > legacy > CmsLegacySecurityException


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/legacy/CmsLegacySecurityException.java,v $
3  * Date : $Date: 2005/09/11 13:27:06 $
4  * Version: $Revision: 1.10 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (C) 2002 - 2005 Alkacon Software (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31  
32 package com.opencms.legacy;
33
34 import org.opencms.i18n.CmsMessageContainer;
35 import org.opencms.main.CmsException;
36 import org.opencms.security.CmsSecurityException;
37
38 import java.util.Locale JavaDoc;
39
40 /**
41  * Exception to keep the legacy packages com.opencms.* and com.opencms.*
42  * with the old exception handling mechanism running.<p>
43  *
44  * @author Alexander Kandzior (a.kandzior@alkacon.com)
45  * @author Jan Baudisch (j.baudisch@alkacon.com)
46  * @version $Revision: 1.10 $
47  * @since 5.1.4
48  */

49 public class CmsLegacySecurityException extends CmsSecurityException {
50     
51     /** Serial version UID required for safe serialization. */
52     private static final long serialVersionUID = -5680076356022909019L;
53
54     /**
55      * MessageContainer with string-constructor, to be used only in this class.
56      * CmsLegacyMessageContainers are not localized. <p>
57      */

58     private static class CmsLegacyMessageContainer extends CmsMessageContainer {
59         
60         /**
61          * Creates a new message container with the specified message.<p>
62          *
63          * @param message the message to use
64          */

65         public CmsLegacyMessageContainer(String JavaDoc message) {
66
67             super(Messages.get(), message);
68         }
69         
70         /**
71          * Returns the message described by this container.<p>
72          *
73          * @return the message described by this container
74          */

75         public String JavaDoc key() {
76
77             return getKey();
78         }
79
80         /**
81          * Returns the message described by this container. The message is not localized and the locale argument will
82          * not be taken into account.<p>
83          *
84          * @param locale the locale to use
85          * @return the message described by this container
86          */

87         public String JavaDoc key(Locale JavaDoc locale) {
88
89             return getKey();
90         }
91
92     }
93     
94     /** Stores the error code of the CmsLegacyException. */
95     protected int m_type;
96     
97     /** No permissions to perform operation. */
98     public static final int C_SECURITY_NO_PERMISSIONS = 303;
99        
100     /** Invalid password (only for password change and validation of password). */
101     public static final int C_SECURITY_INVALID_PASSWORD = 305;
102
103     /**
104      * Creates a new localized Exception that also containes a root cause.<p>
105      *
106      * @param message the localized message container to use
107      * @param cause the Exception root cause
108      */

109     public CmsLegacySecurityException(CmsMessageContainer message, Throwable JavaDoc cause) {
110
111         super(message);
112         initCause(cause);
113     }
114     
115
116     /**
117      * Creates a CmsLegacySecurityException with the provided description message and error code.<p>
118      *
119      * @param message the description message
120      * @param type exception error code
121      */

122     public CmsLegacySecurityException(String JavaDoc message, int type) {
123
124         super(new CmsLegacyMessageContainer(message));
125         m_type = type;
126     }
127     
128     /**
129      * Creates a copied instance of this localized exception.<p>
130      *
131      * @param container the message container
132      * @param cause the root cause
133      *
134      * @return a copied instance of this localized exception
135      */

136     public CmsException createException(CmsMessageContainer container, Throwable JavaDoc cause) {
137         
138         return new CmsLegacySecurityException(container, cause);
139     }
140
141     /**
142      * Returns the type of the CmsLegacySecurityException.<p>
143      *
144      * @return the type of the CmsLegacySecurityException
145      */

146     public int getType() {
147
148         return m_type;
149     }
150     
151     /**
152      * Returns the description String for the provided CmsException type.<p>
153      *
154      * @param type exception error code
155      * @return the description String for the provided CmsException type
156      */

157     protected String JavaDoc getErrorDescription(int type) {
158         switch (type) {
159             case C_SECURITY_NO_PERMISSIONS:
160                 return "No permissions to perform this operation";
161             case C_SECURITY_INVALID_PASSWORD:
162                 return "Invalid password";
163             default:
164                 return this.getClass().getName();
165         }
166     }
167 }
168
Popular Tags