- java.lang.Object
- 
- javax.script.ScriptEngineManager
 
- 
 public class ScriptEngineManager extends Object TheScriptEngineManagerimplements a discovery and instantiation mechanism forScriptEngineclasses 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 theServiceLoaderclass to enumerate all the implementations ofScriptEngineFactory.
 TheScriptEngineManagerprovides 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 Bindingsof key/value pairs, referred to as the "Global Scope" maintained by the manager is available to all instances ofScriptEnginecreated by theScriptEngineManager. The values in theBindingsare generally exposed in all scripts.- Since:
- 1.6
 
- 
- 
Constructor SummaryConstructors Constructor Description ScriptEngineManager()The effect of calling this constructor is the same as callingScriptEngineManager(Thread.currentThread().getContextClassLoader()).ScriptEngineManager(ClassLoader loader)This constructor loads the implementations ofScriptEngineFactoryvisible to the givenClassLoaderusing the service provider mechanism.
 If loader isnull, the script engine factories that are bundled with the platform are loaded.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description Objectget(String key)Gets the value for the specified key in the Global ScopeBindingsgetBindings()getBindingsreturns the value of theglobalScopefield.ScriptEnginegetEngineByExtension(String extension)Look up and create aScriptEnginefor a given extension.ScriptEnginegetEngineByMimeType(String mimeType)Look up and create aScriptEnginefor a given mime type.ScriptEnginegetEngineByName(String shortName)Looks up and creates aScriptEnginefor a given name.List<ScriptEngineFactory>getEngineFactories()Returns a list whose elements are instances of all theScriptEngineFactoryclasses found by the discovery mechanism.voidput(String key, Object value)Sets the specified key/value pair in the Global Scope.voidregisterEngineExtension(String extension, ScriptEngineFactory factory)Registers aScriptEngineFactoryto handle an extension.voidregisterEngineMimeType(String type, ScriptEngineFactory factory)Registers aScriptEngineFactoryto handle a mime type.voidregisterEngineName(String name, ScriptEngineFactory factory)Registers aScriptEngineFactoryto handle a language name.voidsetBindings(Bindings bindings)setBindingsstores the specifiedBindingsin theglobalScopefield.
 
- 
- 
- 
Constructor Detail- 
ScriptEngineManagerpublic ScriptEngineManager() The effect of calling this constructor is the same as callingScriptEngineManager(Thread.currentThread().getContextClassLoader()).- See Also:
- Thread.getContextClassLoader()
 
 - 
ScriptEngineManagerpublic ScriptEngineManager(ClassLoader loader) This constructor loads the implementations ofScriptEngineFactoryvisible to the givenClassLoaderusing the service provider mechanism.
 If loader isnull, the script engine factories that are bundled with the platform are loaded.- Parameters:
- loader- ClassLoader used to discover script engine factories.
 
 
- 
 - 
Method Detail- 
setBindingspublic void setBindings(Bindings bindings) setBindingsstores the specifiedBindingsin theglobalScopefield. ScriptEngineManager sets thisBindingsas global bindings forScriptEngineobjects created by it.- Parameters:
- bindings- The specified- Bindings
- Throws:
- IllegalArgumentException- if bindings is null.
 
 - 
getBindingspublic Bindings getBindings() getBindingsreturns the value of theglobalScopefield. ScriptEngineManager sets thisBindingsas global bindings forScriptEngineobjects created by it.- Returns:
- The globalScope field.
 
 - 
putpublic void put(String key, Object value) Sets the specified key/value pair in the Global Scope.- Parameters:
- key- Key to set
- value- Value to set.
- Throws:
- NullPointerException- if key is null.
- IllegalArgumentException- if key is empty string.
 
 - 
getpublic Object get(String key) Gets the value for the specified key in the Global Scope- Parameters:
- key- The key whose value is to be returned.
- Returns:
- The value for the specified key.
 
 - 
getEngineByNamepublic ScriptEngine getEngineByName(String shortName) Looks up and creates aScriptEnginefor a given name. The algorithm first searches for aScriptEngineFactorythat has been registered as a handler for the specified name using theregisterEngineNamemethod.
 If one is not found, it searches the set ofScriptEngineFactoryinstances stored by the constructor for one with the specified name. If aScriptEngineFactoryis found by either method, it is used to create instance ofScriptEngine.- Parameters:
- shortName- The short name of the- ScriptEngineimplementation. returned by the- getNamesmethod of its- ScriptEngineFactory.
- Returns:
- A ScriptEnginecreated by the factory located in the search. Returns null if no such factory was found. TheScriptEngineManagersets its ownglobalScopeBindingsas theGLOBAL_SCOPEBindingsof the newly createdScriptEngine.
- Throws:
- NullPointerException- if shortName is null.
 
 - 
getEngineByExtensionpublic ScriptEngine getEngineByExtension(String extension) Look up and create aScriptEnginefor a given extension. The algorithm used bygetEngineByNameis used except that the search starts by looking for aScriptEngineFactoryregistered to handle the given extension usingregisterEngineExtension.- Parameters:
- extension- The given extension
- Returns:
- The engine to handle scripts with this extension.  Returns nullif not found.
- Throws:
- NullPointerException- if extension is null.
 
 - 
getEngineByMimeTypepublic ScriptEngine getEngineByMimeType(String mimeType) Look up and create aScriptEnginefor a given mime type. The algorithm used bygetEngineByNameis used except that the search starts by looking for aScriptEngineFactoryregistered to handle the given mime type usingregisterEngineMimeType.- Parameters:
- mimeType- The given mime type
- Returns:
- The engine to handle scripts with this mime type.  Returns nullif not found.
- Throws:
- NullPointerException- if mimeType is null.
 
 - 
getEngineFactoriespublic List<ScriptEngineFactory> getEngineFactories() Returns a list whose elements are instances of all theScriptEngineFactoryclasses found by the discovery mechanism.- Returns:
- List of all discovered ScriptEngineFactorys.
 
 - 
registerEngineNamepublic void registerEngineName(String name, ScriptEngineFactory factory) Registers aScriptEngineFactoryto handle a language name. Overrides any such association found using the Discovery mechanism.- Parameters:
- name- The name to be associated with the- ScriptEngineFactory.
- factory- The class to associate with the given name.
- Throws:
- NullPointerException- if any of the parameters is null.
 
 - 
registerEngineMimeTypepublic void registerEngineMimeType(String type, ScriptEngineFactory factory) Registers aScriptEngineFactoryto handle a mime type. Overrides any such association found using the Discovery mechanism.- Parameters:
- type- The mime type to be associated with the- ScriptEngineFactory.
- factory- The class to associate with the given mime type.
- Throws:
- NullPointerException- if any of the parameters is null.
 
 - 
registerEngineExtensionpublic void registerEngineExtension(String extension, ScriptEngineFactory factory) Registers aScriptEngineFactoryto handle an extension. Overrides any such association found using the Discovery mechanism.- Parameters:
- extension- The extension type to be associated with the- ScriptEngineFactory.
- factory- The class to associate with the given extension.
- Throws:
- NullPointerException- if any of the parameters is null.
 
 
- 
 
-