01: // Copyright (c) Corporation for National Research Initiatives
02:
03: package org.python.core;
04:
05: import java.security.SecureClassLoader;
06: import java.util.Vector;
07:
08: /**
09: * A java2 classloader for loading compiled python modules.
10: */
11: class BytecodeLoader2 extends SecureClassLoader implements Loader {
12: private Vector parents;
13:
14: public BytecodeLoader2() {
15: this .parents = BytecodeLoader.init();
16: }
17:
18: public void addParent(ClassLoader referent) {
19: if (!this .parents.contains(referent)) {
20: this .parents.add(0, referent);
21: }
22: }
23:
24: // override from abstract base class
25: protected Class loadClass(String name, boolean resolve)
26: throws ClassNotFoundException {
27: Class c = findLoadedClass(name);
28: if (c != null) {
29: return c;
30: }
31: return BytecodeLoader.findParentClass(this .parents, name);
32: }
33:
34: public Class loadClassFromBytes(String name, byte[] data) {
35: Class c = defineClass(name, data, 0, data.length, this
36: .getClass().getProtectionDomain());
37: resolveClass(c);
38: BytecodeLoader.compileClass(c);
39: return c;
40: }
41:
42: }
|