JavaTM IDL Initialization

Before a Java program can use CORBA objects, it must initialize itself as follows:

Creating an ORB

Before it can create or invoke a CORBA object, an applet or application must first create an ORB object. Doing so introduces the applet or application to the ORB and obtains access to important operations that are defined on the ORB object.

Applets and applications create ORB instances slightly differently, because their parameters, which must be passed in the ORB.init() call, are arranged differently.

This fragment shows how an application might create an ORB:

    import org.omg.CORBA.ORB;
 
    public static void main(String args[])
    {
	try{
	    ORB orb = ORB.init(args, null);

An applet creates an ORB like this:

    import org.omg.CORBA.ORB;
 
    public void init() {
	try {
            ORB orb = ORB.init(this, null);

The first argument to ORB.init(), which is required, gives the ORB access to the application's or applet's parameters. The second argument to ORB.init() is a java.util.Properties object, which may be null. The init() operation uses these parameters, as well as the System Properties object, to obtain information it needs to configure the ORB.

The init() operation searches for ORB configuration properties in the following places and order:

  1. the application or applet parameters (first argument)
  2. the Properties object (second argument), if one has been supplied
  3. The System Properties object

The first value found for a particular property is the value the init() operation uses. If a configuration property can't be found in any of these places, the init() operation assumes an implementation-specific value for it. For maximum portability among ORB implementations, applets and applications should explicitly specify configuration property values that affect their operation, rather than relying on the assumptions of the ORB they happen to be running in.

With respect to the System Properties object, note that Sun's Java virtual machine adds -D command line arguments to the System Properties object. Other Java virtual machines may or may not do the same.

Currently, the following configuration property is defined for all ORB implementations:

org.omg.CORBA.ORBClass
The name of the Java class that implements the org.omg.CORBA interfaces. Applets and applications do not need to supply this property unless they must have a particular ORB implementation. The value for the Java IDL ORB is com.sun.CORBA.iiop.ORB.
 
Note: An applet or application that must have a particular ORB can alternatively hard-code the name of the ORB, for example:
com.sun.CORBA.iiop.ORB orb = com.sun.CORBA.iiop.ORB.init(args, props);

In addition to the standard property listed above, Java IDL supports the following properties:

org.omg.CORBA.ORBInitialHost
The host name of a machine running an ORB that provides initial services, such as a name service. The default value for this property is localhost for applications. For applets it is the applet host, equivalent to getCodeBase().getHost().
org.omg.CORBA.ORBInitialPort
The port the initial service ORB listens to. The default value is 900.


Note: When specifying a property as a command-line argument to a Java IDL application, omit the "org.omg.CORBA." portion of the property name. For example, in a command line that starts an application:
    -ORBInitialPort 800

Applet parameters should specify the full property names. The conventions for applications differ from applets so as not to expose language-specific details in command-line invocations.


Obtaining Initial Object References

To invoke a CORBA object, an applet or application must have a reference for it. There are three ways to get a reference for a CORBA object:

  1. from a string that was specially created from an object reference
  2. from another object, such as a naming context
  3. from the ORB operation resolve_initial_reference()

Stringified Object References

The first technique, converting a stringified reference to an actual object reference, is ORB-implementation-independent: No matter what Java ORB an applet or application runs on, it can convert a stringified object reference. However, it's up to the applet or application developer to:

The following fragment shows how a CORBA object reference can be made into a string and vice versa:

org.omg.CORBA.Object obj = // Set the reference ... 
String stringifiedRef = ORB.object_to_string(obj);
obj =  ORB.string_to_object(stringifiedRef); 

Getting References from an ORB

If you don't use a stringified reference to get an initial CORBA object, you use the ORB itself to produce an initial object reference. However, doing so may make your applet or application ORB-dependent, because, although the CORBA specification defines the interface for getting initial object references, it doesn't yet provide enough information for ORB vendors to implement it in a standard way. Applet and application developers should therefore be cautious when using this operation until the standard is more tightly specified. To guarantee ORB-implementation-independence, use the stringified object reference technique instead.

The ORB pseudo-object interface defines an operation called resolve_initial_reference() that is intended for bootstrapping object references into a newly started application or applet. The operation takes a string argument that names one of a few recognized objects; it returns a CORBA Object, which must be narrowed to the type the applet or application knows it to be. Two string values are presently defined:

NameService
Passing this value returns a reference to a root naming context which, after narrowing, can be used to lookup references for objects whose names are known to the applet or application (assuming those objects are registered by those names in the root or subordinate naming contexts).
InterfaceRepository
This value returns a reference to an interface repository, a CORBA object that contains interface definitions.

The Java IDL implementation of resolve_initial_reference() requires an already-running naming service whose host and port are identified by the ORBInitialHost and ORBInitialPort properties described previously, or by their default values. See The JavaIDL Name Server for details on starting the Java IDL name server.

 


Overview | Guide | API | idltojava | Mapping | Release Notes


Copyright © 1996,1997 Sun Microsystems, Inc., 2550 Garcia Ave., Mtn. View, CA. 94043-1100 USA., All rights reserved.