If Construct
Objective
This sample illustrates the usage of the <if/>
construct in verifying a logical condition.
Introducing the IF Construct
<if> <condition>number($tmpVar)=number(2)</condition> <assign name="assignError"> <copy> <from> <literal>Worked</literal> </from> <to variable="myVar" part="TestPart"/> </copy> </assign> <else> <assign name="assignZut"> <copy> <from> <literal>Failed</literal> </from> <to variable="myVar" part="TestPart"/> </copy> </assign> </else> </if>
The <condition/>
element inside <if/>
is used to implement the logical condition. Normally, an XPath expression is used. <else/>
is used to implement false case. In the above example, value of tmpVar
variable is converted to a number and checked against number 2 as follows:
<condition>number($tmpVar)=number(2)</condition>
Based on the tmpVar
value, "TestPart"
element value in myVar variable will be "Worked"
or "Failed"
.
Note
Apache ODE runtime has default support for http://www.w3.org/TR/xpath/
, where the number($var)
is defined.
Deploying the Sample
WSO2 BPS provides a sample, which can be deployed and executed to understand the IF constructs discussed above. Follow the instructions below to deploy and trigger the process.
1. Log in into BPS server management console and select "Processes -> Add" under the "Main" menu.
2. Upload the IfCondition.zip
found in the BPS_Home/repository/samples/bpel
directory. (Samples are also located at our sample repository).
3. In the "Deployed Processes" window, click the "Process ID" to access its "Process Information" window.
4. Under the "WSDL Details" widget, trigger the process using the "TryIt" link to create an instance of it.