Java 8 Invocable - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Invocable class.

This code example shows how to use the following methods:invokeFunction
        ScriptEngine engine = factory.getEngineByName("groovy");
        String fact = "def factorial(n) { n == 1 ? 1 : n * factorial(n - 1) }";
        engine.eval(fact);
        Invocable inv = (Invocable) engine;
        Object[] params = {5}; 
        Object result = inv.invokeFunction("factorial", params);
        assertEquals(new Integer(120), result);
        // end::jsr223_invocable[] 
    } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getInterface
                        return; 
                    } 
                    scriptEngine.eval(expScript);
                    if (scriptEngine instanceof Invocable) {
                        Invocable inv = (Invocable) scriptEngine;
                        expInv = inv.getInterface(IExperience.class);
                        isUsable = true;
                    } else { 
                        isUsable = false;
                    } 
                } catch (ScriptException e) {
                    e.printStackTrace();
                    DebugLogger.printThrowable(e);
                    isUsable = false;
                } 
            } else { 
                isUsable = false;
            } 
        } 
    } 
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:invokeFunction
            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;
 
    } 
 
	/** 
	 * 
	 * 计算登录时密码HASH值 
	 * 
	 * @param uin a long. 
	 * @param plain a {@link java.lang.String} object. 
	 * @param verify a {@link java.lang.String} object. 
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getInterface
 
    public void register(String uniqueName, Object object, String iFace) {
        try { 
            Class<?> lookupClass = Class.forName(iFace);
            Invocable inv = (Invocable) engine;
            Object part = inv.getInterface(object, lookupClass);
            if (part == null) { 
                throw Exceptions.handle() 
                        .withSystemErrorMessage("Cannot convert JavaScript-Object '%s' into '%s'!", 
                                object, 
                                lookupClass)
                        .to(LOG)
                        .handle(); 
            } 
            Injector.context().registerDynamicPart(uniqueName, part, lookupClass);
        } catch (ClassNotFoundException e) {
            throw Exceptions.handle() 
                    .withSystemErrorMessage("Cannot find class: %s as dynamic part: %s (%s)", iFace)
                    .to(LOG)
                    .error(e)
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:invokeMethod
 
			RubyObject rubyObject = (RubyObject) object;
			if (rubyObject.getMetaClass().getName().equals("DateTime")) {
 
				try { 
					object = i.invokeMethod(object, "strftime", "%Y-%m-%d");
//					object = i.invokeMethod(object, "to_i"); 
//					object = new Date(Long.parseLong(object.toString())); 
 
				} 
				catch (Exception e) {
					throw new RuntimeException(e);
				} 
			} 
		} 
 
		return object; 
	} 
 
	public void setScriptEngine(ScriptEngine engine) {
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:invokeFunction
    @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();
    } 
 
    public static void main(String[] args) throws Exception {
        new UglifyJSCompressor(ResourceType.JS).compress(null, null); 
    } 
} 
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:invokeFunction
 
	public synchronized static String parse(String content) {
		if(content == null || content.isEmpty()) return null;
		try { 
			Invocable invocable = (Invocable) js;
			Object result = invocable.invokeFunction("marked", content);
			return result.toString(); 
		} catch (ScriptException | NoSuchMethodException e) {
			throw new RuntimeException(e);
		} 
	} 
 
} 
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:invokeFunction
        Product product = new Product();
        product.setName("Rubber");
        product.setPrice(1.99);
        product.setStock(1337);
 
        ScriptObjectMirror result = (ScriptObjectMirror)
                invocable.invokeFunction("calculate", product);
        System.out.println(result.get("name") + ": " + result.get("valueOfGoods"));
    } 
 
    public static void getProduct(ScriptObjectMirror result) {
        System.out.println(result.get("name") + ": " + result.get("valueOfGoods"));
    } 
 
} 
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:invokeMethod
            // As above, scripts must require('geoscript') first for this to 
            // work with GeoScript objects. 
            geoArgs = args; 
        } 
        try { 
            results = invocable.invokeMethod(exports, "run", geoObject, geoArgs);
            results = GeoObject.jsToJava(results); 
        } catch (NoSuchMethodException e) {
            throw new ScriptException(e);
        } finally { 
            Context.exit(); 
        } 
        return results; 
    } 
 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:invokeFunction
        Product product = new Product();
        product.setName("Rubber");
        product.setPrice(1.99);
        product.setStock(1037);
 
        Object result = invocable.invokeFunction("getValueOfGoods", product);
        System.out.println(result);
    } 
 
} 
3
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Java 8 Invocable Methods: