/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.script;
import java.util.*;
import java.net.URL;
import java.io.*;
import java.security.*;
import sun.misc.Service;
import sun.misc.ServiceConfigurationError;
/**
* The ScriptEngineManager implements a discovery and instantiation
* mechanism for ScriptEngine classes and also maintains a
* collection of key/value pairs storing state shared by all engines created
* by the Manager. This class uses the service provider mechanism to enumerate all the
* implementations of ScriptEngineFactory.
* The ScriptEngineManager provides a method to return a list of all these factories
* as well as utility methods which look up factories on the basis of language name, file extension
* and mime type.
*
* The Bindings of key/value pairs, referred to as the "Global Scope" maintained
* by the manager is available to all instances of ScriptEngine created
* by the ScriptEngineManager. The values in the Bindings are
* generally exposed in all scripts.
*
* @author Mike Grogan
* @author A. Sundararajan
* @since 1.6
*/
public class ScriptEngineManager {
private static final boolean DEBUG = false;
/**
* If the thread context ClassLoader can be accessed by the caller,
* then the effect of calling this constructor is the same as calling
* ScriptEngineManager(Thread.currentThread().getContextClassLoader()).
* Otherwise, the effect is the same as calling ScriptEngineManager(null).
*
* @see java.lang.Thread#getContextClassLoader
*/
public ScriptEngineManager() {
ClassLoader ctxtLoader = Thread.currentThread().getContextClassLoader();
init(ctxtLoader);
}
/**
* This constructor loads the implementations of
* ScriptEngineFactory visible to the given
* ClassLoader using the service provider mechanism.
* If loader is null, the script engine factories that are
* bundled with the platform and that are in the usual extension
* directories (installed extensions) are loaded.
*
* @param loader ClassLoader used to discover script engine factories.
*/
public ScriptEngineManager(ClassLoader loader) {
init(loader);
}
private void init(final ClassLoader loader) {
globalScope = new SimpleBindings();
engineSpis = new HashSet();
nameAssociations = new HashMap();
extensionAssociations = new HashMap();
mimeTypeAssociations = new HashMap();
AccessController.doPrivileged(new PrivilegedAction