4. Activities
   4.1 Java Activities
   4.2 Input and Output Context
   4.3 Configuration
 4. Activities
JawFlow allows you to write activities that are automatically executed by the system. These activities can be written in Java or in a scripting language supported by BSF (using the ScriptActivity)
 4.1 Java Activities
The Java Activities can be classes that must implement:

net.arsretia.jawflow.kernel.processmgr.IRunnableActivity

defined as

public interface IRunnableActivity extends Serializable { public int doWork(InputContext oInput,OutputContext oOutput); public void forceQuit(); public void gracefulStop(); }

The doWork method must return one of the following statuses defined in

net.arsretia.jawflow.objectmodel.IStates

public static final int iACTIVITY_CLOSED = 0x00F0; public static final int iACTIVITY_CLOSED_ABORTED = 0x0020; public static final int iACTIVITY_CLOSED_TERMINATED = 0x0040; public static final int iACTIVITY_CLOSED_COMPLETED = 0x0080;

depending on the end activity status The forceQuit method must stop the activity immediately.
The gracefulStop method can shutdown cleanly the activity.
A typical doWork method can be:

public int doWork(InputContext oInput,OutputContext oOutput); while(boRunning){ // do some important stuff here } if(boForcedQuit){ return IStates.iACTIVITY_CLOSED_TERMINATED; } if(boCleanShutdown){ return IStates.iACTIVITY_CLOSED_COMPLETED; } return IStates.iACTIVITY_CLOSED_COMPLETED; }

 4.2 Input and Output Context
The doWork method parameters are of the type InputContext and OutputContext In the InputContext there is every parameter declared as

<ExtendedAttribute Name="InputVariable" Value="..."/>

in the xpdl referring to Workflow Data and every other ExtendedAttribute Since an ExtendedAttribute can refer one or many parameters with the same name the method getAttribute of InputContext always returns a
java.util.List
It is responsability of the programmer to fetch the first (and only) attribute in case there is only one.
e.g.:

String myVar = (String)((List)oInput.getAttribute("MyVAR")).get(0)

The OutputContext allows to set the value of variables declared in the xpdl as

<ExtendedAttribute Name="OutputVariable" Value="..."/>

If you try to set a variable not declared as OutputAttribute you get an InvalidAttributeException
It is possible, for user defined variables, to refer to a workflow variable with the prefix $
e.g.:

<ExtendedAttribute Name="MyVar" Value="$Var1/$Var2"/>
 4.2 Input and Output Context
The automatic activity is declared in the XPDL with an ExtendedAttribute in the following way:

... <ExtendedAttributes> <ExtendedAttribute Name="java.class.name" Value="<classname>"/> <ExtendedAttribute Name="activity.class.path" Value="<classpath>"/> ... </ExtendedAttributes> ...

where
<classname>is the name of the class implementing net.arsretia.jawflow.kernel.processmgr.IRunnableActivity
<classpath>is the classpath where the class can be found
Chapter 3 Contents Chapter 5