Java Reference
In-Depth Information
<java name="send-verification-email" expr="#{customerService}"
method="sendCustomerVerificationEmail">
<arg> <object expr="#{customerId}" /> </arg>
<transition to="confirm-receipt-of-verification-email" />
</java>
<state name="confirm-receipt-of-verification-email">
<transition to="send-welcome-email" />
</state>
<java name="send-welcome-email"
expr="#{customerService}" method="sendWelcomeEmail">
<arg> <object expr="#{customerId}" /> </arg>
</java>
</process>
In the
customerService
bean, a client will use
createCustomer
to create a customer record. In a real-
world example, you might imagine exposing these services as a SOAP endpoint to be consumed by
various clients such as a web application or other business applications. You can imagine it being called
as a result of a successful form on a web site. When it executes, it creates a new
Customer
object and uses
Hibernate to persist it. Inside the
createCustomer
method, we use jBPM to start the business process to
track the
Customer
. This is done with the
startProcessInstanceByKey
method. In the invocation, we give
jBPM variables through a
Map<String,Object>
instance (acting as something of a context for the process
variables). Those variables are accessible inside the business process as Expression Language
expressions and allow you to parameterize the business process in much the same way you might
parameterize a macro or a Java method. We give the process instance a custom business key, instead of
letting it generate its own.
executionService.startProcessInstanceByKey(
REGISTER_CUSTOMER_PROCESS_KEY, vars, Long.toString(customer.getId()));
The last parameter is the key. Here we're using the String id of the customer as the key. This makes it
easy to find the process instance later, though you could also query for the process instance, predicating
on process variables that, taken together, should make the process instance unique. You might also
query by roles or users assigned to certain tasks, or simply note the id of the business process itself in
your domain model and reference that later when looking up the process instance. Here, we know that
there's only ever going to be one sign-up process for a customer, so we key it with a valid ID that will
only work once: the
Customer
's
id
value.
When the process starts, it will start executing the steps in your process definition. First, it will go to
the
<start>
element. It will evaluate the one transition it has and proceed through that transition to the
next step,
send-verification-email
.
Once in the
java
element named
send-verification-email
, jBPM will invoke
sendCustomerVerificationEmail
on the
customerService
bean in Spring. It uses an Expression
Language construct to reference the Spring bean by name:
<java name="send-verification-email"
expr="#{customerService}"
method="sendCustomerVerificationEmail">
…
</java>
Search WWH ::
Custom Search