Rhino / Direct Scripting of Java

Rhino extends the JavaScript language with a couple of functions, as for example Array.prototype.toSource(), uneval(Object) and seal(Object) (see http://www.mozilla.org/rhino/rhino15R5.html for details).

But more importantly, Rhino provides full access to any kind of Java class that has been loaded into the Runtime Environment. A feature that gives Helma developers (nearly) the full power of Java at their fingertips, and let's them take advantage of available Java libraries within their application.

Assuming that your Java classes are already loaded into Helma (which is for example done by dropping your jared-library into [HelmaHome]/lib/ext or to [AppDir], and restarting Helma), you can call its static methods, access constants, instantiate new objects, and so forth.

The following example demonstrates the use of the freely available GeoIP Java API to look up country codes for ip-addresses. See http://www.maxmind.com/app/java for more information on this package.

var ls = new Packages.com.maxmind.geoip.LookupService("modGeoIP.dat", 
var code = ls.getCountry("").getCode();

As you can see, Java classes are made accessible through a top-level variable named Packages. The basic java classes (starting with 'java.') do not require this prefix, but are directly accessible. See the following example:

var hash = new java.util.Hashtable(); 
hash.put("key01", "a string"); 
hash.put("key02", new Date());

Note that Rhino takes care of all the necessary type conversion.

Make sure that (at least at some point) you read through the 'Scripting Java' tutorial located on the Rhino website: http://www.mozilla.org/rhino/ScriptingJava.html, which also explains how to instantiate Java arrays, implement interfaces and call overloaded methods.