2. Call an EGL Program From Java

Download Report

Transcript 2. Call an EGL Program From Java

®
IBM Software Group
Java Calling EGL
You may need to find ways for your Java Classes and EJBs to call EGL resources.
Here are steps and directions.
© 2006 IBM Corporation
OPTIONAL TOPIC – Calling EGL From Java Classes Using JavaWrappers
As mentioned in the beginning of this unit, you can call EGL programs, from native
(hand-coded) Java classes.
 To do this, you will “wrap” the EGL programs and their parameters with EGL “Java
Wrappers”
 What are Java Wrappers?
Java classes that simplify calling EGL programs from Java
Your Java code works with Java types, and conversion to EGL types is performed
automatically by the wrapper.
Steps:
1. Create the EGL Program
 Code
 Syntax check and validate
2. Create a new build descriptor with options set for wrapping an EGL program
– Set the build descriptor option: enableJavaWrapperGen = YES
 Create a CallLink (Linkage Option) element for the EGL called program, with:
– type = remoteCall, javaWrapper = YES
 Assign to the JavaWrapper Build Descriptor to the new program
 Generate the Program
3. Create (code) the native Java Class and Save (which will generate)
4. Run the Java Class – which will call your EGL program
Last update: 12/04/2007
2
1. Call an EGL Program From Java – Create the EGL Program
From the \programs\ folder, under \EGLSource\ create a new EGL program named:
JavaCallEGL
 Notes:
 Use this code – for the lab (see screen capture)
 Make the program name start with an upper-case character
 The generated JavaWrapper will have an upper-case character, by default
 The Notes contains this code (if you’re in a hurry )
 Save (Ctrl/S) and make sure you have no syntax errors
Last update: 12/04/2007
3
 2. Call an EGL Program From Java – Create a New Build Descriptor
As you did earlier in the course, create a new EGL Build
Descriptor for your new program, following these
detailed directions:
From the Project Explorer, you will copy the existing batchBuildFile
options:
1. Right-click over batchBuildFile.eglbld and select: Open With > Text Editor
2. From inside the file: Press Ctrl/A (to select all) … then Ctrl/C (to copy all
selected text to the Windows buffer)
3. Close the file
Next you will create a new EGL build file, and paste the copied entries
into it:
4. From Project Explorer, right-click over \EGLSource\ and select: New >
Other…
 Expand EGL and select: EGL Build File
5 From the next wizard, name the file: JavaWrapBuildDescriptor
6. Close the new build file (you need to re-open and edit it in Text Editor mode)
7. Reopen JavaWrapBuildDescriptor file using the Text Editor
8. From the ***Notes part of this slide, copy and paste the contents 
9. Save your changes (Ctrl/S) and close the file
Now you will assign (or associate) the new JavaWrapBuildDescriptor to
the new program:
10. From Project Explorer, right-click over your new JavaCallEGLProgram Under \EGLSource\programs\ select:
 Properties (note this option is usually at or near the bottom of the Context
Menu)
11. From EGL Default Build Descriptors, select
<JavaWrapBuildDescriptor.eglbld> for both:
 Target system build descriptor
 Debug build descriptor
12. Close the Properties view
13. Generate
Last update: 12/04/2007
the JavaCallEGL program
4
From the above, note the following:
 Standard <BuildDescriptor…> entries
 <ResourceAssocations…> entry,
Which would be used if the program
accessed an external file
 LinkageOptions entry (named javaWrapOption)
With a single <callLink> entry
For a <remoteCall…> to your EGL program
With option: javaWrapper=“YES” specified
 3. Call an EGL Program From Java – Create the Java Class
As you did earlier in the course, create a new Java Class file, following these detailed instructions:
 From Project Explorer: Right-click over \Java Resources: src\egljava\ package and create a new
Java Class named:
Last update: 12/04/2007
InvokeEGL
- Using the copy/paste code in the ***Notes
5
 4. Call an EGL Program From Java – Run the Java Class
From Project Explorer:
Right-click over
\Java Resources:
src\egljava\
package\InvokeEGL.java and
select :
Run As >
1. Java Application
Note the Console when the
run completes
Last update: 12/04/2007
6