1 23 24 37 package com.sun.enterprise.util.i18n; 38 39 import java.util.ResourceBundle ; 40 import java.util.Locale ; 41 import java.util.Hashtable ; 42 import java.text.MessageFormat ; 43 44 import java.util.logging.Level ; 45 import java.util.logging.Logger ; 46 import com.sun.logging.LogDomains; 47 48 89 public class StringManager extends StringManagerBase { 90 91 92 private static Logger _logger=LogDomains.getLogger(LogDomains.UTIL_LOGGER); 93 94 95 private ResourceBundle _resourceBundle = null; 96 97 98 private static final String RES_BUNDLE_NM = ".LocalStrings"; 99 100 101 102 private static Hashtable managers = new Hashtable (); 103 104 109 private StringManager(String packageName) { 110 super(packageName + RES_BUNDLE_NM); 111 } 112 113 120 public synchronized static StringManager getManager(String packageName) { 121 122 StringManager mgr = (StringManager) managers.get(packageName); 123 124 if (mgr == null) { 125 mgr = new StringManager(packageName); 126 try { 127 managers.put(packageName, mgr); 128 } catch (Exception e) { 129 _logger.log(Level.SEVERE,"iplanet_util.error_while_caching",e); 130 } 131 } 132 return mgr; 133 } 134 135 143 public synchronized static StringManager getManager(Class callerClass) { 144 145 try { 146 Package pkg = callerClass.getPackage(); 147 if (pkg != null) { 148 String pkgName = pkg.getName(); 149 return getManager(pkgName); 150 } else { 151 String pkgName = callerClass.getName(); 153 return getManager(pkgName); 154 } 155 } catch (Exception e) { 156 _logger.log(Level.SEVERE, "iplanet_util.error_in_getMgr", e); 157 158 return getManager(""); 160 } 161 } 162 163 164 169 public static void main(String [] args) { 170 171 long b = System.currentTimeMillis(); 172 try { 173 StringManager sm = 174 StringManager.getManager("com.sun.enterprise.util.i18n"); 175 176 String ls = sm.getString( 177 "test", 178 new Integer (7), new java.util.Date (System.currentTimeMillis()), 179 "a disturbance in the Force"); 180 181 System.out.println(ls); 182 183 System.out.println( sm.getString("bad") ); 184 185 } catch (Exception e) { 186 System.out.println("---- Error ---- "); 187 e.printStackTrace(); 188 } finally { 189 long a = System.currentTimeMillis(); 190 System.out.println("Time: " + (a-b) ); 191 } 192 } 193 } 194 | Popular Tags |