KickJava   Java API By Example, From Geeks To Geeks.

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


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

3 package org.python.core;
4 import java.io.*;
5 import java.util.*;
6
7 /**
8  * A java1 classloader for loading compiled python modules.
9  */

10 class BytecodeLoader1 extends ClassLoader JavaDoc implements Loader {
11     private Vector parents;
12
13     public BytecodeLoader1() {
14         parents = BytecodeLoader.init();
15     }
16
17     public void addParent(ClassLoader JavaDoc referent) {
18         if (!parents.contains(referent))
19             parents.addElement(referent);
20     }
21
22     // override from abstract base class
23
protected Class JavaDoc loadClass(String JavaDoc name, boolean resolve)
24         throws ClassNotFoundException JavaDoc
25     {
26         Class JavaDoc c = findLoadedClass(name);
27         if (c != null)
28             return c;
29         return BytecodeLoader.findParentClass(parents, name);
30     }
31
32
33     public Class JavaDoc loadClassFromBytes(String JavaDoc name, byte[] data) {
34         Class JavaDoc c = defineClass(name, data, 0, data.length);
35         resolveClass(c);
36         BytecodeLoader.compileClass(c);
37         return c;
38     }
39 }
40
Popular Tags