Index Changes
E4X's native XML Scripting makes Javascript very attractive for working on xml documents. It is motivation for us to integrate Javascript engine with BPEL-SE.

Its value addition is demonstrated using following example. Let us write a business process to filter expensive items from a purchase order and do it using XPath 1.0 constructs and Javascript (E4X).

Filtering expensive items using XPath 1.0

                <assign name="Assign1">
                    <copy ignoreMissingFromData="yes">
                        <from>0</from>
                        <to variable="expItemCount"/>
                    </copy>
                </assign>
                <forEach name="ForEach1" parallel="no" counterName="ForEach1Counter">
                    <startCounterValue>1</startCounterValue>
                    <finalCounterValue>count($inputVar.po/ns2:item)</finalCounterValue>
                    <scope name="Scope1">
                        <if name="If2">
                            <condition>$inputVar.po/ns2:item[$ForEach1Counter]/ns2:qty &gt; 5 and $inputVar.po/ns2:item[$ForEach1Counter]/ns2:price &gt; 99
                                
                            </condition>
                            <sequence>
                                <assign name="Assign2">
                                    <copy>
                                        <from>$expItemCount + 1</from>
                                        <to variable="expItemCount"/>
                                    </copy>
                                </assign>
                                <assign name="Assign3">
                                    <copy>
                                        <from>$inputVar.po/ns2:item[$ForEach1Counter]
                                            <sxed:editor>
                                                <sxed:predicate path="$inputVar.po/ns2:item[$ForEach1Counter]" source="from"/>
                                            </sxed:editor>
                                        </from>
                                        <to>$outputVar.expensiveItems/ns2:item[$expItemCount]
                                            <sxed:editor>
                                                <sxed:predicate path="$outputVar.expensiveItems/ns2:item[$expItemCount]" source="to"/>
                                            </sxed:editor>
                                        </to>
                                    </copy>
                                </assign>
                            </sequence>
                        </if>
                    </scope>
                </forEach>

Same using Javascript

                    <assign name="Assign4">
                        <extensionAssignOperation><sunxd:Expression xmlns:sunxd="http://www.sun.com/wsbpel/2.0/process/executable/SUNExtension/DataHandling"
                            expressionLanguage="urn:sun:bpel:JavaScript"
                            inputVars="order=inputVar.po"
                            outputVars="outputVar.expensiveItems=expensiveItems">
                            <![CDATA[
                                var order1 = new XML(order);
                                default xml namespace = "http://xml.netbeans.org/schema/Synchronous";
                                var expensiveItems = <items/>;
                                expensiveItems.item = 0;
                                var rIndex=0;

                                for each (item in order1.item) {
                                    if ((item.qty > 5) & (item.price > 99)) {
                                        expensiveItems.item[rIndex++] = item;
                                    }
                                }
                            ]]>
                            </sunxd:Expression></extensionAssignOperation>
                    </assign>

Design time in Netbeans

JSPWiki v2.4.100
[RSS]
« Home Index Changes Prefs
This page (revision-5) was last changed on 18-May-09 21:28 PM, -0700 by Murali