Assigning numerical values to the variables

Assigning different numerical values to variables is not directly a BPEL or Java feature. However, BPEL variables are basically XML variables. The variable definitions are based on the XML schema where we define different numeric types for three variable elements.

Getting ready

This recipe builds on the two BPEL processes we created in the previous two recipes named Manipulate1_1 and Manipulate2_0.

How to do it…

In the following steps, we define variables with various types in a BPEL process. All of the following variables can also be defined through the JDeveloper wizards the same way we defined the global and local variables:

  1. Open the Manipulate1_1 BPEL process and add the assign activity (AssignNumerical).

    We will define several variables for assigning the numerical values.

    Tip

    The XSD namespace refers to http://www.w3.org/2001/XMLSchema.

  2. Define the xsd:int variable as follows:
    <variable name = "Var_int" type = "xsd:int"/>
  3. Define the xsd:long variable as follows:
    <variable name = "Var_long" type = "xsd:long"/>
  4. Define the xsd:short variable as follows:
    <variable name = "Var_short" type = "xsd:short"/>
  5. Define the xsd:decimal variable as follows:
    <variable name = "Var_decimal" type = "xsd:decimal"/>
  6. Define the xsd:float variable as follows:
    <variable name = "Var_float" type = "xsd:float"/>
  7. Define the xsd:double variable as follows:
    <variable name = "Var_double" type = "xsd:double"/>

Open the AssignNumerical assign activity to assign the numerical values to the variables. We define the following copy rules for the assign activity:

  1. Assign the value 2013 to the xsd:int variable as follows:
    <copy>
      <from expression = "2013"/>
      <to variable = "Var_int"/>
    </copy>
  2. Assign the value 9223372036854775807 to the xsd:long variable as follows:
    <copy>
      <from expression = "9223372036854775807"/>
      <to variable = "Var_long"/>
    </copy>
  3. Assign the value 32767 to the xsd:short variable as follows:
    <copy>
      <from expression = "32767"/>
      <to variable = "Var_short"/>
    </copy>
  4. Assign the value 1234.456 to the xsd:decimal variable as follows:
    <copy>
      <from expression = "1234.456"/>
      <to variable = "Var_decimal"/>
    </copy>
  5. Assign the value -1.2344e56 to the xsd:float variable as follows:
    <copy>
      <from expression = "-1.2344e56"/>
      <to variable = "Var_float"/>
    </copy>
  6. Assign the value -1.2344e56 to the xsd:double variable as follows:
    <copy>
      <from expression = "-1.2344e56"/>
      <to variable = "Var_double"/>
    </copy>

    Note

    The numerical values are assigned to the variables through the XPath expressions. For example, in the Expression Builder, we can enter a number (100) to define the number value.

    The XML schema types follow the value range conventions. However, BPEL ignores any checks against the value the variable is carrying. The validation of the values in the variables is left over to the developer of the BPEL process.

    If, for example, we have the variable of the type xsd:short and we insert the value 32800 into the variable, even if the maximum allowed value is 32767, BPEL will not report any errors.

There's more…

In BPEL 2.0, it is possible to initialize with the inline from-spec definition. For that purpose, we open the Manipulate2_0 BPEL process and define the variables with the initialized values as follows:

<variable name = "Var_long" type = "xsd:long">
  <from>9223372036854775807</from>
</variable>
<variable name = "Var_short" type = "xsd:short">
  <from>32767</from>
</variable>
<variable name = "Var_decimal" type = "xsd:decimal">
  <from>1234.456</from>
</variable>
<variable name = "Var_float" type = "xsd:float">
  <from>1.2343444</from>
</variable>
<variable name = "Var_double" type = "xsd:double">
  <from>-1.23492111</from>
</variable>

You will notice that the code is simpler and cleaner compared to the BPEL 1.1 process.

See also

  • We can use mathematical calculations with the numeric variables we defined in this recipe. Read the next recipe, Applying mathematical calculations on data in the variables, to explore the usage of mathematical calculations.
..................Content has been hidden....................

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