01: // Copyright 2000 Samuele Pedroni
02:
03: package jxxload_help;
04:
05: public class PackageManager extends org.python.core.PathPackageManager {
06:
07: private JavaLoaderFactory factory;
08: private ClassLoader loader;
09:
10: public synchronized ClassLoader getLoader() {
11: if (loader == null)
12: loader = factory.makeLoader();
13: return loader;
14: }
15:
16: public synchronized ClassLoader checkLoader() {
17: return loader;
18: }
19:
20: public synchronized void resetLoader() {
21: loader = null;
22: }
23:
24: // ??pending add cache support?
25: public PackageManager(org.python.core.PyList path,
26: JavaLoaderFactory factory) {
27: this .factory = factory;
28:
29: for (int i = 0; i < path.__len__(); i++) {
30: String entry = path.__finditem__(i).toString();
31: if (entry.endsWith(".jar") || entry.endsWith(".zip")) {
32: addJarToPackages(new java.io.File(entry), false);
33: } else {
34: java.io.File dir = new java.io.File(entry);
35: if (entry.length() == 0 || dir.isDirectory())
36: addDirectory(dir);
37: }
38: }
39: }
40:
41: public Class findClass(String pkg, String name, String reason) {
42: if (pkg != null && pkg.length() > 0)
43: name = pkg + '.' + name;
44: try {
45: return getLoader().loadClass(name);
46: } catch (ClassNotFoundException e) {
47: return null;
48: } catch (LinkageError e) {
49: throw org.python.core.Py.JavaError(e);
50: }
51: }
52:
53: public void addJarDir(String jdir, boolean cache) {
54: throw new RuntimeException(
55: "addJarDir not supported for reloadable packages");
56: }
57:
58: public void addJar(String jdir, boolean cache) {
59: throw new RuntimeException(
60: "addDir not supported for reloadable packages");
61: }
62: }
|