A Java wrapper is a set of classes that act as an interface between the following executables:
You generate the Java wrapper classes if you use a build descriptor that has these characteristics:
If an EJB session bean mediates between the Java wrapper classes and an EGL-generated program, you generate the EJB session if you use a build descriptor that has these characteristics:
For further details on using the classes, see Java wrapper classes. For details on the class names, see Generated output (reference).
Related concepts
COBOL program
Generated output
Java program, page handler, and library
Run-time configurations
Related tasks
Generating Java wrappers
Related reference
Generated output (reference)
Java wrapper classes
Output of Java wrapper generation
When you request that a program part be generated as a Java wrapper, EGL produces a wrapper class for each of the following:
An example of a record part with a substructured array is as follows:
Record myPart type basicRecord 10 MyTopStructure CHAR(20)[5]; 20 MyStructureItem01 CHAR(10); 20 MyStructureItem02 CHAR(10); end
Later descriptions refer to the wrapper classes for a given program as the program wrapper class, the parameter wrapper classes, the dynamic array wrapper classes, and the substructured-item-array wrapper classes.
EGL generates a BeanInfo class for each parameter wrapper class, dynamic array wrapper class, or substructured-item-array wrapper class. The BeanInfo class allows the related wrapper class to be used as a Java-compliant Java bean. You probably will not interact with the BeanInfo class.
To use the wrapper classes to communicate with a program generated with VisualAge Generator or EGL, do as follows in the native Java program:
import com.ibm.vgj.cso.*; public class MyNativeClass { /* declare a variable for middleware */ CSOPowerServer powerServer = null; try { powerServer = new CSOLocalPowerServerProxy(); } catch (CSOException exception) { System.out.println("Error initializing middleware" + exception.getMessage()); System.exit(8); } }
The call to the constructor includes the middleware object:
myProgram = new MyprogramWrapper(powerServer);
Mypart myParm = myProgram.getMyParm(); Mypart2 myParm2 = myProgram.getMyParm2();
If your program has parameters that are dynamic arrays, declare additional variables that are each based on a dynamic array wrapper class:
myRecArrayVar myParm3 = myProgram.getMyParm3();
For details on interacting with dynamic arrays, see Dynamic array wrapper classes.
The userid and password are not used for database access.
You set and review the userid and password by using the callOptions variable of the program object, as in this example:
myProgram.callOptions.setUserID("myID"); myProgram.callOptions.setPassword("myWord"); myUserID = myProgram.callOptions.getUserID(); myPassword = myProgram.callOptions.getPassword();
myProgram.execute();
If the database unit of work is under client control, processing includes use of commit and rollback methods of the middleware object:
powerServer.commit(); powerServer.rollback();
if (powerServer != null) { try { powerServer.close(); powerServer = null; } catch(CSOException error) { System.out.println("Error closing middleware" + error.getMessage()); System.exit(8); } }
The program wrapper class includes a private instance variable for each parameter in the generated program. If the parameter is a record or form, the variable refers to an instance of the related parameter wrapper class. If the parameter is a data item, the variable has a primitive Java type.
A table at the end of this help page describes the conversions between EGL and Java types.
A program wrapper object includes the following public methods:
purposeParmname()
Instead of assigning values to the instance variables, you can do as follows:
The program wrapper object also includes the callOptions variable, which has the following purposes:
setPassword(passWord) setUserid(userid) getPassword() getUserid()
The userid and password are used when you set the remoteComType property of the callLink element to one of the following values:
Finally, consider the following situation: your native Java code requires notification when a change is made to a parameter of primitive type. To make such a notification possible, the native code registers as a listener by invoking the addPropertyChangeListener method of the program wrapper object. In this case, either of the following situations triggers the PropertyChange event that causes the native code to receive notification at run time:
The PropertyChange event is described in the JavaBean specification of Sun Microsystems, Inc.
A parameter wrapper class is produced for each record that is declared as a parameter in the generated program. In the usual case, you use a parameter wrapper class only to declare a variable that references the parameter, as in the following example:
Mypart myRecWrapperObject = myProgram.getMyrecord();
In this case, you are using the memory allocated by the program wrapper object.
You also can use the parameter wrapper class to declare memory, as is necessary if you invoke the call method (rather than the execute method) of the program object.
The parameter wrapper class includes a set of private instance variables, as follows:
The parameter wrapper class includes several public methods:
purposesiName()
purposesiNameNullIndicator()
A substructured-item-array wrapper class is an inner class of a parameter class and represents a substructured array in the related parameter. The substructured-item-array wrapper class includes a set of private instance variables that refer to the structure items at and below the array itself:
The substructured-item-array wrapper class includes the following methods:
In most cases, the name of the top-most substructured-item-array wrapper class in a parameter wrapper class is of the following form:
ParameterClassname.ArrayClassName
Consider the following record, for example:
Record CompanyPart type basicRecord 10 Departments CHAR(20)[5]; 20 CountryCode CHAR(10); 20 FunctionCode CHAR(10)[3]; 30 FunctionCategory CHAR(4); 30 FunctionDetail CHAR(6); end
If the parameter Company is based on CompanyPart, you use the string CompanyPart.Departments as the name of the inner class.
An inner class of an inner class extends use of a dotted syntax. In this example, you use the symbol CompanyPart.Departments.Functioncode as the name of the inner class of Departments.
For additional details on how the substructured-item-array wrapper classes are named, see Output of Java wrapper generation.
A dynamic array wrapper class is produced for each dynamic array that is declared as a parameter in the generated program. Consider the following EGL program signature:
Program myProgram(intParms int[], recParms MyRec[])
The name of the dynamic array wrapper classes are IntParmsArray and MyRecArray.
You use a dynamic array wrapper class to declare a variable that references the dynamic array, as in the following examples:
IntParmsArray myIntArrayVar = myProgram.getIntParms(); MyRecArray myRecArrayVar = myProgram.getRecParms();
After declaring the variables for each dynamic array, you might add elements:
// adding to an array of Java primitives // is a one-step process myIntArrayVar.add(new Integer(5)); // adding to an array of records or forms // requires multiple steps; in this case, // begin by allocating a new record object MyRec myLocalRec = (MyRec)myRecArrayVar.makeNewElement(); // the steps to assign values are not shown // in this example; but after you assign values, // add the record to the array myRecArrayVar.add(myLocalRec); // next, run the program myProgram.execute(); // when the program returns, you can determine // the number of elements in the array int myIntArrayVarSize = myIntArrayVar.size(); // get the first element of the integer array // and cast it to an Integer object Integer firstIntElement = (Integer)myIntArrayVar.get(0); // get the second element of the record array // and cast it to a MyRec object MyRec secondRecElement = (MyRec)myRecArrayVar.get(1);
As suggested by that example, EGL provides several methods for manipulating the variables that you declared.
Method of the dynamic array class | Purpose |
---|---|
add(int, Object) | To insert an object at the position specified by int and to shift the current and subsequent elements to the right. |
add(Object) | To append an object to the end of the dynamic array. |
addAll(ArrayList) | To append an ArrayList to the end of the dynamic array. |
get() | To retrieve the ArrayList object that contains all elements in the array |
get(int) | To retrieve the element that is in the position specified by int |
makeNewElement() | To allocate a new element of the array-specific type and to retrieve that element, without adding that element to the dynamic array. |
maxSize() | To retrieve an integer that indicates the maximum (but not actual) number of elements in the dynamic array |
remove(int) | To remove the element that is in the position specified by int |
set(ArrayList) | To use the specified ArrayList as a replacement for the dynamic array |
set(int, Object) | To use the specified object as a replacement for the element that is in the position specified by int |
size() | To retrieve the number of elements that are in the dynamic array |
Exceptions occur in the following cases, among others:
EGL creates a name in accordance with these rules:
The following rules apply to dynamic array wrapper classes:
The next table indicates the relationship of EGL primitive types in the generated program and the Java data types in the generated wrapper.
EGL primitive type | Length in chars or digits | Length in bytes | Decimals | Java data type | Maximum precision in Java |
---|---|---|---|---|---|
CHAR | 1-32767 | 2-32766 | NA | String | NA |
DBCHAR | 1-16383 | 1-32767 | NA | String | NA |
MBCHAR | 1-32767 | 1-32767 | NA | String | NA |
UNICODE | 1-16383 | 2-32766 | NA | String | NA |
HEX | 2-75534 | 1-32767 | NA | byte[] | NA |
BIN, SMALLINT | 4 | 2 | 0 | short | 4 |
BIN, INT | 9 | 4 | 0 | int | 9 |
BIN, BIGINT | 18 | 8 | 0 | long | 18 |
BIN | 4 | 2 | >0 | float | 4 |
BIN | 9 | 4 | >0 | double | 15 |
BIN | 18 | 8 | >0 | double | 15 |
DECIMAL, PACF | 1-3 | 1-2 | 0 | short | 4 |
DECIMAL, PACF | 4-9 | 3-5 | 0 | int | 9 |
DECIMAL, PACF | 10-18 | 6-10 | 0 | long | 18 |
DECIMAL, PACF | 1-5 | 1-3 | >0 | float | 6 |
DECIMAL, PACF | 7-18 | 4-10 | >0 | double | 15 |
NUM, NUMC | 1-4 | 1-4 | 0 | short | 4 |
NUM, NUMC | 5-9 | 5-9 | 0 | int | 9 |
NUM, NUMC | 10-18 | 10-18 | 0 | long | 18 |
NUM, NUMC | 1-6 | 1-6 | >0 | float | 6 |
NUM, NUMC | 7-18 | 7-18 | >0 | double | 15 |
Related concepts
Java wrapper
Run-time configurations
Related tasks
Generating Java wrappers
Related reference
callLink element
How Java wrapper names are aliased
Linkage properties file (details)
Output of Java wrapper generation
remoteBind in callLink element
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.