Use the following code to initialize the newly created Java wrapper object (based on the IDL object described in Sample IDL Object) with its three parameters:

  • A string
  • A 32-bit long value
  • An array that has two rows and three columns, containing 32-bit long values

See createObject for more information about object parameters. See IDL Java Object API for information on JIDL* objects.

  1. Create a Java file named idlexfoo_example.java and save it in the Export directory created by the Assistant. Include the following lines of code in the file:
// Reference the default package generated by the Assistant.
package idlexfoo;
 
// Reference the javaidl export bridge classes.
import com.idl.javaidl.*;
 
//Create main class, subclassing from object created by
//Bridge Assistant. You can either subclass or create a
//member variable of the object.
public class idlexfoo_example extends idlexfoo implements JIDLOutputListener
{
  //Create a variable referencing the exported object
  private idlexfoo fooObj;
   
  // Constructor.
  public idlexfoo_example()
  {
  // These are the parameters we want to pass to
  // the ::Init method
  String str = "I am a string parameter";
  int var = 24;
  int[][] array = {{10, 11, 12}, {20, 21, 22}};
   
  // Wrap the Java types using Export Bridge data types
  JIDLString parmStr = new JIDLString(str);
  JIDLInteger parmVar = new JIDLInteger(var);
  JIDLArray parmArray = new JIDLArray(array);
   
  // Create the wrapper object
  fooObj = new idlexfoo();
   
  // Set up parameters to pass to createObject
  final int ARGC = 3;
  Object[] argv = new Object[ARGC];
  int[] argp = new int[ARGC];
   
  // NOTE: JIDLConst.PARMFLAG_CONST indicates
  // "in-only" parameter argv[0] = parmStr;
  argp[0] = JIDLConst.PARMFLAG_CONST;
  argv[1] = parmVar;
  argp[1] = JIDLConst.PARMFLAG_CONST;
  argv[2] = parmArray;
  argp[2] = JIDLConst.PARMFLAG_CONST;
   
  // Add output listener to access IDL output.
  fooObj.addIDLOutputListener(this);
   
  // Create the underlying IDL object and call
  // its ::Init method with parameters
  fooObj.createObject(ARGC, argv, argp);
  fooObj.executeString("PRINT, 'Created object'");
  }
   
  // implement JIDLOutputListener
  public void IDLoutput(JIDLObjectI obj, String sMessage)
  {
  System.out.println("IDL: "+sMessage);
  }
   
  //Instantiate a member of the class.
  public static void main(String[] argv)
  {
  idlexfoo_example exampleObj = new idlexfoo_example();
  }
}
  1. Open the Windows Command window by selecting Start > Run and enter
    cmd in the textbox.
  2. Use the cd command to change to the directory containing the idlexfoo directory.
  3. Reference the classpath of javaidlb.jar in the compile statement. Enter the following two commands (as single lines) to compile and execute the program, replacing IDL_DIR with the IDL installation directory:
    javac -classpath ".;IDL_DIR\resource\bridges\export\java\javaidlb.jar" idlexfoo\idlexfoo_example.java
    java -classpath ".;IDL_DIR\resource\bridges\export\java\javaidlb.jar" idlexfoo.idlexfoo_example

Tip: See Note on Running the Java Examples for information on non-Windows-style compile and execution commands.

After compiling and running the project, the output message will appear in the command window.