Search in sources :

Example 6 with ScriptEngineDefinition

use of com.serotonin.m2m2.module.ScriptEngineDefinition in project ma-core-public by MangoAutomation.

the class ScriptService method getScriptEngine.

private ScriptAndEngine getScriptEngine(MangoScript script) {
    ScriptEngine engine;
    ScriptEngineDefinition definition;
    if (script instanceof CompiledMangoScript) {
        engine = ((CompiledMangoScript) script).compiled.getEngine();
        definition = definitionForFactory(engine.getFactory());
    } else {
        ScriptEngineFactory factory = getFactoryByName(script.getEngineName());
        definition = definitionForFactory(factory);
        engine = definition.createEngine(factory, script);
    }
    PermissionHolder user = Common.getUser();
    permissionService.ensurePermission(user, definition.requiredPermission());
    permissionService.hasSupersetOfRoles(user, script);
    return new ScriptAndEngine(script, definition, engine);
}
Also used : ScriptEngineFactory(javax.script.ScriptEngineFactory) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) ScriptEngine(javax.script.ScriptEngine) ScriptEngineDefinition(com.serotonin.m2m2.module.ScriptEngineDefinition)

Aggregations

ScriptEngineDefinition (com.serotonin.m2m2.module.ScriptEngineDefinition)6 ScriptEngine (javax.script.ScriptEngine)6 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)2 EngineNotInvocableException (com.infiniteautomation.mango.spring.script.MangoScriptException.EngineNotInvocableException)2 ScriptEvalException (com.infiniteautomation.mango.spring.script.MangoScriptException.ScriptEvalException)2 ScriptIOException (com.infiniteautomation.mango.spring.script.MangoScriptException.ScriptIOException)2 ScriptInterfaceException (com.infiniteautomation.mango.spring.script.MangoScriptException.ScriptInterfaceException)2 ScriptBindingsDefinition (com.serotonin.m2m2.module.ScriptBindingsDefinition)2 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)2 IOException (java.io.IOException)2 Reader (java.io.Reader)2 Bindings (javax.script.Bindings)2 Invocable (javax.script.Invocable)2 ScriptContext (javax.script.ScriptContext)2 ScriptEngineFactory (javax.script.ScriptEngineFactory)2 ScriptException (javax.script.ScriptException)2