遍历一个BPEL数组
我需要在java嵌入活动中遍历一个数组(输入到BPEL)并需要生成一个BPEL流程的响应(输出变量)。遍历一个BPEL数组
我使用JDeveloper和SOA11克
以下是我的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>
到目前为止,我能够管理在输入数组
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());
遍历但我的业务需求是基于某些逻辑设置输出数组中的值。 为此我使用下面的示例代码。
for(int i=1; i < 4 ;i++)
{
setVariableData("outputVariable","payload","/client:processResponse/client:arrayofObjectsoutput['i']/client:output1",i);
setVariableData("outputVariable","payload","/client:processResponse/client:arrayofObjectsoutput['i']/client:output2",i);
}
我的感觉是阵列将长度3和值来创建将settes(1,1)(2,2)(3,3),但在输出值仅(3,3)。 请告诉我如何实现相同。
示例代码将不胜感激。
我为类似的情况做的方式是使用转换来创建第一个元素,然后使用bpelx:insertAfter
插入其他数组元素,然后设置它们。
<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>
您好,我做了同样的结果也有,但有一个疑问,当我使用bpelx时:insertAfter>
好的,为了防止指数级增长,请使用此代替:
如果所有权扩展不起作用,您可以尝试标准BPEL方法并使用XSLT脚本来迭代构建结果文档。
举例BPEL 2.0 specification, pp 65,查找迭代文档构建。
基本上,要添加的列表和要添加的元素(通过doXSLTransform XPath函数)传递给XSLT脚本,该脚本将元素复制到列表并返回新文档。然后将其分配给一个变量。
我觉得没有必要为这么简单的任务编写自定义的Java代码。下面的代码(BPEL2.0)完成了复制值的工作。
<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>
谢谢,但我的要求是创建一个基于一些业务逻辑的数组。请你更清楚我怎么能达到相同的。说我有一个班主任(价值对象)我将创建这个类的5个实例,并从BPEL流程返回它。那么我必须使用Array来返回它。在我的xsd中,我使用arrayofObjectsoutput元素进行了相同的模拟。请给我一些建议。 – Pedantic 2011-05-04 02:57:09
您是否在寻找XQuery? – CMR 2011-05-03 03:54:32
我的需求是一个BPEL流程,它必须返回一个对象数组。我们如何在我的java嵌入式活动中创建aray。并返回它。因为我也粘贴了我的xsd,其中我们可以看到输出变量是arrayofObjectsoutput。请问我该怎么做(到目前为止,我尝试过并且只能遍历输入数组) – Pedantic 2011-05-03 04:56:35
这个问题又是供应商特定的,所以请添加一个关于您使用的产品/工具的注释。除此之外,如果使用BPELJ活动,在大多数情况下,它被认为是一种难闻的气味。更好的方法是使用活动或将业务逻辑重构为服务。 –
vanto
2011-05-03 09:33:28