開始之前,您必須先完成練習 1.3:建立訊息緩衝區類別。
/******************************************************************************* * 授權資料 - IBM 財產 * * com.ibm.j2c.cheatsheet.content * *Copyright IBM Corporation 2004. All Rights Reserved. * * Note to U.S. Government Users Restricted Rights: Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *******************************************************************************/ package sample.ims; import com.ibm.etools.marshall.util.MarshallIntegerUtils; import sample.ims.data.*; public class TestMultiSeg { public static void main (String[] args) { byte[] segBytes = null; int srcPos = 0; int dstPos = 0; int totalLen = 0; int remainLen = 0; byte[] buff; short LL = 0; short ZZ = 0; try { // --------------------------------------------------- // 將資料移入 IMS 交易輸入訊息。 // 利用輸入訊息格式處理常式方法 // getSize() 來設定輸入訊息的 LL 欄位。 // --------------------------------------------------- InputMsg input = new InputMsg(); input.setIn__ll((short) input.getSize()); input.setIn__zz((short) 0); //----------------------------------------------------------- // 找出 IMS 管理者的交易碼 //---------------------------------------------------------- input.setIn__trcd("SKS6 "); input.setIn__data1("M2 SI1"); input.setIn__data2("M3 SI1"); // --------------------------------------------------- // 執行 IMS 交易。會傳回多重區段輸出 // 訊息。 // --------------------------------------------------- MSOImpl proxy = new MSOImpl(); sample.ims.CCIBuffer output = proxy.runMultiSegOutput(input); // --------------------------------------------------- // 擷取多重區段輸出訊息, // 作為一個使用輸出訊息格式 // 處理常式方法 getBytes() 的位元組陣列。 // --------------------------------------------------- System.out.println( "\nSize of output message is: " + output.getSize()); segBytes = output.getBytes(); srcPos = 0; dstPos = 0; totalLen = segBytes.length; remainLen = totalLen; // --------------------------------------------------- // 從緩衝區移入第一個區段物件。 // --------------------------------------------------- buff = null; // 取得區段長度。 LL = MarshallIntegerUtils.unmarshallTwoByteIntegerFromBuffer( segBytes, srcPos, true, MarshallIntegerUtils.SIGN_CODING_TWOS_COMPLEMENT); // 將區段放置在位元組陣列中。 buff = new byte[LL]; System.arraycopy(segBytes, srcPos, buff, dstPos, LL); remainLen -= LL; // 從位元組陣列建立及移入區段物件。 OutputSeg1 S1 = new OutputSeg1(); S1.setBytes(buff); System.out.println( "\nOutSeg1 LL is: " + S1.getOut__ll() + "\nOutSeg1 ZZ is: " + S1.getOut__zz() + "\nOutSeg1_DATA1 is: " + S1.getOut__data1()); // --------------------------------------------------- // 從緩衝區移入第二個區段物件。 // --------------------------------------------------- srcPos += LL; buff = null; // 取得區段長度。 LL = MarshallIntegerUtils.unmarshallTwoByteIntegerFromBuffer( segBytes, srcPos, true, MarshallIntegerUtils.SIGN_CODING_TWOS_COMPLEMENT); // 將區段放置在位元組陣列中。 buff = new byte[LL]; System.arraycopy(segBytes, srcPos, buff, dstPos, LL); remainLen -= LL; // 從位元組陣列建立及移入區段物件。 OutputSeg2 S2 = new OutputSeg2(); S2.setBytes(buff); System.out.println( "\nOutSeg2 LL is: " + S2.getOut__ll() + "\nOutSeg2 ZZ is: " + S2.getOut__zz() + "\nOutSeg2_DATA1 is: " + S2.getOut__data1() + "\nOutSeg2_DATA2 is: " + S2.getOut__data2()); // --------------------------------------------------- // 從緩衝區移入第三個區段物件。 // --------------------------------------------------- srcPos += LL; buff = null; // 取得區段長度。 LL = MarshallIntegerUtils.unmarshallTwoByteIntegerFromBuffer( segBytes, srcPos, true, MarshallIntegerUtils.SIGN_CODING_TWOS_COMPLEMENT); // 將區段放置在位元組陣列中。 buff = new byte[LL]; System.arraycopy(segBytes, srcPos, buff, dstPos, LL); remainLen -= LL; // 從位元組陣列建立及移入區段物件。 OutputSeg3 S3 = new OutputSeg3(); S3.setBytes(buff); System.out.println( "\nOutSeg3 LL is: " + S3.getOut__ll() + "\nOutSeg3 ZZ is: " + S3.getOut__zz() + "\nOutSeg3_DATA1 is: " + S3.getOut__data1() + "\nOutSeg3_DATA2 is: " + S3.getOut__data2() + "\nOutSeg3_DATA3 is: " + S3.getOut__data3()); } catch (Exception e) { System.out.println("\nCaught exception is: " + e); } } }
恭喜!您已完成「MultiSegment 輸出指導教學」。
請檢視摘要中的資料來完成您的指導教學。