Back to Embedded_Java Script, or Embedded_Java Script Info
| At line 1 changed 1 line. |
| E4X's native XML Scripting makes Javascript very attractive for working on xml documents. It is motivation for integrating Javascript engine with BPEL-SE. |
| 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. |
| At line 3 changed 1 line. |
| Please refer to attached business process, this business process filters expensive items in a purchase order. It has two implementations. First one in IF block (activity name "if1" ) uses XPath and predicate. Second one is in else block uses Javascript. |
| 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). |
| At line 5 changed 1 line. |
| This example should help in understand the value of Javascript integration. |
| 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 > 5 and $inputVar.po/ns2:item[$ForEach1Counter]/ns2:price > 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> |
| }}} |
| At line 7 removed 1 line. |
| Please let me know if it is not clear. If you like to see the working version, please drop-in. |
| At line 49 added 28 lines. |
| 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|http://wiki.open-esb.java.net/Wiki.jsp?page=Embedded_JavaScript_UI] in Netbeans |