Example usage for javax.script ScriptEngine eval

List of usage examples for javax.script ScriptEngine eval

Introduction

In this page you can find the example usage for javax.script ScriptEngine eval.

Prototype

public Object eval(Reader reader) throws ScriptException;

Source Link

Document

Same as eval(String) except that the source of the script is provided as a Reader

Usage

From source file:org.eclairjs.nashorn.sql.JSUDF16.java

@SuppressWarnings({ "null", "unchecked" })
@Override//www .j  a v a  2s  .  co m
public Object call(Object o, Object o2, Object o3, Object o4, Object o5, Object o6, Object o7, Object o8,
        Object o9, Object o10, Object o11, Object o12, Object o13, Object o14, Object o15, Object o16)
        throws Exception {
    ScriptEngine e = NashornEngineSingleton.getEngine();
    if (this.fn == null) {
        this.fn = e.eval(func);
    }
    Invocable invocable = (Invocable) e;

    Object params[] = { this.fn, o, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, o13, o14, o15, o16 };

    if (this.args != null && this.args.length > 0) {
        params = ArrayUtils.addAll(params, this.args);
    }

    Object ret = invocable.invokeFunction("Utils_invoke", params);
    ret = this.castValueToReturnType(ret);
    return ret;
}

From source file:org.eclairjs.nashorn.sql.JSUDF17.java

@SuppressWarnings({ "null", "unchecked" })
@Override/*from  w w  w .j  a v  a 2 s.  c o m*/
public Object call(Object o, Object o2, Object o3, Object o4, Object o5, Object o6, Object o7, Object o8,
        Object o9, Object o10, Object o11, Object o12, Object o13, Object o14, Object o15, Object o16,
        Object o17) throws Exception {
    ScriptEngine e = NashornEngineSingleton.getEngine();
    if (this.fn == null) {
        this.fn = e.eval(func);
    }
    Invocable invocable = (Invocable) e;

    Object params[] = { this.fn, o, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, o13, o14, o15, o16, o17 };

    if (this.args != null && this.args.length > 0) {
        params = ArrayUtils.addAll(params, this.args);
    }

    Object ret = invocable.invokeFunction("Utils_invoke", params);
    ret = this.castValueToReturnType(ret);
    return ret;
}

From source file:org.eclairjs.nashorn.sql.JSUDF18.java

@SuppressWarnings({ "null", "unchecked" })
@Override/*from   w  w  w .  ja  v a 2  s .  c  o  m*/
public Object call(Object o, Object o2, Object o3, Object o4, Object o5, Object o6, Object o7, Object o8,
        Object o9, Object o10, Object o11, Object o12, Object o13, Object o14, Object o15, Object o16,
        Object o17, Object o18) throws Exception {
    ScriptEngine e = NashornEngineSingleton.getEngine();
    if (this.fn == null) {
        this.fn = e.eval(func);
    }
    Invocable invocable = (Invocable) e;

    Object params[] = { this.fn, o, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, o13, o14, o15, o16, o17,
            o18 };

    if (this.args != null && this.args.length > 0) {
        params = ArrayUtils.addAll(params, this.args);
    }

    Object ret = invocable.invokeFunction("Utils_invoke", params);
    ret = this.castValueToReturnType(ret);
    return ret;
}

From source file:org.eclairjs.nashorn.sql.JSUDF19.java

@SuppressWarnings({ "null", "unchecked" })
@Override/*  w ww.j a v a2s  .c  o m*/
public Object call(Object o, Object o2, Object o3, Object o4, Object o5, Object o6, Object o7, Object o8,
        Object o9, Object o10, Object o11, Object o12, Object o13, Object o14, Object o15, Object o16,
        Object o17, Object o18, Object o19) throws Exception {
    ScriptEngine e = NashornEngineSingleton.getEngine();
    if (this.fn == null) {
        this.fn = e.eval(func);
    }
    Invocable invocable = (Invocable) e;

    Object params[] = { this.fn, o, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, o13, o14, o15, o16, o17, o18,
            o19 };

    if (this.args != null && this.args.length > 0) {
        params = ArrayUtils.addAll(params, this.args);
    }

    Object ret = invocable.invokeFunction("Utils_invoke", params);
    ret = this.castValueToReturnType(ret);
    return ret;
}

From source file:org.eclairjs.nashorn.sql.JSUDF20.java

@SuppressWarnings({ "null", "unchecked" })
@Override/*from  w ww .  j av a2  s  .c om*/
public Object call(Object o, Object o2, Object o3, Object o4, Object o5, Object o6, Object o7, Object o8,
        Object o9, Object o10, Object o11, Object o12, Object o13, Object o14, Object o15, Object o16,
        Object o17, Object o18, Object o19, Object o20) throws Exception {
    ScriptEngine e = NashornEngineSingleton.getEngine();
    if (this.fn == null) {
        this.fn = e.eval(func);
    }
    Invocable invocable = (Invocable) e;

    Object params[] = { this.fn, o, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, o13, o14, o15, o16, o17, o18,
            o19, o20 };

    if (this.args != null && this.args.length > 0) {
        params = ArrayUtils.addAll(params, this.args);
    }

    Object ret = invocable.invokeFunction("Utils_invoke", params);
    ret = this.castValueToReturnType(ret);
    return ret;
}

From source file:org.eclairjs.nashorn.sql.JSUDF21.java

@SuppressWarnings({ "null", "unchecked" })
@Override/*from w w  w .j  a  va  2 s .  c  o m*/
public Object call(Object o, Object o2, Object o3, Object o4, Object o5, Object o6, Object o7, Object o8,
        Object o9, Object o10, Object o11, Object o12, Object o13, Object o14, Object o15, Object o16,
        Object o17, Object o18, Object o19, Object o20, Object o21) throws Exception {
    ScriptEngine e = NashornEngineSingleton.getEngine();
    if (this.fn == null) {
        this.fn = e.eval(func);
    }
    Invocable invocable = (Invocable) e;

    Object params[] = { this.fn, o, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, o13, o14, o15, o16, o17, o18,
            o19, o20, o21 };

    if (this.args != null && this.args.length > 0) {
        params = ArrayUtils.addAll(params, this.args);
    }

    Object ret = invocable.invokeFunction("Utils_invoke", params);
    ret = this.castValueToReturnType(ret);
    return ret;
}

From source file:org.eclairjs.nashorn.sql.JSUDF22.java

@SuppressWarnings({ "null", "unchecked" })
@Override/*from ww  w . j  a  va  2 s  .  c o  m*/
public Object call(Object o, Object o2, Object o3, Object o4, Object o5, Object o6, Object o7, Object o8,
        Object o9, Object o10, Object o11, Object o12, Object o13, Object o14, Object o15, Object o16,
        Object o17, Object o18, Object o19, Object o20, Object o21, Object o22) throws Exception {
    ScriptEngine e = NashornEngineSingleton.getEngine();
    if (this.fn == null) {
        this.fn = e.eval(func);
    }
    Invocable invocable = (Invocable) e;

    Object params[] = { this.fn, o, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, o13, o14, o15, o16, o17, o18,
            o19, o20, o21, o22 };

    if (this.args != null && this.args.length > 0) {
        params = ArrayUtils.addAll(params, this.args);
    }

    Object ret = invocable.invokeFunction("Utils_invoke", params);
    ret = this.castValueToReturnType(ret);
    return ret;
}

From source file:org.geoserver.script.wfs.WfsTxHookTest.java

public void testHookExecution() throws Exception {
    File script = copyOverFile("tx");
    TransactionRequest tx = new TransactionRequest.WFS11(null);
    TransactionResponse res = new TransactionResponse.WFS11(null);

    Map context = new HashMap();

    ScriptEngine eng = scriptMgr.createNewEngine(script);
    eng.eval(new FileReader(script));

    WfsTxHook hook = getScriptManager().lookupWfsTxHook(script);
    hook.handleBefore(eng, tx, context);
    hook.handlePreInsert(eng, null, tx, context);
    hook.handlePostInsert(eng, null, tx, context);
    hook.handlePreUpdate(eng, null, null, tx, context);
    hook.handlePostUpdate(eng, null, null, tx, context);
    hook.handlePreDelete(eng, null, tx, context);
    hook.handlePostDelete(eng, null, tx, context);
    hook.handlePreCommit(eng, tx, context);
    hook.handlePostCommit(eng, tx, res, context);
    hook.handleAbort(eng, tx, res, context);

    assertTrue(context.containsKey("before"));
    assertTrue(context.containsKey("preInsert"));
    assertTrue(context.containsKey("postInsert"));
    assertTrue(context.containsKey("preUpdate"));
    assertTrue(context.containsKey("postUpdate"));
    assertTrue(context.containsKey("preDelete"));
    assertTrue(context.containsKey("postDelete"));
    assertTrue(context.containsKey("preCommit"));
    assertTrue(context.containsKey("postCommit"));
    assertTrue(context.containsKey("abort"));
}

From source file:mondrian.util.UtilCompatibleJdk16.java

public <T> T compileScript(Class<T> iface, String script, String engineName) {
    ScriptEngineManager factory = new ScriptEngineManager();
    ScriptEngine engine = factory.getEngineByName(engineName);
    try {/*  w ww  . ja v a  2s. co  m*/
        engine.eval(script);
        Invocable inv = (Invocable) engine;
        return inv.getInterface(iface);
    } catch (ScriptException e) {
        throw Util.newError(e, "Error while compiling script to implement " + iface + " SPI");
    }
}

From source file:org.suren.autotest.web.framework.data.JavaScriptDynamicData.java

@Override
public String getValue(String orginData) {
    String value = null;/*  www  . j  a v  a 2  s  .c o m*/
    ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript");
    try {
        Object resObj = engine.eval(orginData);
        if (resObj != null) {
            value = resObj.toString();
        } else {
            value = "js not return!";
        }
    } catch (ScriptException e) {
        value = e.getMessage();
        e.printStackTrace();
    }

    return value;
}