以下是带有具有子结构的数组的固定记录部件的示例:
Record myPart type basicRecord 10 MyTopStructure CHAR(20)[5]; 20 MyStructureItem01 CHAR(10); 20 MyStructureItem02 CHAR(10); end
在后面的描述中,将给定程序的包装器类称为程序包装器类、参数包装器类、动态数组包装器类和具有子结构的项数组包装器类。
EGL 为每个参数包装器类、动态数组包装器类或具有子结构的项数组包装器类生成一个 BeanInfo 类。BeanInfo 类允许将相关包装器类用作与 Java 相符的 Java bean。您基本上不会与 BeanInfo 类进行交互操作。
在生成包装器时,被调用程序的参数列表不能包括类型为 BLOB、CLOB、STRING、Dictionary、ArrayDictionary 或非固定记录的参数。
import com.ibm.javart.v6.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); } }
myProgram = new MyprogramWrapper(powerServer);
Mypart myParm = myProgram.getMyParm(); Mypart2 myParm2 = myProgram.getMyParm2();
myRecArrayVar myParm3 = myProgram.getMyParm3();
有关与动态数组进行交互的详细信息,请参阅动态数组包装器类。
用户标识和密码不用于数据库访问。
myProgram.callOptions.setUserID("myID"); myProgram.callOptions.setPassword("myWord"); myUserID = myProgram.callOptions.getUserID(); myPassword = myProgram.callOptions.getPassword();
myProgram.execute();
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); } }
程序包装器类包含生成的程序中的每个参数的专用实例变量。如果参数是记录或表单,则变量表示相关参数包装器类的实例。如果参数是数据项,则变量具有基本 Java 类型。
本帮助页面末尾的表描述了 EGL 与 Java 类型之间的转换。
purposeParmname()
setPassword(passWord) setUserid(userid) getPassword() getUserid()
Sun 公司的 JavaBean 规范对 PropertyChange 事件作了描述。
Mypart myRecWrapperObject = myProgram.getMyrecord();
在此例中,您正在使用由程序包装器对象分配的内存。
也可以使用参数包装器类来声明内存,如果调用程序对象的 call 方法(而不是 execute 方法),则必需执行此操作。
purposesiName()
purposesiNameNullIndicator()
ParameterClassname.ArrayClassName
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
如果参数 Company 基于 CompanyPart,则使用字符串 CompanyPart.Departments 作为内部类的名称。
内部类的内部类扩展了点线语法的使用。在此示例中,使用符号 CompanyPart.Departments.Functioncode 来作为 Departments 的内部类名称。
有关如何命名具有子结构的项数组包装器类的其它详细信息,请参阅 Java 包装器生成的输出。
Program myProgram(intParms int[], recParms MyRec[])
动态数组包装器类的名称是 IntParmsArray 和 MyRecArray。
IntParmsArray myIntArrayVar = myProgram.getIntParms(); MyRecArray myRecArrayVar = myProgram.getRecParms();
在为每个动态数组声明变量之后,您可能会添加元素:
// 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);
如该示例所建议的那样,EGL 提供了多个用于处理所声明的变量的方法。
动态数组类的方法 | 用途 |
---|---|
add(int, Object) | 在 int 指定的位置插入对象并将当前及后续元素向右移。 |
add(Object) | 将对象追加至动态数组末尾。 |
addAll(ArrayList) | 将 ArrayList 追加至动态数组末尾。 |
get() | 检索包含数组中的所有元素的 ArrayList 对象 |
get(int) | 检索位于由 int 指定的位置中的元素 |
makeNewElement() | 分配具有特定于数组的类型的新元素并检索该元素,而不将该元素添加到动态数组中。 |
maxSize() | 检索一个整数,该整数指示了动态数组中的最大元素数目(但不是实际元素数目) |
remove(int) | 除去位于由 int 指定的位置中的元素 |
set(ArrayList) | 使用指定的 ArrayList 来替换动态数组 |
set(int, Object) | 使用指定的对象来替换位于由 int 指定的位置中的元素 |
size() | 检索动态数组中的元素数目 |
下表指示生成的程序中的 EGL 基本类型与生成的包装器中的 Java 数据类型之间的关系。
EGL 基本类型 | 按字符或数字所计的长度 | 按字节计的长度 | 小数位数 | Java 数据类型 | Java 的最大精度 |
---|---|---|---|---|---|
CHAR | 1-32767 | 2-32766 | 不适用 | String | 不适用 |
DBCHAR | 1-16383 | 1-32767 | 不适用 | String | 不适用 |
MBCHAR | 1-32767 | 1-32767 | 不适用 | String | 不适用 |
UNICODE | 1-16383 | 2-32766 | 不适用 | String | 不适用 |
HEX | 2-75534 | 1-32767 | 不适用 | byte[] | 不适用 |
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 |
相关任务
生成 Java 包装器