Hitachi

VisiBroker Version 5 Borland(R) Enterprise Server VisiBroker(R) デベロッパーズガイド


17.2 汎用的なオブジェクトリファレンスを取得

DIIを使用する場合,クライアントプログラムで従来のバインド方法を使用してターゲットオブジェクトのリファレンスを取得する必要はありません。コンパイル時に,ターゲットオブジェクトのクラス定義をクライアントがわからない場合があるためです。

コードサンプル17-1に,VisiBroker ORBオブジェクトが提供するbindメソッドをクライアントプログラムが使用して,オブジェクト名を指定することによってオブジェクトにバインドする方法を示します。このメソッドは汎用CORBA::Object(C++)を返します。

コードサンプル17-1 汎用的なオブジェクトリファレンスを取得する(C++)
. . .
CORBA::Object_var account;
try {
   // initialize the ORB.
   CORBA::ORB_ptr orb = CORBA::ORB_init(argc, argv);
} catch (const CORBA::Exception& e)
   cout << "Failure during ORB_init " << endl;
   cout << e << endl;
}
. . .
try {
   // Request ORB to bind to object supporting the
   // account interface.
   account = orb->bind("IDL:Account:1.0");
} catch (const CORBA::Exception& excep)
   cout << "Error binding to account" << endl;
   cout << excep << endl;
}
cout << "Bound to account object " << endl;
. . .

コードサンプル17-2に,VisiBroker ORBオブジェクトが提供するbindメソッドをクライアントプログラムが使用して,オブジェクト名を指定することによってオブジェクトにバインドする方法を示します。このメソッドは汎用org.omg.CORBA.Object(Java)を返します。

コードサンプル17-2 汎用的なオブジェクトリファレンスを取得する(Java)
. . .
org.omg.CORBA.Object account;
try {
   // initialize the ORB.
   com.inprise.vbroker.CORBA.ORB orb = 
                                    (com.inprise.vbroker.CORBA.ORB) 
                                    org.omg.CORBA.ORB.init(args, null);
}catch(Exception e) {
   System.err.println ("Failure during ORB_init");
   e.printStackTrace();
}
. . .
 
try {
   // Request ORB to bind to the object supporting
   // the account interface.
   account = orb.bind("IDL:Account:1.0",
                      "BankManager", null, null);
}catch(Exception excep) {
   System.err.println ("Error binding to account" );
   excep.printStackTrace();
}
System.out.println ("Bound to account object");
. . .