[Enterprise Extensions only]
  Next topic

Writing a WebSphere Enterprise JavaBean as a CORBA client, invoking a servant object

An enterprise bean acting as a client to a CORBA server uses the servant objects in the same way as any other CORBA client: it obtains a reference to the object and invokes the methods. This work is typically done within the implementation of the methods in the enterprise bean's remote interface.

In the example on which this task is based, the methods in the remote interface are implemented by calling methods in several supporting classes. For example, the remote interface provides calls to test the CORBA Primitive and Complex interfaces. Methods in the Primitive interface are called by the client-side TestPrimitive class, which is used in the implementation of the remote interface. (The structurally similar TestComplex class performs the same tasks for the Complex interface.) The TestPrimitive class provides the following:

From an organizational perspective, the class is structured as follows:
package com.ibm.orb.interop.samples;

// Java
import java.util.Properties;

// CORBA
import org.omg.CORBA.ORB;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextHelper;

// Application-specific
import com.ibm.orb.interop.samples.Defs;
import com.ibm.orb.interop.samples.idl.*;
import com.ibm.orb.interop.samples.util.Report;


public class TestPrimitive
{
   private boolean    showData = false;
   private ClientOrb  clientOrb = null;
   private Report     testReport = null;
   private Primitive  primitive = null;   // Target server reference


   // Constructors
   public TestPrimitive(ClientOrb clientOrb, Primitive primitive)
   { ... }
   public TestPrimitive(ClientOrb clientOrb,
                        org.omg.CORBA.Object primitive)
   { ... }

   /// Methods to exercise the Primitive interface
   public void testOctet(String testName) { ... }
   public void testBoolean(String testName) { ... }
   public void testShort(String testName) { ... }
   ...
}
The TestPrimitve class provides the following kinds of code:

  1. Two constructors, which are used to obtain a reference to the client-side ORB and to narrow a CORBA Object reference to a Primitive servant object.
    public TestPrimitive(ClientOrb clientOrb, Primitive primitive)
    {
       super();
    
       this.clientOrb = clientOrb;
       this.primitive = primitive;
       ...
    }
    
    public TestPrimitive(ClientOrb clientOrb,
                         org.omg.CORBA.Object primitive)
    {
       this(clientOrb, PrimitiveHelper.narrow(primitive));
    }
    
  2. Methods for testing each of the methods in the Primitive interface. A typical TestPrimitive method calls the three Primitive methods for a particular data type. In the Primitive interface, each data type has three methods, each designed to exercise a different way of returning values: as the value of the method, as an out argument, and as an inout argument. The typical TestPrimitive methods follows this pattern: compute the expected return value, call the remote method that returns the result as the value of the method, compare the actual and expected results, log the results, call the remote method that returns the result as an out, compare the result to the expected value, log the results, call the remote method that returns the result as an inout, compare and log the results. For illustration, the code fragment shows the relevant parts of the TestPrimitive.testShort method, which calls the methods in the Primitive interface that work with short integers.
    short initial = 32000;
    short expected = PrimitiveOps.processShort(initial);
    org.omg.CORBA.ShortHolder holder = new org.omg.CORBA.ShortHolder();
    
    try
    {
       // Test the first of three methods.
       short result = primitive.testShortIn(initial);
       ...
       testReport.log("Initial: " + initial
           + ",  Expected: " + expected
           + ",  Result: " + result );
    
    }
    catch (Exception e)
    { ... }
    
    try
    {
       // Test the second of three methods.
       primitive.testShortOut(initial, holder);
       short result = holder.value;
       ...
       testReport.log("Initial: " + initial
           + ",  Expected: " + expected
           + ",  Result: " + result );
    }
    catch (Exception e)
    { ... }
    
    try
    {
       // Test the third of three methods.
       holder.value = initial;
       primitive.testShortInOut(holder);
       short result = holder.value;
       ...
       testReport.log("Initial: " + initial
           + ",  Expected: " + expected
           + ",  Result: " + result );
    }
    catch (Exception e)
    { ... }
    
  Next topic