Example usage for javax.script ScriptEngineManager ScriptEngineManager

List of usage examples for javax.script ScriptEngineManager ScriptEngineManager

Introduction

In this page you can find the example usage for javax.script ScriptEngineManager ScriptEngineManager.

Prototype

public ScriptEngineManager() 

Source Link

Document

The effect of calling this constructor is the same as calling ScriptEngineManager(Thread.currentThread().getContextClassLoader()).

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    ScriptEngineManager mgr = new ScriptEngineManager();
    List<ScriptEngineFactory> engines = mgr.getEngineFactories();
    for (ScriptEngineFactory engine : engines) {
        System.out.println(engine.getEngineName());
        for (String n : engine.getNames()) {
            System.out.println("Short name : " + n);
        }/*from w  ww .  j a v a2s . co  m*/
    }
}

From source file:Main.java

public static void main(String[] args) {
    ScriptEngineManager manager = new ScriptEngineManager();

    // Get the list of all available engines
    List<ScriptEngineFactory> list = manager.getEngineFactories();

    // Print the details of each engine
    for (ScriptEngineFactory f : list) {
        System.out.println("Engine Name:" + f.getEngineName());
        System.out.println("Engine Version:" + f.getEngineVersion());
        System.out.println("Language Name:" + f.getLanguageName());
        System.out.println("Language Version:" + f.getLanguageVersion());
        System.out.println("Engine Short Names:" + f.getNames());
        System.out.println("Mime Types:" + f.getMimeTypes());
        System.out.println("===");
    }/*w  ww  .j  a va  2 s  .  c  om*/
}

From source file:RegisteredNameDemo.java

public static void main(String[] args) {
    ScriptEngineManager manager = new ScriptEngineManager();
    List<ScriptEngineFactory> factories = manager.getEngineFactories();
    for (ScriptEngineFactory factory : factories) {
        List<String> regNames = factory.getNames();
        for (int i = 0; i < regNames.size(); i++) {
            System.out.printf("Registered name " + i + " " + (String) regNames.get(i) + "\n");
        }//w  w w  .j  ava2s.c o  m
    }
}

From source file:FileExtensionsDemo.java

public static void main(String[] args) {
    ScriptEngineManager manager = new ScriptEngineManager();
    List<ScriptEngineFactory> factories = manager.getEngineFactories();
    for (ScriptEngineFactory factory : factories) {
        List<String> ext = factory.getExtensions();
        for (int i = 0; i < ext.size(); i++) {
            System.out.printf("Supported file extension: " + (String) ext.get(i) + "\n");
        }//from   w  w  w.  ja  v a 2  s.  c  o  m
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("JavaScript");

    if (engine instanceof Compilable) {
        System.out.println("Script compilation is supported.");
    } else {/* w  w  w  .j  a  v  a 2  s  .  com*/
        System.out.println("Script compilation is not supported.");
    }

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
    engine.eval("load('res/nashorn5.js')");

    Invocable invocable = (Invocable) engine;

    Product product = new Product();
    product.setName("Rubber");
    product.setPrice(1.99);//  ww w  .  j av a2  s.co  m
    product.setStock(1037);

    Object result = invocable.invokeFunction("getValueOfGoods", product);
    System.out.println(result);
}

From source file:Main.java

public static void main(String[] args) {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("JavaScript");

    Bindings params = engine.createBindings();

    params.put("stringKey", "Hello");
    params.put("valueKey", 2015);

    Object msg = params.get("stringKey");
    Object year = params.get("valueKey");
    System.out.println("stringKey" + msg);
    System.out.println("valueKey = " + year);

    params.remove("valueKey");
    year = params.get("valueKey");

    boolean containsYear = params.containsKey("valueKey");
    System.out.println("valueKey = " + year);
    System.out.println("params contains year = " + containsYear);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    // create a script engine manager
    ScriptEngineManager factory = new ScriptEngineManager();
    // create a JavaScript engine
    ScriptEngine engine = factory.getEngineByName("JavaScript");
    // evaluate JavaScript code from String
    Object obj = engine.eval("1+2");
    System.out.println(obj);/*www. j  a v a2s  .  c om*/
}

From source file:JavaObjectDemo.java

public static void main(String[] args) throws Exception {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine jsEngine;/*w w w . ja  v a2s  . c  o m*/
    jsEngine = manager.getEngineByExtension("js");
    jsEngine.eval("importPackage(javax.swing);var optionPane =JOptionPane.showMessageDialog(null, 'Hello!);");
}

From source file:Main.java

public static void main(String[] args) throws ScriptException {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine rhino = manager.getEngineByName("JavaScript");

    Double result = (Double) rhino.eval("1 + 2");
    Integer i = result.intValue();
    System.out.println(i);//  ww  w  .  j a  va2 s . co  m
}