|
IDL Connectivity Bridges: Creating Custom Java Export Objects |
|
Nondrawable objects provide access to the enormous processing power of IDL, but do not provide IDL drawing capabilities. This is useful for applications that need the data manipulation capabilities of IDL, but have no need for, or have independent drawing capabilities.
The following simple example creates an IDL object with a single function method that accepts one argument, and walks through the process of exporting the object using the Export Bridge Assistant. Once the export files are created, a simple Java application shows how to access the object method and capture its output.
Complete the following steps to duplicate this example.
helloworldex__define.pro in your working directory:
; Method returns message based on presence or
; absence of argument.
FUNCTION helloworldex::HelloFrom, who
IF (N_ELEMENTS(who) NE 0) THEN BEGIN
message = "Hello World from " + who
RETURN, message
ENDIF ELSE BEGIN
message = 'Hello World'
RETURN, message
ENDELSE
END
; Init returns object reference on successful
; initialization.
FUNCTION helloworldex::INIT
RETURN, 1
END
; Object definition.
PRO helloworldex__define
struct = {helloworldex, $
who: '' , $
message: ' ' $
}
END
| Note It is a good idea to test the functionality of an object before exporting it. After compiling the file, enter the following lines at the command line and make sure the output is what is expected for this object. ohello = OBJ_NEW("HELLOWORLDEX") PRINT, ohello->HelloFrom() PRINT, ohello->HelloFrom('Mr. Bill') |
New Project
Java and browse to select the helloworldex__define.pro file. Click Open to load the file into the Export Assistant.
| Note Export Bridge Assistant details are available in Specifying Information for Exporting. Refer to that section if you need more information about the following steps. |
Save project. Accept the default name and location or make changes as desired.
Build object. The Build log panel shows the results of the build process. A subdirectory, named helloworldex (based on the object name), contains the .java and .class files, and is located in the Output directory. The following simple Java application uses the wrapper object created in the previous section.
| Example Code The file for this example, helloworldex_example.java, is located in the examples/doc/bridges/java subdirectory of the IDL distribution. |
helloworldex_example.java in the previously referenced directory and save the file in the helloworldex directory.
Run and enter cmd in the textbox.
cd command to change to the directory containing the helloworldex directory.
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" helloworldex\helloworldex_example.java java -classpath ".;IDL_DIR\resource\bridges\export\java\javaidlb.jar" helloworldex.helloworldex_example
| Tip See Note on Running the Java Examples for information on executing Java commands on a non-Windows platform. |
After compiling and running the project, the output message will appear in the command window.
IDL Online Help (March 06, 2007)