Getting a pointer to the root naming context

Why and when to perform this task

Before a CORBA server can create and make available a servant object, it must have a logical name space for the servant object to exist in. This logical name space is a naming context for servant objects. The server can create a new naming context within any location within the root naming context. For example, a server called servantServer might create a new naming context called servantContext into which the server binds the servant object. Optionally, this context might be located within a domain context, which in turn is located within the root naming context. (You can create a servant context with only the root naming context as its parent or with one or more intermediary parent contexts.)

Use this task to get a pointer to the root naming context. This task adds a "get name context" method (for example, get_name_context) to the source file for a CORBA client. This method is used to access the naming service and return a pointer to the root naming context. The method performs the following actions after the client environment has been initialized:

  1. Receives a pointer to the naming service
  2. Receives a pointer to the root naming context

Steps for this task

  1. Add the get_name_context() method as shown in the following code extract:
    // This method accesses the Name Service and then gets 
    // the root naming context, which it returns;
    // the WSLogger context.
    
    ::CosNaming::NamingContext_ptr get_naming_context() 
    {
      ::CosNaming::NamingContext_ptr rootNameContext = NULL;
      ::CORBA::Object_ptr objPtr;
    
      // Get access to the Naming Service.
      try
      {
        objPtr = op->resolve_initial_references( "NameService" );
      }
    
      // catch exceptions ...
    
      if ( objPtr == NULL )
      {
        cerr << "ERROR: resolve_initial_references returned NULL" << endl;
        release_resources( op );
        return( NULL );
      }
      else
        cout << "resolve_initial_references returned = " << objPtr << endl;
    
      // Get the root naming context.
      rootNameContext = ::CosNaming::NamingContext::_narrow(objPtr);
      if ( ::CORBA::is_nil( rootNameContext ) )
      {
        cerr << "ERROR: rootNameContext narrowed to nil" << endl;
        release_resources( op );
        return( NULL );
      }
      else
        cout << "rootNameContext = " << rootNameContext << endl;
      // Release the temporary pointer.
      ::CORBA::release(objPtr);
    
      return( rootNameContext );
    }
    

    where

    rootNameContext
    is the pointer to the root naming context.

    This code receives a pointer to the naming service, narrows the pointer object to the appropriate object type, assigns it to the new pointer object called rootNameContext, performs some checks, and releases the original pointer object, objPtr.

  2. Add a statement to the main method to call the new method as shown in bold in the following code extract:
    ...
      if ( ( rc = perform_initialization( argc, argv ) ) != 0 )
        exit( rc );
     
      // Get the root naming context.
      rootNameContext = get_naming_context();
      if ( ::CORBA::is_nil( rootNameContext ) )
        exit( -1 );
    

Results

This step returns a pointer object, rootNameContext, to the root naming context.

What to do next

Add code to the client source file to access the servant object created by the server as described in Adding code to access the servant object.

Related tasks
Creating the CORBA client main code (client.cpp)
Accessing the servant object



Searchable topic ID:   tcor_pgmc1d
Last updated: Jun 21, 2007 8:07:48 PM CDT    WebSphere Business Integration Server Foundation, Version 5.0.2
http://publib.boulder.ibm.com/infocenter/wasinfo/index.jsp?topic=/com.ibm.wasee.doc/info/ee/corba/tasks/tcor_pgmc1d.html

Library | Support | Terms of Use | Feedback