KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > python > core > BytecodeLoader2


1 // Copyright (c) Corporation for National Research Initiatives
2

3 package org.python.core;
4 import java.io.*;
5 import java.util.*;
6 import java.security.*;
7
8 /**
9  * 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         parents = BytecodeLoader.init();
16     }
17
18     public void addParent(ClassLoader JavaDoc referent) {
19         if (!parents.contains(referent))
20             parents.addElement(referent);
21     }
22
23     // override from abstract base class
24
protected Class JavaDoc loadClass(String JavaDoc name, boolean resolve)
25         throws ClassNotFoundException JavaDoc
26     {
27         Class JavaDoc c = findLoadedClass(name);
28         if (c != null)
29             return c;
30         return BytecodeLoader.findParentClass(parents, name);
31     }
32
33
34     public Class JavaDoc loadClassFromBytes(String JavaDoc name, byte[] data) {
35         Class JavaDoc c = defineClass(name, data, 0, data.length,
36                               this.getClass().getProtectionDomain());
37         resolveClass(c);
38         BytecodeLoader.compileClass(c);
39         return c;
40     }
41
42 }
43
Popular Tags