Helma Logo
main list history

Version 18 by hannes on 29. November 2006, 01:32

1Content of this page was obsoletedObsolete, see new *RhinoLoader branch|Source/browse/helma/branches/rhinoloader/*. New wiki page coming soon.*RhinoLoader*

Version 17 by hannes on 24. November 2006, 23:02

1====Content of this page was obsoleted, What you needsee new *RhinoLoader branch|Source/browse/helma/branches/rhinoloader/*. New wiki page coming soon.
2
3All you need is the *bare bones helma package|http://dev.helma.org/static/helma.dev/Wiki/Using%20Helma%202%20as%20Library/bare_bones_helma-0.1.zip*  or a snapshot from the *bare bones helma branch|source/helma/branches/bare-bones-branch*.
4
5==== How it works
6
7Helma 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 the following JavaScript syntax:
8
9 this.__extends__ = javaClassName;
10 this.__implements__ = [javaInterfaceName, ...];
11
12The scripted class can override any Java methods and define new ones.  (Note that functions that don't have a corresponding method in a Java class or Interface can't be invoked from Java, though!) Overridden methods in the super class can be called using the super$ prefix:
13
14  this.super$put(key, value);
15
16==== A simple example
17
18The Java side:
19
20 import org.helma.javascript.RhinoLoader;
21 import java.io.File;
22 import java.io.IOException;
23 
24 public class Test {
25 
26    public static void main(String[] args)
27            throws IOException, ClassNotFoundException {
28        RhinoLoader loader = new RhinoLoader(new File("scriptdir"));
29        Runnable test = (Runnable) loader.getInstance("Test");
30        new Thread(test).start();
31    }
32 }
33
34This tries to load an instance of a class implementing java.lang.Runnable from a file called scriptdir/Test.js. The script file might look as simple as this:
35
36 this.__implements__ = "java.lang.Runnable";
37 
38 function run() {
39    java.lang.System.err.println("Running!");
40 }
41
42==== Advanced features
43
44TODO
45
46* Pass JS <a href="http://www.mozilla.org/rhino/tutorial.html#JavaScriptHostObjects">Host objects classes</a> as second argument to to RhinoLoader constructor
47* Pass global variable map as second argument to getInstance()
48* Usage example in <a href="http://www.springframework.org/">Spring</a> using <a href="http://static.springframework.org/spring/docs/1.2.x/reference/beans.html#beans-instance-factory-method">instance factory method</a>

Version 16 by hannes on 10. March 2006, 12:19

3All you need is the *bare bones helma|http://devhelma package|http://dev.helma.org/static/helma.dev/Wiki/Using%20Helma%202%20as%20Library/bare_bones_helma-0.1.zip* package  or a snapshot from the *bare bones helma branch|source/helma/branches/bare-bones-branch*.

Version 15 by hannes on 10. March 2006, 12:19

3All you need are is the js*bare bones helma|http://dev.jar and helma.jar files you get from building the *svn snapshot|source*org/static/helma. When Helma 2 is released, there will be dev/Wiki/Using%20Helma%202%20as%20Library/bare_bones_helma-0.1.zip* package or a bare bones library download option that will exclude Jetty and snapshot from the Helma web framework*bare bones helma branch|source/helma/branches/bare-bones-branch*.

Version 14 by hannes on 14. October 2005, 16:24

48* Usage example in <a href="http://www.springframework.org/">Spring</a> using <a href="http://static.springframework.org/spring/docs/1.2.x/reference/beans.html#beans-instance-factory-method">instance factory method</a>

Version 13 by hannes on 14. October 2005, 16:18

46* Pass JS Host <a href="http://www.mozilla.org/rhino/tutorial.html#JavaScriptHostObjects">Host objects classes classes</a> as second argument to to RhinoLoader constructor

Version 12 by hannes on 14. October 2005, 16:14

44FIXMETODO

Version 11 by hannes on 14. October 2005, 16:14

42==== Advanced features
43
44FIXME
45
46* Pass JS Host objects classes as second argument to to RhinoLoader constructor
47* Pass global variable map as second argument to getInstance()

Version 10 by hannes on 14. October 2005, 13:45

3All you need are the js.jar and helma.jar files you get from building the *svn snapshot|source*. When Helma 2 is released, there will be a bare bones library download options option that will exclude Jetty and the Helma web framework.

Version 9 by hannes on 14. October 2005, 13:42

3All you need are the js.jar and helma.jar files you get from building the *source|svn snapshot**svn snapshot|source*. When Helma 2 is released, there will be a bare bones library download options without that will exclude Jetty and the Helma web framework.

Version 8 by hannes on 14. October 2005, 13:41

1==== What you need
2
3All you need are the js.jar and helma.jar files you get from building the *source|svn snapshot*. When Helma 2 is released, there will be a bare bones library download options without Jetty and the web framework
4
5==== How it works
6

Version 7 by hannes on 14. October 2005, 13:35

28This tries to load an instance of a script class implementing java.lang.Runnable from a file called scriptdir/Test.js that implements java.lang.Runnablejs. The script file might look as simple as this:

Version 6 by hannes on 14. October 2005, 13:33

6====The scripted class can override any Java methods and define new ones. A trivial example (Note that functions that don't have a corresponding method in a Java class or Interface can't be invoked from Java, though!) Overridden methods in the super class can be called using the super$ prefix:
8  this.super$put(key, value);
9
10==== A simple example
11
32
33The scripted class can override any Java methods and define new ones.  (Note that functions that don't have a corresponding method in a Java class or Interface can't be invoked from Java, though!) Overridden methods in the super class can be called using the super$ prefix:
34
35  this.super$put(key, value);
36

Version 5 by hannes on 14. October 2005, 13:33

32The scripted class can override any Java methods and define new ones.  (Note that functions that don't have a corresponding method in a Java class or Interface can't be invoked from Java, though!) Overridden methods in the super class can be called using the super$ prefix:
33
34  this.super$put(key, value);

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

1Helma 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:
2
3 this.__extends__ = javaClassName;
4 this.__implements__ = [javaInterfaceName, ...];

Version 3 by hannes on 14. October 2005, 13:26

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

Version 2 by hannes on 14. October 2005, 13:21

10 
12 
24 

Version 1 by hannes on 14. October 2005, 13:21

1Helma 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.
2
3==== A trivial example
4
5The Java side:
6
7 import org.helma.javascript.RhinoLoader;
8 import java.io.File;
9 import java.io.IOException;
10
11 public class Test {
12
13    public static void main(String[] args)
14            throws IOException, ClassNotFoundException {
15        RhinoLoader loader = new RhinoLoader(new File("scriptdir"));
16        Runnable test = (Runnable) loader.getInstance("Test");
17        new Thread(test).start();
18    }
19 }
20
21This tries to load a script from a file called scriptdir/Test.js that implements java.lang.Runnable. The scirpt might look like this:
22
23 this.__implements__ = "java.lang.Runnable";
24
25 function run() {
26    java.lang.System.err.println("Running!");
27 }
28
29