Defining local variables in a BPEL process

Too many global variables can cause a lot of confusion and can also consume a lot of memory. Hence, we define global variables only when we need data to be available all the time. For that reason, we omit the scope variable visibility by defining them locally. By doing this, we also achieve higher clarity of the BPEL process source code. This recipe will explain the difference between global and local variables in the BPEL processes.

Getting ready

For this recipe, we will extend the BPEL process from the previous recipe. Note that the variables are tightly related to the scope, which encloses them. We will add a scope to our BPEL process and reuse the same web service. The BPEL process outlook is as shown in the following screenshot:

Getting ready

How to do it…

To define a local variable in a BPEL process, we perform the following steps:

  1. We define a local variable by pressing the (X) icon in the left-side toolbar of the scope. The dialog opens global . However, this time there are no variables in the dialog. This is reasonable, since there are no local variables defined yet.
  2. We click on the plus (+) icon and create the variable as shown in the following screenshot:
    How to do it…
  3. Click on the OK button. Notice how the new variable definition appeared in the Variables dialog. Again, click on the OK button. Now we have the new local variable defined in the LocalScope scope of the BPEL process.

How it works…

The easiest way to check the local variable definition is to examine the source code of the BPEL process. We search for the msg variable in the following code:

<scope name = "LocalScope" variableAccessSerializable = "no">
  <variables>
    <variable name = "msg" type = "xsd:string"/>
  </variables>
</scope>

The local variable is defined inside the scope definition. So, the variable is accessible as soon as we enter the scope. Consequently, we lose access to the variable as soon as we leave the scope enclosing the local variable definition.

There's more…

Similar to the global variable definition, we can also define the variable from the toolbar of the BPEL process. This time, we already have one local variable listed as shown in the following screenshot:

There's more…

To define a global variable, we select the Variables folder under the Process node. However, to define a local variable, we need to select the Variables folder under the Scope – LocalScope node.

When creating the <receive>, <reply>, <invoke>, and <catch> activities, we have the possibility to create a global or local variable. This option is presented through the Create Variable dialog as shown in the following screenshot:

There's more…

See also

  • In this recipe we defined a variable. The variable itself does not contain any value. To set values to the variables, refer to the Initializing a variable with an XML literal and Initializing a variable with an inline from-spec recipes.
..................Content has been hidden....................

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