21.5.3 サーバ用タイプドオブジェクトラッパーの登録

C++の場合
クライアントアプリケーションと同様,タイプドオブジェクトラッパーをサーバ側に登録するには,<interface_name>::addメソッドを呼び出します。サーバ側タイプドオブジェクトラッパーはORB_initメソッドが呼び出されたあと,ただしオブジェクトインプリメンテーションがリクエストを処理する前に登録されなければなりません。コードサンプル21-13にタイプドオブジェクトラッパーを登録するTypedServer.Cファイルの部分を示します。
コードサンプル21-13 サーバ側タイプドオブジェクトラッパーの登録(C++)

// TypedServer.C
#include "Bank_s.hh"
#include "BankImpl.h"
#include "BankWrap.h"
USE_STD_NS
int main(int argc, char* const* argv) {
  try {
     // Initialize the ORB.
     CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
     // Initialize the POA.
     CORBA::Object_var obj =
           orb->resolve_initial_references("RootPOA");
     PortableServer::POA_var rootPoa =
           PortableServer::POA::_narrow(obj);
     CORBA::PolicyList policies;
     policies.length(1);
     policies[(CORBA::ULong)0] =
          rootPoa->create_lifespan_policy(
          PortableServer::PERSISTENT);
     // Get the POA Manager.
     PortableServer::POAManager_var poa_manager =
          rootPoa->the_POAManager();
     // Create myPOA With the Right Policies.
     PortableServer::POA_var myPOA = rootPoa->create_POA(
                "bank_ow_poa",
           poa_manager,
           policies);
     // Install Typed Object Wrappers for Account Manager.
     Bank::AccountManagerObjectWrapper::add(orb,
           SecureAccountManagerObjectWrapper::factory,
           VISObjectWrapper::Server);
     Bank::AccountManagerObjectWrapper::add(orb,
           CachingAccountManagerObjectWrapper::factory,
                 VISObjectWrapper::Server);
     // Create the Account Manager Servant.
     AccountManagerImpl managerServant;
     // Decide on ID for Servant.
     PortableServer::ObjectId_var managerId =
           PortableServer::string_to_ObjectId("BankManager");
     // Activate the Servant with the ID on myPOA.
     myPOA->activate_object_with_id(
           managerId, &managerServant);
     // Activate the POA Manager.
     rootPoa->the_POAManager()->activate();
     cout << "Manager is ready." << endl;
     // Wait for Incoming Requests.
     orb->run();
  } catch(const CORBA::Exception& e) {
     cerr << e << endl;
     return 1;
  }
  return 0;
}

Javaの場合
クライアントアプリケーションと同様,タイプドオブジェクトラッパーをサーバ側に登録するには,Helperクラスが提供するaddServerObjectWrapperClassメソッドを呼び出します。サーバ側タイプドオブジェクトラッパーはORB.initメソッドが呼び出されたあと,ただしオブジェクトインプリメンテーションがリクエストを処理する前に登録されなければなりません。コードサンプル21-14にタイプドオブジェクトラッパーを登録するTypedServer.javaファイルの部分を示します。
コードサンプル21-14 サーバ側タイプドオブジェクトラッパーのインストール(Java)

// TypedServer.java
import org.omg.PortableServer.*;
import com.inprise.vbroker.PortableServerExt.
                               BindSupportPolicyValue;
import com.inprise.vbroker.PortableServerExt.
                               BindSupportPolicyValueHelper;
import com.inprise.vbroker.PortableServerExt.
                               BIND_SUPPORT_POLICY_TYPE;

public class TypedServer {
  public static void main(String[ ] args) throws Exception {
     // Initialize the ORB.
     org.omg.CORBA.ORB orb =
                          org.omg.CORBA.ORB.init(args,null);
     // Add two typed object wrappers for AccountManager
     // objects
     Bank.AccountManagerHelper.addServerObjectWrapperClass
      (orb, BankWrappers.SecureAccountManagerObjectWrapper.
       class);
     Bank.AccountManagerHelper.addServerObjectWrapperClass
      (orb, BankWrappers.CachingAccountManagerObjectWrapper.
       class);
     // get a reference to the rootPOA
     POA rootPOA = POAHelper.narrow
                (orb.resolve_initial_references("RootPOA"));
     // Create a BindSupport Policy that makes POA register
     // each servant with osagent
     org.omg.CORBA.Any any = orb.create_any();
     BindSupportPolicyValueHelper.insert(any,
                        BindSupportPolicyValue.BY_INSTANCE);
     org.omg.CORBA.Policy bsPolicy =
        orb.create_policy(BIND_SUPPORT_POLICY_TYPE.value,
                          any);
     // Create policies for our testPOA
     org.omg.CORBA.Policy[ ] policies = {
        rootPOA.create_lifespan_policy(LifespanPolicyValue.
        PERSISTENT), bsPolicy
     };
     // Create myPOA with the right policies
     POA myPOA = rootPOA.create_POA("lilo",
                        rootPOA.the_POAManager(), policies);
     // Create the account manager object.
     AccountManagerImpl managerServant =
                                   new AccountManagerImpl();
     // Decide on the ID for the servant
     byte[ ] managerId = "BankManager".getBytes();
     // Activate the servant with the ID on myPOA
     myPOA.activate_object_with_id(managerId, managerServant);
     // Activate the POA manager
     rootPOA.the_POAManager().activate();
     System.out.println(
                   "AccountManager: BankManager is ready.");
     for( int i = 0; i < args.length; i++ ) {
        if ( args[i].equalsIgnoreCase("-runCoLocated") ) {
           if( args[i+1].equalsIgnoreCase("Client") ) {
              Client.doMain(orb, new String[0]);
           } else if( args[i+1].
                          equalsIgnoreCase("TypedClient") ) {
              TypedClient.doMain(orb, new String[0]);
           }
           if( args[i+1].equalsIgnoreCase("UntypedClient") ) {
              UntypedClient.doMain(orb, new String[0]);
           }
           System.exit(1);
        }
     }
     // Wait for incoming requests
     orb.run();
  }
}

サーバが,ある特定のクラスのオブジェクトのインスタンスを複数生成する場合,各インスタンス用にオブジェクトラッパーのセットが生成されます。