Resolving objects using the CosNaming interface

The service provider interface (SPI) uses the CosNaming interface to connect to the EAServer name server and retrieve the CORBA Interoperable Object Reference (IOR) associated with the server’s manager object. Once the IOR is retrieved, the naming service creates a session with the manager object and then creates an instance of the requested object. The SPI returns an instance of the requested object to the client.

After initializing the ORB, call the orb.resolve_initial_references method to obtain the initial naming context. The naming context is an object that implements the CosNaming::NamingContext IDL interface; it is used to resolve EAServer component and service names to server-side objects.

The initial NamingContext has the name context that was specified in the com.sybase.CORBA.NameServiceURL ORB initialization property. Your client program invokes the NamingContext::resolve operation to obtain an instance of the EAServer authentication service as well as component instances.

The NamingContext::resolve operation takes a CosNaming::Name parameter, which is a sequence of CosNaming::NameComponent structures. The Java definitions of these types and the NamingContext::resolve operation follow:

package org.omg.CORBA.CosNaming;

class NameComponent {
  public String id;    // Represents a node in a name
  public String kind;  // Unused, can contain comments

  // Construct a NameComponent instance with the
  // specified initial values for id and kind fields
  public NameComponent(String id, String kind);
}

interface NamingContext {
  ... other methods not shown ...
  public org.omg.CORBA.Object resolve
   (NameComponent[] n)
   throws 
   org.omg.CosNaming.NamingContextPackage.NotFound,
  org.omg.CosNaming.NamingContextPackage.CannotProced,
  org.omg.CosNaming.NamingContextPackage.InvalidName;
}

In Java, a name is represented by an array of NameComponent instances, with the id field of each instance set to a node of the name. For example, the name:

USA/Sybase/Jaguar/TestPackage/TestComponent 

can be represented by the array theName which is created in this code fragment:

import org.omg.CORBA.CosNaming.*;
import org.omg.CORBA.CosNaming.NamingContextPackage.*;
public class myApplet extends Applet {

  NamingContext nc;
  ... deleted code that retrieves initial NamingContext ...

  NameComponent theName[] = {
    new NameComponent("USA", ""), 
    new NameComponent("Sybase", ""),
    new NameComponent("Jaguar", ""),
    new NameComponent("TestPackage", ""),
    new NameComponent("TestComponent", "")
  } ;

For convenience, the naming service allows you to specify multiple nodes of a name in one NameComponent instance, using a forward slash (/) to separate nodes. The name from the example above can be represented in a one-element array as shown below:

  NameComponent theName[] = {
    new NameComponent(
     "USA/Sybase/Jaguar/TestPackage/TestComponent","")
  };

NamingContext::resolve resolves a name to an object; this method either returns an org.omg.CORBA.Object instance or throws an exception.

For complete information about instantiating and resolving objects with CORBA naming services, see Chapter 12, “Creating CORBA Java Clients,” in the EAServer Programmer’s Guide.