OAF_開發系列27_實現OAF中Java類型併發程式開發調用XML Publisher(案例)

20150814 Created By BaoXinjianjava

1、摘要sql


經過Java Concurrent Program導入XML文件和RTF文件導出PDF報表,一種官方的源碼解讀,經過如下三個關鍵程序實現 服務器

1. 經過DataProcess設定XML數據來源
併發

2. 經過RtfProcess設定RTF模板來源oracle

3. 經過FoProcess產生PDF文件app

 

2、方案設計 - 代碼
post


Step1. 建立XML數據定義文件(EmpDataTemplate.xml),並上傳至服務器的/u2/VIS/visappl/gavin/concprog/目錄
測試

<?xml version="1.0" encoding="UTF-8" ?> <dataTemplate name="EmpData" description="Employee Details" Version="1.0"> <parameters> <parameter name="p_DeptNo" dataType="character" /> </parameters> <dataQuery> <sqlStatement name="Q1"> <![CDATA[ SELECT d.DEPTNO DEPTNO ,d.DNAME DNAME ,d.LOC LOC ,e.EMPNO EMPNO ,e.ENAME ENAME ,e.JOB JOB ,e.MGR MGR ,TO_CHAR(e.HIREDATE,'YYYY/MM/DD') HIREDATE ,e.SAL SAL ,nvl(e.COMM, 0) COMM FROM scott.dept d ,scott.emp e WHERE d.deptno = e.deptno AND d.deptno = nvl( :p_DeptNo, d.deptno) ]]> </sqlStatement> </dataQuery> <dataStructure> <group name="G_DEPT" source="Q1"> <element name="DEPT_NUMBER" value="DEPTNO" /> <element name="DEPT_NAME" value="DNAME" /> <element name="LOCATION" value="LOC" /> <element name="EMPLOYEE_NUMBER" value="EMPNO" /> <element name="NAME" value="ENAME" /> <element name="JOB" value="JOB" /> <element name="MANAGER" value="MGR" /> <element name="HIREDATE" value="HIREDATE" /> <element name="SALARY" value="SAL" /> <element name="COMMISSION" value="COMM" /> </group> </dataStructure> </dataTemplate>

Step2. 建立rtf模板(EmpDataTemplate.rtf)並上傳至服務器的/u2/VIS/visappl/gavin/concprog/目錄:
spa

Step3. 建立java concurrent程序(EmpDataTemplate.java)。若是不能編譯經過,需到服務器上的$JAVA_TOP目錄下載相關類文件(可以使用zip命令打包下載: zip -r ~/conclib ./oracle/apps/fnd/cp/*):
.net

package bxj.oracle.apps.ap.java; import java.sql.Connection; import oracle.apps.fnd.cp.request.CpContext; import oracle.apps.fnd.cp.request.JavaConcurrentProgram; import oracle.apps.xdo.dataengine.DataProcessor; import oracle.apps.fnd.util.ParameterList; import oracle.apps.fnd.cp.request.ReqCompletion; import oracle.apps.fnd.cp.request.OutFile; import oracle.apps.fnd.cp.request.LogFile; import oracle.apps.fnd.util.NameValueType; import oracle.apps.xdo.template.RTFProcessor; import oracle.apps.xdo.template.FOProcessor; import com.sun.java.util.collections.Hashtable; import java.io.File; public class runEmpXMLConcProg implements JavaConcurrentProgram { public runEmpXMLConcProg() { } String deptNo; public void runProgram(CpContext cpContext) { ParameterList params = cpContext.getParameterList(); ReqCompletion compl = cpContext.getReqCompletion(); OutFile outFile = cpContext.getOutFile(); LogFile logFile = cpContext.getLogFile(); logFile.writeln(">>1 start ..", LogFile.STATEMENT); while (params.hasMoreElements()) { NameValueType val = params.nextParameter(); if (val.getName().equals("P_DEPTNO")) deptNo = val.getValue(); } logFile.writeln(">>2 P_DEPTNO = " + deptNo, LogFile.STATEMENT); Connection jdbcConnection = cpContext.getJDBCConnection(); try { //Initialization – instantiate the DataProcessor class// DataProcessor dataProcessor = new DataProcessor(); //Set Data Template to be executed  dataProcessor.setDataTemplate("/u2/VIS/visappl/gavin/concprog/EmpDataTemplate.xml");
logFile.writeln(">>3 dataProcessor.setDataTemplate", LogFile.STATEMENT); // Assign parameter Hashtable parameters = new Hashtable(); parameters.put("p_DeptNo", deptNo); dataProcessor.setParameters(parameters); logFile.writeln(">>4 dataProcessor.setParameters", LogFile.STATEMENT); // Set the jdbc connection dataProcessor.setConnection(jdbcConnection); logFile.writeln(">>5 dataProcessor.setConnection", LogFile.STATEMENT); // Specify the output directory and file for the data file dataProcessor.setOutput("/u2/VIS/visappl/gavin/concprog/EmpDetails.xml"); logFile.writeln(">>6 dataProcessor.setOutput", LogFile.STATEMENT); // Process the data template dataProcessor.processData(); logFile.writeln(">>6.1 dataProcessor.processData", LogFile.STATEMENT); // Convert rtf to xsl RTFProcessor rtfProcessor = new RTFProcessor("/u2/VIS/visappl/gavin/concprog/EmpDataTemplate.rtf");
logFile.writeln(">>7 new RTFProcessor()", LogFile.STATEMENT); rtfProcessor.setOutput("/u2/VIS/visappl/gavin/concprog/EmpDataTemplate.xsl"); rtfProcessor.process(); logFile.writeln(">>8 rtfProcessor.process()", LogFile.STATEMENT); // Geneate PDF FOProcessor foProcessor = new FOProcessor(); foProcessor.setData("/u2/VIS/visappl/gavin/concprog/EmpDetails.xml"); logFile.writeln(">>9 foProcessor.setData()", LogFile.STATEMENT); foProcessor.setTemplate("/u2/VIS/visappl/gavin/concprog/EmpDataTemplate.xsl"); logFile.writeln(">>10 foProcessor.setTemplate()", LogFile.STATEMENT); foProcessor.setOutput("/u2/VIS/visappl/gavin/concprog/EmpDetails001.pdf"); logFile.writeln(">>11 foProcessor.setOutput()", LogFile.STATEMENT); foProcessor.setOutputFormat(FOProcessor.FORMAT_PDF); foProcessor.generate(); logFile.writeln(">>12 foProcessor.generate() 001", LogFile.STATEMENT); compl.setCompletion(ReqCompletion.NORMAL, "Concurrent Normal Completed!"); } catch (Exception e) { logFile.writeln("Java Concurrent Program Error: "+e.toString(), LogFile.STATEMENT); compl.setCompletion(ReqCompletion.ERROR, e.toString()); } } }

 

3、方案設計 - 應用設定


Step1. 將XML文件和RTF文件上傳至服務器相應目錄

Step2.  將RunProgram Class包上傳至相應目錄

Step3. 設定併發可執行程序

 Step4. 設定併發程式及其參數

 

4、運行測試


Step1. 調用Request

Step2. 系統會自動依次產生三個文件xsl->xml->pdf

Step3. 查看xml data文件

Step4. 查看pdf

 

Thanks and Regards

參考:LiaoDunxia - http://blog.csdn.net/t0nsha/article/details/6336872

相關文章
相關標籤/搜索