Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

J2SE 1.4 breathes new life into the CORBA community, Part 4

Portable interceptors and the Interoperable Naming Service

  • Print
  • Feedback

Page 3 of 5

The Interoperable Naming Service features

The INS provides the following features:

  1. Support for stringified names
  2. URLs for CORBA object references
  3. Standardized bootstrapping


Support for stringified names

Those of you who have used the CORBA Naming Service know that creating the desired tree structure and associated bindings can prove tedious. For example, here is some sample code:

// Create the Departments context
NameComponent nc = new NameComponent("Departments", "");
NameComponent[] name = {nc};
NamingContext ctxDepartments = ctxRoot.bind_new_context(name);
// Create a name binding within the Departments context
nc = new NameComponent("HR", "");
name[0] = nc;
ctxDepartments.rebind(name, objRef);


How many of you have created your own libraries to enable code such as the following:

String binding = "Departments/HR";
namingFacade.rebind(binding,objRef);


The INS now gives you a standard way of achieving the same functionality, as shown below:

ctxRoot.rebind(ctxRoot.to_name("Deptartments/HR"));


The INS defines a new interface called NamingContextExt that features several new methods to assist converting between the tedious names that methods such as rebind() require and the friendlier stringified names. These methods are:

  1. to_string(): converts a NameComponent array into a stringified name
  2. to_name(): converts a stringified name into a NameComponent array
  3. resolve_str(): resolves a stringified name into an object reference


Obtaining a root NamingContextExt is no different from obtaining a root NamingContext, as shown below:

NamingContextExt ctxRoot =  
  NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService"));


URLs for CORBA object references

So far, the only standard way to obtain a readable IOR is to use the object_to_string() method on the ORB instance to obtain a long sequence of alphanumeric characters. Although readable, this is no way to remember an object reference. Think about network addresses: remembering each address as www.DoesNotExist.com proves much easier than trying to remember each as 204.224.196.10. The INS comes to the rescue with two human-readable URL formats for CORBA object references:

  1. corbaloc: The corbaloc: format proves useful for CORBA client programs and typically resolves the reference using the GIOP (General Inter-ORB Protocol) LocateRequest or Request messages. For example, a corbaloc: object reference might look like this: corbaloc:iiop:1.2@XYZ.com:1050/TraderService. This example shows how to get an object reference for TraderService from host XYZ.com on port 1050.
  2. corbaname: The corbaname: format provides a mechanism for a client to bootstrap directly and is typically used to resolve the stringified name from the root naming context. For example, a corbaname: object reference might look like this: corbaname::ABC.com:1050#Departments/HR, where ABC.com is the host and 1050 is the port. The reference portion up to the hash mark (corbaname::ABC.com:1050) is the URL that returns the root naming context. The URL's remainder (Departments/HR) is the path to the object within the root naming context.


We can modify Part 3's bank program to use these URL formats. Here's what the modified program looks like:

  • Print
  • Feedback

Resources