1 7 package com.inversoft.error; 8 9 10 import java.text.MessageFormat ; 11 import java.util.Locale ; 12 import java.util.MissingResourceException ; 13 import java.util.ResourceBundle ; 14 15 16 35 public class ErrorRegistry { 36 37 58 public static String getError(String bundleName, String key, Locale locale, 59 Object caller, Object [] params) throws MissingResourceException { 60 if (locale == null) { 62 locale = Locale.getDefault(); 63 } 64 65 ResourceBundle rb = ResourceBundle.getBundle(bundleName, locale); 66 String error = null; 67 68 if (caller != null) { 69 StringBuffer buf = new StringBuffer (caller.getClass().getName()); 70 buf.append(".").append(key); 71 error = rb.getString(buf.toString()); 72 73 } else { 74 error = rb.getString(key); 75 } 76 77 if (params != null) { 78 error = MessageFormat.format(error, params); 79 } 80 81 return error; 82 } 83 84 87 public static String getError(String bundleName, String key, Locale locale, 88 Object caller) { 89 return getError(bundleName, key, locale, caller, null); 90 } 91 92 97 public static BasicError getBasicError(String bundleName, String key, 98 Locale locale, Object caller) { 99 String error = getError(bundleName, key, locale, caller, null); 100 BasicError be = new BasicError(error, locale); 101 102 return be; 103 } 104 105 110 public static BasicError getBasicError(String bundleName, String key, 111 Locale locale, Object caller, Object [] params) { 112 String error = getError(bundleName, key, locale, caller, params); 113 BasicError be = new BasicError(error, locale); 114 115 return be; 116 } 117 118 123 public static PropertyError getPropertyError(String bundleName, String key, 124 Locale locale, String property, Object caller) { 125 String error = getError(bundleName, key, locale, caller, null); 126 PropertyError pe = new PropertyError(property, error, locale); 127 128 return pe; 129 } 130 131 136 public static PropertyError getPropertyError(String bundleName, String key, 137 Locale locale, String property, Object caller, Object [] params) { 138 String error = getError(bundleName, key, locale, caller, params); 139 PropertyError pe = new PropertyError(property, error, locale); 140 141 return pe; 142 } 143 } | Popular Tags |