1 package de.webman.template.jsp; 2 3 import java.util.*; 4 import java.io.*; 5 import com.teamkonzept.lib.*; 6 import org.apache.log4j.Category; 7 8 14 public class JSPClassLoader extends ClassLoader 15 { 16 private static final int BUFFER_SIZE = 8000; 17 private static Category cat = Category.getInstance(JSPClassLoader.class); 18 String rootDir; 19 ClassLoader parent; 20 21 private Hashtable cache = new Hashtable(); 23 24 public JSPClassLoader(String _rootDir, ClassLoader _parent) 25 { 26 super(); 27 rootDir = _rootDir; 28 parent = _parent; 29 } 30 31 public void unloadClass(String name) 32 { 33 cache.remove(name); 34 } 35 36 private byte[] loadClassData(String name) throws IOException 37 { 38 FileInputStream f = new FileInputStream(rootDir + File.separator + name + ".class"); 40 byte[] data = new byte[BUFFER_SIZE]; 41 ByteArrayOutputStream out = new ByteArrayOutputStream(BUFFER_SIZE); 42 int read = 1; 43 while (read > 0) 44 { 45 read = f.read(data); 46 if (read > 0) 47 out.write(data, 0, read); 48 } 49 return out.toByteArray(); 50 } 51 52 public synchronized Class loadClass(String name, boolean resolve) 53 { 54 try 55 { 56 Class c = parent.loadClass(name); 57 if ( c != null) 58 return c; 59 } 60 catch (ClassNotFoundException e) 61 { 62 cat.debug("Parent hat Klasse nicht gefunden " + name); 64 } 65 try 66 { 67 Class c = (Class )cache.get(name); 68 if (c == null) { 69 byte data[] = loadClassData(name); 70 c = defineClass(data, 0, data.length); 71 cache.put(name, c); 72 } 73 if (resolve) 74 resolveClass(c); 75 return c; 76 } 77 catch (IOException e) 78 { 79 cat.error("loadClass", e); 80 return null; 82 } 83 } 84 85 } | Popular Tags |