Java Script eval(String name, Map params)

Here you can find the source of eval(String name, Map params)

Description

eval

License

Open Source License

Declaration

public static Object eval(String name, Map<String, Object> params) throws ScriptException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.script.Bindings;

import javax.script.CompiledScript;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class Main {
    private static ScriptEngine engine = new ScriptEngineManager().getEngineByName("js");
    private static Map<String, CompiledScript> scripts = new ConcurrentHashMap<String, CompiledScript>();

    public static Object eval(String name, Map<String, Object> params) throws ScriptException {
        CompiledScript script = scripts.get(name);
        if (script == null) {
            throw new ScriptException("no such methor!");
        }//from   ww  w  . j  a va  2s . c o m

        Bindings b = engine.createBindings();
        if (params != null) {
            b.putAll(params);
        }
        return script.eval(b);
    }
}

Related

  1. convert(Object from)
  2. dbObjectFromMap(Map from)
  3. decodeB64_TO_UTF8(String encodedStr)
  4. escapeJavascript(String str)
  5. eval(String expression, Object... arguments)
  6. eval(String script)
  7. evaluateExpression(String expr)
  8. evaluateExpression(String s)
  9. executeAppleScript(String script)