IBM Support

BPML Coding Patterns

Technical Blog Post


Abstract

BPML Coding Patterns

Body

Have you ever wondered how the basic programming paradigms work for ISBI's BPML dialect? In this short Introduction a few of the basic BPML coding patterns are explained:

  • IF THEN
  • IF THEN ELSE
  • SWITCH
  • FOR
  • WHILE
  • FOR EACH

IF THEN

Lets start with a simple IF THEN. In the ISBI Version of BPML there is a separation between the definition of the condition and the evaluation.

  • In the rule the condition is defined
  • In choice the rule is evaluated
  • In the example below we want to check if value is set to true
  • If this is the case then the action action will be executed.
<process name = "IfThen">
	<rule name="condition">
		<condition>value/text()='true'</condition>
	</rule>
	<sequence>
		<assign to="value">true</assign>
		<choice>
			<select>
				<case ref="condition" activity="IfAction" />            
			</select>         
			<sequence name="IfAction">
				<assign to="Result">IF Branch</assign>
			</sequence>
		</choice>
	</sequence>
</process>

IF THEN ELSE

The IF THEN ELSE is pretty much like the IF THEN pattern. The ELSE Branch of the code is addressed by using the negative="true" line in the select operation. It makes sure if the condition is negative another activity will be executed.

<process name = "IfThenElse">
	<rule name="condition">
		<condition>value/text()='true'</condition>
	</rule>
	<sequence>
		<assign to="value">false</assign>
		<choice>
			<select>
				<case ref="condition" activity="IfAction" />            
				<case ref="condition" negative="true" activity="ElseAction" />            
			</select>         
			<sequence name="IfAction">
				<assign to="Result">IF Branch</assign>
			</sequence>
			<sequence name="ElseAction">
				<assign to="Result">ELSE Branch</assign>
			</sequence>
		</choice>
	</sequence>
</process>

SWITCH

The switch Operation itself does not exist in the ISBI BPML Dialect. But due to the nature of the mechanics of the rule/condition choice/select you can have multiple case statements in the select operation.

  • First you have to set the rule/conditiondefinitions. One for each case
  • In the choice you will then use the select to pick the right activity
<process name = "SWITCH">
	<rule name="conditionOne">
		<condition>value/text()='ONE'</condition>
	</rule>
	<rule name="conditionTwo">
		<condition>value/text()='TWO'</condition>
	</rule>
	<rule name="conditionThree">
		<condition>value/text()='THREE'</condition>
	</rule>
	<sequence>
		<assign to="value">TWO</assign>
		<choice>
			<select>
				<case ref="conditionOne" activity="OneAction" />
				<case ref="conditionTwo" activity="TwoAction" />
				<case ref="conditionThree" activity="ThreeAction" />
			</select>         
			<sequence name="OneAction">
				<assign to="Result">One Piece</assign>
			</sequence>
			<sequence name="TwoAction">
				<assign to="Result">Two Pieces</assign>
			</sequence>
			<sequence name="ThreeAction">
				<assign to="Result">Three Pieces</assign>
			</sequence>
		</choice>
	</sequence>
</process>

WHILE

The WHILE coding pattern is implemented with a choice and a repeat operation. The Engine would call a certain operation over and over again until a certain condition is true

As an example we will concatenate a character to a string variable until a certain length is achieved

  • First you define a condition. This example would be true as long as the length of value would be less than 10
  • Next is the select/case that would execute a certain activity if the condition is true
  • Inside this activity you will see the repeat step that will make sure that you jump back to the beginning of the Loop
<process name="while">
	<rule name="conditionToRun">
		<condition>string-length(value) < 10</condition>
	</rule>
	<sequence name="loopSequence">
		<assign to="value">X</assign>
		<choice name="loop">
			<select>
				<case ref="conditionToRun" activity="proceed" />
			</select>
			<sequence name="proceed">
				<assign to="currentValue" append="true" from="value/text()" />
				<assign to="value" from="concat(value,'X' )" />
				<repeat ref='loop' />
			</sequence>
		</choice> 
	</sequence>
</process>

FOR

The FOR in ISBI BPML is just a special case of the WHILE pattern. Think of it as a WHILE operation combined with a counter

In this example we do the classic

for(int i=0;i<10;i++){//Do something with i}

implementation

 

  • The condition will be true as long as counter is less than 10
  • In the sequence we start with initializing the counter to 0
  • Then we start a loop that runs until the countver is 10
<process name="forLoop">
	<rule name="conditionToRun">
		<condition>counter<10</condition>
	</rule>
	<sequence name="loopSequence">
		<assign to="counter">0</assign>
		<choice name='loop'>
			<select>
				<case ref="conditionToRun" activity="proceed"/>
			</select>
			<sequence name="proceed">
				<assign to="counter" from="counter+1" />
				<assign to="currentValue" append="true" from="counter/text()" />
				<repeat ref='loop' />
			</sequence>
		</choice> 
	</sequence>
</process>

FOR EACH

The FOR EACH pattern is used to go through a list of objects and execute an operation on each of those objects.

  • In our sample we first create a set of Elements with the same name as test data. This is the kind of data that you would usually get from certain Adapters that create lists
  • In the next operation we calculate the number of elements that we received dynamically by using the count XPATH operation
  • Here as well a counter is initialized with 0
  • From there on it is a WHILE pattern that would loop until the counter would reach the number of Elements that was evaluated with the count operation
<process name="foreach">
	<rule name="conditionToRun">
		<condition>counter<numberOfMyElements</condition>
	</rule>
	<sequence name="loopSequence">
	    <!-- Test Data -->
		<assign to="input/value">one</assign>
		<assign to="input/value" append="true">two</assign>
		<assign to="input/value" append="true">three</assign>
		<assign to="input/value" append="true">four</assign>
		<assign to="input/value" append="true">five</assign>
		
		<!-- Calculate number of elements -->
		<assign to="numberOfMyElements" from="count(/ProcessData/input/value)" />
		<assign to="counter">0</assign>
		<!-- now loop over the elements -->
		<sequence name="loopSequence">
		<choice name='loop'>
			<select>
				<case ref="conditionToRun" activity="proceed"/>
			</select>
			<sequence name="proceed">
				<assign to="counter" from="counter+1" />
				<assign to="temp" from="concat('Element ' , counter)" />
				<assign to="temp" from="concat(temp, ' contains Value ')" />
				<assign to="temp" from="concat(temp, /ProcessData/input/value[number(/ProcessData/counter)])" />
				<assign to="currentValue" append="true" from="temp/text()" />
				<repeat ref='loop' />
			</sequence>
		</choice> 
	</sequence>
	</sequence>
</process>
[{"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SS3JSW","label":"IBM Sterling B2B Integrator"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

UID

ibm11121841