当前位置: 首页>>代码示例>>Java>>正文


Java ScriptEngine.getFactory方法代码示例

本文整理汇总了Java中javax.script.ScriptEngine.getFactory方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptEngine.getFactory方法的具体用法?Java ScriptEngine.getFactory怎么用?Java ScriptEngine.getFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.script.ScriptEngine的用法示例。


在下文中一共展示了ScriptEngine.getFactory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getEngineInfo

import javax.script.ScriptEngine; //导入方法依赖的package包/类
private String getEngineInfo(ScriptEngine engine) {
    StringBuilder sb = new StringBuilder();
    ScriptEngineFactory f = engine.getFactory();
    sb.append("LanguageName=");
    sb.append("\"").append(f.getLanguageName()).append("\"");
    sb.append(" ");
    sb.append("LanguageVersion=");
    sb.append("\"").append(f.getLanguageVersion()).append("\"");
    sb.append(" ");
    sb.append("EngineName=");
    sb.append("\"").append(f.getEngineName()).append("\"");
    sb.append(" ");
    sb.append("EngineNameAliases=");
    sb.append(Arrays.toString(f.getNames().toArray(new String[f.getNames().size()])));
    sb.append(" ");
    sb.append("EngineVersion=");
    sb.append("\"").append(f.getEngineVersion()).append("\"");
    return sb.toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:NbPacScriptEvaluator.java

示例2: factoryTests

import javax.script.ScriptEngine; //导入方法依赖的package包/类
@Test
public void factoryTests() {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");
    assertNotNull(e);

    final ScriptEngineFactory fac = e.getFactory();

    assertEquals(fac.getLanguageName(), "ECMAScript");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");
    assertEquals(fac.getLanguageVersion(), "ECMA - 262 Edition 5.1");
    assertEquals(fac.getEngineName(), "Oracle Nashorn");
    assertEquals(fac.getOutputStatement("context"), "print(context)");
    assertEquals(fac.getProgram("print('hello')", "print('world')"), "print('hello');print('world');");
    assertEquals(fac.getParameter(ScriptEngine.NAME), "javascript");

    boolean seenJS = false;
    for (final String ext : fac.getExtensions()) {
        if (ext.equals("js")) {
            seenJS = true;
        }
    }

    assertEquals(seenJS, true);
    final String str = fac.getMethodCallSyntax("obj", "foo", "x");
    assertEquals(str, "obj.foo(x)");

    boolean seenNashorn = false, seenJavaScript = false, seenECMAScript = false;
    for (final String name : fac.getNames()) {
        switch (name) {
            case "nashorn": seenNashorn = true; break;
            case "javascript": seenJavaScript = true; break;
            case "ECMAScript": seenECMAScript = true; break;
        default:
            break;
        }
    }

    assertTrue(seenNashorn);
    assertTrue(seenJavaScript);
    assertTrue(seenECMAScript);

    boolean seenAppJS = false, seenAppECMA = false, seenTextJS = false, seenTextECMA = false;
    for (final String mime : fac.getMimeTypes()) {
        switch (mime) {
            case "application/javascript": seenAppJS = true; break;
            case "application/ecmascript": seenAppECMA = true; break;
            case "text/javascript": seenTextJS = true; break;
            case "text/ecmascript": seenTextECMA = true; break;
        default:
            break;
        }
    }

    assertTrue(seenAppJS);
    assertTrue(seenAppECMA);
    assertTrue(seenTextJS);
    assertTrue(seenTextECMA);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:60,代码来源:ScriptEngineTest.java


注:本文中的javax.script.ScriptEngine.getFactory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。