attachment_14052326_ExternalTypes

Download Report

Transcript attachment_14052326_ExternalTypes

Topic
EGL and Remote Programs
Sub-Topics:
 EGL Calls to Remote Programs (Overview)
 Java (terms and concepts)
 Calling Java using EGL’s externalType Part
 Calling Java using JavaLib
 Calling COBOL Programs
 Calling RPG Programs
1
EGL externalType Part
 An externalType part provides the EGL mapping to a Java Class. This is similar to the
mapping that an EGL Interface provides for Web Service functions, but extends to map Java
class variables and constructors.
 Invoking ExternalType functions
 If the class or function is marked static,
 Simply invoke it using the name of its externalType part and use dot syntax to reference the methods
typeName.methodName();

If the class or function is non-static (more typical)
 Create a variable based on its externalType part – initialize it with a new keyword
 Use it in much the same way you would a library name (use dot syntax for the methods)
externalTypeVariable.methodName();
externalType Declaration
Two class variables
One custom method
class “constructor method”
Variable of externalType(TaxModule)
Create new (non-static) instance
Initialize class variable values
Call calculateTax routine
2
EGL externalType for the HelloEGLworld Class
 The externalType we will use to interface with the HelloEGLworld Java class
EGL variable declaration for the externalType. Notes:
- Creates a new instance of the Java class (in memory)
- Passes two values into the class variables
List of EGL  Java types.
3
Workshop – Create a Java Class and Call it From an EGL Program
 To see how all this works together, you will complete a workshop as follows (from 10,000 feet)

You will:
 Create a new Java Class
 Create a new EGL program that contains:


An EGL externalType of the Java Class
Calls to the Java functions – through the externalType
 Access of the Java class variables - through the externalType

After finishing that, we’ll do two additional things:
 Learn how to call Java API’s through the EGL JavaLib (built-in system) functions
 Pass string arrays back and forth between EGL and Java
4
Create a new Java Package and Class
 From Navigator,
 Right-click over \Java Resources: src\ and
create a folder named: egljava
 Right-click over egljava and create a new
Java class named: HelloEGLworld
 Using the copy/paste code in the Notes, create
your first Java class…
Press Ctrl/S – to save
and compile your .java
source to a .class file
5
Workshop continued – Create a new EGL Program
 From Project Explorer, right-click over the \EGLSource\programs\ directory, and
create a new, EGL program
callJava

Name the program:

From within the code, copy/delete and replace the boilerplate code, with the complete program
solution shown below, in the Notes area of this slide
Functions
externalType Definition
Top section of callJava program
With your mouse cursor inside
the source, press:
• Ctrl/S (why)?
• Ctrl/G (why)?
6
Workshop continued – Debug the EGL Program and Java Calls
 Add a Breakpoint to the callJava.egl program
 From Project Explorer, right-click over the \EGLSource\programs\callJava.egl
select Debug EGL Program…

Step through the
code

Note the variable
values before and
after the calls
to the Java Class!
7
Additional Info on External Types
 When creating external types, you may
run into a Java ”final” type variable
within the Java class you’re calling.
 If you need to access this variable from
EGL, it will need to be defined in your
externalType.
 The syntax is the same as with any
other variable. Note, you do not need to
include a “final” indicator.
 Additionally, a cross-language conflict
can occur when creating external types
that have conflicting method/variable
names.
 i.e. If the name of a Java method is the
same as an EGL reserved word, your
externalType will not compile.
 To fix this you must add the “JavaName”
property to the function declaration.
Invalid
Valid
8
Topic
EGL and Remote Programs
Sub-Topics:
 EGL Calls to Remote Programs (Overview)
 Java (terms and concepts)
 Calling Java using the externalType Part
 Calling Java using JavaLib
 Calling COBOL Programs
 Calling RPG Programs
9
EGL’s JavaLib Built-in System Function
 If you are not calling a custom Java Class, but only calling a static Java API (think of these
as Java library “built-in-functions”) – you can dispense with having to define a new
externalType, and call the API using the JavaLib Built-in Function.
Here are the JavaLib
function calls
We are interested in:
 invoke()
 store()
10
EGL’s JavaLib invoke() and store() Functions
 With JavaLib you can:
 invoke() – call a static Java API (i.e. call a class that does NOT need to be created as a new instance)

Format: JavaLib.invoke(“packge.class”,”method”,<Optional parameter>);
 store() – call a non-Static Java API and return an Object (instead of a Java primitive)

Format: JavaLib.store(“objVariable” as "objID:java", “package.class", “method“);
Notes on store()
 You tell Java to create a new Class instance (i.e. an object) and store it, in a temporary variable
identified as the first parameter to store()
 You add the boilerplate: as "objID:java",
 You specify which package.sub-package.class, etc.
 And the method that returns the Java object into the temporary variable
11
Workshop - EGL’s JavaLib invoke() and store() Functions
 From Project Explorer, edit the \EGLSource\programs\callJava.egl
 Towards the end of the program (as shown here in the screen capture) insert the
following two functions (found in the Notes section of this slide)
 Un-comment the calls to these functions in the main() function
With your mouse cursor
inside the source, press:
• Ctrl/S
• Ctrl/G
12
OPTIONAL Workshop – Passing a String Array Between Java and EGL
 There are some situations in your projects where you may need to send an array of strings
from EGL to Java. You would use an externalType to do this (and – it’s pretty easy). Follow
these steps to see how (easy )
 From \JavaResources :src\egljava\HelloEGLworld.java – add the following new method to
the existing Java class (source code is in the Notes section of the slides):
New
Method
 Press Ctrl/S – and you will get syntax errors in the code. Add the following import statement
to the top of the file:
13
Workshop continued – Debug the EGL Program and Java Calls
 From Project Explorer, right-click over the \EGLSource\programs\callJava.egl
select Debug EGL Program and once again, step through the code
14
OPTIONAL Workshop – Passing a String Array – Modify the externalType
 From \Programs\callJava.egl – modify the EGL externalType definition we’ve been using.
Add a new function for the new Java Class method at the bottom of the externalType
Press:
 Ctrl/S
 Ctrl/G
15
OPTIONAL Workshop – Passing a String Array – Create a new JSP Page
 From \WebContent\ – As you’ve done before, create a new JSP page, named: callJavaPage
 For the page’s JSFHandler, add the following code (which you can copy from the Notes section
below)
Notes:
 Import statement – to provide reference-ability to the externalType definition
 Declare two fixed-length string arrays – one initialized with values (to be passed into the Java Class),
one empty that will contain data returned from the Java Class call
 Declare a variable for the externalType – used in the previous workshop
16
OPTIONAL Workshop – Passing a String Array – Create a new JSP Page
 From Page Designer, and from Page Data, drag and drop: strArray2 – string[] on to the page,
and create output controls.
17
OPTIONAL Workshop – Run the Page on the Server
 Right-click over the page, and select Run on Server
Note the following:




The Java class was called, and an array of strings was passed to the function
The function concatenated the values passed in, with the literal “: Java”
The array returned (and eventually displayed through the page’s dataTable) is a copy of this new data
Open the Console view. Scroll up, and you’ll see the following SystemOut messages,
written there by the Java function
18