Contents Using IOM Component Stubs Previous Next

Output Parameters

CORBA includes the concept of output parameters, which are parameters that are uninitialized at the time of a call to a CORBA operation (CORBA operations map to Java methods), then initialized by the operation, and returned to the caller. Many IOM objects have operations that use output parameters.

Unfortunately, the concept of output parameters does not map well into Java. In Java method calls, parameters of primitive types are always passed by value and parameters of reference types are always passed by reference. In general, only the member variables of an object or elements of an array can be modified during a method call and returned to the caller. Furthermore, some objects are immutable, which means their members cannot be changed after the objects are constructed. Java CORBA programmers need a general way to use both primitive types and reference types for output parameters in method calls on Java CORBA stubs.

For this purpose, each data type that can be used for an output parameter in a method call on a Java CORBA stub is associated with a Holder class. A Holder class is a wrapper that has one public member variable of the targeted data type. When a Holder is used in a method call on a Java CORBA stub, the method implementation can set the member variable of the Holder to be the output value of parameter, and the caller can fetch that value by getting the value of the member variable.

The value of the member variable in a Holder object before it is used in a method call with an output parameter is ignored, and, in the case of Holder classes for reference types, it can be null.

CORBA also includes the concept of update parameters, which are parameters that are initialized by the caller of a CORBA operation, possibly modified by the operation, and returned to the caller. In Java CORBA stubs, Holder classes are also used to handle update parameters.

As an example, here is the definition of the class org.omg.CORBA.IntHolder, which is the Holder class for the Java primitive type int.

     final public class IntHolder
     {
          public int value;
          public IntHolder()
          {
          }
          public IntHolder(int initial)
          {
               value = initial;
          }
     }

The following example shows how the org.omg.CORBA.IntHolder class could be used in a method call that requires an output int parameter.

     org.omg.CORBA.IntHolder intHolder = new org.omg.CORBA.IntHolder();
     myApplication.myMethod(intHolder);
     int intValue = intHolder.value;

The language service example shows a more practical use of Holder classes.

Contents Using IOM Component Stubs Previous Next