Java Reference
In-Depth Information
A ScriptEngineManager locates and instantiates all available ScriptEngineFactory
classes. You can get a list of instances of all factory classes using the
getEngineFactories() method of the ScriptEngineManager class. When you call
a method of the manager to get a script engine based on a criterion such as the
getEngineByName(String shortName) method to get an engine by name, the manager
searches all factories for that criterion and returns the matching script engine reference.
If no factories are able to provide a matching engine, the manager returns null . Please
refer to Listing 1-3 for more details on listing all available factories and describing script
engines that they can create.
Now you know that a ScriptEngineManager does not create instances of a script
engine. Rather, it queries all available factories and passes the reference of a script engine
created by the factory back to the caller.
To make the discussion complete, let's add a twist to the ways a script engine can be
created. You can create an instance of a script engine in three ways:
Instantiate the script engine class directly.
Instantiate the script engine factory class directly and call its
getScriptEngine() method.
Use one of the
getEngineByXxx() methods of the
ScriptEngineManager class.
It is advised to use the ScriptEngineManager class to get instances of a script
engine. This method allows all engines created by the same manager to share a state
that is a set of key-value pairs stored as an instance of the Bindings interface. The
ScriptEngineManager instance stores this state.
it is possible to have more than one instance of the ScriptEngineManager class
in an application. in that case, each ScriptEngineManager instance maintains a state
common to all engines that it creates. that is, if two engines are obtained by two different
instances of the ScriptEngineManager class, those engines will not share a common state
maintained by their managers unless you make it happen programmatically.
Tip
 
Search WWH ::




Custom Search