You can easily call Java code from your Flowscripts, for example:
</p>
<source>
var map = new java.util.HashMap();
map.put("foo", "bar");
</source>
<s2 title="Imports">
<p>Classes in packages under <code>java</code> are accessible directly in your scripts.</p>
<p>Note that classes under <code>java.lang</code> are not automatically imported, however:</p>
<source>var n = new java.lang.Integer(3);</source>
<p>All other java packages and classes are accessible under the property <code>Packages</code>:</p>
<source>var tree = new Packages.javax.swing.JTree();</source>
<p>You can get the effect of Java imports using the <code>importPackage()</code> and <code>importClass()</code> functions:</p>
<table>
<tr>
<td>
In Java:
</td>
<td>
In JavaScript:
</td>
</tr>
<tr>
<td>
import foo.*;
</td>
<td>
importPackage(Packages.foo);
</td>
</tr>
<tr>
<td>
import foo.Bar;
</td>
<td>
importClass(Packages.foo.Bar);
</td>
</tr>
</table>
<p>Example:</p>
<source>
importPackage(java.util);
var set = new TreeSet();</source>
<p>
</p>
</s2>
<s2 title="Bean Properties">
<p>
If your Java classes have getters and setters you can access them as properties in JavaScript:</p>
<source>
var d = new java.util.Date();
d.year = 2003; // same effect as d.setYear(2003);
</source>
<p/>
</s2>
<s2 title="Dynamic Compilation">
<p>
Cocoon includes an embedded Java compiler that can dynamically compile Java source files and load and execute the resulting classes at runtime. During development you can take advantage of this capability to rapidly develop, test, and debug your applications. The Cocoon source resolver is used to locate source files.
</p>
<p>Example:</p>
<source>
// Cause com.xyz.MyClass to be compiled and loaded:
importClass(Packages.com.xyz.MyClass);
var obj = new MyClass("foo", 123); // call a constructor
obj.someMethod(); // call a method
</source>
<p/>
<s3 title="Configuration">
<p>You control this behavior by specifying configuration properties in the <code>cocoon.xconf</code> file located in the WEB-INF/ directory of your application. These properties are located in the <code>component-instance</code> element under <code>flow-interpreters</code> whose <code>name</code> attribute has the value <code>"javascript"</code>. The following properties may be set:
</p>
<table>
<tr>
<td>
Property:
</td>
<td>
Description:
</td>
</tr>
<tr>
<td>
reload-scripts
</td>
<td>
Determines whether Cocoon should attempt to detect changes to source files and reload them. This applies to both JavaScript and Java source files
</td>
</tr>
<tr>
<td>
check-time
</td>
<td>
Specifies an interval in milliseconds after which Cocoon will check for changes to source files (ignored if reload-scripts is false or unspecified)
</td>
</tr>
<tr>
<td>
classpath
</td>
<td>
A semicolon separated list of URL's that will be searched for Java source files