01: package org.python.core;
02:
03: /**
04: * Load Java classes.
05: */
06: public class JavaImporter extends PyObject {
07:
08: public JavaImporter() {
09: super ();
10: }
11:
12: public PyObject __call__(PyObject args[], String keywords[]) {
13: if (args[0].toString().endsWith("__classpath__")) {
14: return this ;
15: }
16: throw Py.ImportError("unable to handle");
17: }
18:
19: /**
20: * Find the module for the fully qualified name.
21: *
22: * @param name the fully qualified name of the module
23: * @return a loader instance if this importer can load the module, None
24: * otherwise
25: */
26: public PyObject find_module(String name) {
27: return find_module(name, Py.None);
28: }
29:
30: /**
31: * Find the module for the fully qualified name.
32: *
33: * @param name the fully qualified name of the module
34: * @param path if installed on the meta-path None or a module path
35: * @return a loader instance if this importer can load the module, None
36: * otherwise
37: */
38: public PyObject find_module(String name, PyObject path) {
39: Py.writeDebug("import", "trying " + name
40: + " in packagemanager for path " + path);
41: PyObject ret = PySystemState.packageManager.lookupName(name
42: .intern());
43: if (ret != null) {
44: Py.writeComment("import", "'" + name + "' as java package");
45: return this ;
46: }
47: return Py.None;
48: }
49:
50: public PyObject load_module(String name) {
51: return PySystemState.packageManager.lookupName(name.intern());
52: }
53:
54: /**
55: * Returns a string representation of the object.
56: *
57: * @return a string representation of the object.
58: */
59: public String toString() {
60: return this.getType().toString();
61: }
62: }
|