Karajan:JavaElement
From Java CoG Kit
(Redirected from Karajan/JavaElement)
The Java class definition
Package declaration:
package my.example.element;
Import declarations:
import org.globus.cog.karajan.arguments.Arg; import org.globus.cog.karajan.stack.VariableStack; import org.globus.cog.karajan.util.TypeUtil; import org.globus.cog.karajan.workflow.ExecutionException; import org.globus.cog.karajan.workflow.nodes.SequentialWithArguments;
SequentialWithArguments (or should it be ElementWithArgumentsEvaluatedSequentially?) will automatically evaluate its arguments in sequential order.
public class MyElement extends SequentialWithArguments {
Tell it what arguments the element accepts:
public static final Arg FIRST = new Arg.Positional("first");
public static final Arg SECOND = new Arg.Positional("second");
public static final Arg OPTIONAL = new Arg.Optional("optional");
static {
setArguments(MyElement.class, new Arg[] { FIRST, SECOND, OPTIONAL });
}
Implement the functionality; post() gets called after all the arguments have been evaluated.
public void post(VariableStack stack) throws ExecutionException {
//add the 'first' and 'second' and multiply with 'optional' if present
double first = TypeUtil.toDouble(FIRST.getValue(stack));
double second = TypeUtil.toDouble(SECOND.getValue(stack));
double result = first + second;
if (OPTIONAL.isPresent(stack)) {
result *= TypeUtil.toDouble(OPTIONAL.getValue(stack));
}
//return the result
ret(stack, new Double(result));
//without this the system won't know we're done
super.post(stack);
}
}
The library definition
Now the mapping of the name to the implementation. Let's call the file my.xml:
<karajan>
The namespace is not required, but it may help. It's unrelated to XML namespaces.
<namespace prefix="my">
The actual definition:
<elementDef type="example" className="my.example.element.MyElement"/>
</namespace>
</karajan>
Actual use
test.xml:
<karajan>
<include file="sys.xml"/>
<include file="my.xml"/>
<set name="result1">
<example first="1" second="2"/>
</set>
<set name="result2">
<my:example first="1" second="2" optional="3"/>
</set>
<print message="{result1}, {result2}"/>
</karajan>
Or the other syntax. test.k:
include("sys.k")
include("my.xml")
set(result1, example(1, 2))
set(result2, my:example(1, 2, optional = 3))
print("{result1}, {result2}")
