Search in sources :

Example 1 with Interpreter

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);
}
Also used : Interpreter(bsh.Interpreter) Bundle(android.os.Bundle)

Example 2 with Interpreter

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);
}
Also used : Interpreter(bsh.Interpreter) NameSpace(bsh.NameSpace)

Example 3 with Interpreter

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);
    }
}
Also used : Interpreter(bsh.Interpreter) StringReader(java.io.StringReader) EvalError(bsh.EvalError) IOException(java.io.IOException) ScriptCompilationException(org.springframework.scripting.ScriptCompilationException) Map(java.util.Map)

Example 4 with Interpreter

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;
    }
}
Also used : Interpreter(bsh.Interpreter)

Example 5 with Interpreter

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;
}
Also used : Interpreter(bsh.Interpreter)

Aggregations

Interpreter (bsh.Interpreter)24 EvalError (bsh.EvalError)9 TargetError (bsh.TargetError)5 Map (java.util.Map)3 Bundle (android.os.Bundle)2 ParseException (bsh.ParseException)2 Async (br.com.brjdevs.java.utils.async.Async)1 CollectionUtils.random (br.com.brjdevs.java.utils.collections.CollectionUtils.random)1 NameSpace (bsh.NameSpace)1 XThis (bsh.XThis)1 Color (java.awt.Color)1 File (java.io.File)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 SQLException (java.sql.SQLException)1 java.util (java.util)1