Java examples for javax.script:ScriptEngine
get Script Language Names
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.script.ScriptEngine; import javax.script.ScriptEngineFactory; import javax.script.ScriptEngineManager; public class Main{ private static ScriptEngineManager scriptEngineManager; private static final Map<String, List<ScriptEngineFactory>> languageFactoryMap = new HashMap<String, List<ScriptEngineFactory>>(); private static List<ScriptEngineFactory> engineFactories = null; public static List<String> getScriptLanguageNames() { List<String> scriptEngineNames = new ArrayList<String>(); engineFactories = getScriptEngineManager().getEngineFactories(); if (engineFactories != null) { for (ScriptEngineFactory factory : engineFactories) { final String engineName = factory.getLanguageName(); scriptEngineNames.add(engineName); }//from w w w . j ava2 s . c o m } return scriptEngineNames; } public static ScriptEngineManager getScriptEngineManager() { if (scriptEngineManager == null) { System.setProperty("org.jruby.embed.localvariable.behavior", "persistent");// required for JRuby, transparent // for others scriptEngineManager = new ScriptEngineManager( ScriptUtils.class.getClassLoader()); populateEngineFactoryMap(); } return scriptEngineManager; } private static void populateEngineFactoryMap() { engineFactories = getScriptEngineManager().getEngineFactories(); if (engineFactories != null) { for (ScriptEngineFactory factory : engineFactories) { final String languageName = factory.getLanguageName(); List<ScriptEngineFactory> languageFactories = languageFactoryMap .get(languageName); if (languageFactories == null) { languageFactories = new ArrayList<ScriptEngineFactory>(); languageFactoryMap.put(languageName, languageFactories); } languageFactories.add(factory); } } } }