Time for action – copying variable parts

Let's now copy the BookstoreBResponse variable to the BookStoreWithLowestQuantity variable. Because the BookstoreBResponse variable is of a different message type than the BookStoreWithLowestQuantity variable, we cannot copy variables directly.

However, both message variables use the same XML element, namely BookDataResponse as payload. Therefore, we can copy the payloads of both variables:

  1. Open the BookWarehousingBPEL.bpel window.
  2. Scroll to the <if> activity and locate the elseifBookstoreBLowerOrEqual branch.
  3. Drag-and-drop the Assign activity from the right-hand side BPEL Constructs / Basic Activities toolbar and place it after the existing AssignBookstoreB assign.
  4. Double-click on the assign activity and the Edit Assign window will appear. Here you need to open the BookstoreBResponse variable (by clicking on the plus sign in front of it). You also need to open the BookStoreWithLowestQuantity variable. Then, you need to connect payload from the left-hand side with payload on the right-hand side of the dialog window:
    Time for action – copying variable parts
  5. Finally, switch to the General tab and rename the assign activity name to AssignBookStoreWithLowestQuantity.

What just happened?

We have added the assign activity to copy the payload part of the BookstoreBResponse variable to the payload part of the BookStoreWithLowestQuantity variable. This is possible because both payloads are of the same XML element from the same XML namespace. The following source code has been generated:

What just happened?

Other options for copying data

In addition to copying variable parts, we can also copy constant expressions and literals. The following example shows how to copy a constant string to the BookstoreLocationWithLowestStockQuantity variable (which is of the type string):

<assign>
  <copy>
    <from>string('BookstoreA')</from>
    <to variable="BookstoreLocationWithLowestStockQuantity"/>
  </copy>
</assign>

We are not restricted to such simple expressions. We can use any valid XPath 1.0 expressions (or the expressions of the selected expression language).

Another way of expressing the preceding copy would be the following:

<assign>
  <copy>
    <from>'BookstoreA'</from>
    <to>$BookstoreLocationWithLowestStockQuantity<to/>
  </copy>
</assign>

We can also do a copy to a specific node of the variable, such as:

<assign>
  <copy>
    <from>'BookstoreB'</from>
    <to>$outputVariable.payload/ 
    client:SelectedBookstoreLocation<to/>
  </copy>
</assign>

Optional attributes

We can specify two optional attributes for the <copy> activity:

  • keepSrcElementName: This specifies whether the element name of the destination will be replaced by the element name of the source. The default is No.
  • ignoreMissingFromData: This specifies whether the BPEL engine should ignore missing data in the <from> part of the copy assignment (and not raise a fault). The default is No.

We can also specify an optional attribute for the <assign> activity:

  • validate: If set to yes, the assign activity will validate all variables being modified by the <assign> activity. The default is No.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset