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

    • server-context is the root naming context for the server where the component is installed. You can view and edit this setting in the Naming Services tab of the Server Properties window. The default for a new server is “/”. If you specify an initial name context when initializing the ORB properties, then resolved names are assumed to be relative to the initial name context.

    • package is the EAServer package name in which the component is installed, as displayed in EAServer Manager.

    • component is the component name, as displayed in EAServer Manager.

  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;
}