01: package de.webman.template.jsp;
02:
03: import java.util.*;
04: import java.io.*;
05: import com.teamkonzept.lib.*;
06: import org.apache.log4j.Category;
07:
08: /**
09: laedt die von Jasper uebersetzte Klasse ins System, damit der
10: Request abgearbeitet werden kann
11: * @author $Author: alex $
12: * @version $Revision: 1.2 $
13: */
14: public class JSPClassLoader extends ClassLoader {
15: private static final int BUFFER_SIZE = 8000;
16: private static Category cat = Category
17: .getInstance(JSPClassLoader.class);
18: String rootDir;
19: ClassLoader parent;
20:
21: // cached die Definitionen
22: private Hashtable cache = new Hashtable();
23:
24: public JSPClassLoader(String _rootDir, ClassLoader _parent) {
25: super ();
26: rootDir = _rootDir;
27: parent = _parent;
28: }
29:
30: public void unloadClass(String name) {
31: cache.remove(name);
32: }
33:
34: private byte[] loadClassData(String name) throws IOException {
35: // load the class data from the directory
36: FileInputStream f = new FileInputStream(rootDir
37: + File.separator + name + ".class");
38: byte[] data = new byte[BUFFER_SIZE];
39: ByteArrayOutputStream out = new ByteArrayOutputStream(
40: BUFFER_SIZE);
41: int read = 1;
42: while (read > 0) {
43: read = f.read(data);
44: if (read > 0)
45: out.write(data, 0, read);
46: }
47: return out.toByteArray();
48: }
49:
50: public synchronized Class loadClass(String name, boolean resolve) {
51: try {
52: Class c = parent.loadClass(name);
53: if (c != null)
54: return c;
55: } catch (ClassNotFoundException e) {
56: // ist ok, aber JTest zwing mich dazu
57: cat.debug("Parent hat Klasse nicht gefunden " + name);
58: }
59: try {
60: Class c = (Class) cache.get(name);
61: if (c == null) {
62: byte data[] = loadClassData(name);
63: c = defineClass(data, 0, data.length);
64: cache.put(name, c);
65: }
66: if (resolve)
67: resolveClass(c);
68: return c;
69: } catch (IOException e) {
70: cat.error("loadClass", e);
71: // wie bekomme ich eine bessere Meldung?
72: return null;
73: }
74: }
75:
76: }
|