public class ScriptEngineManager extends Object
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.
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.
| Constructor and Description |
|---|
ScriptEngineManager()
The effect of calling this constructor is the same as calling
ScriptEngineManager(Thread.currentThread().getContextClassLoader()).
|
ScriptEngineManager(ClassLoader
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.
|
| Modifier and Type | Method and Description |
|---|---|
Object |
get(String
Gets the value for the specified key in the Global Scope
|
Bindings |
getBindings()
getBindings returns the value of the
globalScope field.
|
ScriptEngine |
getEngineByExtension(String
Look up and create a
ScriptEngine for a given extension.
|
ScriptEngine |
getEngineByMimeType(String
Look up and create a
ScriptEngine for a given mime type.
|
ScriptEngine |
getEngineByName(String
Looks up and creates a
ScriptEngine for a given name.
|
List |
getEngineFactories()
Returns a list whose elements are instances of all the
ScriptEngineFactory classes found by the discovery mechanism.
|
void |
put(String
Sets the specified key/value pair in the Global Scope.
|
void |
registerEngineExtension(String
Registers a
ScriptEngineFactory to handle an extension.
|
void |
registerEngineMimeType(String
Registers a
ScriptEngineFactory to handle a mime type.
|
void |
registerEngineName(String
Registers a
ScriptEngineFactory to handle a language name.
|
void |
setBindings(Bindings
setBindings stores the specified
Bindings in the
globalScope field.
|
public ScriptEngineManager()
ScriptEngineManager(Thread.currentThread().getContextClassLoader()).
Thread.getContextClassLoader()
public ScriptEngineManager(ClassLoaderloader)
ScriptEngineFactory visible to the given
ClassLoader using the
service provider mechanism.
null, the script engine factories that are bundled with the platform and that are in the usual extension directories (installed extensions) are loaded.
loader - ClassLoader used to discover script engine factories.
public void setBindings(Bindingsbindings)
setBindings stores the specified
Bindings in the
globalScope field. ScriptEngineManager sets this
Bindings as global bindings for
ScriptEngine objects created by it.
bindings - The specified
Bindings
IllegalArgumentException - if bindings is null.
public BindingsgetBindings()
getBindings returns the value of the
globalScope field. ScriptEngineManager sets this
Bindings as global bindings for
ScriptEngine objects created by it.
public void put(Stringkey, Object value)
key - Key to set
value - Value to set.
NullPointerException - if key is null.
IllegalArgumentException - if key is empty string.
public Objectget(String key)
key - The key whose value is to be returned.
public ScriptEnginegetEngineByName(String shortName)
ScriptEngine for a given name. The algorithm first searches for a
ScriptEngineFactory that has been registered as a handler for the specified name using the
registerEngineName method.
ScriptEngineFactory instances stored by the constructor for one with the specified name. If a
ScriptEngineFactory is found by either method, it is used to create instance of
ScriptEngine.
shortName - The short name of the
ScriptEngine implementation. returned by the
getNames method of its
ScriptEngineFactory.
ScriptEngine 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.
NullPointerException - if shortName is null.
public ScriptEnginegetEngineByExtension(String extension)
ScriptEngine for a given extension. The algorithm used by
getEngineByName is used except that the search starts by looking for a
ScriptEngineFactory registered to handle the given extension using
registerEngineExtension.
extension - The given extension
null if not found.
NullPointerException - if extension is null.
public ScriptEnginegetEngineByMimeType(String mimeType)
ScriptEngine for a given mime type. The algorithm used by
getEngineByName is used except that the search starts by looking for a
ScriptEngineFactory registered to handle the given mime type using
registerEngineMimeType.
mimeType - The given mime type
null if not found.
NullPointerException - if mimeType is null.
public List<ScriptEngineFactory > getEngineFactories()
ScriptEngineFactory classes found by the discovery mechanism.
ScriptEngineFactorys.
public void registerEngineName(Stringname, ScriptEngineFactory factory)
ScriptEngineFactory to handle a language name. Overrides any such association found using the Discovery mechanism.
name - The name to be associated with the
ScriptEngineFactory.
factory - The class to associate with the given name.
NullPointerException - if any of the parameters is null.
public void registerEngineMimeType(Stringtype, ScriptEngineFactory factory)
ScriptEngineFactory to handle a mime type. Overrides any such association found using the Discovery mechanism.
type - The mime type to be associated with the
ScriptEngineFactory.
factory - The class to associate with the given mime type.
NullPointerException - if any of the parameters is null.
public void registerEngineExtension(Stringextension, ScriptEngineFactory factory)
ScriptEngineFactory to handle an extension. Overrides any such association found using the Discovery mechanism.
extension - The extension type to be associated with the
ScriptEngineFactory.
factory - The class to associate with the given extension.
NullPointerException - if any of the parameters is null.