1 34 package net.myvietnam.mvncore.exception; 35 36 import java.util.Locale ; 37 38 import net.myvietnam.mvncore.MVNCoreResourceBundle; 39 40 public class NotLoginException extends Exception { 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 msg) { 55 super(msg); 56 } 57 58 public NotLoginException(int reason) { 59 exceptionReason = reason; 60 } 61 62 public NotLoginException(String msg, int reason) { 63 super(msg); 64 exceptionReason = reason; 65 } 66 67 public int getReason() { 68 return exceptionReason; 69 } 70 71 public String 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 getReasonExplanation() { 93 Locale locale = Locale.getDefault(); 94 return getReasonExplanation(locale); 95 } 96 97 public String getReasonExplanation(Locale 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 getMessage() { 119 if (super.getMessage() == null) { 120 return getReasonExplanation(); 121 } 122 return super.getMessage(); 123 } 124 } 125 | Popular Tags |