Whole document tree InitializationBefore a Java program can use CORBA objects, it must initialize itself as follows:
Topics in this section include: Creating an ORB ObjectBefore 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. Creating an ORB for an ApplicationThis 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); // code continues Creating an ORB for an AppletAn applet creates an ORB like this: import org.omg.CORBA.ORB; public void init() { try { ORB orb = ORB.init(this, null); // code continues Some web browsers have an ORB built directly into them. This can cause problems if that ORB is not perfectly compliant. In this case, special steps must be taken to initialize the Java IDL ORB specifically. For example, because of missing classes in the installed ORB in Netscape Communicator 4.01, an applet displayed in that browser must contain code similar to the following in its init() method: import java.util.Properties; import org.omg.CORBA.*; public class MyApplet extends java.applet.Applet { public void init() { // Instantiate the Java IDL ORB, passing in this applet // so that the ORB can retrieve the applet properties. Properties props = new Properties(); props.put("org.omg.CORBA.ORBClass", "com.sun.CORBA.iiop.ORB"); ORB orb = ORB.init(this, props); ... } } Arguments to ORB.init()For both applications and applets, the arguments for the initialization method are:
The init() operation uses these parameters, as well as the system properties, to obtain information it needs to configure the ORB. It searches for ORB configuration properties in the following places and order:
The first value found for a particular property is the value the init() operation uses. If a configuration property cannot 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. System PropertiesWith respect to the system Properties object, note that Sun's Java virtual machine* adds -D command line arguments to it. Other Java virtual machines may or may not do the same. Currently, the following configuration properties are defined for all ORB implementations:
In addition to the standard properties listed above, Java IDL also supports the following properties:
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, a command line that starts an application looks like this: -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 ReferencesTo 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:
Stringified Object ReferencesThe 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 is up to the applet or application developer to:
The following fragment shows how a server converts a CORBA object reference to a string: org.omg.CORBA.ORB orb = // get an ORB object org.omg.CORBA.Object obj = // create the object reference String str = orb.object_to_string(obj); // make the string available to the client This code fragment shows how a client converts the stringified object reference back to an object: org.omg.CORBA.ORB orb = // get an ORB object String stringifiedref = // read string org.omg.CORBA.Object obj = orb.string_to_object(stringifiedref); Getting References from an ORBIf 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 interface defines an operation called resolve_initial_references() 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:
The Java IDL implementation of resolve_initial_references() 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 Naming Service for details on starting the Java IDL name server. *As used on this web site, the terms "Java Virtual Machine" or "JVM" mean a virtual machine for the Java platform.
Copyright © 1996, 1997 Sun Microsystems, Inc., 2550 Garcia Ave., Mtn. View, CA. 94043-1100 USA., All rights reserved. |