1

我需要在 java embed 活动中遍历一个数组(BPEL 的输入),并且需要生成一个 BPEL 流程的响应(输出变量)。

我正在使用 Jdeveloper 和 SOA 11g

以下是我的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) 。请告诉我我怎样才能做到这一点。

示例代码将不胜感激。

4

3 回答 3

1

如果专有扩展不起作用,您可以尝试标准 BPEL 方法并使用 XSLT 脚本迭代地构造结果文档。

BPEL 2.0 规范中给出了一个示例,第 65 页,查找迭代文档构造

基本上,列表和要添加的元素(通过 doXSLTransform XPath 函数)传递给 XSLT 脚本,该脚本将要添加的元素复制到列表中并返回新文档。然后将其分配给一个变量。

于 2011-05-03T10:15:38.047 回答
1

我在类似情况下所做的方法是使用转换来创建第一个元素,然后使用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>
于 2011-05-07T06:25:15.777 回答
0

我觉得没有必要为这样一个简单的任务编写自定义 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>

于 2011-05-03T17:02:30.397 回答