ページの先頭行へ戻る
Interstage Application Server アプリケーション作成ガイド(CORBAサービス編)
Interstage

11.1.2 クライアントアプリケーションのプログラミング

(1) Factoryインタフェースのオブジェクトリファレンスの獲得

ネーミングサービスより、Factoryインタフェースのオブジェクトリファレンスを獲得します。

CosNaming::Name_ptr           name; 
CosNaming::NameComponent_var  *name_component; 

CORBA::Object_ptr
      obj = orb->resolve_initial_references( CORBA_ORB_ObjectId_NameService, env ); 

CosNaming::NamingContext_ptr
      NamingContext_obj = CosNaming::NamingContext::_narrow( obj ); 
CORBA::release( obj ); 

name_component = CosNaming::Name::allocbuf(1); 
name_component[0]->id = (const CORBA::Char *)"ODsample::factory";
name_component[0]->kind = (const CORBA::Char *)"";
name = new CosNaming::Name(1, 1, name_component,CORBA_TRUE); 
obj = NamingContext_obj->resolve( *name, env ); 
CORBA::release( NamingContext_obj ); 
delete name;

(2) Factoryインタフェースに実装したメソッドの呼び出し

ネーミングサービスより獲得したオブジェクトリファレンスを使用してcreate_objメソッドを呼び出します。OD_impl_instコマンドでサーバアプリケーションをインプリメンテーションリポジトリに登録する場合は、定義ファイル(“OD_impl_inst -ax”)で“iswitch=ON”を指定すると、メソッドの初回呼出し時にサーバアプリケーション内にクライアントごとのインスタンスデータが作成されます。

// インタフェース"intf1"のオブジェクトリファレンスの獲得
ODsample::factory_ptr ap = ODsample::factory::_narrow( obj ); 
ODsample::factory_var av = ap; 

ODsample::intf1_var target = av->create_obj( env );