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


Java ScriptEngineManager.getEngineFactories方法代碼示例

本文整理匯總了Java中javax.script.ScriptEngineManager.getEngineFactories方法的典型用法代碼示例。如果您正苦於以下問題:Java ScriptEngineManager.getEngineFactories方法的具體用法?Java ScriptEngineManager.getEngineFactories怎麽用?Java ScriptEngineManager.getEngineFactories使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.script.ScriptEngineManager的用法示例。


在下文中一共展示了ScriptEngineManager.getEngineFactories方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isJavaScriptAvailable

import javax.script.ScriptEngineManager; //導入方法依賴的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: factoryClassLoaderTest

import javax.script.ScriptEngineManager; //導入方法依賴的package包/類
@Test
public void factoryClassLoaderTest() {
    final ScriptEngineManager sm = new ScriptEngineManager();
    for (final ScriptEngineFactory fac : sm.getEngineFactories()) {
        if (fac instanceof NashornScriptEngineFactory) {
            final NashornScriptEngineFactory nfac = (NashornScriptEngineFactory)fac;
            final MyClassLoader loader = new MyClassLoader();
            // set the classloader as app class loader
            final ScriptEngine e = nfac.getScriptEngine(loader);
            try {
                e.eval("Packages.foo");
                // check that the class loader was attempted
                assertTrue(loader.reached(), "did not reach class loader!");
            } catch (final ScriptException se) {
                se.printStackTrace();
                fail(se.getMessage());
            }
            return;
        }
    }

    fail("Cannot find nashorn factory!");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:TrustedScriptEngineTest.java

示例3: factoryOptionsTest

import javax.script.ScriptEngineManager; //導入方法依賴的package包/類
@Test
public void factoryOptionsTest() {
    final ScriptEngineManager sm = new ScriptEngineManager();
    for (final ScriptEngineFactory fac : sm.getEngineFactories()) {
        if (fac instanceof NashornScriptEngineFactory) {
            final NashornScriptEngineFactory nfac = (NashornScriptEngineFactory)fac;
            // specify --no-syntax-extensions flag
            final String[] options = new String[] { "--no-syntax-extensions" };
            final ScriptEngine e = nfac.getScriptEngine(options);
            try {
                // try nashorn specific extension
                e.eval("var f = funtion(x) 2*x;");
                fail("should have thrown exception!");
            } catch (final Exception ex) {
                //empty
            }
            return;
        }
    }

    fail("Cannot find nashorn factory!");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:TrustedScriptEngineTest.java

示例4: noLoaderPerCompilerTest

import javax.script.ScriptEngineManager; //導入方法依賴的package包/類
@Test
/**
 * Test repeated evals with --loader-per-compile=false
 * We used to get "class redefinition error".
 */
public void noLoaderPerCompilerTest() {
    final ScriptEngineManager sm = new ScriptEngineManager();
    for (final ScriptEngineFactory fac : sm.getEngineFactories()) {
        if (fac instanceof NashornScriptEngineFactory) {
            final NashornScriptEngineFactory nfac = (NashornScriptEngineFactory)fac;
            final String[] options = new String[] { "--loader-per-compile=false" };
            final ScriptEngine e = nfac.getScriptEngine(options);
            try {
                e.eval("2 + 3");
                e.eval("4 + 4");
            } catch (final ScriptException se) {
                se.printStackTrace();
                fail(se.getMessage());
            }
            return;
        }
    }
    fail("Cannot find nashorn factory!");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:TrustedScriptEngineTest.java

示例5: noLoaderPerCompilerWithSameNameTest

import javax.script.ScriptEngineManager; //導入方法依賴的package包/類
@Test
/**
 * Test that we can use same script name in repeated evals with --loader-per-compile=false
 * We used to get "class redefinition error" as name was derived from script name.
 */
public void noLoaderPerCompilerWithSameNameTest() {
    final ScriptEngineManager sm = new ScriptEngineManager();
    for (final ScriptEngineFactory fac : sm.getEngineFactories()) {
        if (fac instanceof NashornScriptEngineFactory) {
            final NashornScriptEngineFactory nfac = (NashornScriptEngineFactory)fac;
            final String[] options = new String[] { "--loader-per-compile=false" };
            final ScriptEngine e = nfac.getScriptEngine(options);
            e.put(ScriptEngine.FILENAME, "test.js");
            try {
                e.eval("2 + 3");
                e.eval("4 + 4");
            } catch (final ScriptException se) {
                se.printStackTrace();
                fail(se.getMessage());
            }
            return;
        }
    }
    fail("Cannot find nashorn factory!");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:TrustedScriptEngineTest.java

示例6: L2ScriptEngineManager

import javax.script.ScriptEngineManager; //導入方法依賴的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

示例7: main

import javax.script.ScriptEngineManager; //導入方法依賴的package包/類
public static void main(String ... args) throws ScriptException {
    ScriptEngineManager manager = new ScriptEngineManager();

    for (ScriptEngineFactory f : manager.getEngineFactories()) {
        System.out.println(f.getEngineName() + " -> " + f.getLanguageName() + " (" + String.join(", ", f.getExtensions()) + ")");
    }

    System.out.println("");

    ScriptEngine python_engine;
    ScriptEngine javascript_engine;
    ScriptEngine lua_engine;

    long start_time;
    long end_time;

    System.out.println("Testing Python interpreter...");

    python_engine = manager.getEngineByExtension("py");
    start_time = System.currentTimeMillis();

    python_engine.eval("print(\"Hello, world!\")");

    end_time = System.currentTimeMillis();
    System.out.println("Time taken: " + String.valueOf((end_time - start_time)) + "ms\n");

    System.out.println("Testing JavaScript interpreter...");

    javascript_engine = manager.getEngineByExtension("js");
    start_time = System.currentTimeMillis();

    javascript_engine.eval("print(\"Hello, world!\")");

    end_time = System.currentTimeMillis();
    System.out.println("Time taken: " + String.valueOf((end_time - start_time)) + "ms\n");

    System.out.println("Testing Lua interpreter...");

    lua_engine = manager.getEngineByExtension("lua");
    start_time = System.currentTimeMillis();

    lua_engine.eval("print(\"Hello, world!\")");

    end_time = System.currentTimeMillis();
    System.out.println("Time taken: " + String.valueOf((end_time - start_time)) + "ms\n");
}
 
開發者ID:ScriptyMod,項目名稱:Scripty,代碼行數:47,代碼來源:ScriptTest.java


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