KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > myvietnam > mvncore > exception > NotLoginException


1 /*
2  * $Header: /cvsroot/mvnforum/myvietnam/src/net/myvietnam/mvncore/exception/NotLoginException.java,v 1.13 2006/04/15 02:59:19 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.13 $
5  * $Date: 2006/04/15 02:59:19 $
6  *
7  * ====================================================================
8  *
9  * Copyright (C) 2002-2006 by MyVietnam.net
10  *
11  * All copyright notices regarding MyVietnam and MyVietnam CoreLib
12  * MUST remain intact in the scripts and source code.
13  *
14  * This library is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU Lesser General Public
16  * License as published by the Free Software Foundation; either
17  * version 2.1 of the License, or (at your option) any later version.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27  *
28  * Correspondence and Marketing Questions can be sent to:
29  * info at MyVietnam net
30  *
31  * @author: Minh Nguyen
32  * @author: Mai Nguyen
33  */

34 package net.myvietnam.mvncore.exception;
35
36 import java.util.Locale JavaDoc;
37
38 import net.myvietnam.mvncore.MVNCoreResourceBundle;
39
40 public class NotLoginException extends Exception JavaDoc {
41
42     public static final int NOT_LOGIN = 0;
43     public static final int ILLEGAL_STATE = 1;
44     public static final int WRONG_NAME = 2;
45     public static final int WRONG_PASSWORD = 3;
46     public static final int ACCOUNT_DISABLED = 4;
47     public static final int NOT_ENOUGH_RIGHTS = 5;
48     public static final int NOT_ACTIVATED = 6;
49     public static final int COOKIE_NOT_ALLOWED = 7;
50     public static final int LOGIN_DISABLED = 8;
51
52     private int exceptionReason = NOT_LOGIN;
53
54     public NotLoginException(String JavaDoc msg) {
55         super(msg);
56     }
57
58     public NotLoginException(int reason) {
59         exceptionReason = reason;
60     }
61
62     public NotLoginException(String JavaDoc msg, int reason) {
63         super(msg);
64         exceptionReason = reason;
65     }
66
67     public int getReason() {
68         return exceptionReason;
69     }
70
71     public String JavaDoc getReasonString() {
72         if (exceptionReason == ILLEGAL_STATE) {
73             return "reason: ILLEGAL_STATE";
74         } else if (exceptionReason == WRONG_NAME) {
75             return "reason: WRONG_NAME";
76         } else if (exceptionReason == WRONG_PASSWORD) {
77             return "reason: WRONG_PASSWORD";
78         } else if (exceptionReason == ACCOUNT_DISABLED) {
79             return "reason: ACCOUNT_DISABLED";
80         } else if (exceptionReason == NOT_ENOUGH_RIGHTS) {
81             return "reason: NOT_ENOUGH_RIGHTS";
82         } else if (exceptionReason == NOT_ACTIVATED) {
83             return "reason: NOT_ACTIVATED";
84         } else if (exceptionReason == COOKIE_NOT_ALLOWED) {
85             return "reason: COOKIE_NOT_ALLOWED";
86         } else if (exceptionReason == LOGIN_DISABLED) {
87             return "reason: LOGIN_DISABLED";
88         }
89         return "reason: NOTLOGIN";
90     }
91
92     public String JavaDoc getReasonExplanation() {
93         Locale JavaDoc locale = Locale.getDefault();
94         return getReasonExplanation(locale);
95     }
96
97     public String JavaDoc getReasonExplanation(Locale JavaDoc locale) {
98         if (exceptionReason == ILLEGAL_STATE) {
99             return MVNCoreResourceBundle.getString(locale, "mvncore.exception.NotLoginException.illegal_state");
100         } else if (exceptionReason == WRONG_NAME) {
101             return MVNCoreResourceBundle.getString(locale, "mvncore.exception.NotLoginException.wrong_name");
102         } else if (exceptionReason == WRONG_PASSWORD) {
103             return MVNCoreResourceBundle.getString(locale, "mvncore.exception.NotLoginException.wrong_password");
104         } else if (exceptionReason == ACCOUNT_DISABLED) {
105             return MVNCoreResourceBundle.getString(locale, "mvncore.exception.NotLoginException.account_disabled");
106         } else if (exceptionReason == NOT_ENOUGH_RIGHTS) {
107             return MVNCoreResourceBundle.getString(locale, "mvncore.exception.NotLoginException.not_enough_rights");
108         } else if (exceptionReason == NOT_ACTIVATED) {
109             return MVNCoreResourceBundle.getString(locale, "mvncore.exception.NotLoginException.not_activated");
110         } else if (exceptionReason == COOKIE_NOT_ALLOWED) {
111             return MVNCoreResourceBundle.getString(locale, "mvncore.exception.NotLoginException.cookie_not_allowed");
112         } else if (exceptionReason == LOGIN_DISABLED) {
113             return MVNCoreResourceBundle.getString(locale, "mvncore.exception.NotLoginException.login_disabled");
114         }
115         return MVNCoreResourceBundle.getString(locale, "mvncore.exception.NotLoginException.default");
116     }
117
118     public String JavaDoc getMessage() {
119         if (super.getMessage() == null) {
120             return getReasonExplanation();
121         }
122         return super.getMessage();
123     }
124 }
125
Popular Tags