2362N/A * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * The <code>ScriptEngineManager</code> implements a discovery and instantiation 0N/A * mechanism for <code>ScriptEngine</code> classes and also maintains a 0N/A * collection of key/value pairs storing state shared by all engines created 0N/A * by the Manager. This class uses the <a href="../../../technotes/guides/jar/jar.html#Service%20Provider">service provider</a> mechanism to enumerate all the 0N/A * implementations of <code>ScriptEngineFactory</code>. <br><br> 4841N/A * The <code>ScriptEngineManager</code> provides a method to return a list of all these factories 0N/A * as well as utility methods which look up factories on the basis of language name, file extension 0N/A * The <code>Bindings</code> of key/value pairs, referred to as the "Global Scope" maintained 0N/A * by the manager is available to all instances of <code>ScriptEngine</code> created 0N/A * by the <code>ScriptEngineManager</code>. The values in the <code>Bindings</code> are 0N/A * generally exposed in all scripts. 0N/A * @author Mike Grogan 0N/A * @author A. Sundararajan 0N/A private static final boolean DEBUG =
false;
0N/A * If the thread context ClassLoader can be accessed by the caller, 0N/A * then the effect of calling this constructor is the same as calling 0N/A * <code>ScriptEngineManager(Thread.currentThread().getContextClassLoader())</code>. 0N/A * Otherwise, the effect is the same as calling <code>ScriptEngineManager(null)</code>. 0N/A * @see java.lang.Thread#getContextClassLoader 0N/A * This constructor loads the implementations of 0N/A * <code>ScriptEngineFactory</code> visible to the given 0N/A * If loader is <code>null</code>, the script engine factories that are 0N/A * bundled with the platform and that are in the usual extension 0N/A * directories (installed extensions) are loaded. <br><br> 0N/A * @param loader ClassLoader used to discover script engine factories. 0N/A // do not throw any exception here. user may want to 0N/A // manage his/her own factories using this manager 0N/A // by explicit registratation (by registerXXX) methods. 0N/A // one factory failed, but check other factories... 0N/A // do not throw any exception here. user may want to 0N/A // manage his/her own factories using this manager 0N/A // by explicit registratation (by registerXXX) methods. 0N/A * <code>setBindings</code> stores the specified <code>Bindings</code> 0N/A * in the <code>globalScope</code> field. ScriptEngineManager sets this 0N/A * <code>Bindings</code> as global bindings for <code>ScriptEngine</code> 0N/A * objects created by it. 0N/A * @param bindings The specified <code>Bindings</code> 0N/A * @throws IllegalArgumentException if bindings is null. 0N/A * <code>getBindings</code> returns the value of the <code>globalScope</code> field. 0N/A * ScriptEngineManager sets this <code>Bindings</code> as global bindings for 0N/A * <code>ScriptEngine</code> objects created by it. 0N/A * @return The globalScope field. 0N/A * Sets the specified key/value pair in the Global Scope. 0N/A * @param key Key to set 0N/A * @param value Value to set. 0N/A * @throws NullPointerException if key is null. 0N/A * @throws IllegalArgumentException if key is empty string. 0N/A * Gets the value for the specified key in the Global Scope 0N/A * @param key The key whose value is to be returned. 0N/A * @return The value for the specified key. 0N/A * Looks up and creates a <code>ScriptEngine</code> for a given name. 0N/A * The algorithm first searches for a <code>ScriptEngineFactory</code> that has been 0N/A * registered as a handler for the specified name using the <code>registerEngineName</code> 4841N/A * <br><br> If one is not found, it searches the set of <code>ScriptEngineFactory</code> instances 0N/A * stored by the constructor for one with the specified name. If a <code>ScriptEngineFactory</code> 0N/A * is found by either method, it is used to create instance of <code>ScriptEngine</code>. 0N/A * @param shortName The short name of the <code>ScriptEngine</code> implementation. 0N/A * returned by the <code>getNames</code> method of its <code>ScriptEngineFactory</code>. 0N/A * @return A <code>ScriptEngine</code> created by the factory located in the search. Returns null 0N/A * if no such factory was found. The <code>ScriptEngineManager</code> sets its own <code>globalScope</code> 0N/A * <code>Bindings</code> as the <code>GLOBAL_SCOPE</code> <code>Bindings</code> of the newly 0N/A * created <code>ScriptEngine</code>. 0N/A * @throws NullPointerException if shortName is null. 0N/A //look for registered name first 0N/A * Look up and create a <code>ScriptEngine</code> for a given extension. The algorithm 0N/A * used by <code>getEngineByName</code> is used except that the search starts 0N/A * by looking for a <code>ScriptEngineFactory</code> registered to handle the 0N/A * given extension using <code>registerEngineExtension</code>. 0N/A * @param extension The given extension 0N/A * @return The engine to handle scripts with this extension. Returns <code>null</code> 0N/A * @throws NullPointerException if extension is null. 0N/A //look for registered extension first 0N/A * Look up and create a <code>ScriptEngine</code> for a given mime type. The algorithm 0N/A * used by <code>getEngineByName</code> is used except that the search starts 0N/A * by looking for a <code>ScriptEngineFactory</code> registered to handle the 0N/A * given mime type using <code>registerEngineMimeType</code>. 0N/A * @param mimeType The given mime type 0N/A * @return The engine to handle scripts with this mime type. Returns <code>null</code> 0N/A * @throws NullPointerException if mimeType is null. 0N/A //look for registered types first 4841N/A * Returns a list whose elements are instances of all the <code>ScriptEngineFactory</code> classes 0N/A * found by the discovery mechanism. 0N/A * @return List of all discovered <code>ScriptEngineFactory</code>s. 0N/A * Registers a <code>ScriptEngineFactory</code> to handle a language 0N/A * name. Overrides any such association found using the Discovery mechanism. 0N/A * @param name The name to be associated with the <code>ScriptEngineFactory</code>. 0N/A * @param factory The class to associate with the given name. 0N/A * @throws NullPointerException if any of the parameters is null. 0N/A * Registers a <code>ScriptEngineFactory</code> to handle a mime type. 0N/A * Overrides any such association found using the Discovery mechanism. 0N/A * @param type The mime type to be associated with the 0N/A * <code>ScriptEngineFactory</code>. 0N/A * @param factory The class to associate with the given mime type. 0N/A * @throws NullPointerException if any of the parameters is null. 0N/A * Registers a <code>ScriptEngineFactory</code> to handle an extension. 0N/A * Overrides any such association found using the Discovery mechanism. 0N/A * @param extension The extension type to be associated with the 0N/A * <code>ScriptEngineFactory</code>. 0N/A * @param factory The class to associate with the given extension. 0N/A * @throws NullPointerException if any of the parameters is null. 0N/A /** Set of script engine factories discovered. */ 0N/A /** Map of engine name to script engine factory. */ 0N/A /** Map of script file extension to script engine factory. */ 0N/A /** Map of script script MIME type to script engine factory. */ 0N/A /** Global bindings associated with script engines created by this manager. */