Package javax.script

Examples of javax.script.Invocable


        }
        catch (ScriptException e)
        {
            throw new ActivityUserException(e);
        }
        Invocable inv = (Invocable)engine;
        ScriptActivity activity = inv.getInterface(ScriptActivity.class);
        try
        {
            LOG.debug("Processing script");
            activity.process(mInputs, mOutputs);
        }
View Full Code Here


            Object result = null;

            String methodName = method.getName();
            Bindings bindings = scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE);
            if (bindings.containsKey(methodName)) {
                Invocable invocable;
                try {
                    invocable = (Invocable)scriptEngine;
                } catch (ClassCastException exception) {
                    throw new SerializationException(exception);
                }

                result = invocable.invokeFunction(methodName, args);
            }

            // If the function didn't return a value, return the default
            if (result == null) {
                Class<?> returnType = method.getReturnType();
View Full Code Here

        }

        public Object evaluate(Object value) {
            Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE);
            if (bindings.containsKey(functionName)) {
                Invocable invocable;
                try {
                    invocable = (Invocable)scriptEngine;
                } catch (ClassCastException exception) {
                    throw new RuntimeException(exception);
                }

                try {
                    value = invocable.invokeFunction(functionName, value);
                } catch (NoSuchMethodException exception) {
                    throw new RuntimeException(exception);
                } catch (ScriptException exception) {
                    throw new RuntimeException(exception);
                }
View Full Code Here

        this.baseFolder = ".";
    }

    public EntryTransformer getEntryTransformer(String scriptName) {
        String content = load("entry", scriptName);
        Invocable invocable = (Invocable) engine;
        try {
            engine.eval(content);
        } catch (ScriptException ex) {
            throw new IllegalStateException("Cannot evaluate script", ex);
        }
        return invocable.getInterface(EntryTransformer.class);
    }
View Full Code Here

    }

    public RowTransformer getRowTransformer(String scriptName) {

        String content = load("row", scriptName);
        Invocable invocable = (Invocable) engine;
        try {
            engine.eval(content);
        } catch (ScriptException ex) {
            throw new IllegalStateException("Cannot evaluate script", ex);
        }
        RowTransformer scriptedTransformer = invocable.getInterface(RowTransformer.class);

        return (Row input) -> {
            try {
                return scriptedTransformer.execute(input);
            } catch (RuntimeException e) {
View Full Code Here

            Object result = null;

            String methodName = method.getName();
            Bindings bindings = scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE);
            if (bindings.containsKey(methodName)) {
                Invocable invocable;
                try {
                    invocable = (Invocable)scriptEngine;
                } catch (ClassCastException exception) {
                    throw new SerializationException(exception);
                }

                result = invocable.invokeFunction(methodName, args);
            }

            // If the function didn't return a value, return the default
            if (result == null) {
                Class<?> returnType = method.getReturnType();
View Full Code Here

        @Override
        public Object evaluate(Object value) {
            Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE);
            if (bindings.containsKey(functionName)) {
                Invocable invocable;
                try {
                    invocable = (Invocable)scriptEngine;
                } catch (ClassCastException exception) {
                    throw new RuntimeException(exception);
                }

                try {
                    value = invocable.invokeFunction(functionName, value);
                } catch (NoSuchMethodException exception) {
                    throw new RuntimeException(exception);
                } catch (ScriptException exception) {
                    throw new RuntimeException(exception);
                }
View Full Code Here

    for(String scriptFile: scriptFiles) {
      engine.eval(FileUtils.readFileToString(new File("src/main/javascript/" + scriptFile)));
    }
  }
  protected <T extends Bird> T getJs(String identifier, Class<T> c) {
    Invocable inv = (Invocable) engine;
    return (T) inv.getInterface(engine.get(identifier), c);
  }
View Full Code Here

  @Test
  public void test_nashorn_loading() throws Throwable {
    CodeLoader loader = new CodeLoader();
    ScriptEngine check = loader.nashorn("check");
    Invocable invocable = (Invocable) check;
    assertEquals(42, invocable.invokeFunction("truth"));
    assertEquals(11, invocable.invokeFunction("incr", 10));
  }
View Full Code Here

            ScriptEngineManager factory = new ScriptEngineManager();
            this.engine = factory.getEngineByName("JavaScript");
            if (this.engine == null){
                this.getLogman().error(NO_JAVASCRIPT_MESSAGE);
            } else {
                Invocable inv = (Invocable)this.engine;
                //File f = new File(this.getJarPath());
                InputStreamReader reader = new InputStreamReader(getClass()
                                                                 .getClassLoader()
                                                                 .getResourceAsStream("boot.js"));
                this.engine.eval(reader);
                inv.invokeFunction("__scboot", this, engine, getClass().getClassLoader());
            }

            Canary.commands().registerCommands(this, this, false);
        }catch(Exception e){
            e.printStackTrace();
View Full Code Here

TOP

Related Classes of javax.script.Invocable

Copyright © 2018 www.massapicom. 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.