use of bsh.NameSpace in project qi4j-sdk by Qi4j.
the class BeanShellMixin method invoke.
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Interpreter runtime;
synchronized (BeanShellMixin.class) {
runtime = runtimes.get(module);
}
if (runtime == null) {
runtime = new Interpreter();
BshClassManager.createClassManager(runtime);
Class compositeType = me.getClass().getInterfaces()[0];
NameSpace namespace = buildNamespace(compositeType, runtime);
runtime.setNameSpace(namespace);
synchronized (BeanShellMixin.class) {
runtimes.put(module, runtime);
}
runtime.set("compositeBuilderFactory", compositeBuilderFactory);
runtime.set("unitOfWorkFactory", uowFactory);
}
if (mixins == null) {
mixins = extractMixins(runtime.getClassManager());
}
Object instance = mixins.get(method.getDeclaringClass());
return method.invoke(instance, args);
}
use of bsh.NameSpace in project qi4j-sdk by Qi4j.
the class BeanShellMixin method buildNamespace.
private static NameSpace buildNamespace(Class compositeType, Interpreter runtime) throws IOException {
ClassLoader loader = compositeType.getClassLoader();
BshClassManager classManager = BshClassManager.createClassManager(runtime);
classManager.setClassLoader(loader);
NameSpace namespace = new NameSpace(classManager, compositeType.getName());
URL scriptUrl = getFunctionResource(compositeType);
if (scriptUrl == null) {
return null;
}
Reader source = getSource(compositeType, scriptUrl);
try {
runtime.eval(source, namespace, scriptUrl.toString());
} catch (EvalError evalError) {
//TODO: Auto-generated, need attention.
evalError.printStackTrace();
}
return namespace;
}
Aggregations