Package javax.script

Examples of javax.script.Invocable


    private ScriptEngine engine;

    public void testInvokeFunctionInXML() throws ScriptException, XMLStreamException, FactoryConfigurationError, NoSuchMethodException {
        engine.eval("function isXML(xml) { return typeof xml == 'xml'; }" );
        assertTrue(engine instanceof Invocable);
        Invocable invocableScript = (Invocable) engine;

        Object xmlIn = xmlHelper.toScriptXML(createOMElement("<a><b>petra</b></a>"));

        Object o = invocableScript.invokeFunction("isXML", new Object[]{xmlIn});
        assertTrue(o instanceof Boolean);
        assertTrue(((Boolean)o).booleanValue());
    }
View Full Code Here


    }

    public void testInvokeFunctionOutXML() throws ScriptException, XMLStreamException, FactoryConfigurationError, NoSuchMethodException {
        engine.eval("function hello(xml) { return <foo>{xml.b}</foo>; }" );
        assertTrue(engine instanceof Invocable);
        Invocable invocableScript = (Invocable) engine;

        Object xmlIn = xmlHelper.toScriptXML(createOMElement("<a><b>petra</b></a>"));

        Object xmlOut = invocableScript.invokeFunction("hello", new Object[]{xmlIn});
        OMElement omOut = xmlHelper.toOMElement(xmlOut);
        assertEquals("<foo><b>petra</b></foo>", omOut.toString());
    }
View Full Code Here

        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByExtension("js");
        assertNotNull("engine should not be null", engine);
        engine.eval("function hello(s) { return 'Hello ' + s; }" );
        assertTrue(engine instanceof Invocable);
        Invocable invocableScript = (Invocable) engine;
        assertEquals("Hello petra", invocableScript.invokeFunction("hello", new Object[]{"petra"}));
    }
View Full Code Here

        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByExtension("js");
        assertNotNull("engine should not be null", engine);
        engine.eval("function hello(s) { return 'Hello ' + s; }" );
        assertTrue(engine instanceof Invocable);
        Invocable invocableScript = (Invocable) engine;

        Object thiz = engine.eval("this;");
        assertEquals("Hello petra", invocableScript.invokeMethod(thiz, "hello", new Object[]{"petra"}));
    }
View Full Code Here

        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByExtension("py");
        assertNotNull("engine should not be null", engine);
        engine.eval("def hello(name):\n return 'Hello ' + name");
        assertTrue("engine should be invocable",engine instanceof Invocable);
        Invocable invocableScript = (Invocable) engine;
        assertEquals("Hello Monty", invocableScript.invokeFunction("hello", new Object[] { "Monty" }));
    }
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(final Object value) {
            Object result = 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 {
                    result = invocable.invokeFunction(functionName, result);
                } catch (NoSuchMethodException exception) {
                    throw new RuntimeException(exception);
                } catch (ScriptException exception) {
                    throw new RuntimeException(exception);
                }
View Full Code Here

        this.callableObject = callableObject;
    }


    public void actionPerformed(AnActionEvent anActionEvent) {
        Invocable invocableEngine = (Invocable) engine;
        try {
            invocableEngine.invokeMethod(callableObject, "actionPerformed", anActionEvent);
        } catch (Throwable e) {
            //don't care if the method doesn't exist
        }
    }
View Full Code Here

    }

    @Override
    public void update(AnActionEvent anActionEvent) {
        super.update(anActionEvent);
        Invocable invocableEngine = (Invocable) engine;
        try {
            invocableEngine.invokeMethod(callableObject, "update", anActionEvent);
        } catch (Throwable e) {
            //don't care if the method doesn't exist
        }
    }
View Full Code Here

  }

  public Invocable invocableEngine() throws HttpException {
    ScriptEngineManager engineMgr = new ScriptEngineManager();
    ScriptEngine scriptEngine = engineMgr.getEngineByName("jython");
    Invocable invocableEngine = null;
    try {
      scriptEngine.eval(script);
      invocableEngine = (Invocable) scriptEngine;
    } catch (ScriptException e) {
      throw new UserException(e.getMessage());
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.