Page 2 of 6
IORs are convenient because they are easy to use and are ORB-implementation-independent, but they present a small challenge: How does a client obtain a copy of the stringified IOR? Although this article won't present any "real" solutions to this problem, let me offer a few possibilities:
Web publishing -- The server process writes the stringified IOR to a known location in the server's document root using a servlet or CGI script, enabling client programs to easily retrieve stringified references from the Web server using the HTTP protocol
Database -- The server process writes the IOR to a table of IORs using a symbolic name as the primary key value and client programs retrieve the IOR using any suitable database API
A future column will demonstrate how to use Java Naming and Directory Interface (JNDI) to access naming and directory services, and then provide several techniques to publish CORBA objects and IORs.
A CORBA object is uniquely identified by an object reference. The IIOP specification defines an IOR as an ORB-independent
object reference. Given a stringified object reference, a client can create a proxy that enables requests to be forwarded
to the remote CORBA object. Java IDL, along with the underlying OMG CORBA standard, defines two org.omg.CORBA.ORB methods used for stringification:
String object_to_string(org.omg.CORBA.Object o) -- Converts the given CORBA object reference to a stringified IOR. Note: the string returned by this method is not designed to be human readable, as is the case with the Object toString() method.org.omg.CORBA.Object string_to_object(String ior) -- Converts a stringified IOR produced by the method object_to_string() back to a CORBA object reference.
The stringification process is illustrated in Figure 1.

Figure 1. The stringification process
The following code sample creates a SimpleObject implementation, generates a stringified IOR, and writes it to a file called simple.ior.
package ior;
import org.omg.CORBA.ORB;
import java.io.*;
public class IorServer {
public static void main(String args[]) throws IOException {
//create object and register with ORB
SimpleObjectImpl simple = new
SimpleObjectImpl();
//initialize ORB and stringify object
ORB orb = ORB.init(args, null);
String ior = orb.object_to_string(simple);
System.out.println("IOR: " + ior);
//write stringified object to file
FileWriter fw = new FileWriter("simple.ior");
fw.write(ior);
fw.close();
//block to prevent application from terminating
//CORBA does not create any user threads to service clients
System.out.println("Ready for client requests to simple
object...");try {
Thread.currentThread().join();
} catch(InterruptedException ex) {}
}
}
After using the command-line parameters to initialize the ORB, a stringified IOR is generated using the object_to_string(). The IOR is written to a file which the client program will read to obtain the IOR. Java IDL does not create any user threads
to service client requests, so the program deadlocks the interpreter's thread to prevent the application from terminating.
Running the application yields the following output: