當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。