-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathJavaImporter.java
More file actions
66 lines (58 loc) · 1.94 KB
/
JavaImporter.java
File metadata and controls
66 lines (58 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package org.python.core;
import java.util.logging.Logger;
import java.util.logging.Level;
/**
* Load Java classes.
*/
@Untraversable
public class JavaImporter extends PyObject {
public static final String JAVA_IMPORT_PATH_ENTRY = "__classpath__";
private static Logger log = Logger.getLogger("org.python.import");
@Override
public PyObject __call__(PyObject args[], String keywords[]) {
if(args[0].toString().endsWith(JAVA_IMPORT_PATH_ENTRY)){
return this;
}
throw Py.ImportError("unable to handle");
}
/**
* Find the module for the fully qualified name.
*
* @param name the fully qualified name of the module
* @return a loader instance if this importer can load the module, None
* otherwise
*/
public PyObject find_module(String name) {
return find_module(name, Py.None);
}
/**
* Find the module for the fully qualified name.
*
* @param name the fully qualified name of the module
* @param path if installed on the meta-path None or a module path
* @return a loader instance if this importer can load the module, None
* otherwise
*/
public PyObject find_module(String name, PyObject path) {
log.log(Level.FINE, "# trying {0} in package manager for path {1}",
new Object[] {name, path});
PyObject ret = PySystemState.packageManager.lookupName(name.intern());
if (ret != null) {
log.log(Level.CONFIG, "import {0} # as java package", name);
return this;
}
return Py.None;
}
public PyObject load_module(String name) {
return PySystemState.packageManager.lookupName(name.intern());
}
/**
* Returns a string representation of the object.
*
* @return a string representation of the object.
*/
@Override
public String toString() {
return this.getType().toString();
}
}