Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 2. Tutorial
Study the following tutorial to learn how to use basic process constructs in the JPDL. The tutorial also demonstrates ways in which to manage run-time executions via the application programming interface.
The examples in this tutorial can be found in the JBPM download package (located in the
src/java.examples
sub-directory).
Note
Red Hat recommends creating a project at this point. You can then freely experiment and create variations of each of the examples.
First, download and install the JBPM.
jBPM includes a graphical designer tool for authoring the XML that is shown in the examples. You can find download instructions for the graphical designer in the Downloadables Overview section.. You don't need the graphical designer tool to complete this tutorial.
2.1. "Hello World" Example Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
A process definition is a directed graph, made up of nodes and transitions. The
Hello World
process definition has three of these nodes. (It is best to learn how the pieces fit together by studying this simple process without using the Designer Tool.) The following diagram presents a graphical representation of the Hello World
process:
Figure 2.1. The Hello World Process Graph
2.2. Database Example Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
One of the jBPM's basic features is the ability to make the execution of database processes persist while they are in a
wait state
. The next example demonstrates this ability, storing a process instance in the jBPM database.
It works by creating separate
methods
for different pieces of user code. For instance, a piece of user code in a web application starts a process and "persists" the execution in the database. Later, a message-driven bean loads that process instance and resumes the execution of it.
Here, separate
methods
are created for different pieces of user code. For instance, a piece of code in a web application starts a process and "persists" the execution in the database. Later, a message-driven bean loads the process instance and resumes executing it.
Note
More information about jBPM persistence can be found in Chapter 4, Persistence .
2.3. Contextual Example: Process Variables Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
Whilst processes are executed, the context information is held in process variables. These are similar to
java.util.Map
classes, in that they map variable names to values, the latter being Java objects. (The process variables are "persisted" as part of the process instance.)
Note
In order to keep the following example simple, only the application programming interface that is needed to work with variables is shown (without any persistence functionality.)
Note
Find out more about variables by reading Chapter 7, The Context
2.4. Task Assignment Example Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
The next example demonstrates how to assign a task to a user. Because of the separation between the jBPM workflow engine and the organizational model, expression languages will always be too limited to use to calculate actors. Instead, specify an implementation of
AssignmentHandler
and use it to include the calculation of actors for tasks.
2.5. Example of a Custom Action Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
Actions are mechanisms designed to bind custom Java code to jBPM processes. They can be associated with their own nodes (if these are relevant to the graphical representation of the process.) Alternatively, actions can be "placed on" events (for instance, when taking a transition, or entering or leaving a node.) If they are placed on events, the actions are not treated as part of the graphical representation (but they are still run when the events are "fired" during a run-time process execution.)
Firstly, look at the action handler implementation to be used in the next example:
MyActionHandler
. It is not particularly impressive of itself: it merely sets the Boolean variable isExecuted
to true
. Note that this variable is static so one can access it from within the action handler (and from the action itself) to verify its value.
Note
More information about "actions" can be found in Section 6.5, “Actions”
Important
Prior to each test, set the static field
MyActionHandler.isExecuted
to false
.
// Each test will start with setting the static isExecuted // member of MyActionHandler to false. public void setUp() { MyActionHandler.isExecuted = false; }
// Each test will start with setting the static isExecuted
// member of MyActionHandler to false.
public void setUp() {
MyActionHandler.isExecuted = false;
}
The first example illustrates an action on a transition:
The next example shows the same action now being placed on both the
enter-node
and leave-node
events. Note that a node has more than one event type. This is in contrast to a transition, which has only one event. Hence, when placing actions on a node, always put them in an event element.