本文整理汇总了Java中javax.script.ScriptEngineFactory.getNames方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptEngineFactory.getNames方法的具体用法?Java ScriptEngineFactory.getNames怎么用?Java ScriptEngineFactory.getNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.script.ScriptEngineFactory
的用法示例。
在下文中一共展示了ScriptEngineFactory.getNames方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isJavaScriptAvailable
import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
private boolean isJavaScriptAvailable() {
if(isJSAvailableChecked) {
return isJSAvailable;
}
ScriptEngineManager mgr = new ScriptEngineManager();
List<ScriptEngineFactory> factories = mgr.getEngineFactories();
for (ScriptEngineFactory factory: factories) {
List<String> engNames = factory.getNames();
for(String name: engNames) {
if(name.equalsIgnoreCase("js") || name.equalsIgnoreCase("javascript")) { //NOI18N
isJSAvailableChecked = true;
isJSAvailable = true;
return isJSAvailable;
}
}
}
isJSAvailableChecked = true;
isJSAvailable = false;
return isJSAvailable;
}
示例2: listEngines
import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
/**
* Display all script engines.
*/
public static void listEngines() {
final ScriptEngineManager mgr = new ScriptEngineManager();
final List<ScriptEngineFactory> factories =
mgr.getEngineFactories();
for (final ScriptEngineFactory factory: factories) {
System.out.println("ScriptEngineFactory Info");
final String engName = factory.getEngineName();
final String engVersion = factory.getEngineVersion();
final String langName = factory.getLanguageName();
final String langVersion = factory.getLanguageVersion();
System.out.printf("\tScript Engine: %s (%s)\n", engName, engVersion);
final List<String> engNames = factory.getNames();
for (final String name: engNames) {
System.out.printf("\tEngine Alias: %s\n", name);
}
System.out.printf("\tLanguage: %s (%s)\n", langName, langVersion);
}
}
示例3: findScriptEngineCandidates
import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
private Map<ScriptEngine, Integer> findScriptEngineCandidates(boolean findByName) {
Map<ScriptEngine, Integer> matchPositionPerScriptEngineCandidate = new HashMap<>();
int matchPosition;
List<String> lookupCriteria;
for (ScriptEngineFactory factory : new ScriptEngineManager().getEngineFactories()) {
matchPosition = 0;
if (findByName) {
lookupCriteria = factory.getNames();
} else {
lookupCriteria = factory.getExtensions();
}
for (String criteria : lookupCriteria) {
if (criteria.equalsIgnoreCase(scriptEngineLookupName)) {
matchPositionPerScriptEngineCandidate.put(factory.getScriptEngine(), matchPosition);
}
matchPosition++;
}
}
return matchPositionPerScriptEngineCandidate;
}
示例4: list
import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
@Test
public void list() {
ScriptEngineManager manager = new ScriptEngineManager();
List<ScriptEngineFactory> factories = manager.getEngineFactories();
for (ScriptEngineFactory factory : factories) {
System.out.println(String.format("Engine: %s v%s; %s v%s",
factory.getEngineName(),
factory.getEngineVersion(),
factory.getLanguageName(),
factory.getLanguageVersion()));
List<String> extensions = factory.getExtensions();
System.out.println("Extensions:");
print(extensions);
List<String> names = factory.getNames();
System.out.println("Names:");
print(names);
List<String> mimeTypes = factory.getMimeTypes();
System.out.println("MIME Types:");
print(mimeTypes);
}
}
示例5: availableEngines
import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
public Map<String, Map<String, Object>> availableEngines() {
Map<String, Map<String, Object>> result = new LinkedHashMap<>();
List<ScriptEngineFactory> factories = ENGINE_MANAGER.getEngineFactories();
for (ScriptEngineFactory factory : factories) {
Map<String, Object> f = new LinkedHashMap<>();
String engName = factory.getEngineName();
String engVersion = factory.getEngineVersion();
List<String> engNames = factory.getNames();
String langName = factory.getLanguageName();
String langVersion = factory.getLanguageVersion();
result.put(engName, f);
f.put("language name", langName);
f.put("language version", langVersion);
f.put("aliases", engNames);
f.put("version", engVersion);
}
return result;
}
示例6: logSupportedScriptEngines
import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
/**
* log the availability of scripting engines supported in this environment.
*/
public static void logSupportedScriptEngines() {
ScriptEngineManager manager = new ScriptEngineManager();
logger.error("Available Script Engines:");
for (final ScriptEngineFactory scriptEngine : manager
.getEngineFactories()) {
logger.error(scriptEngine.getEngineName() + " "
+ scriptEngine.getEngineVersion());
logger.error("\tLanguage: " + scriptEngine.getLanguageName() + " "
+ scriptEngine.getLanguageVersion());
StringBuilder es = new StringBuilder();
for (final String engineAlias : scriptEngine.getNames()) {
es.append(engineAlias).append(",");
}
logger.error("\tAliases: " + es.toString());
}
}
示例7: javaInfo
import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
public static void javaInfo(){
ScriptEngineManager mgr = new ScriptEngineManager();
List<ScriptEngineFactory> factories =
mgr.getEngineFactories();
for (ScriptEngineFactory factory: factories) {
System.out.println("ScriptEngineFactory Info");
String engName = factory.getEngineName();
String engVersion = factory.getEngineVersion();
String langName = factory.getLanguageName();
String langVersion = factory.getLanguageVersion();
System.out.printf("\tScript Engine: %s (%s)\n",
engName, engVersion);
List<String> engNames = factory.getNames();
for(String name: engNames) {
System.out.printf("\tEngine Alias: %s\n", name);
}
System.out.printf("\tLanguage: %s (%s)\n",
langName, langVersion);
}
}
示例8: listKnownScriptEngines
import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
public void listKnownScriptEngines() {
ScriptEngineManager mgr = new ScriptEngineManager();
List<ScriptEngineFactory> factories =
mgr.getEngineFactories();
for (ScriptEngineFactory factory: factories) {
System.out.println("ScriptEngineFactory Info");
String engName = factory.getEngineName();
String engVersion = factory.getEngineVersion();
String langName = factory.getLanguageName();
String langVersion = factory.getLanguageVersion();
System.out.printf("\tScript Engine: %s (%s)\n",
engName, engVersion);
List<String> engNames = factory.getNames();
for(String name: engNames) {
System.out.printf("\tEngine Alias: %s\n", name);
}
System.out.printf("\tLanguage: %s (%s)\n",
langName, langVersion);
}
}
示例9: L2ScriptEngineManager
import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
private L2ScriptEngineManager()
{
ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
List<ScriptEngineFactory> factories = scriptEngineManager.getEngineFactories();
if (USE_COMPILED_CACHE)
_cache = this.loadCompiledScriptCache();
else
_cache = null;
_log.info("Initializing Script Engine Manager");
for (ScriptEngineFactory factory : factories)
try
{
ScriptEngine engine = factory.getScriptEngine();
boolean reg = false;
for (String name : factory.getNames())
{
ScriptEngine existentEngine = _nameEngines.get(name);
if (existentEngine != null)
{
double engineVer = Double.parseDouble(factory.getEngineVersion());
double existentEngVer = Double.parseDouble(existentEngine.getFactory().getEngineVersion());
if (engineVer <= existentEngVer)
continue;
}
reg = true;
_nameEngines.put(name, engine);
}
if (reg)
_log.info("Script Engine: " + factory.getEngineName() + " " + factory.getEngineVersion() + " - Language: " + factory.getLanguageName() + " - Language Version: " + factory.getLanguageVersion());
for (String ext : factory.getExtensions())
if (!ext.equals("java") || factory.getLanguageName().equals("java"))
_extEngines.put(ext, engine);
}
catch (Exception e)
{
_log.warning("Failed initializing factory. ");
e.printStackTrace();
}
this.preConfigure();
}
示例10: loadScriptEngineJar
import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
public static void loadScriptEngineJar(File pluginFile) throws Exception{
URLClassLoader classLoader = new URLClassLoader(new URL[]{pluginFile.toURI().toURL()},ClassLoader.getSystemClassLoader());//Thread.currentThread().getContextClassLoader()
String url = "jar:"+pluginFile.toURI().toURL()+"!"+"/META-INF/services/javax.script.ScriptEngineFactory";
Class<?> engineFactory=classLoader.loadClass(Res.getUrlContentsWithoutComments(url).replace("\n","").trim());
ScriptEngineFactory factory= (ScriptEngineFactory) engineFactory.newInstance();
List<String> names = factory.getNames();
for(String name:names){
Main.scriptEngineManager.registerEngineName(name,factory);
}
}
示例11: retrieveEngineByName
import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
/**
* Retrieve a {@link ScriptEngine} from the given {@link ScriptEngineManager}
* by name, delegating to {@link ScriptEngineManager#getEngineByName} but
* throwing a descriptive exception if not found or if initialization failed.
* @param scriptEngineManager the ScriptEngineManager to use
* @param engineName the name of the engine
* @return a corresponding ScriptEngine (never {@code null})
* @throws IllegalArgumentException if no matching engine has been found
* @throws IllegalStateException if the desired engine failed to initialize
*/
public static ScriptEngine retrieveEngineByName(ScriptEngineManager scriptEngineManager, String engineName) {
ScriptEngine engine = scriptEngineManager.getEngineByName(engineName);
if (engine == null) {
Set<String> engineNames = new LinkedHashSet<String>();
for (ScriptEngineFactory engineFactory : scriptEngineManager.getEngineFactories()) {
List<String> factoryNames = engineFactory.getNames();
if (factoryNames.contains(engineName)) {
// Special case: getEngineByName returned null but engine is present...
// Let's assume it failed to initialize (which ScriptEngineManager silently swallows).
// If it happens to initialize fine now, alright, but we really expect an exception.
try {
engine = engineFactory.getScriptEngine();
engine.setBindings(scriptEngineManager.getBindings(), ScriptContext.GLOBAL_SCOPE);
}
catch (Throwable ex) {
throw new IllegalStateException("Script engine with name '" + engineName +
"' failed to initialize", ex);
}
}
engineNames.addAll(factoryNames);
}
throw new IllegalArgumentException("Script engine with name '" + engineName +
"' not found; registered engine names: " + engineNames);
}
return engine;
}
示例12: resolveScriptEngine
import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
@SuppressWarnings({"rawtypes"})
@Override
public ScriptEngine resolveScriptEngine(String name) {
try {
BufferedReader in = new BufferedReader(new InputStreamReader(configFile.openStream()));
String className = in.readLine();
in.close();
Class cls = bundle.loadClass(className);
if (!ScriptEngineFactory.class.isAssignableFrom(cls)) {
throw new IllegalStateException("Invalid ScriptEngineFactory: " + cls.getName());
}
ScriptEngineFactory factory = (ScriptEngineFactory) cls.newInstance();
List<String> names = factory.getNames();
for (String test : names) {
if (test.equals(name)) {
ClassLoader old = Thread.currentThread().getContextClassLoader();
ScriptEngine engine;
try {
// JRuby seems to require the correct TCCL to call
// getScriptEngine
Thread.currentThread().setContextClassLoader(factory.getClass().getClassLoader());
engine = factory.getScriptEngine();
} finally {
Thread.currentThread().setContextClassLoader(old);
}
LOGGER.trace("Resolved ScriptEngineFactory: {} for expected name: {}", engine, name);
return engine;
}
}
LOGGER.debug("ScriptEngineFactory: {} does not match expected name: {}", factory.getEngineName(), name);
return null;
} catch (Exception e) {
LOGGER.warn("Cannot create ScriptEngineFactory: {}", e.getClass().getName(), e);
return null;
}
}
示例13: getScriptNames
import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private List<String> getScriptNames(ScriptEngineFactory factory) {
List<String> names;
if (factory != null) {
names = factory.getNames();
} else {
// return an empty script name list
names = Collections.EMPTY_LIST;
}
return names;
}
示例14: sameNames
import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
private static boolean sameNames(final ScriptEngineFactory factory, final String engine) {
final List<String> names = factory.getNames();
if (names != null) {
for (final String name : names) {
if (TextUtils.containsIgnoreCase(name, engine)) {
return true;
}
}
}
return false;
}
示例15: resolveScriptEngine
import javax.script.ScriptEngineFactory; //导入方法依赖的package包/类
public ScriptEngine resolveScriptEngine(String name) {
try {
BufferedReader in = new BufferedReader(new InputStreamReader(configFile.openStream()));
String className = in.readLine();
in.close();
Class cls = bundle.loadClass(className);
if (!ScriptEngineFactory.class.isAssignableFrom(cls)) {
throw new IllegalStateException("Invalid ScriptEngineFactory: " + cls.getName());
}
ScriptEngineFactory factory = (ScriptEngineFactory) cls.newInstance();
List<String> names = factory.getNames();
for (String test : names) {
if (test.equals(name)) {
ClassLoader old = Thread.currentThread().getContextClassLoader();
ScriptEngine engine;
try {
// JRuby seems to require the correct TCCL to call getScriptEngine
Thread.currentThread().setContextClassLoader(factory.getClass().getClassLoader());
engine = factory.getScriptEngine();
} finally {
Thread.currentThread().setContextClassLoader(old);
}
LOGGER.finest("Resolved ScriptEngineFactory: " + engine + " for expected name: " + name);
return engine;
}
}
LOGGER.fine("ScriptEngineFactory: " + factory.getEngineName() + " does not match expected name: " + name);
return null;
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Cannot create ScriptEngineFactory: " + e.getClass().getName(), e);
return null;
}
}