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.
This recipe builds on the two BPEL processes we created in the previous two recipes named Manipulate1_1
and Manipulate2_0
.
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:
Manipulate1_1
BPEL process and add the assign activity (AssignNumerical
).We will define several variables for assigning the numerical values.
The XSD namespace refers to http://www.w3.org/2001/XMLSchema.
xsd:int
variable as follows:<variable name = "Var_int" type = "xsd:int"/>
xsd:long
variable as follows:<variable name = "Var_long" type = "xsd:long"/>
xsd:short
variable as follows:<variable name = "Var_short" type = "xsd:short"/>
xsd:decimal
variable as follows:<variable name = "Var_decimal" type = "xsd:decimal"/>
xsd:float
variable as follows:<variable name = "Var_float" type = "xsd:float"/>
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:
2013
to the xsd:int
variable as follows:<copy> <from expression = "2013"/> <to variable = "Var_int"/> </copy>
9223372036854775807
to the xsd:long
variable as follows:<copy> <from expression = "9223372036854775807"/> <to variable = "Var_long"/> </copy>
32767
to the xsd:short
variable as follows:<copy> <from expression = "32767"/> <to variable = "Var_short"/> </copy>
1234.456
to the xsd:decimal
variable as follows:<copy> <from expression = "1234.456"/> <to variable = "Var_decimal"/> </copy>
-1.2344e56
to the xsd:float
variable as follows:<copy> <from expression = "-1.2344e56"/> <to variable = "Var_float"/> </copy>
-1.2344e56
to the xsd:double
variable as follows:<copy> <from expression = "-1.2344e56"/> <to variable = "Var_double"/> </copy>
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.
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.