當前位置: 首頁>>代碼示例>>Java>>正文


Java ScriptEngineFactory.getNames方法代碼示例

本文整理匯總了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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:JFXActionProvider.java

示例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);
  }
}
 
開發者ID:soulmachine,項目名稱:JythonExample,代碼行數:25,代碼來源:JythonExample.java

示例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;
}
 
開發者ID:ow2-proactive,項目名稱:scheduling,代碼行數:24,代碼來源:Script.java

示例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);
	}
}
 
開發者ID:RockManJoe64,項目名稱:fixprotocol-test-suite,代碼行數:24,代碼來源:ListAllEngines.java

示例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;
}
 
開發者ID:fhoeben,項目名稱:hsac-fitnesse-fixtures,代碼行數:22,代碼來源:ScriptLanguageFixture.java

示例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());
    }
}
 
開發者ID:sassoftware,項目名稱:unravl,代碼行數:20,代碼來源:UnRAVLPlugins.java

示例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);
    }
}
 
開發者ID:Razi91,項目名稱:JavaBlock,代碼行數:21,代碼來源:misc.java

示例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);
    }
}
 
開發者ID:crotwell,項目名稱:sod,代碼行數:21,代碼來源:SodUtil.java

示例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();
}
 
開發者ID:L2jBrasil,項目名稱:L2jBrasil,代碼行數:41,代碼來源:L2ScriptEngineManager.java

示例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);
    }
}
 
開發者ID:whitewoodcity,項目名稱:xbrowser,代碼行數:13,代碼來源:Res.java

示例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;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:37,代碼來源:StandardScriptUtils.java

示例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;
    }
}
 
開發者ID:flowable,項目名稱:flowable-engine,代碼行數:37,代碼來源:Extender.java

示例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;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:12,代碼來源:Activator.java

示例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;
}
 
開發者ID:vbauer,項目名稱:jconditions,代碼行數:12,代碼來源:ScriptUtils.java

示例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;
  }
}
 
開發者ID:logicalhacking,項目名稱:SecureBPMN,代碼行數:34,代碼來源:Extender.java


注:本文中的javax.script.ScriptEngineFactory.getNames方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。