172 CHAPTER 9 SCRIPTING AND JSR 223
CHAPTER 9 SCRIPTING AND JSR 223 173 factory.getLanguageVersion(), factory.getExtensions(), factory.getMimeTypes(), factory.getNames()); ScriptEngine engine = factory.getScriptEngine(); } } } Running the program demonstrates that the only installed engine is version 1.6, release 2, of the Mozilla Rhino engine. > java ListEngines Name: Mozilla Rhino Version: 1.6 release 2 Language name: ECMAScript Language version: 1.6 Extensions: [js] Mime types: [application/javascript, application/ecmascript, text/javascript, text/ecmascript] Names: [js, rhino, JavaScript, javascript, ECMAScript, ecmascript] The last line represents the different names that can be used to locate this engine from the manager. While getting the scripting engine from the factory that was acquired from the scripting manager certainly works, you don t need to go through that level of indirection. Instead, you can ask the manager directly for the engine associated with a particular extension, mime type, or name, as follows: ScriptEngine engine1 = manager.getEngineByExtension(”js”); ScriptEngine engine2 = manager.getEngineByMimeType(”text/javascript”); ScriptEngine engine3 = manager.getEngineByName(”javascript”); The getEngineByXXX() methods are not static methods of ScriptEngineManager, so you have to create an instance first; but if you know you want to evaluate a JavaScript expression, just ask for the JavaScript engine, and then use the returned engine to evaluate the expression. Note There are two constructors for ScriptEngineManager, with a class loader passed into one, allowing you to provide multiple contexts for where to locate additional engines.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services