use of bsh.Interpreter in project cw-omnibus by commonsguy.
the class BshInterpreter method executeScript.
public Bundle executeScript(Bundle input) {
Interpreter i = new Interpreter();
Bundle output = new Bundle(input);
String script = input.getString(InterpreterService.SCRIPT);
if (script != null) {
try {
i.set(InterpreterService.BUNDLE, input);
i.set(InterpreterService.RESULT, output);
Object eval_result = i.eval(script);
output.putString("result", eval_result.toString());
} catch (Throwable t) {
output.putString("error", t.getMessage());
}
}
return (output);
}
use of bsh.Interpreter 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.Interpreter in project spring-framework by spring-projects.
the class BshScriptEvaluator method evaluate.
@Override
public Object evaluate(ScriptSource script, Map<String, Object> arguments) {
try {
Interpreter interpreter = new Interpreter();
interpreter.setClassLoader(this.classLoader);
if (arguments != null) {
for (Map.Entry<String, Object> entry : arguments.entrySet()) {
interpreter.set(entry.getKey(), entry.getValue());
}
}
return interpreter.eval(new StringReader(script.getScriptAsString()));
} catch (IOException ex) {
throw new ScriptCompilationException(script, "Cannot access BeanShell script", ex);
} catch (EvalError ex) {
throw new ScriptCompilationException(script, ex);
}
}
use of bsh.Interpreter in project spring-framework by spring-projects.
the class BshScriptUtils method determineBshObjectType.
/**
* Evaluate the specified BeanShell script based on the given script source,
* returning the Class defined by the script.
* <p>The script may either declare a full class or return an actual instance of
* the scripted object (in which case the Class of the object will be returned).
* In any other case, the returned Class will be {@code null}.
* @param scriptSource the script source text
* @param classLoader the ClassLoader to use for evaluating the script
* @return the scripted Java class, or {@code null} if none could be determined
* @throws EvalError in case of BeanShell parsing failure
*/
static Class<?> determineBshObjectType(String scriptSource, ClassLoader classLoader) throws EvalError {
Assert.hasText(scriptSource, "Script source must not be empty");
Interpreter interpreter = new Interpreter();
interpreter.setClassLoader(classLoader);
Object result = interpreter.eval(scriptSource);
if (result instanceof Class) {
return (Class<?>) result;
} else if (result != null) {
return result.getClass();
} else {
return null;
}
}
use of bsh.Interpreter in project symmetric-ds by JumpMind.
the class BshColumnTransform method getInterpreter.
protected Interpreter getInterpreter(Context context) {
Interpreter interpreter = (Interpreter) context.get(INTERPRETER_KEY);
if (interpreter == null) {
interpreter = new Interpreter();
context.put(INTERPRETER_KEY, interpreter);
}
return interpreter;
}
Aggregations