Package javax.script

Examples of javax.script.Invocable.invokeMethod()


        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



    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

      rubyEngine.eval(scriptReader);
      // Call function
      obj = rubyInvocableEngine.invokeFunction("function_two",
          "HelloWord");
      // Call method (procedure)
      rubyInvocableEngine.invokeMethod("", "function_one", new Object[0]);
      scriptReader.close();
      System.out.printf("Return of the function '%s'\n", obj);

    } catch (ScriptException se) {
      System.out.println("########EXCEPTION");
View Full Code Here

        System.out.println( b );

        engine.put( "listener", new JavascriptTestEnvironment() );
        Invocable invocable = ( Invocable ) engine;
        invocable.invokeFunction( "test" );
        invocable.invokeMethod( o, "b" );
        System.out.println();
    }


    private static String readScript() throws IOException {
View Full Code Here

        Invocable invocable = (Invocable) engine;
        if (null == instance) {
          o = invocable.invokeFunction(name, args);
        } else {
          try {
            o = invocable.invokeMethod(instance, name, args);
          } catch (NoSuchMethodException nex) {
            log.debug("Method not found: " + name);
            try {
              // try to invoke it directly, this will work if the
              // function is in the engine context
View Full Code Here

        try {
          if (isMethod) {
            Object target = engine.get(objectName);
            if (target != null) {
              try {
                return invocable.invokeMethod(target, functionName, args);
              } catch (NoSuchMethodException e) {
                throw new ApiException("UnknownFunction", "Method \""+functionName+"\" not defined on object \""+objectName+"\"");
              }
            }
          } else {
View Full Code Here

          return;
        }
        String objectName = parts[0];
        String methodName = parts[1];
        Object obj = engine.get(objectName);
        inv.invokeMethod(obj, methodName, args);
       
      }
    } catch (Exception e) {
      shellState.printException(e);
    }
View Full Code Here

    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

        ScriptEngine pythonEngine = manager.getEngineByName("python");
        Invocable invocableEngine = (Invocable) pythonEngine;

        assertNull(pythonEngine.eval("def f(x): return abs(x)"));
        assertEquals(Integer.valueOf(5), invocableEngine.invokeFunction("f", Integer.valueOf(-5)));
        assertEquals("spam", invocableEngine.invokeMethod(new PyString("  spam  "), "strip"));
        assertEquals("spam", invocableEngine.invokeMethod("  spam  ", "strip"));
    }

    public void testInvokeFunctionNoSuchMethod() throws ScriptException {
        ScriptEngineManager manager = new ScriptEngineManager();
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.