Introduction to CosNaming name resolution  Using CORBA ORB implementations other than EAServer

Chapter 15: Creating CORBA C++ Clients

Resolving component proxies

Proxy objects are instantiated as follows:

  1. Create a NameComponent array that names the component. Component names are composed as follows:

    server-context/package/component
    

    where

  2. Call the NamingContext::resolve method to instantiate a factory object for the component.

  3. Narrow the CORBA Object reference to a SessionManager::Factory instance.

  4. Call the factory’s create method and narrow the return value by calling the _narrow method in the class for the interface. The create method requires a username and password to authenticate the end user.

The example below instantiates a component “CPPArithmetic,” installed in package “Tutorial,” hosted on a server with a null root context. The username and password are Guest and GuestPassword, respectively. The component implements the IDL interface Tutorial::CPPArithmetic, and the code narrows the proxy object to that interface.

// Build a CosNaming::Name object that contains the
// name of the tutorial component, Tutorial/CPPArithmetic

name[0].id = CORBA::string_dup( component_name );
name[0].kind = CORBA::string_dup( "" );

// Obtain a factory for component instances by
// resolving the component name
cout << "Creating component instance for "
  << component_name << "\n\n";
obj = nc->resolve(name);
SessionManager::Factory_var arithFactory =
  SessionManager::Factory::_narrow(obj);

if (CORBA::is_nil(arithFactory)) {
  cout << "ERROR: Null component factory. " << tutorial_help ;
  return -1;
}

// Use the factory to create an instance, passing the
// username and password for authorization
Tutorial::CPPArithmetic_var arith =
  Tutorial::CPPArithmetic::_narrow
    ( arithFactory->create("Guest", "GuestPassword"));

// Verify that we really have an instance.
if (CORBA::is_nil(arith)) {
  cout << "ERROR: Null component instance. " << tutorial_help ;
  return -1;
}




Copyright © 2005. Sybase Inc. All rights reserved. Using CORBA ORB implementations other than EAServer

View this book as PDF