1 55 56 package org.apache.bsf.util.event.generator; 57 58 import java.util.*; 59 import org.apache.bsf.debug.util.DebugLog; 60 61 public class AdapterClassLoader extends ClassLoader 62 { 63 private static Hashtable classCache = new Hashtable(); 64 private Class c; 65 66 public AdapterClassLoader() 67 { 68 super(); 69 } 70 public synchronized Class defineClass(String name, byte[] b) 71 { 72 if ((c = getLoadedClass(name)) == null) 73 { 74 c = defineClass(name, b, 0, b.length); 75 put(name, c); 76 } 77 else 78 { 79 DebugLog.stderrPrintln("AdapterClassLoader: " + c + 80 " previously loaded. Can not redefine class.", 81 DebugLog.BSF_LOG_L2); 82 } 83 84 return c; 85 } 86 final protected Class findClass(String name) 87 { 88 return get(name); 89 } 90 final protected Class get(String name) 91 { 92 return (Class )classCache.get(name); 93 } 94 public synchronized Class getLoadedClass(String name) 95 { 96 Class c = findLoadedClass(name); 97 98 if (c == null) 99 { 100 try 101 { 102 c = findSystemClass(name); 103 } 104 catch (ClassNotFoundException e) 105 { 106 } 107 } 108 109 if (c == null) 110 { 111 c = findClass(name); 112 } 113 114 return c; 115 } 116 protected synchronized Class loadClass(String name, boolean resolve) 117 throws ClassNotFoundException 118 { 119 Class c = getLoadedClass(name); 120 121 if (c != null && resolve) 122 { 123 resolveClass(c); 124 } 125 126 return c; 127 } 128 134 final protected void put(String name, Class c) 135 { 136 classCache.put(name, c); 137 } 138 } 139 | Popular Tags |