本文整理汇总了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);
}