📄 errormessages.java
字号:
package com.ebusiness.ebank.exception;/** * <p>Title: </p> * <p>Description: This class defines Message keys and provides a static method * to get langauge-based message</p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: eBusiness Inc., All right reserved</p> * @author unascribed * @version 1.0 */import java.util.Map;import java.util.HashMap;import java.util.Set;import java.util.HashSet;import java.util.Properties;import java.util.Enumeration;import java.util.Locale;import java.io.InputStream;import org.apache.log4j.Logger;import org.apache.log4j.MDC;public class ErrorMessages{ //Business Error Message key Definition //Please note: The actual message descriptions are defined in errorMessage properties files //common message keys public final static String RECORD_CHANGED = "common.RecordChanged"; public final static String RECORD_DELETED = "common.RecordDeleted"; public final static String NO_RECORD_FOUND = "common.NoRecordFound"; public final static String INVALID_FLAG = "common.InvalidFlag"; public final static String INVALID_LANGUAGE = "common.InvalidLanguage"; public final static String NOT_ENOUGH_DATA = "common.NotEnoughData"; public final static String INVALID_EXPIRY_DATE= "common.InvalidExpiryDate"; //common message keys specific for Security public final static String NO_SAVE_AUTHORIZED = "security.NoSaveAuthorized"; public final static String NO_UPDATE_AUTHORIZED = "security.NoUpdateAuthorized"; public final static String NO_DELETE_AUTHORIZED = "security.NoDeleteAuthorized"; public final static String NO_VIEW_AUTHORIZED = "security.NoViewAuthorized"; public final static String NO_TRANSFER_AUTHORIZED = "security.NoTransferAuthorized"; public final static String NO_DEPOSIT_AUTHORIZED = "security.NoDepositAuthorized"; public final static String NO_WITHDRAWAL_AUTHORIZED = "security.NoWithdrawalAuthorized"; public final static String NO_PAYBILL_AUTHORIZED = "security.NoPayBillAuthorized"; //ClientCard related message keys public final static String WRONG_PASSWORD = "clientcard.WrongPassword"; public final static String MISSING_NEWPASSWORD = "clientcard.MissingNewPassword"; public final static String PASSWORD_NOT_MATCH = "clientcard.PasswordNotMatch"; public final static String PASSWORD_DUPLICATE = "clientcard.PasswordDuplicate"; public final static String NO_CLIENTCARD_FOUND = "clientcard.NoClientCardFound"; //Cardholder related message keys public final static String INVALID_SIN = "cardholder.InvalidSIN"; public final static String NO_CARDHOLDER_FOUND = "cardholder.NoCardholderFound"; //Address related message keys public final static String CANNOT_DELETE_ADDRESS = "address.CannotDeleteAddress"; public final static String INVALID_ADDRESS_TYPE = "address.InvalidAddressType"; public final static String COUNTRY_NOT_EXIST = "address.CountryNotExist"; public final static String STATE_NOT_EXIST = "address.StateNotExist"; public final static String INCORRECT_POSTAL_CODE_FORMAT = "address.IncorrectPostalCodeFormat"; //Account related message keys public final static String INVALID_ACCOUNT = "account.InvalidAccount"; public final static String EXCEED_LIMIT = "account.ExceedLimit"; public final static String WITHDRAWAL_RESTRICTED = "account.WithdrawalRestricted"; public final static String CANNOT_TRANSFER_TO_ITSELF = "account.CannotTransferToItself"; public final static String NO_ACCOUNT_FOUND = "account.NoAccountFound"; //Below Defines System Error Messages public final static String FAIL_TO_CREATE_DATABASE_CONNECTION = "Fail to establish database connection"; public final static String FAIL_TO_CLOSE_DATABASE_STATEMENT = "Fail to close database statement"; public final static String FAIL_TO_CLOSE_DATABASE_CONNECTION = "Fail to close database connection"; public final static String FAIL_TO_ROLL_BACK = "Fail to roll back database changes"; public final static String OTHER_DATABASE_ERROR = "Database Error"; public final static String FAIL_TO_INSTANTIATE_SERVICELOCATOR = "Fail to instantiate ServiceLocator"; public final static String FAIL_TO_LOOKUP_LOCALHOME = "Fail to lookup LocalHome"; public final static String FAIL_TO_LOOKUP_REMOTEHOME = "Fail to lookup RemoteHome"; public final static String FAIL_TO_LOOKUP_DATASOURCE = "Fail to lookup DataSource"; public final static String CLASS_CAST = "Class Cast Exception"; public final static String EJB_CREATE_ERROR = "Fail to Create EJB"; public final static String EJB_LOCALEXCEPTION_ERROR = "EJB LocalException error"; public final static String EJB_REMOTEEXCEPTION_ERROR = "EJB RemoteException error"; public final static String EJB_FINDEREXCEPTION_ERROR = "EJB FinderException error"; public final static String NO_VALUE = "No current value available"; //Hold message key and message description (value) private static Map messages; private static Map messagesByKey; //Hold all language codes which are available for the application private static String languages[]; private static Logger log = Logger.getLogger("com.ebusiness.ebank.exception.ErrorMessages"); //load error message properties and store them to HashMap static { messages = new HashMap(); messagesByKey = new HashMap(); initMessages(); } //return message descriptions in all languages for the specified message key public static Map getMessages(String key) { Map map = (Map)messagesByKey.get(key); if (map != null) return map; map = new HashMap(); for (int i = 0; i < languages.length; i++) { map.put(languages[i], ((Map)messages.get(languages[i])).get(key)); } messagesByKey.put(key, map); //put the messages to messagesByKey for future access return map; } /** * <p>Description: Read and load all error messages from properties files(one file for each language) * to HashMap for reuse. * * The English properties file will be errorMessages.properties. All other language * properties files format is errorMessages_ concatenating with ISO languageCode * and concatenating with .properties. For example: * errorMessages_fr.properties is French errorMessages properties file * </p> * */ private static void initMessages() { Class clazz = null; try { clazz = Class.forName("com.ebusiness.ebank.exception.ErrorMessages"); } catch (Exception e) { log.error("Cannot find ErrorMessages class: "); } InputStream inStream; String[] lCodes = Locale.getISOLanguages(); Properties prop; Enumeration props; Map mesgsWithSameLang; String fileName; String key; for (int i = 0; i < lCodes.length; i++) { if ("en".equals(lCodes[i])) fileName = "errorMessage.properties"; else fileName = "errorMessage_" + lCodes[i] + ".properties"; try { inStream = clazz.getResourceAsStream(fileName); if (inStream != null) { prop = new Properties(); prop.load(inStream); props = prop.propertyNames(); mesgsWithSameLang = new HashMap(); while(props.hasMoreElements()) { key = (String)props.nextElement(); mesgsWithSameLang.put(key, prop.getProperty(key)); } //If messages in this languages is not empty, then put them to messages if (!mesgsWithSameLang.isEmpty()) messages.put(lCodes[i], mesgsWithSameLang); } } catch (Exception e) { log.error("Cannot load file: " + fileName); } } languages = (String[])messages.keySet().toArray(new String[messages.size()]); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -