01: // Copyright 2000 Samuele Pedroni
02:
03: package jxxload_help;
04:
05: public class PathVFSJavaLoader extends ClassLoader {
06: private ClassLoader parent;
07:
08: private PathVFS vfs;
09:
10: public java.util.Vector interfaces = new java.util.Vector();
11:
12: public PathVFSJavaLoader(PathVFS vfs, ClassLoader parent) {
13: this .vfs = vfs;
14: this .parent = parent;
15: }
16:
17: protected Class loadClass(String name, boolean resolve)
18: throws ClassNotFoundException {
19: Class c;
20:
21: c = findLoadedClass(name);
22: if (c != null)
23: return c;
24:
25: try {
26: if (parent != null)
27: return parent.loadClass(name);
28: } catch (ClassNotFoundException e) {
29: }
30:
31: java.io.InputStream in = vfs.open(name.replace('.', '/')
32: + ".class");
33: if (in == null)
34: throw new ClassNotFoundException(name);
35: try {
36: byte[] buf = org.python.core.FileUtil.readBytes(in);
37: in.close();
38: return loadClassFromBytes(name, buf);
39: } catch (java.io.IOException e) {
40: throw new ClassNotFoundException(name);
41: }
42: }
43:
44: private Class loadClassFromBytes(String name, byte[] data) {
45: Class c = defineClass(name, data, 0, data.length);
46: resolveClass(c);
47: if (c.isInterface())
48: interfaces.addElement(c);
49: if (!org.python.core.Options.skipCompile) {
50: Compiler.compileClass(c);
51: }
52: return c;
53: }
54:
55: }
|