本文整理匯總了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();
}
示例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);
}