1 23 24 package com.sun.enterprise.admin.jmx.remote; 25 26 import com.sun.enterprise.admin.jmx.remote.IStringManager; 27 28 import java.lang.reflect.Method ; 29 import java.util.logging.Logger ; 31 32 40 public class StringManager implements IStringManager { 41 42 private static final Logger logger = Logger.getLogger( 43 DefaultConfiguration.JMXCONNECTOR_LOGGER); 45 46 private static Class asStringManagerClass = null; 47 private static Method getStr = null; 48 private static Method getStrDef = null; 49 private static Method getStrGeneric = null; 50 private static Method getManager = null; 51 52 private Object asStringManager = null; 54 55 public StringManager(String packageName) { 56 try { 57 if (asStringManagerClass == null) { 58 asStringManagerClass = Class.forName("com.sun.enterprise.util.i18n.StringManager"); 59 getStr = asStringManagerClass.getMethod("getString", new Class [] { String .class}); 60 getStrDef = asStringManagerClass.getMethod("getString", new Class [] { String .class, Object .class }); 61 getStrGeneric = asStringManagerClass.getMethod("getString", new Class [] { String .class, Object [].class }); 62 getManager = asStringManagerClass.getMethod("getManager", new Class [] { String .class }); 63 } 64 65 asStringManager = getManager.invoke(asStringManagerClass, new Object [] { packageName }); 66 } catch (Throwable e) { 67 e.printStackTrace(); 68 StackTraceElement [] ste = e.getStackTrace(); 69 for (int i =0; i<ste.length; i++) logger.severe(ste[i].toString()); 70 logger.severe("StringManager could not be configured"); 71 } 72 } 73 74 public String getString(String key) { 75 try { 76 return (String ) getStr.invoke(asStringManager, new Object [] { key }); 77 } catch(Exception ex) { 78 logger.severe("Method invocation failed on com.sun.enterprise.util.i18n.StringManager"); 79 return null; 80 } 81 } 82 83 public String getString(String key, Object arg) { 84 try { 85 return (String ) getStrDef.invoke(asStringManager, new Object [] { key, arg }); 86 } catch(Exception ex) { 87 logger.severe("Method invocation failed on com.sun.enterprise.util.i18n.StringManager"); 88 return null; 89 } 90 } 91 92 public String getString(String key, Object [] args) { 93 try { 94 return (String ) getStrGeneric.invoke(asStringManager, new Object [] { key, args }); 95 } catch(Exception ex) { 96 logger.severe("Method invocation failed on com.sun.enterprise.util.i18n.StringManager"); 97 return null; 98 } 99 } 100 } 101 | Popular Tags |