BPM Events can manipulate complex Java objects in rules. The following example shows how to use values of type Vector in rules and modules. Note the use of the cast operator, which in Java is a program action that converts an object from one type to another. Here, the cast operator (shown in bold) enforces the mapping to a BPM Events type, and ensures downcasting to a Java type. Downcasting is checked at run-time.
application BP_test_suites
using java.util.Vector;
using java.lang;
module jobj_event_test
fun gen(i: int){
val vec = new ~Vector();
vec.add(i);
val evt = event A::B{vec: vec};
notify evt;
}fun gen1(i: int){
val vec = new ~Vector();
val v = new ~Vector();
v.add(222);
vec.add(v);
val evt = event A1::B{vec: vec};
notify evt;
}group jobj_event_test
rule rule_1
activated by
evt1 of A::B,
evt2 of A1::B
then {
val vec: ~Vector = evt1.vec;
for (var i = 0; i < 10; i++) {
vec.add(new ~Integer(2*i*i));
vec.add(i*i);
}
for (var iter = vec.iterator(); iter.hasNext(); ) {
val i = cast(int)iter.next();
println(">> <1>i: "+i);
}
}
rule rule_2
activated by
evt1 of A::B,
evt2 of A1::B
if ((cast(~Vector)evt2.vec).size() > 2)
then {
val vec: ~Vector = evt2.vec;
for (var i = 0; i < 10; i++) {
val v = new ~Vector();
v.add(2*i*i);
vec.add(v);
}
for (var iter = vec.iterator(); iter.hasNext(); ) {
val v = cast(~Vector)iter.next();
val i = cast(int)v.elementAt(0);
println(">> <2>i: "+i);
} }
{println(">> start: jobj_event_test");
gen1(100);
gen(200);
gen(300);
println(">> done: jobj_event_test");
}
Note: Global Java object references are not recoverable in the current version of BPM Events.