Helma Logo
main list history
previous version  overview  next version

Version 4 by hannes on 14. October 2005, 13:27

Helma 2 can be used as a library to instantly add scripting capability to any Java program. Scripts loaded from .js files can extend any Java class and implement any Java interface just using this.__extends__ = javaClassName and this.__implements__ = [javaInterfaceName, ...], respectively. the following JavaScript syntax:

this.__extends__ = javaClassName;
this.__implements__ = [javaInterfaceName, ...];

==== A trivial example

The Java side:

import org.helma.javascript.RhinoLoader;
import java.io.File;
import java.io.IOException;
 
public class Test {
 
    public static void main(String[] args)
            throws IOException, ClassNotFoundException {
        RhinoLoader loader = new RhinoLoader(new File("scriptdir"));
        Runnable test = (Runnable) loader.getInstance("Test");
        new Thread(test).start();
    }
}

This tries to load a script from a file called scriptdir/Test.js that implements java.lang.Runnable. The script file might look as simple as this:

this.__implements__ = "java.lang.Runnable";
 
function run() {
    java.lang.System.err.println("Running!");
}



     removed
     added