Package javax.script

Examples of javax.script.ScriptEngine.eval()


    }
    if(logger.isDebugEnabled())
      logger.debug("Transition Expressopn End");
   
    try {
      Object result = engine.eval(expression, variables);
      if(result instanceof Boolean && (Boolean)result) {
        return true;
      } else
        return false;
    } catch (Exception e) {
View Full Code Here


    ScriptEngineManager factory = new ScriptEngineManager();
    ScriptEngine engine = factory.getEngineByName("JavaScript");
    String content = configFile.getContent();
    engine.put("config", this);
    try {
      engine.eval(content);
    } catch (ScriptException e) {
      throw new IllegalStateException("There was an arror evaluating config script: " + configFile.getPath(), e);
    }

  }
View Full Code Here

                        bvp.addBindings(b);
                    }
                }
                log.debug("All Bindings added: {}", b.keySet());

                final Object value = engine.eval(expression, b);
                if(value!=null && "true".equals(value.toString().toLowerCase())) {
                    resultLog.debug("Expression [{}] evaluates to true as expected", expression);
                } else {
                    resultLog.warn("Expression [{}] does not evaluate to true as expected, value=[{}]", expression, value);
                }
View Full Code Here

    public void testPreserveScopeBetweenEvals() throws ScriptException {
        MockRhinoJavaScriptEngineFactory factory = new MockRhinoJavaScriptEngineFactory();
        ScriptEngine engine = factory.getScriptEngine();
        Bindings context = new SimpleBindings();
        engine.eval("var f = 1", context);
        Object result = null;
        try {
            result = engine.eval("f += 1", context);
        } catch (ScriptException e) {
            TestCase.fail(e.getMessage());
View Full Code Here

        ScriptEngine engine = factory.getScriptEngine();
        Bindings context = new SimpleBindings();
        engine.eval("var f = 1", context);
        Object result = null;
        try {
            result = engine.eval("f += 1", context);
        } catch (ScriptException e) {
            TestCase.fail(e.getMessage());
        }
        assertTrue(result instanceof Double);
        assertEquals(2.0, result);
View Full Code Here

    private static Logger log = Logger.getLogger(ExecuteGroovyFromJSR223.class.getName());
   
    public static void main(String[] args) {
        ScriptEngine engine = new ScriptEngineManager().getEngineByName("groovy");
        try {
            engine.eval("println 'Hello, Groovy!'");
            engine.eval(new FileReader("src/mjg/scripting/hello_world.groovy"));
           
            engine.put("street","Blackheath Avenue");
            engine.put("city","Greenwich");
            engine.put("state","UK");
View Full Code Here

   
    public static void main(String[] args) {
        ScriptEngine engine = new ScriptEngineManager().getEngineByName("groovy");
        try {
            engine.eval("println 'Hello, Groovy!'");
            engine.eval(new FileReader("src/mjg/scripting/hello_world.groovy"));
           
            engine.put("street","Blackheath Avenue");
            engine.put("city","Greenwich");
            engine.put("state","UK");
            engine.eval(new FileReader("src/geocodeV3.groovy"));
View Full Code Here

            engine.eval(new FileReader("src/mjg/scripting/hello_world.groovy"));
           
            engine.put("street","Blackheath Avenue");
            engine.put("city","Greenwich");
            engine.put("state","UK");
            engine.eval(new FileReader("src/geocodeV3.groovy"));
            double latitude = Double.parseDouble((String) engine.get("lat"));
            double longitude = Double.parseDouble((String) engine.get("lng"));
            log.info("latitude = " + latitude);
            log.info("longitude = " + longitude);
        } catch (ScriptException | FileNotFoundException e) {
View Full Code Here

        ScriptEngine engine = new ScriptEngineManager().getEngineByName("groovy");
        engine.put("street", "Blackheath Avenue");
        engine.put("city","Greenwich");
        engine.put("state", "UK");
        try {
            engine.eval(new FileReader("src/geocodeV3.groovy"));
        } catch (ScriptException | FileNotFoundException e) {
            e.printStackTrace();
        }
        assertEquals(51.4752654,
            Double.parseDouble((String) engine.get("lat")),0.000001);
View Full Code Here

    ScriptEngine engine = discoverEngine(script, arguments);

    Bindings bindings = (!CollectionUtils.isEmpty(arguments) ? new SimpleBindings(arguments) : null);

    try {
      return (bindings == null ? engine.eval(script.getScriptAsString()) : engine.eval(
          script.getScriptAsString(), bindings));
    } catch (IOException ex) {
      throw new ScriptCompilationException(script, "Cannot access script", ex);
    } catch (ScriptException ex) {
      throw new ScriptCompilationException(script, "Execution failure", ex);
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.