1 23 24 package com.sun.enterprise.admin.jmx.remote; 25 26 import com.sun.enterprise.admin.jmx.remote.IStringManager; 27 import com.sun.enterprise.admin.jmx.remote.StringManager; 28 import com.sun.enterprise.admin.jmx.remote.DefaultConfiguration; 29 30 import java.lang.reflect.Constructor ; 31 import java.util.logging.Logger ; 32 import java.util.Hashtable ; 33 import java.util.Map ; 34 35 public class StringManagerFactory { 36 37 38 private static Hashtable managers = new Hashtable (); 39 40 private static final Logger logger = Logger.getLogger( 41 DefaultConfiguration.JMXCONNECTOR_LOGGER); 48 public static IStringManager getServerStringManager(String packageName) { 49 String stringMgrClassName = System.getProperty(DefaultConfiguration.STRING_MANAGER_CLASS_NAME); 50 return getManager(packageName, stringMgrClassName); 51 } 52 53 public static IStringManager getClientStringManager(String packageName, Map env) { 54 String stringMgrClassName = null; 55 if (env != null) 56 stringMgrClassName = (String )env.get(DefaultConfiguration.STRING_MANAGER_CLASS_NAME); 57 return getManager(packageName, stringMgrClassName); 58 } 59 60 63 public static IStringManager getServerStringManager(Class inputClass) { 64 String packageName = inputClass.getPackage().getName(); 65 String stringMgrClassName = System.getProperty(DefaultConfiguration.STRING_MANAGER_CLASS_NAME); 66 return getManager(packageName, stringMgrClassName); 67 } 68 69 public static IStringManager getClientStringManager(Class inputClass, Map env) { 70 String packageName = inputClass.getPackage().getName(); 71 String stringMgrClassName = null; 72 if (env != null) 73 stringMgrClassName = (String )env.get(DefaultConfiguration.STRING_MANAGER_CLASS_NAME); 74 return getManager(packageName, stringMgrClassName); 75 } 76 77 public static IStringManager getManager(String packageName, String stringMgrClassName) { 78 79 IStringManager mgr = (IStringManager) managers.get(packageName); 80 81 if (mgr != null) return mgr; 82 83 if (stringMgrClassName == null) mgr = new StringManager(packageName); 84 else { 85 try { 86 Class customClass = Class.forName(stringMgrClassName); 87 Constructor constructor = 88 customClass.getConstructor(new Class [] { String .class }); 89 mgr = (IStringManager) constructor.newInstance(new Object [] {packageName}); 90 } catch (Exception e) { 91 logger.severe("StringManager could not be configured"); 92 } 93 } 94 95 if (mgr != null) managers.put(packageName, mgr); 96 else logger.severe("Custom StringManager Class could not be instantiated"); 97 98 return mgr; 99 } 100 } | Popular Tags |