1 55 56 package org.apache.bsf.util.event; 57 58 import java.util.Hashtable ; 59 import org.apache.bsf.util.event.generator.EventAdapterGenerator; 60 61 82 public class EventAdapterRegistry { 83 private static Hashtable reg = new Hashtable (); 84 private static ClassLoader cl = null; 85 private static String adapterPackage = "org.apache.bsf.util.event.adapters"; 86 private static String adapterSuffix = "Adapter"; 87 private static boolean dynamic = true; 88 89 public static Class lookup (Class listenerType) { 90 String key = listenerType.getName().replace ('.', '_'); 91 Class adapterClass = (Class ) reg.get (key); 92 93 if (adapterClass == null) { 94 String en = key.substring (0, key.lastIndexOf ("Listener")); 95 String cn = adapterPackage + "." + en + adapterSuffix; 96 97 try { 98 adapterClass = (cl != null) ? cl.loadClass (cn) : Class.forName (cn); 100 } catch (ClassNotFoundException e) { 101 if (dynamic) { 102 adapterClass = 104 EventAdapterGenerator.makeEventAdapterClass (listenerType, false); 105 } 106 } 107 108 if (adapterClass != null) { 109 reg.put (key, adapterClass); 110 } 111 } 112 113 return adapterClass; 114 } 115 public static void register (Class listenerType, Class eventAdapterClass) { 116 String key = listenerType.getName().replace('.', '_'); 117 reg.put (key, eventAdapterClass); 118 } 119 122 public static void setClassLoader (ClassLoader cloader) { 123 cl = cloader; 124 } 125 135 public static void setDynamic (boolean dynamic) { 136 EventAdapterRegistry.dynamic = dynamic; 137 } 138 } 139 | Popular Tags |