Last week, we looked at process lifecycles. This week, we'll take a look at the assign and other basic activities, and study flow. This article, the fourth in a series, is excerpted from chapter 12 of Building Web Services with Java: Making sense of XML, SOAP, WSDL, and UDDI, written by Steve Graham et al. (Sams; ISBN: 0672326418).
Now let's look at how data can be manipulated and assigned as part of the process logic. BPEL provides a special activity type for updating variables: the assign activity. It lets you copy type-compatible data from one variable to another; you can also construct and insert new data using general XPath expressions. Expressions also provide for simple computations—for example, to prepare data for the invocation of Web services.
The following snippets depict samples of various usages of assign activities. The first shows the copying of an entire variable:
In the following, you see a more complex assign activity that copies two selected elements from one variable to another. This assignment is performed as an atomic operation. The selection of elements involves queries expressed in XPath as the query language:
The assign activity can also copy endpoint references to and from partner links. This aspect is useful whenever endpoint references are to be treated as data—for example, to exchange endpoint references with business partners as part of messages, or to compute endpoint references.
SkatesTown uses this feature to send its endpoint reference to the supplier. It requests additional supplies using the orderSupplies operation. As part of this request, SkatesTown provides its endpoint reference. This enables the supplier to asynchronously respond to the request without the need to be statically bound to one particular seller. The supplier uses this endpoint reference to submit its response—for example, to invoke the seller's orderSuppliesOk operation. The following BPEL snippet depicts how SkatesTown's endpoint reference is copied to the request message. The assign activity copies the endpoint reference from role myRole of partner link supplier to the orderSuppliesRequest variable. This variable then serves as input for the orderSupplies operation: