Last week, we looked at the assign and other basic activities, and studied flow. This week, we'll be examining more sturctured activities, and fault handling. This article, the fifth in a six-part 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).
More Structured Activities: sequence, while, switch, scope
Besides the pick and flow activities, BPEL provides several additional types of structured activities. The sequence activity lets you specify that activities are to be executed in the order in which they are provided. The following snippet shows three activities from the purchase order process. They always run in the specified order; the purchase order request is received first, then processed, and finally answered:
The while activity has a nested activity that is repeatedly executed as long as a specified Boolean condition is evaluated as true. The condition is provided as an XPath expression. In our example, such an activity is used at the point where the local stock needs to be replenished. Additional goods are ordered from the supplier as long as the purchase order can't be processed from the local stock:
The switch activity can be compared to similar constructs in programming languages: for example, the switch statement in Java with its case and default branches. It lets you select exactly one branch out of a given set of choices. For each choice, provided as a list of case elements with a Boolean condition, a nested activity must be specified. The activity on the first branch (in the order of specification) whose condition
evaluates to true is executed. If an otherwise element is provided, then its nested activity is executed if none of the case conditions evaluate to true:
<!-- add shipping and handling fee -->
<!-- do nothing -->
<!-- subtract rebate for large orders -->
The scope activity is used to specify visibility boundaries. Scopes have the same structure as the overall process, except for partnerLinks and partners, which can only be declared globally in the process, and a compensation handler, which can only be declared in scopes:
Definitions at the scope level apply to all nested activities. The only mandatory element is the nested activity, which may be a structured activity as well. Variables and correlation sets declared in a scope are only visible to activities nested within that scope.
Fault handlers, compensation handlers, and event handlers can be declared in a scope as well. Let's now examine these handlers in detail.