Chapter 2 Jaguar Naming Services


CORBA CosNaming API support

The Jaguar naming service is an implementation of the CORBA CosNaming component. The CosNaming component is a collection of interfaces that defines the naming service. These interfaces provide support for object binding and lookup.

Jaguar implements the NamingContext interface to bind a name to an object, thereby creating a NamingContext object. Client applications use the NamingContext interface to "resolve" a bound name to its referenced object.

CosNaming::Name represents a name context that can be bound to an object implementation or another name context. CosNaming::Name is a sequence of one or more NameComponent structures. The NameComponent consists of two attributes: the identifier and the type. Both of these attributes are represented as IDL strings.

The IDL specification for NameComponent and the NamingContext interface is:

module CosNaming
typedef string Istring;
struct NameComponent {
Istring id;
Istring kind;
};
typedef sequence<NameComponent> Name;
};

Binding names

There are four methods to create bindings:

To remove an object reference from a name context, Jaguar uses the unbind function. When you shut down the Jaguar server, all bound objects are automatically unbound using this function. However, you can also use unbind when you delete a package or component from the repository. If you use persistent name storage, use unbind to remove references to deleted packages and components on the external server.

Resolving Jaguar objects

Jaguar uses the resolve method to retrieve an object based on the name context into which it is bound. The name context used to retrieve an object must be identical to the object's bound name context. The Jaguar naming service performs the "narrowing" of the object to the appropriate return type. In other words, the client does not need to cast the returned object to a more specialized interface.

There are two ways for Java clients to access the naming service to resolve object names:

Resolving objects using the CosNaming interface

The service provider interface (SPI) uses the CosNaming interface to connect to the Jaguar 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 Jaguar 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 Jaguar 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 Jaguar 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 13, "Creating CORBA-Compatible Java Clients" in the Jaguar CTS Programmer's Guide.

 


Copyright © 2000 Sybase, Inc. All rights reserved.