Package javax.script

Examples of javax.script.ScriptEngine.eval()


    // create an R engine
    ScriptEngine engine = factory.getScriptEngine();

    HashMap<String, String> h = new HashMap<String, String>();
    engine.put("h", h);
    engine.eval("import(java.util.HashMap) \n"
                    + " print(h$size())");
  }
 
}
View Full Code Here


        engine.put("user", user);
        engine.put("date", new Date());
        try {

            Object result = engine.eval(script);
            if (result instanceof Boolean) {
                return ((Boolean) result).booleanValue();
            }

        } catch (ScriptException e) {
View Full Code Here

            for (Map.Entry<String, Object> entry : entries) {
                engine.put(entry.getKey(), entry.getValue());
            }
        }
        try {
            this.result = engine.eval(script);
        } catch (ScriptException e) {
            this.result = e.getMessage();
        }
    }
View Full Code Here

            }
            if (Debug.verboseOn()) {
                Debug.logVerbose("Begin processing script [" + script + "] using engine " + engine.getClass().getName(), module);
            }
            ScriptContext scriptContext = createScriptContext(context);
            return engine.eval(script, scriptContext);
        } catch (Exception e) {
            String errMsg = "Error running " + language + " script [" + script + "]: " + e.toString();
            Debug.logWarning(e, errMsg, module);
            throw new IllegalArgumentException(errMsg);
        }
View Full Code Here

            Debug.logVerbose("Begin processing script [" + filePath + "] using engine " + engine.getClass().getName(), module);
        }
        engine.setContext(scriptContext);
        URL scriptUrl = FlexibleLocation.resolveLocation(filePath);
        FileReader reader = new FileReader(new File(scriptUrl.getFile()));
        Object result = engine.eval(reader);
        if (UtilValidate.isNotEmpty(functionName)) {
            try {
                Invocable invocableEngine = (Invocable) engine;
                result = invocableEngine.invokeFunction(functionName, args == null ? EMPTY_ARGS : args);
            } catch (ClassCastException e) {
View Full Code Here


    maybeInvocableEngine.setContext(globalScriptContext);
    try
    {
      maybeInvocableEngine.eval(globalScript);
    }
    catch (ScriptException e)
    {
      throw new ReportDataFactoryException("DataFactoryScriptingSupport: Failed to execute datafactory init script.", e);
    }
View Full Code Here

        throw new ScriptException(String.format
            ("DataFactoryScriptingSupport: Failed to locate scripting engine for language '%s'.", scriptLanguage));
      }

      scriptEngine.setContext(context);
      return scriptEngine.eval(script);
    }

    public Object evalFile(final String file) throws ScriptException
    {
      return evalFile(file, defaultScriptLanguage);
View Full Code Here

                // Don't pollute the engine namespace with the listener functions
                scriptEngine.setBindings(new SimpleBindings(), ScriptContext.ENGINE_SCOPE);

                try {
                    scriptEngine.eval(script);
                } catch (ScriptException exception) {
                    reportException(exception, script);
                    break;
                }
View Full Code Here

                        }

                        BufferedReader scriptReader = null;
                        try {
                            scriptReader = new BufferedReader(new InputStreamReader(scriptLocation.openStream()));
                            scriptEngine.eval(scriptReader);
                        } catch(ScriptException exception) {
                            reportException(exception);
                        } finally {
                            if (scriptReader != null) {
                                scriptReader.close();
View Full Code Here

                    }

                    scriptEngine.setBindings(scriptEngineManager.getBindings(), ScriptContext.ENGINE_SCOPE);

                    try {
                        scriptEngine.eval(script);
                    } catch (ScriptException exception) {
                        reportException(exception, script);
                    }
                }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.