CCI アプリケーションのサンプル・コード

CCI アプリケーションの以下のサンプル・コードでは、接続後に IMSInteraction オブジェクトを取得して、IMS トランザクションを実行する方法を示しています。

管理対象環境では、CCI API を使用して JNDI 名前空間から IMSConnectionFactory インスタンスを検索し、そのインスタンスを使用して IMSConnection インスタンスを取得します。

ConnectionFactory cf = null;
if (isManaged) {
   //Use JNDI lookup to get ConnectionFactory instance 
   //Assume the connection factory has a JNDI name of MyIMS
   Context ic = new InitialContext();
   cf = (ConnectionFactory) ic.lookup("MyIMS");
 

JNDI が構成されていない場合、CCI アプリケーションが手動で IMSManagedConnectionFactory オブジェクトを構成し、それを使用して接続ファクトリーを取得します。

IMSManagedConnectionFactory mcf = new IMSManagedConnectionFactory();
mcf.setDataStoreName("MyDSName");
mcf.setHostName("myHostNm");
mcf.setPortNumber(new Integer(1234));
...
//Create connection factory from ManagedConnectionFactory
cf = (IMSConnectionFactory) mcf.createConnectionFactory();
次の例では、CCI インターフェースを使用して、 EIS でコマンドを実行しています。
public void execute() {
   try {
      ConnectionFactory cf = null;
      if (isManaged) {
         //Use JNDI lookup to get ConnectionFactory instance - assumes 
         //connection factory has JNDI name of MyIMS
         Context ic = new InitialContext();
         cf = (ConnectionFactory) ic.lookup("MyIMS");
      } else {
         //Create and set values for ManagedConnectionFactory
         IMSManagedConnectionFactory mcf = new IMSManagedConnectionFactory();
         mcf.setDataStoreName("MyDSName");
         mcf.setHostName("myHostNm");
         mcf.setPortNumber(new Integer(1234));
         //Create connection factory from ManagedConnectionFactory
         cf = (IMSConnectionFactory) mcf.createConnectionFactory();
      }
      // Create an IMSConnection object
      Connection connection = cf.getConnection();

      //Create an IMSInteraction from the connection to
      //interact with IMS to run the IVTNO transaction (Phonebook)
      IMSInteraction interaction = (IMSInteraction) connection.createInteraction();
      IMSInteractionSpec ixnSpec = new IMSInteractionSpec();
      ixnSpec.setInteractionVerb(IMSInteractionSpec.SYNC_SEND_RECEIVE);

      //Create new input record 
      input = new PhoneBookInputRecordField("cp037");
      input.setIn__ll((short)59);
      input.setIn__zz((short) 0);
      input.setIn__trcd("IVTNO");
      input.setTranCodeLength(10);
      input.setIn__command("DISPLAY");
      input.setIn__name1("LAST3");
      input.setIn__name2("");
      input.setAllFieldsGiven(false);
      PhoneBookOutputRecordField

      //Create new output record 
      output = new PhoneBookOutputRecordField("cp037");

      //Execute interaction by calling the execute() method
      interaction.execute(ixnSpec, input, output);

      //Display output
      System.out.println ("Output is: ");
      System.out.println("¥nMessage: "
         + output.getOut__mesg()
         + "¥nName:"
         + output.getOut__name1()
         + " "
         + output.getOut__name2()
         + "¥nExtension: "
         + output.getOut__extn()
         + "¥nZipcode: "
         + output.getOut__zip());

   } catch (Exception e) {
      e.printStackTrace();
      } finally {
      //Close both the interaction and the connection
      interaction.close();
      connection.close();
   }
}

フィードバック