| previous section: Using the Almo application: Building a Workflow with the Almo application |
next section: Integrating Almo in Java applications: Using the Almo GUI |
Integrating Almo in Java applications: Loading and executing a Workflow
Content
Requirements
Almo 2.0 requires:
- Java 5.0
- almo.jar (The Almo library)
- Apache log4j library
- Hydra libraries
- Jena libraries
The required libraries are included in the release.
Loading a Workflow
We will use the Almo document we have created in the previous section as input data:
try {
WorkflowConfiguration w = AlmoFactory.createWorkflow(false,new FileInputStream("examples/tutorial_1.almo"),null);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IllegalLabelException e) {
e.printStackTrace();
} catch (IllegalSettingsException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalInstanceException e) {
e.printStackTrace();
}
![]() |
The first argument of the createWorkflow method is used to configure log4j or not, the second argument is the InputStream to read from and the third argument is the Object used for the initObject method (see previous section). For more details about the various Exceptions consult the Javadoc Pages. |
If no Exception is thrown, this code will result in the WorkflowConfiguration of the input data: All required elements are added & all include / exclude actions, that you have specified, are executed. If you know that there is no WorkflowInstance available in the input data, then you could generate it by calling the createInstance method. But since our input data has a WorkflowInstance, we will carry on with that.
Accessing the WorkflowInstance
Use the getInstance method from the WorkflowConfiguration object to get the WorkflowInstance. If you set the verbose value to 1, you will get all messages conveyed to the print method of the elements.
try {
WorkflowInstance i = w.getInstance();
i.setVerbose(1);
i.startWorkflow();
} catch (NoInstanceAvailableException e) {
e.printStackTrace();
}
![]() |
If no WorkflowInstance is available, the NoInstanceAvailableException is thrown by the getInstance method. |
![]() |
If the WorkflowInstance is available, execute the Workflow. |
The output of will be:
t1: started o1: started ERROR(o1): error at start ERROR(o1): error at 1 o1: 1 o1: 2 o1: 3 o1: 4 o1: 5 o1: 6 o1: 7 o1: 8 o1: 9 o1: 10 o1: finished t1: finished t2: started o2: started o2: 1 ERROR(o2): error at 2 o2: 2 o2: 3 o2: 4 o2: 5 o2: 6 o2: 7 o2: 8 o2: 9 o2: 10 o2: finished c1: started o3: started o4: started o3: 1 o4: 1 o3: 2 o4: 2 ERROR(o3): error at 3 o3: 3 o4: 3 o3: 4 ERROR(o4): error at 4 o4: 4 o3: 5 o4: 5 o3: 6 o4: 6 o3: 7 o4: 7 o3: 8 o4: 8 o3: 9 o4: 9 o3: 10 o3: finished o4: 10 o4: finished c1: finished t2: finished looped to: t1 t1: started o1: started ERROR(o1): error at start ERROR(o1): error at 1 o1: 1 o1: 2 o1: 3 o1: 4 o1: 5 o1: 6 o1: 7 o1: 8 o1: 9 o1: 10 o1: finished t1: finished t2: started o2: started o2: 1 ERROR(o2): error at 2 o2: 2 o2: 3 o2: 4 o2: 5 o2: 6 o2: 7 o2: 8 o2: 9 o2: 10 o2: finished c1: started o3: started o4: started o3: 1 o4: 1 o3: 2 o4: 2 ERROR(o3): error at 3 o3: 3 o4: 3 o3: 4 ERROR(o4): error at 4 o4: 4 o3: 5 o4: 5 o3: 6 o4: 6 o3: 7 o4: 7 o3: 8 o4: 8 o3: 9 o4: 9 o3: 10 o3: finished o4: 10 o4: finished c1: finished t2: finished t3: started o5: started o5: 1 o5: 2 o5: 3 o5: 4 ERROR(o5): error at 5 o5: 5 o5: 6 o5: 7 o5: 8 o5: 9 o5: 10 o5: finished t3: finished
The WorkflowInstance was successfully executed and you got all print messages. Since all our example implementations use some features of the Almo GUI this output might not be very intelligent, but it gives you an idea what you could do.
In the next sections we will take a look at how to use the visual components of Almo in your application.
| previous section: Using the Almo application: Building a Workflow with the Almo application |
next section: Integrating Almo in Java applications: Using the Almo GUI |
