helma.rhino
hide
ContentsThe helma.rhino module provides methods to access the Helma NG Rhino engine. Setting up Host objectsBy default, Helma NG does not contain any custom host objects. This makes sense when using Helma NG in other contexts than the typical web application. The helma.rhino module provides a utility method called You can also register your own host objects using the helma.rhino.addHostObject() method, passing the host object java class as only argument. Scripting Java classesHelma NG allows you to add methods and properties to existing Java classes. The helma.rhino.extendJavaClass() takes a java class as argument and returns an extended java class wrapper. You can add Javascript functions to the java class like it was a Javascript constructor, using the class wrapper's prototype property.
Note that while the class wrapper works as constructor for the extended class, the added functions and properties are available also on objects created using the standard java constructor and even objects created and returned from java code. The Helma NG object wrapper takes care of this. Note that this is different from Rhino's JavaAdapter. JavaAdapter allows you to create new java classes in javascript, extending existing classes and implementing existing interfaces. The Helma NG java class extension feature allows you to add scripted functions to existing java classes without creating a new class. You can also script java superclasses and interfaces. However, Helma NG currently does not implement extended class merging or chaining. In other words, if both java.util.HashMap, java.util.Map and java.lang.Object classes are extended, java instances will only have the "nearest" extension: HashMap instances will only have the extended properties of java.util.HashMap, TreeMap objects those of java.util.Map, and ArrayList those of java.lang.Object. Managing callbackshelma.rhino provides addCallback(), removeCallback(), and invokeCallback() methods to register, remove and invoke callbacks. Setting the Rhino optimization levelThe helma.rhino.setRhinoOptimizationLevel() method allows you to set the Rhino optimization level. Accepted values are integer numbers between -1 and 9. The default level is 0 and implements basic Javascript to Java bytecode compilation. Level -1 disables the bytecode compiler and sets Rhino to interpreter mode, which is required for some features such as continuations. Levels 1 to 9 add some optimizations that may or may not be detrimental to your health. Note that Helma NG can run in both Java-compiled and interpreted mode in the same application, so you can call this on a per-request basis in the onInvoke callback. Also note that setting the optimization level in the 0..9 range does not cause scripts that have already been compiled and cached to be recompiled. Going furtherThe rhino module provides utility methods getRhinoContext() and getRhinoEngine() to access the current Rhino Context and Rhino Engine instances. These classes provide a lot of Javascript related functionality that can be easily used from application code. Pages linking to this page: Release 0.2 |
navigation
Download
Community
Weblog
Mailing Lists
IRC Channel
Documentation
Introductions
Tools
Reference
Project
Roadmap
Bug Reporting
Source
Helma NG Wiki
Wiki
Tags
Updates
Related Projects
Sites using Helma
Shop
search
tags for this page
all tags
Tagsapps (1) bugs (2) class (1) community (2) compatibility (1) concurrency (1) continuations (2) Documentation (6) dogfood (1) formatting (1) gobi (1) helma (6) helma 1.6 (13) helma 1.7 (8) helma 2 (11) helma ng (17) hopobject (1) html (1) inheritance (5) introspection (1) java (2) javascript (5) jetty (1) JSDoc (1) lazy (1) marius person (1) metaprogramming (2) modules (3) oop (1) organization (2) ORM (2) parsing (1) plugins (1) project (2) projects (1) prototype (1) Rabbit (2) Reference (1) REPL (1) rhino (4) roadmap (3) shell (1) shop (0) Skin Rendering (5) Snippets (1) source svn (1) sugar (3) templates (13) testing (4) Tobi (7) xml (1) Pages linking to this page: Wiki Overview Text Draft, wiki pages linking here
|