2011-05-03 159 views
1

我需要在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)。 請告訴我如何實現相同。

示例代碼將不勝感激。

+0

您是否在尋找XQuery? – CMR 2011-05-03 03:54:32

+0

我的需求是一個BPEL流程,它必須返回一個對象數組。我們如何在我的java嵌入式活動中創建aray。並返回它。因爲我也粘貼了我的xsd,其中我們可以看到輸出變量是arrayofObjectsoutput。請問我該怎麼做(到目前爲止,我嘗試過並且只能遍歷輸入數組) – Pedantic 2011-05-03 04:56:35

+0

這個問題又是供應商特定的,所以請添加一個關於您使用的產品/工具的註釋。除此之外,如果使用BPELJ活動,在大多數情況下,它被認爲是一種難聞的氣味。更好的方法是使用活動或將業務邏輯重構爲服務。 – vanto 2011-05-03 09:33:28

回答

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> 
+0

您好,我做了同樣的結果也有,但有一個疑問,當我使用bpelx時:insertAfter> 這段代碼拷貝整個陣列的中iteself和數組的長度呈指數級增長..你能告訴我這條線的重要性嗎? – Pedantic 2011-05-09 10:11:47

+0

好的,爲了防止指數級增長,請使用此代替: 2011-05-14 05:13:41

1

如果所有權擴展不起作用,您可以嘗試標準BPEL方法並使用XSLT腳本來迭代構建結果文檔。

舉例BPEL 2.0 specification, pp 65,查找迭代文檔構建

基本上,要添加的列表和要添加的元素(通過doXSLTransform XPath函數)傳遞給XSLT腳本,該腳本將元素複製到列表並返回新文檔。然後將其分配給一個變量。

+0

嗨Vanto,分享鏈接。但我無法做到這一點,你可以分享一些簡單的例子.. – Pedantic 2011-05-03 12:50:56

+0

對不起,我沒有一個方便的例子。你可以在http://svn.apache.org/viewvc/ode/branches/ode-1.3.5.x/bpel-test/src/test/resources/bpel/2.0/TestXslTransform查看這個例子 - 它可以不附加到數組,但它顯示瞭如何在BPEL中使用XSL。因此,與BPEL規範中的示例一起,您應該能夠找到可行的解決方案。 – vanto 2011-05-03 13:24:17

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> 

+0

謝謝,但我的要求是創建一個基於一些業務邏輯的數組。請你更清楚我怎麼能達到相同的。說我有一個班主任(價值對象)我將創建這個類的5個實例,並從BPEL流程返回它。那麼我必須使用Array來返回它。在我的xsd中,我使用arrayofObjectsoutput元素進行了相同的模擬。請給我一些建議。 – Pedantic 2011-05-04 02:57:09