Oracle® SOA Suite Developer's Guide 10g (10.1.3.1.0) Part Number B28764-01 |
|
|
View PDF |
Conditional branching introduces decision points to control the flow of execution of a BPEL process. You can use a switch activity to produce different actions based on conditional branching. You set up two or more branches, with each branch in the form of an XPath expression. If the expression is true, then the branch is executed. If the expression is false, then the BPEL process moves to the next branch condition, until it either finds a valid branch condition, encounters an otherwise branch, or runs out of branches. If more than one branch condition is true, then BPEL executes the first true branch.
Figure 7-15 shows a conditional branch from the SOA Order Booking application. The SelectByPrice switch activity is used to select the supplier that provides the lowest quote.
Figure 7-15 Conditional Branching with a Switch Activity
Figure 7-16 shows the XPath expression that defines the case branch. Select Manufacturer is selected if its price quote is less than Rapid Manufacturer's price quote.
Figure 7-16 The Case Branch of the SelectByPrice Switch Activity
If the case branch evaluates to false, then Rapid Manufacturer is selected.
See Oracle BPEL Process Manager Developer's Guide for information on the following conditional branching topics:
Using a while activity to create a while loop to select between two actions
Adding events and timeouts to a conditional branch
To add conditional branching to a BPEL process, use a switch activity.
To create conditional branching using a switch activity:
Drag and drop a Switch activity into a BPEL flow.
Double-click the Switch_1 icon to enter a name for the activity.
Expand the Switch activity to see the switch cases.
The Switch activity has two switch case branches by default, each with a box for functional elements. To add more branches, right-click the Switch icon and select Add Switch Case or Add Switch Otherwise.
Double-click <case> in the first branch.
Use the Switch Case dialog to specify the conditional branching logic, as shown in Figure 7-17.
Figure 7-17 Creating the Case Branch in the SelectByPrice Switch Activity
Enter a name for the case in the Name field.
Click the notepad icon to use the XPath Expression Builder to create an XPath Boolean expression in the Expression field.
Click OK to close both the Expression Builder and the SwitchCase dialogs.
Example 7-7 shows the source code for the SelectByPrice switch activity in the SOA Order Booking application.
Example 7-7 Source Code for the SelectByPrice Switch
<switch name="SelectByPrice"> <!--case condition="number(bpws:getVariableData('selectManufacturerResponse', 'parameters','/ns22:processRequestQuoteResponseElement/ns22:result/ ns22:supplierPrice')) < number(bpws:getVariableData ('rapidManufacturerResponse','parameters','/ns23:OrderQuoteResponse/ ns24:return/ns25:supplierPrice'))"--> <case condition="true()"> <assign name="AssignSelectManufacturer"> <copy> <from variable="selectManufacturerResponse" part="parameters" query="/ ns17:processRequestQuoteResponseElement/ns17:return/ns17:supplierPrice"/> <to variable="inputVariable" part="payload" query="/ client:SOAOrderBookingProcessRequest/ client:purchaseOrder/ns4:SupplierInfo/ns4:SupplierPrice"/> </copy> <copy> <from variable="selectManufacturerResponse" part="parameters" query="/ ns17:processRequestQuoteResponseElement/ns17:return/ns17:supplierName"/> <to variable="inputVariable" part="payload" query="/ client:SOAOrderBookingProcessRequest/client:purchaseOrder/ns4:SupplierInfo/ ns4:SupplierName"/> </copy> </assign> </case> <otherwise> <assign name="AssignRapidManufacturer"> <copy> <from variable="rapidManufacturerResponse" part="parameters" query="/ ns23:POItemsQuoteResponse/ns30:return/ns30:supplierPrice"/> <to variable="inputVariable" part="payload" query="/ client:SOAOrderBookingProcessRequest/client:purchaseOrder/ns4:SupplierInfo/ ns4:SupplierPrice"/> </copy> <copy> <from variable="rapidManufacturerResponse" part="parameters" query="/ ns23:POItemsQuoteResponse/ns30:return/ns30:supplierName"/> <to variable="inputVariable" part="payload" query="/ client:SOAOrderBookingProcessRequest/client:purchaseOrder/ns4:SupplierInfo/ ns4:SupplierName"/> </copy> </assign> </otherwise> </switch>