Skip Headers
Oracle® SOA Suite Developer's Guide
10g (10.1.3.1.0)

Part Number B28764-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

7.7 Creating Conditional Branching Using a Switch Activity

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

Description of Figure 7-15 follows
Description of "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

Description of Figure 7-16 follows
Description of "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:

7.7.1 How to Create Conditional Branching Using a Switch Activity

To add conditional branching to a BPEL process, use a switch activity.

To create conditional branching using a switch activity:

  1. Drag and drop a Switch activity into a BPEL flow.

  2. Double-click the Switch_1 icon to enter a name for the activity.

  3. 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.

  4. Double-click <case> in the first branch.

  5. 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

    Description of Figure 7-17 follows
    Description of "Figure 7-17 Creating the Case Branch in the SelectByPrice Switch Activity"

    1. Enter a name for the case in the Name field.

    2. Click the notepad icon to use the XPath Expression Builder to create an XPath Boolean expression in the Expression field.

    3. Click OK to close both the Expression Builder and the SwitchCase dialogs.

7.7.2 What Happens When You Create Conditional Branching Using a Switch Activity

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')) &lt; 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>