traversing a BPEL array
I need to traverse an array (input to BPEL) in java embed activity and need to generate a response (output variable) of BPEL process.
I am using Jdeveloper and SOA 11g
following is my xsd
<?xml version="1.0" encoding="UTF-8"?>
<schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://xmlns.oracle.com/BPELInpuandOutPutArray_jws/Project1/BPEL_input_output_array" xmlns="http://www.w3.org/2001/XMLSchema">
<element name="process">
<complexType>
<sequence>
<element name="simpleinput" type="string"/>
<element name="arrayofObjects" maxOccurs="unbounded" nillable="true">
<complexType>
<sequence>
<element name="input1" type="string"/>
<element name="input2" type="string"/>
</sequence>
</complexType>
</element>
</sequence>
</complexType>
</element>
<element name="processResponse">
<complexType>
<sequence>
<element name="arrayofObjectsoutput" maxOccurs="unbounded" nillable="true">
<complexType>
<sequence>
<element name="output1" type="string"/>
<element name="output2" type="string"/>
</sequence>
</complexType>
</element>
</sequence>
</complexType>
</element>
</schema>
so far I am able to manage for traversing in input array
oracle.xml.parser.v2.XMLElement e1=
(oracle.xml.parser.v2.XMLElement)getVariableData("inputVariable","payload","/client:process/client:arrayofObjects[1]/client:input1");
System.out.println(e1.getFirstChild().getNodeValue());
But my business requirement is to based on some logic set the values in output array. for this I used following sample code.
for(int i=1; i < 4 ;i++)
{
setVariableData("outputVariable","payload","/client:processResponse/client:arrayofObjectsoutput['i']/client:output1",i);
setVariable开发者_如何学GoData("outputVariable","payload","/client:processResponse/client:arrayofObjectsoutput['i']/client:output2",i);
}
My feeling is array would be created of length 3 and value will be settes(1,1) (2,2) (3,3) but at the output value is only (3,3) . please tell me how can i achieve the same.
sample code will be appreciated.
The way I did it for a similar situation was to use a transformation to create the first element and then use the bpelx:insertAfter
to insert additional array elements and then set them.
<assign name="Assign_2">
<bpelx:insertAfter>
<bpelx:from variable="outputVariable" part="payload"
query="/client:ArrayManipulationProcessResponse/client:arrayofObjectsoutput"/>
<bpelx:to variable="outputVariable" part="payload"
query="/client:ArrayManipulationProcessResponse/client:arrayofObjectsoutput"/>
</bpelx:insertAfter>
<copy>
<from expression="'MyOutput1-Index2'"/>
<to variable="outputVariable" part="payload"
query="/client:ArrayManipulationProcessResponse/client:arrayofObjectsoutput[2]/client:output1"/>
</copy>
<copy>
<from expression="'MyOutput2-Index2'"/>
<to variable="outputVariable" part="payload"
query="/client:ArrayManipulationProcessResponse/client:arrayofObjectsoutput[2]/client:output2"/>
</copy>
</assign>
If proprietary extensions do not work, you can try the standard BPEL approach and use an XSLT script to iteratively construct a result document.
An example is given in the BPEL 2.0 specification, pp 65, look for Iterative document construction.
Basically, the list and the element to add is passed (via the doXSLTransform XPath function) to an XSLT script, which copies the element to add to the list and returns the new document. This is then assigned to a variable.
I feel there is no need to write custom Java code for such a simple task. The following code (BPEL2.0) does the job of copying the values.<assign name="Copy values">
<extensionAssignOperation>
<bpelx:copyList>
<bpelx:from>$inputVariable.payload/ns1:arrayofObjects</bpelx:from>
<bpelx:to>$outputVariable.payload/ns1:arrayofObjectsoutput</bpelx:to>
</bpelx:copyList>
</extensionAssignOperation>
</assign>
精彩评论