Interstage Application Server アプリケーション作成ガイド (CORBAサービス編)
目次 索引 前ページ次ページ

第6章 アプリケーションの開発(Java言語)> 6.17 データ型に対するマッピング

6.17.10 属性宣言(attribute)のマッピング

(1)IDLマッピング

 IDL言語でattributeを指定した場合、 Java言語ではIDLで定義された変数名と同じ名前のメンバ変数、およびその変数に対するデータ設定/取得用のメソッド(変数名と同じ名前)にマッピングされます。
 IDL言語での定義が、以下のように定義されていた場合について、アプリケーションプログラムの例を示します。

【IDL言語】

  module ODsample{
      interface attrtest{
          attribute long para1; 
          attribute string para2; 
          readonly attribute long para3; 
      };
  };

 これをJava言語で記述すると以下のようになります。

【Java言語】

  <インタフェース>
  package ODsample; 
  public interface attrtestOperations
  {
      public int para1();
      public void para1( int value ); 
      public java.lang.String para2();
      public void para2( java.lang.String value ); 
      public int para3();
  }
  <Holderクラス>
  package ODsample; 
  public final class attrtestHolder  implements org.omg.CORBA.portable.Streamable {
      public ODsample.attrtest value; 
      public attrtestHolder() {...}
      public attrtestHolder(ODsample.attrtest __arg) {...}
      public void _write(org.omg.CORBA.portable.OutputStream out) {...}
      public void _read(org.omg.CORBA.portable.InputStream in) {...}
      public org.omg.CORBA.TypeCode _type() {...}
  }
  <Helperクラス>
  package ODsample; 
  public class attrtestHelper
  {
      public static void
          insert(org.omg.CORBA.Any a, ODsample.attrtest value){...}
      public static ODsample.attrtest
          extract(org.omg.CORBA.Any a){...} 
      public static String
          id(){...}
      public java.lang.Object
          read_Object(org.omg.CORBA.portable.InputStream istream){...} 
      public void
          write_Object(org.omg.CORBA.portable.OutputStream ostream, 
                       Object value){...} 
      public java.lang.String
          get_id( ){...} 
      public org.omg.CORBA.TypeCode
          get_type(){...}
      private static org.omg.CORBA.TypeCode _type; 
      synchronized public static org.omg.CORBA.TypeCode
          type(){...}
      public static ODsample.attrtest
          read(org.omg.CORBA.portable.InputStream istream){...} 
      public static void
          write(org.omg.CORBA.portable.OutputStream ostream, 
                ODsample.attrtest value){...} 
      public static ODsample.attrtest
          narrow( org.omg.CORBA.Object obj) 
                 throws org.omg.CORBA.BAD_PARAM{...}
      private static ODsample.attrtest
          narrow( org.omg.CORBA.Object obj, boolean ignore_check) 
                 throws org.omg.CORBA.BAD_PARAM{...}
  }

(2)クライアントアプリケーションでの処理

 サーバオブジェクトのデータの直接設定および取り出しを行います。

  import org.omg.CORBA.*; 
  import ODsample.*; 

  public class attributeClient {
      public static void main(String args[]) {
          // ORBの前処理
          // オブジェクトリファレンスの獲得
              :
         try{
             // サーバアプリケーション変数の設定
             java.util.Date  dt = new java.util.Date();
             target.para1( (int)dt.getTime() ); 
             target.para2( dt.toString() ); 

             // サーバアプリケーション変数の参照
             System.out.println( target.para1() ); 
             System.out.println( target.para2() ); 
             System.out.println( target.para3() ); 

          }
          catch ( Exception e ) {
              //エラー処理
                 :
          }
      }
  }

(3)サーバアプリケーションでの処理

 サーバアプリケーションのServantクラスでは、インタフェースクラス変数の参照/設定処理を実装します。

  import org.omg.CORBA.*; 
  import org.omg.PortableServer.*; 
  import ODsample.*; 

  // Servantクラス
  // サーバアプリケーションのメソッド
  class attributeServant extends attrtestPOA {

      // 変数の初期化
      private int    value1 = 0; 
      private String value2 = "";
      private int    value3 = 999; 
    
      public int para1(){
          return( value1 ); 
      }
      public void para1(int arg){ 
          value1 = arg; 
      }
      public String para2(){
          return( value2 ); 
      }
      public void para2( String arg ){ 
          value2 = arg; 
      }
      public int para3(){
          return( value3 ); 
      }
  }

  public class attributeServer {
      public static void main(String args[]) {
          try {
               // ORBの前処理
                :
               // POAオブジェクトの生成
                :
               // Servantの生成とそのPOAへの登録
                :
               // POAManagerの活性化
                :
          }
          catch (java.lang.Exception e) {
              //エラー処理
                :
          }
      }
  }

目次 索引 前ページ次ページ

All Rights Reserved, Copyright(C) 富士通株式会社 2005