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 described in the
java.util.ServiceLoader class to enumerate all the
implementations of ScriptEngineFactory. 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.
| Modifier and Type | Field and Description |
|---|---|
| private static final Comparator | |
| private static final boolean | |
| private final TreeSet | engineSpis
Set of script engine factories discovered. |
| private final HashMap | extensionAssociations
Map of script file extension to script engine factory. |
| private Bindings | globalScope
Global bindings associated with script engines created by this manager. |
| private final HashMap | mimeTypeAssociations
Map of script MIME type to script engine factory. |
| private final HashMap | nameAssociations
Map of engine name to script engine factory. |
| Access | Constructor and Description |
|---|---|
| public | ScriptEngineManager()
The effect of calling this constructor is the same as calling
|
| public | ScriptEngineManager(ClassLoader
ClassLoader used to discover script engine factories. loader)This constructor loads the implementations of
|
| Modifier and Type | Method and Description |
|---|---|
| private static void | associateFactory(Map<String, ScriptEngineFactory> associations, String association, ScriptEngineFactory factory)
|
| private static void | |
| public Object | |
| public Bindings | |
| private ScriptEngine | getEngineBy(String selector, Map<String, ScriptEngineFactory> associations, Function<ScriptEngineFactory, List<String>> valuesFn)
|
| public ScriptEngine | Returns: The engine to handle scripts with this extension. Returnsnull
if not found.The given extension extension)Look up and create a |
| public ScriptEngine | Returns: The engine to handle scripts with this mime type. Returnsnull
if not found.The given mime type mimeType)Look up and create a |
| public ScriptEngine | Returns: AScriptEngine created by the factory located in the search. Returns null
if no such factory was found. The ScriptEngineManager sets its own globalScope
Bindings as the GLOBAL_SCOPE Bindings of the newly
created ScriptEngine.The short name of the shortName)ScriptEngine implementation.
returned by the getNames method of its ScriptEngineFactory.Looks up and creates a |
| public List | Returns: List of all discoveredScriptEngineFactorys.Returns a list whose elements are instances of all the |
| private ServiceLoader | |
| private void | |
| public void | |
| public void | registerEngineExtension(String
The extension type to be associated with the
extension, ScriptEngineFactory ScriptEngineFactory.The class to associate with the given extension. factory)Registers a |
| public void | registerEngineMimeType(String
The mime type to be associated with the
type, ScriptEngineFactory ScriptEngineFactory.The class to associate with the given mime type. factory)Registers a |
| public void | registerEngineName(String
The name to be associated with the name, ScriptEngineFactory ScriptEngineFactory.The class to associate with the given name. factory)Registers a |
| private static void | |
| public void | setBindings(Bindings
The specified bindings)Bindings
|
| COMPARATOR | back to summary |
|---|---|
| private static final Comparator<ScriptEngineFactory> COMPARATOR | |
| DEBUG | back to summary |
|---|---|
| private static final boolean DEBUG | |
| engineSpis | back to summary |
|---|---|
| private final TreeSet<ScriptEngineFactory> engineSpis Set of script engine factories discovered. | |
| extensionAssociations | back to summary |
|---|---|
| private final HashMap<String, ScriptEngineFactory> extensionAssociations Map of script file extension to script engine factory. | |
| globalScope | back to summary |
|---|---|
| private Bindings globalScope Global bindings associated with script engines created by this manager. | |
| mimeTypeAssociations | back to summary |
|---|---|
| private final HashMap<String, ScriptEngineFactory> mimeTypeAssociations Map of script MIME type to script engine factory. | |
| nameAssociations | back to summary |
|---|---|
| private final HashMap<String, ScriptEngineFactory> nameAssociations Map of engine name to script engine factory. | |
| ScriptEngineManager | back to summary |
|---|---|
| public ScriptEngineManager() The effect of calling this constructor is the same as calling
| |
| ScriptEngineManager | back to summary |
|---|---|
| public ScriptEngineManager(ClassLoader loader) This constructor loads the implementations of
| |
| associateFactory | back to summary |
|---|---|
| private static void associateFactory(Map<String, ScriptEngineFactory> associations, String association, ScriptEngineFactory factory) | |
| debugPrint | back to summary |
|---|---|
| private static void debugPrint(Throwable exp) | |
| get | back to summary |
|---|---|
| public Object get(String key) Gets the value for the specified key in the Global Scope | |
| getBindings | back to summary |
|---|---|
| public Bindings getBindings()
| |
| getEngineBy | back to summary |
|---|---|
| private ScriptEngine getEngineBy(String selector, Map<String, ScriptEngineFactory> associations, Function<ScriptEngineFactory, List<String>> valuesFn) | |
| getEngineByExtension | back to summary |
|---|---|
| public ScriptEngine getEngineByExtension(String extension) Look up and create a
| |
| getEngineByMimeType | back to summary |
|---|---|
| public ScriptEngine getEngineByMimeType(String mimeType) Look up and create a
| |
| getEngineByName | back to summary |
|---|---|
| public ScriptEngine getEngineByName(String shortName) Looks up and creates a
| |
| getEngineFactories | back to summary |
|---|---|
| public List Returns a list whose elements are instances of all the
| |
| getServiceLoader | back to summary |
|---|---|
| private ServiceLoader | |
| initEngines | back to summary |
|---|---|
| private void initEngines(final ClassLoader loader) | |
| put | back to summary |
|---|---|
| public void put(String key, Object value) Sets the specified key/value pair in the Global Scope.
| |
| registerEngineExtension | back to summary |
|---|---|
| public void registerEngineExtension(String extension, ScriptEngineFactory factory) Registers a
| |
| registerEngineMimeType | back to summary |
|---|---|
| public void registerEngineMimeType(String type, ScriptEngineFactory factory) Registers a
| |
| registerEngineName | back to summary |
|---|---|
| public void registerEngineName(String name, ScriptEngineFactory factory) Registers a
| |
| reportException | back to summary |
|---|---|
| private static void reportException(String msg, Throwable exp) | |
| setBindings | back to summary |
|---|---|
| public void setBindings(Bindings bindings)
| |