Hints on using the Dynamic Invocation Interface (DII)

  1. Obtain the object reference (via IOR, naming service, etc.). Let us call the variable with the object reference obref.
  2. Obtain the Request object, providing the name of the operation as argument to the _request call:
       Request      req = obref._request( "OperationName" );
    
  3. Populate the arguments, using the add_in_arg, add_out_arg, or add_inout_arg methods of the Request interface. These methods return an (CORBA-predefined) object of type Any, which provides methods for inserting values into the CORBA Any type, as in the examples below:
       req.add_in_arg().insert_long( 1245 );
       req.add_in_arg().insert_float( 1245.678 );
       req.add_in_arg().insert_boolean( true );
       req.add_in_arg().insert_string( "String value" );
    
    Similar versions of the above insert methods exist for the other predefined CORBA types, as well.
    For user-defined types you must rely on the IDL-generated "helper" classes. For example, if an interface INT defines a type called "longs", as below:
       typedef sequence<long> longs;
    
    the IDL compiler generates two auxiliary classes called longsHelper and longsHolder which are declared in the files longsHelper.java and longsHolder.java, respectively. These classes are placed in a separate Java package, called INTPackage (as a result, the generated files are placed in the subdirectory INTPackage of the directory where the IDL compiler generates code). You must remember to import the contents of this package with the import directive of Java when using these auxiliary calsses. The longsHelper class provides a static method called insert which can be used to insert a vector of long values into an object of type Any. A suitable call looks like this:
       longsHelper.insert( req.add_in_arg(), array_of_longs );
    
    Note that you should add arguments (using the add_in_arg, add_out_arg, or add_inout_arg methods) in the same order as declared in the IDL interface.
  4. If the operation returns a non-void type, you must set the return type, as in the example below:
       req.set_return_type(
            orb.get_primitive_tc(
                  org.omg.CORBA.TCKind.tk_boolean
                                )
                          );
    
    Other types my be obtained by using
       org.omg.CORBA.TCKind.tk_boolean
       org.omg.CORBA.TCKind.tk_long
       org.omg.CORBA.TCKind.tk_float
       org.omg.CORBA.TCKind.tk_string
    
    and others.
    For user-defined return types you must rely on the IDL-generated "helper" classes, as with inserting the values. Assuming the same longs type (as above), a suitable call to get the type set is shown below:
       req.set_return_type( longsHelper.type() );
    
  5. Invoke the operation, as shown below:
       req.invoke();
    
  6. If the operation returns a result, obtain it and extract the value, as in:
       res = req.result().value();
    
       System.out.println( "Returned: " + res.extract_boolean() );
    
    Other versions of extract exist:
       extract_boolean()
       extract_long()
       extract_float()
       extract_string()
    
    and others.
    For user-defined return types you must rely on the IDL-generated "helper" classes, as with inserting the values. Assuming the same longs type (as above), a suitable call to extract the value is shown below:
       long[] values = longsHelper.extract( res );