Search in sources :

Example 1 with ScriptInterfaceException

use of com.infiniteautomation.mango.spring.script.MangoScriptException.ScriptInterfaceException in project ma-core-public by MangoAutomation.

the class ScriptService method getInterface.

public <T> T getInterface(MangoScript script, Class<T> clazz, EvalContext evalContext) {
    ScriptAndEngine scriptAndEngine = getScriptEngine(script);
    ScriptEngine engine = scriptAndEngine.engine;
    if (!(engine instanceof Invocable)) {
        throw new EngineNotInvocableException(engine);
    }
    evalScript(scriptAndEngine, evalContext);
    T instance = ((Invocable) engine).getInterface(clazz);
    if (instance == null) {
        throw new ScriptInterfaceException(clazz);
    }
    ScriptEngineDefinition engineDefinition = scriptAndEngine.engineDefinition;
    T runAsInstance = runAs.runAsProxy(script, instance);
    if (engineDefinition.singleThreadedAccess()) {
        return synchronizedProxy(scriptAndEngine.synchronizationObject, runAsInstance);
    }
    return runAsInstance;
}
Also used : Invocable(javax.script.Invocable) ScriptInterfaceException(com.infiniteautomation.mango.spring.script.MangoScriptException.ScriptInterfaceException) EngineNotInvocableException(com.infiniteautomation.mango.spring.script.MangoScriptException.EngineNotInvocableException) ScriptEngine(javax.script.ScriptEngine) ScriptEngineDefinition(com.serotonin.m2m2.module.ScriptEngineDefinition)

Example 2 with ScriptInterfaceException

use of com.infiniteautomation.mango.spring.script.MangoScriptException.ScriptInterfaceException in project ma-core-public by infiniteautomation.

the class ScriptService method getInterface.

public <T> T getInterface(MangoScript script, Class<T> clazz, EvalContext evalContext) {
    ScriptAndEngine scriptAndEngine = getScriptEngine(script);
    ScriptEngine engine = scriptAndEngine.engine;
    if (!(engine instanceof Invocable)) {
        throw new EngineNotInvocableException(engine);
    }
    evalScript(scriptAndEngine, evalContext);
    T instance = ((Invocable) engine).getInterface(clazz);
    if (instance == null) {
        throw new ScriptInterfaceException(clazz);
    }
    ScriptEngineDefinition engineDefinition = scriptAndEngine.engineDefinition;
    T runAsInstance = runAs.runAsProxy(script, instance);
    if (engineDefinition.singleThreadedAccess()) {
        return synchronizedProxy(scriptAndEngine.synchronizationObject, runAsInstance);
    }
    return runAsInstance;
}
Also used : Invocable(javax.script.Invocable) ScriptInterfaceException(com.infiniteautomation.mango.spring.script.MangoScriptException.ScriptInterfaceException) EngineNotInvocableException(com.infiniteautomation.mango.spring.script.MangoScriptException.EngineNotInvocableException) ScriptEngine(javax.script.ScriptEngine) ScriptEngineDefinition(com.serotonin.m2m2.module.ScriptEngineDefinition)

Aggregations

EngineNotInvocableException (com.infiniteautomation.mango.spring.script.MangoScriptException.EngineNotInvocableException)2 ScriptInterfaceException (com.infiniteautomation.mango.spring.script.MangoScriptException.ScriptInterfaceException)2 ScriptEngineDefinition (com.serotonin.m2m2.module.ScriptEngineDefinition)2 Invocable (javax.script.Invocable)2 ScriptEngine (javax.script.ScriptEngine)2