001: /*
002: * $Header: /cvsroot/mvnforum/myvietnam/src/net/myvietnam/mvncore/exception/NotLoginException.java,v 1.14 2007/01/15 10:31:09 dungbtm Exp $
003: * $Author: dungbtm $
004: * $Revision: 1.14 $
005: * $Date: 2007/01/15 10:31:09 $
006: *
007: * ====================================================================
008: *
009: * Copyright (C) 2002-2007 by MyVietnam.net
010: *
011: * All copyright notices regarding MyVietnam and MyVietnam CoreLib
012: * MUST remain intact in the scripts and source code.
013: *
014: * This library is free software; you can redistribute it and/or
015: * modify it under the terms of the GNU Lesser General Public
016: * License as published by the Free Software Foundation; either
017: * version 2.1 of the License, or (at your option) any later version.
018: *
019: * This library is distributed in the hope that it will be useful,
020: * but WITHOUT ANY WARRANTY; without even the implied warranty of
021: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
022: * Lesser General Public License for more details.
023: *
024: * You should have received a copy of the GNU Lesser General Public
025: * License along with this library; if not, write to the Free Software
026: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
027: *
028: * Correspondence and Marketing Questions can be sent to:
029: * info at MyVietnam net
030: *
031: * @author: Minh Nguyen
032: * @author: Mai Nguyen
033: */
034: package net.myvietnam.mvncore.exception;
035:
036: import java.util.Locale;
037:
038: import net.myvietnam.mvncore.MVNCoreResourceBundle;
039:
040: public class NotLoginException extends Exception {
041:
042: public static final int NOT_LOGIN = 0;
043: public static final int ILLEGAL_STATE = 1;
044: public static final int WRONG_NAME = 2;
045: public static final int WRONG_PASSWORD = 3;
046: public static final int ACCOUNT_DISABLED = 4;
047: public static final int NOT_ENOUGH_RIGHTS = 5;
048: public static final int NOT_ACTIVATED = 6;
049: public static final int COOKIE_NOT_ALLOWED = 7;
050: public static final int LOGIN_DISABLED = 8;
051:
052: private int exceptionReason = NOT_LOGIN;
053:
054: public NotLoginException(String msg) {
055: super (msg);
056: }
057:
058: public NotLoginException(int reason) {
059: exceptionReason = reason;
060: }
061:
062: public NotLoginException(String msg, int reason) {
063: super (msg);
064: exceptionReason = reason;
065: }
066:
067: public int getReason() {
068: return exceptionReason;
069: }
070:
071: public String getReasonString() {
072: if (exceptionReason == ILLEGAL_STATE) {
073: return "reason: ILLEGAL_STATE";
074: } else if (exceptionReason == WRONG_NAME) {
075: return "reason: WRONG_NAME";
076: } else if (exceptionReason == WRONG_PASSWORD) {
077: return "reason: WRONG_PASSWORD";
078: } else if (exceptionReason == ACCOUNT_DISABLED) {
079: return "reason: ACCOUNT_DISABLED";
080: } else if (exceptionReason == NOT_ENOUGH_RIGHTS) {
081: return "reason: NOT_ENOUGH_RIGHTS";
082: } else if (exceptionReason == NOT_ACTIVATED) {
083: return "reason: NOT_ACTIVATED";
084: } else if (exceptionReason == COOKIE_NOT_ALLOWED) {
085: return "reason: COOKIE_NOT_ALLOWED";
086: } else if (exceptionReason == LOGIN_DISABLED) {
087: return "reason: LOGIN_DISABLED";
088: }
089: return "reason: NOTLOGIN";
090: }
091:
092: public String getReasonExplanation() {
093: Locale locale = Locale.getDefault();
094: return getReasonExplanation(locale);
095: }
096:
097: public String getReasonExplanation(Locale locale) {
098: if (exceptionReason == ILLEGAL_STATE) {
099: return MVNCoreResourceBundle
100: .getString(locale,
101: "mvncore.exception.NotLoginException.illegal_state");
102: } else if (exceptionReason == WRONG_NAME) {
103: return MVNCoreResourceBundle.getString(locale,
104: "mvncore.exception.NotLoginException.wrong_name");
105: } else if (exceptionReason == WRONG_PASSWORD) {
106: return MVNCoreResourceBundle
107: .getString(locale,
108: "mvncore.exception.NotLoginException.wrong_password");
109: } else if (exceptionReason == ACCOUNT_DISABLED) {
110: return MVNCoreResourceBundle
111: .getString(locale,
112: "mvncore.exception.NotLoginException.account_disabled");
113: } else if (exceptionReason == NOT_ENOUGH_RIGHTS) {
114: return MVNCoreResourceBundle
115: .getString(locale,
116: "mvncore.exception.NotLoginException.not_enough_rights");
117: } else if (exceptionReason == NOT_ACTIVATED) {
118: return MVNCoreResourceBundle
119: .getString(locale,
120: "mvncore.exception.NotLoginException.not_activated");
121: } else if (exceptionReason == COOKIE_NOT_ALLOWED) {
122: return MVNCoreResourceBundle
123: .getString(locale,
124: "mvncore.exception.NotLoginException.cookie_not_allowed");
125: } else if (exceptionReason == LOGIN_DISABLED) {
126: return MVNCoreResourceBundle
127: .getString(locale,
128: "mvncore.exception.NotLoginException.login_disabled");
129: }
130: return MVNCoreResourceBundle.getString(locale,
131: "mvncore.exception.NotLoginException.default");
132: }
133:
134: public String getMessage() {
135: if (super.getMessage() == null) {
136: return getReasonExplanation();
137: }
138: return super.getMessage();
139: }
140: }
|