Package javax.script

Examples of javax.script.Invocable


        if (this.engine == null){
            this.getLogman().error(NO_JAVASCRIPT_MESSAGE);
            return null;
        }
        try {
            Invocable inv = (Invocable)this.engine;
            inv.invokeFunction("__onTabComplete", result, sender, args, cmd);
        }catch (Exception e){
            sender.message(e.getMessage());
            e.printStackTrace();
        }
        return result;
View Full Code Here


            ScriptEngineManager factory = new ScriptEngineManager();
            this.engine = factory.getEngineByName("JavaScript");
      if (this.engine == null){
    this.getLogger().severe(NO_JAVASCRIPT_MESSAGE);
      } else {
    Invocable inv = (Invocable)this.engine;
    this.engine.eval(new InputStreamReader(this.getResource("boot.js")));
    inv.invokeFunction("__scboot", this, engine);
      }
        }catch(Exception e){
            e.printStackTrace();
            this.getLogger().severe(e.getMessage());
        }finally{
View Full Code Here

  if (this.engine == null){
      this.getLogger().severe(NO_JAVASCRIPT_MESSAGE);
      return null;
  }
        try {
            Invocable inv = (Invocable)this.engine;
            inv.invokeFunction("__onTabComplete", result, sender, cmd, alias, args);
        }catch (Exception e){
            sender.sendMessage(e.getMessage());
            e.printStackTrace();
        }
        return result;
View Full Code Here

        } catch (ScriptException e) {
          scriptManager.getErrorMessage(e, funcStr);
        }
      }
      if (scriptEngine instanceof Invocable) {
        final Invocable invocableEngine = (Invocable) scriptEngine;
        Object[] args = null;
        if (iArgs != null) {
          args = new Object[iArgs.size()];
          int i = 0;
          for (Entry<Object, Object> arg : iArgs.entrySet())
            args[i++] = arg.getValue();
        }
        invocableEngine.invokeFunction(this.function.getName(), args);
      }
    } catch (ScriptException e) {
      throw new OCommandScriptException("Error on execution of the script", this.function.getName(), e.getColumnNumber(), e);
    } catch (NoSuchMethodException e) {
      throw new OCommandScriptException("Error on execution of the script", this.function.getName(), 0, e);
View Full Code Here

      final Object result;

      if (scriptEngine instanceof Invocable) {
        // INVOKE AS FUNCTION. PARAMS ARE PASSED BY POSITION
        final Invocable invocableEngine = (Invocable) scriptEngine;
        Object[] args = null;
        if (iArgs != null) {
          args = new Object[iArgs.size()];
          int i = 0;
          for (Entry<Object, Object> arg : iArgs.entrySet())
            args[i++] = arg.getValue();
        }
        result = invocableEngine.invokeFunction(parserText, args);

      } else {
        // INVOKE THE CODE SNIPPET
        final Object[] args = iArgs == null ? null : iArgs.values().toArray();
        result = scriptEngine.eval(scriptManager.getFunctionInvoke(f, args), binding);
View Full Code Here

        Object o = engine.get( "a" );
        Object b = engine.get( "test" );
        System.out.println( b );

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

    ScriptEngine engine = getJavascriptEngine();
    for(Entry<String, Object>entry: globalVariables.entrySet())
    {
      engine.put(entry.getKey(), entry.getValue());
    }
    Invocable invokableEngine = (Invocable) engine;
    String javascriptFunction = "function result() {" + javascriptFunctionBody + "}"
    engine.eval(javascriptFunction);

    return invokableEngine.invokeFunction("result" );

  }
View Full Code Here

    }

    static void init(Context cx, Scriptable scope, boolean sealed)
    throws RhinoException {
        RhinoTopLevel topLevel = (RhinoTopLevel) scope;
        Invocable engine = topLevel.getScriptEngine();
        JavaAdapter obj = new JavaAdapter(engine);
        obj.setParentScope(scope);
        obj.setPrototype(getFunctionPrototype(scope));
        /*
         * Note that we can't use defineProperty. A property of this
View Full Code Here

        log.debug("Calling: " + name);
      }
      try {
        @SuppressWarnings("unused")
        Method apiMethod = null;
        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
              // ie. the script has been already evaluated
              o = invocable.invokeFunction(name, args);
            } catch (Exception ex) {
              log.debug("Function not found: " + name);
              Class[] interfaces = (Class[]) engine.get("interfaces");
              for (Class clazz : interfaces) {
                // java6 style
                o = invocable.getInterface(engine.get((String) engine.get("className")), clazz);
                if (null != o) {
                  log.debug("Interface return type: " + o.getClass().getName());
                  break;
                }
              }
View Full Code Here

    }

    static void init(Context cx, Scriptable scope, boolean sealed)
    throws RhinoException {
        RhinoTopLevel topLevel = (RhinoTopLevel) scope;
        Invocable engine = topLevel.getScriptEngine();
        JavaAdapter obj = new JavaAdapter(engine);
        obj.setParentScope(scope);
        obj.setPrototype(getFunctionPrototype(scope));
        /*
         * Note that we can't use defineProperty. A property of this
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.