Java Script Engine getEngine(String engineName)

Here you can find the source of getEngine(String engineName)

Description

get Engine

License

Open Source License

Declaration

public static final ScriptEngine getEngine(String engineName) 

Method Source Code


//package com.java2s;
/*/*ww w.  ja v a 2 s.  co  m*/
 * #%L
 * JSR223 Profile Activator Maven Extension
 * %%
 * Copyright (C) 2015 RRQ
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/gpl-3.0.html>.
 * #L%
 */

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

public class Main {

    public static final ScriptEngine getEngine(String engineName) {
        if (engineName != null) {
            ScriptEngineManager factory = new ScriptEngineManager();
            // We'll try to get the engine by name (i.e. JavaScript)
            ScriptEngine engine = factory.getEngineByName(engineName);
            if (engine != null) {
                return engine;
            }
            // We'll try to get the engine by extension (i.e. javascript)
            engine = factory.getEngineByExtension(engineName);
            if (engine != null) {
                return engine;
            }
            // We'll try to get the engine by MimeType (i.e. application/javascript)
            return factory.getEngineByMimeType(engineName);
        }
        // We've just not found any engine matching "engine", so we return null
        return null;
    }
}

Related

  1. evaluateScriptResource(ScriptEngine engine, String resource)
  2. getAppleScriptEngine()
  3. getAvailableEngineGroups()
  4. getDefaultScriptEngineManager()
  5. getEngine()
  6. getScriptEngine()
  7. getScriptEngine(final ClassLoader loader, final String... args)
  8. getScriptEngineManager()
  9. getStringOrExcept(ScriptEngine e, String vname)