Package javax.script

Examples of javax.script.Invocable


    @Override
    public void compress(Reader r, Writer w) throws Exception {
        String script = "function hello(name) { return ('Hello, ' + name); }";
        engine.eval(script);
        Invocable inv = (Invocable) engine;
        inv.invokeFunction("hello", "Scripting!!" );
        throw new UnsupportedOperationException();
    }
View Full Code Here


    try {
      final ScriptEngine engine = new ScriptEngineManager()
      .getEngineByName("nashorn");
      engine.eval(new FileReader(Constants.DATA_PATH
          + "scripts/decrypt.js"));
      final Invocable invocable = (Invocable) engine;

      final Object result = invocable.invokeFunction("getWorkingVideo",
          signature, playercode);
      return (String) result;
    } catch (ScriptException | FileNotFoundException
        | NoSuchMethodException e) {
      // TODO Auto-generated catch block
View Full Code Here

            if (Debug.verboseOn()) {
                Debug.logVerbose("Invoking function/method " + functionName, module);
            }
            ScriptEngine engine = script.getEngine();
            try {
                Invocable invocableEngine = (Invocable) engine;
                result = invocableEngine.invokeFunction(functionName, args == null ? EMPTY_ARGS : args);
            } catch (ClassCastException e) {
                throw new ScriptException("Script engine " + engine.getClass().getName() + " does not support function/method invocations");
            }
        }
        return result;
View Full Code Here

        URL scriptUrl = FlexibleLocation.resolveLocation(filePath);
        FileReader reader = new FileReader(new File(scriptUrl.getFile()));
        Object result = engine.eval(reader);
        if (UtilValidate.isNotEmpty(functionName)) {
            try {
                Invocable invocableEngine = (Invocable) engine;
                result = invocableEngine.invokeFunction(functionName, args == null ? EMPTY_ARGS : args);
            } catch (ClassCastException e) {
                throw new ScriptException("Script engine " + engine.getClass().getName() + " does not support function/method invocations");
            }
        }
        return result;
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

            // end
            ScriptEngineManager mgr = new ScriptEngineManager();
            ScriptEngine engine = mgr
                    .getEngineByMimeType("application/javascript");
            engine.eval(js);
            Invocable inv = (Invocable) engine;
            s = (String) inv.invokeFunction("P", uin, ptwebqq);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return s;
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 AvailabilityType getAvailability() {

        try {
            engine.eval(theScript);
            Invocable inv = (Invocable) engine;
            Object ret = inv.invokeFunction("avail");
            if (ret instanceof Number) {
                int tmp = ((Number)ret).intValue();
                if (tmp>0)
                    return AvailabilityType.UP;
            }
View Full Code Here

        }


         for (MeasurementScheduleRequest req : metrics) {

             Invocable inv = (Invocable) engine;
             if (req.getDataType()== DataType.MEASUREMENT) {
                 MeasurementDataNumeric res;
                 try {
                     Object ret = inv.invokeFunction("metric",req.getName());
                     if (ret instanceof Number) {
                         Double num = ((Number)ret).doubleValue();
                         res = new MeasurementDataNumeric(req,num);
                         report.addData(res);
                     }
                     else {
                         log.debug("Returned value " + ret.toString() + " is no number for metric " + req.getName());
                     }
                 }
                 catch (Exception e) {
                     log.debug(e.getMessage());
                 }
             }
             else if (req.getDataType()==DataType.TRAIT) {
                 MeasurementDataTrait res;
                 try {
                     Object ret = inv.invokeFunction("trait",req.getName());
                     if (ret instanceof String) {
                         String val = ((String)ret);
                         res = new MeasurementDataTrait(req,val);
                         report.addData(res);
                     }
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.