Fujitsu J Adapter Class Generator User Manual

0 (0)
J Adapter Class
Generator User’s Guide
Seventh Edition: August 2005
The contents of this manual may be revised without prior notice. No part of this document may be reproduced or transmitted in any form or by any means, electronic or mechanical, for any purpose, without the express written permission of Fujitsu Limited.

Preface

The "NetCOBOL (adapter class) used to call a Java class. Using the adapter class thus generated makes the Java class library available from COBOL.
A Java runtime environment must be installed to execute the generator or the adapter class generated. See "
J Adapter Class Generator
Preparations
" is a tool that generates a COBOL class
" for required products.

Purpose of This Manual

This manual provides information on how to enable COBOL programs to use Java classes. The information includes the ways of creating adapter classes, writing programs, and running the programs.
Refer to the information on how to develop programs using Fujitsu NetCOBOL, refer to the
NetCOBOL User's Guide
Fujitsu NetCOBOL Language Reference
.
for the COBOL syntax. For
Fujitsu

Intended Readers

This manual is intended for persons who develop COBOL programs using Java classes.

Prerequisites

Readers are required to have the following knowledge to read this manual:
Basic knowledge of COBOL syntax
• • Basic knowledge of COBOL object-oriented programming
Basic knowledge of Java

Organization of This Manual

This manual consists of the following chapters:
Chapter 1. Outline of J Adapter Class Generator
Chapter 1 explains the function and operating environment of the J adapter class generator.
Chapter 2. J Adapter Class Generator Framework
Chapter 2 explains the framework of the J adapter class generator.
Chapter 3. Developing Programs
Chapter 3 explains how to develop programs that uses Java classes.
Chapter 4. Using the Generator Command
Chapter 4 explains how to use the generator command (java2cob).
NetCOBOL J Adapter Class Generator User's Guide 3
Chapter 5. Adapter Class Reference
Chapter 5 provides detailed information on the FJ-JAVA-BASE, FJ-JAVA-CONTROL and FJ-JAVA-ERROR classes provided by the J adapter class generator, and adapter classes generated by the J adapter class generator.
Appendix A. Message List
Appendix A explains the messages output by the J adapter class generator, including the operator responses to the messages.
Appendix B. Exception Type List
The Appendix B describes the types of exception generated by the J adapter class generator and their remedial measures.

How to Use This Manual

When using the J adapter class generator for the first time, begin to read from Chapter 1. Chapter 1 provides an outline of the J adapter class generator, Chapter 2 explains the framework, and Chapter 3 explains the procedures from development to execution.
Chapters 4 and 5 provide detailed information on how to use commands and classes. Read these chapters for program development.
The Appendix A describes the messages that are output form the J adapter class generator and the Appendix B describes the exception types that the J adapter class generator sets. Read them as necessity requires.

Product Names

Product Name Abbreviation
Microsoft® Windows® 98 Operating System Windows® 98 Microsoft® Windows® Me Operating System Windows® Me Microsoft® Windows NT® Workstation Operating System Version
4.0 Microsoft® Windows NT® Server Network Operating System,
Version 4.0 Microsoft® Windows NT® Server Network Operating System,
Enterprise Edition Version 4.0 Microsoft® Windows® 2000 Professional Operating System Windows® 2000 or
Microsoft® Windows® 2000 Server Operating System Windows® 2000 or
Microsoft® Windows® 2000 Advanced Server Operating System Windows® 2000 or
Microsoft® Windows® 2003 Server Operating System Windows® 2003 or
Windows® 98, Windows® Me, Windows NT®, and Windows® 2000 Windows
Windows NT® or Windows NT® 4.0
Windows NT® or Windows NT® 4.0
Windows NT® or Windows NT® 4.0
Windows® 2000 Professional
Windows® 2000 Server
Windows® 2000 Server
Windows® 2000 Server
®
4 NetCOBOL J Adapter Class Generator User's Guide

Registered Trademarks

The registered trademarks appearing in this manual are as follows: Microsoft, Windows, and Windows NT are registered trademarks of Microsoft
Corporation in the U.S. and other countries. Java and other trademarks including Java are trademarks of Sun Microsystems, Inc.
in the U.S. and other countries.
J Adapter Class Generator User's Guide
5
6 NetCOBOL J Adapter Class Generator User's Guide

Contents

Chapter 1. Outline of J Adapter Class Generator.........................................9
What is the J Adapter Class Generator?...............................................................10
What the J Adapter Class Generator Can Do........................................................11
What the J Adapter Class Generator Cannot Do ...................................................11
Preparation.......................................................................................................12
Chapter 2. Adapter Class Generator Framework .......................................13
Adapter Class....................................................................................................14
Adapter Object..................................................................................................15
Chapter 3. Developing Programs ...............................................................17
Creating Adapter Classes ...................................................................................18
Developing an Application That Uses an Adapter Class .........................................22
Running a Program............................................................................................29
Conversion to Java2 ..........................................................................................30
Chapter 4. Using the Generator Command................................................31
Starting the J Adapter Class Generator................................................................32
Optional File .....................................................................................................36
Output .............................................................................................................42
Chapter 5. Adapter Class Reference ..........................................................45
Class Configuration............................................................................................46
FJ-JAVA-BASE class ...........................................................................................47
FJ-JAVA-CONTROL class ....................................................................................48
FJ-JAVA-ERROR class.........................................................................................50
Class or Interface Adapter Class .........................................................................51
java-lang-String class.........................................................................................61
Array Adapter Class...........................................................................................65
Numbering Names.............................................................................................69
Chapter 6. Messages ..................................................................................73
Java2cob Command Messages............................................................................74
Messages Output during Generation....................................................................74
NetCOBOL J Adapter Class Generator User's Guide 7
Messages Output during Execution .....................................................................77
Chapter 7. Samples ....................................................................................81
Sample 1 – Using Classes...................................................................................81
Sample 2 – Specifying Method............................................................................83
Appendix A. Message List...........................................................................85
Java2cob Command Messages............................................................................86
Messages Output during Generation....................................................................87
Messages Output during Execution .....................................................................90
Appendix B. Exception Type List................................................................93
Index...........................................................................................................97
8 NetCOBOL J Adapter Class Generator User's Guide

Chapter 1. Outline of J Adapter Class Generator

This chapter explains the function and operating environment of the J adapter class generator.
10 Chapter 1. Outline of J Adapter Class Generator

What is the J Adapter Class Generator?

Taking advantage of the object-oriented function, Fujitsu NetCOBOL enables programming using class libraries . The Fujitsu NetCOBOL also provides many useful foundation classes. Meantime, as Java becomes popular, many Java class libraries are also provided. However, the class structure varies from language to language and therefore Java class libraries cannot normally be used from COBOL.
The J adapter class generator provides a framework that enables COBOL to use Java classes.
The J adapter class generator enables a COBOL program to:
Use a Java class library.
Call a Java application.
Use an application program interface (API) provided for Java.
The J adapter class generator enables COBOL to be used for systems that previously could only have been implemented in Java.
Use of the J adapter class generator is recommended in the following situations:
Constructing a COBOL system using Java common parts such as EJB components.
Constructing a COBOL system using whole Java applications.
An outline of the J adapter class generator is given below:
Figure 1.1
Chapter 1. Outline of J Adapter Class Generator 11
The Java class interface must be converted into the COBOL interface for a COBOL program to use Java classes. The J adapter class generator generates an adapter class that converts the Java interface into the COBOL interface.

What the J Adapter Class Generator Can Do

Using adapter classes generated by the J adapter class generator enables the following types of operation for Java.
To COBOL programs, Java objects seem to be COBOL objects. Therefore, Java objects can be handled the same way as ordinary COBOL objects.
Accessing a class variable Access to a public class variable (static field) declared in a Java class is enabled.
COBOL handles it as a factory property.
Invoking a class method A public class method (static method) declared in a Java class can be invoked.
COBOL handles it as a factory method.
Generating an instance object (invoking a constructor) Invoking a constructor can create a Java instance object. COBOL handles it as a
factory method that returns an object. Accessing an instance variable
Access to a public instance variable (non-static field) of a Java instance object is enabled. COBOL handles it as an object property.
Invoking an instance method
A public instance method (non-static method) of a Java instance object can be invoked. COBOL handles it as an object method.
Receiving an exception An exception caused when a class method, constructor, or instance method is
invoked can be trapped to perform error processing. COBOL uses the USE statement to receive an exception object.

What the J Adapter Class Generator Cannot Do

The J adapter class generator cannot perform the following types of operation:
• • Inheriting a Java class
A COBOL class inheriting a Java class cannot be defined. Even if a COBOL class inherits an adapter class, the Java class function cannot be overwritten.
Passing a COBOL object as a parameter No COBOL object can be passed as a parameter for invoking a method, nor can
a COBOL object be set for a Java field. Only an adapter object produced by wrapping a Java object can be passed to Java.
12 Chapter 1. Outline of J Adapter Class Generator
Therefore, the following restrictions apply to COBOL:
- Listener
Java registers a listener object, in which event processing logic is written, within an object that generates an event. However, since no COBOL object can be registered in a Java object, COBOL cannot be used to write listeners.
- Collection class
No COBOL object can be registered in a Java collection class. When using COBOL objects as a collection, use a COBOL collection class.
• • Class having a Japanese name
No class name, field name, and method name can include the Japanese character set.
Invoking COBOL from Java No COBOL program can be invoked from Java. A COBOL program invoked from
Java can use no adapter class.

Preparation

The following products are required for the development or execution environment for using the J adapter class generator.

Fujitsu NetCOBOL or Fujitsu NetCOBOL Runtime System

Fujitsu NetCOBOL is required to develop programs using the J adapter class generator. Fujitsu NetCOBOL or Fujitsu NetCOBOL Runtime System is required to execute applications developed by the J adapter class generator.

Java Development Kit or Java Runtime Environment

Java Development Kit (JDK) is provided by Sun Microsystems, Inc. provides the basic general-purpose class libraries required for program development with Java.
Java 2 SDK (J2SDK) is a software development kit available for creating applications conforming to Java 2 released by Sun Microsystems, Inc. J2SDK provides basic general-purpose class libraries required for program development with Java 2.
Java Runtime Environment (JRE) is the JDK runtime environment released by Sun Microsystems, Inc. It is required to run programs developed with Java.
Java 2 Runtime Environment (J2RE) is the run time environment of applications conforming Java 2 released by Sun Microsystems, Inc. It is required to run programs developed with Java 2.
JDK 1.1.8, J2SDK 1.2.2, or a later version is required to develop programs using the J adapter class generator. JDK 1.1.8, J2SDK 1.2.2, JRE 1.1.8, J2RE 1.2.2, or a later version is required to run applications developed using the J adapter class generator.

Chapter 2. Adapter Class Generator Framework

This chapter explains the framework of the J adapter class generator.
14 Chapter 2. Adapter Class Generator Framework

Adapter Class

To make Java classes available to COBOL, a mechanism for converting the Java class interface into the COBOL interface is required. The J adapter class generator works as an interface converting mechanism to generate adapter classes corresponding to Java classes. To use a Java class from a COBOL program, the adapter class created by the generator can be called. The adapter class is written in COBOL and therefore can be called in the same manner as a COBOL class.
The relationship between the Java class/interface and adapter class is shown below:
Figure 2.1: Java class/interface and adapter class

Adapter Object

At execution time, an adapter class generates the adapter object corresponding to a Java instance object. The adapter object:
Holds the pointer to the corresponding Java instance object.
Calls the corresponding Java method of the corresponding Java instance object Only the adapter object can be seen from the COBOL program. Every operation on
the adapter object is transmitted to the corresponding Java object. To the COBOL program, , the adapter object seems as if it were a Java object. The adapter object, since it works for the Java object, is also called a proxy object. The relationship between the Java object and adapter object is shown below:
Chapter 2. Adapter Class Generator Framework 15
Figure 2.2. Java object and adapter object
16 Chapter 2. Adapter Class Generator Framework

Chapter 3. Developing Programs

This chapter explains how to develop programs that use Java classes.
18 Chapter 3. Developing Programs

Creating Adapter Classes

This section explains how to generate an adapter class from a Java class.

Investigating the Java Class

First investigate the specifications of the Java class and interface to be used (class name, package name, usage, and so on) to check whether the J adapter class generator can handle the class and interface. See "
Generator Can Do
information on which classes and interfaces can be used.
" and "

Generating Adapter Class Source

If the target Java class and interface can be used, generate adapter class source. Use the java2cob command to generate adapter classes. The java2cob command reads the class file (extension .class) of the Java class/interface and generates the corresponding adapter class source.
What the J Adapter Class Generator Cannot Do
What the J Adapter Class
" for
The java2cob command generates adapter classes of not only the class specified by the option but also every other class/interface required to use the class.
An example of generating adapter class source from the java.util.Date class is shown below.
Figure 3.1
Note: The class file referenced by the class/interface may not always be available, depending on the execution environment. For information on how to generate
Chapter 3. Developing Programs 19
adapter classes when the class file is not available, see "
when the class file is not available
."
Generating an adapter class

Building an Adapter Class

Finally, compile and link-edit the generated adapter class source to create an adapter class library (DLL). Use the COBOL project manager to do so.
Refer to the Fujitsu NetCOBOL User's Guide for information on how to use the
COBOL project manager
Follow the procedure below to build an adapter class:
1. Create a new project using the project manager.
2. Register the target DLL.
3. Create a COBOL source file folder and store the generated adapter class in it.
4. Specify compiler options.
- Specify XXX\REP (XXX is the J adapter class generator install folder) for
REPIN.
- Specify ALPHAL (WORD).
- When creating an adapter class running with Unicode, specify RCS (UCS2).
5. To determine the compilation order, select “Repository File Search” from the “Edit” menu and then select “All”.
.
6. Create a library folder and store the runtime library F3BIJART.LIB of the J adapter class generator in it. F3BIJART.LIB is available from the LIB folder of the install folder.
7. Execute "build."
The following files are generated:
Adapter class DLL file (required for execution)
Adapter class LIB file (required for link-edition)
Adapter class repository file (required for compilation)
Generating an Adapter Class When the Class File is Not Available
The J adapter class generator references the following class information when generating an adapter class:
Super class/interface
Class/interface specified in the public method, constructor parameter, or return
value
Class/interface specified in the public variable
20 Chapter 3. Developing Programs
Therefore, an adapter class cannot be generated normally without these class files. These class files may not be available depending on the environment. In this case, to create an adapter class normally, dummy class files having these file names must be prepared.
Prepare a dummy class file as follows:
1. Create a folder corresponding to the package name. For package name aaa.bbb.ccc, for instance, create a folder with name aaa\bbb\ccc.
2. Create a Java source program satisfying the following. Assign this file the name "ClassName.java".
package PackageName; public class ClassName {}
3. Compile the source program with the Java compiler.
c:\> javac FolderName\ClassName.java
4. Enter the java2cob command.
c:\> java2cob PackageName.ClassName
Note: If a class file is referred to, but does not exist when attempting to generate an adapter class, processing is terminated with message "
found. Generation was interrupted
."
Class information was not

Reducing the Size of Adapter Class

The adapter class source generated by the J adapter class generator may be simply compiled and linked before it is used.
Since, however, the adapter source class can include class files, which are not used by the applications, there might be cases where the size of the DLL file of the adapter class is significantly larger than necessary. In a case like this, the size of the adapter class can be reduced by the following methods:
Specifying the constructor/method/field
Specifying the -om option or the "Option ReduceClass" parameter

Specifying the Constructor/Method/Field

When the constructors, methods, and fields that are used in the application are known, the number of the adapter classes generated can be reduced by specifying them.
The J adapter class generator generates only the adapter classes that are required by the specified constructors/methods/fields.
Refer to -r option, -gc option, -gm option, -gf option and "Class class­name/interface-name" parameters for details of the procedure of specifying the constructor/method/field.
Chapter 3. Developing Programs 21
Example:
When an application uses only the println (Object) method of the java.io.PrintStream class, specify as follows:
C:\> java2cob -r java.io.PrintStream -gm "println(java.lang.Object)"
Specifying the -om Option or the "Option ReduceClass" Parameter
Specifying the -om option or the "Option ReduceClass" parameter can reduce the number of adapter classes generated. To check for parameter validity at method invocation, the J adapter class generator generates adapter classes corresponding to individual parameters. Thus many adapter classes are generated for one class.
When the -om option or the "Option ReduceClass" parameter is specified, all object­type method parameters are mapped to the java-lang-Object class. This function suppresses the generation of adapter classes corresponding to the method parameters and thereby reduces the number of adapter classes generated.
Notes:
When the method of the adapter class generated with the -om option or the "Option ReduceClass" parameter specified is invoked, BY CONTENT must be specified as an object reference parameter.
When the -om option or the "Option ReduceClass" parameter is specified, the object reference types of method parameters excluding the return value become java-lang-Object and therefore the original parameter types become uncertain. Therefore, for a parameter whose object reference type becomes java-lang­Object, a parameter name is generated according to the following rules so that the original type information is included in the parameter name.
Pn-ClassName
P is followed by a parameter serial number (1 to 99).
The hyphen "-" is followed by an external class name excluding a package name
after conversion into uppercase.
A parameter name exceeding 30 characters is truncated after the 30th character.
Example:
When the -om option or the "Option ReduceClass" parameter is not specified, adapter class source java-io-PrintStream.cob of the java.io.PrintStream class becomes as shown below, and the java-io-OutputStream class is required.
... REPOSITORY. CLASS J-OUTPUTSTREAM AS "java-io-OutputStream" ... LINKAGE SECTION. 01 PARA-1 OBJECT REFERENCE J-OUTPUTSTREAM. ...
When the -om option or the "Option ReduceClass" parameter is specified, the parameter becomes the java-lang-Object type. Therefore, the java-io-OutputStream class is not required or generated.
22 Chapter 3. Developing Programs
... REPOSITORY. CLASS J-OBJECT AS "java-lang-Object" ... LINKAGE SECTION. 01 P1-OUTPUTSTREAM OBJECT REFERENCE J-OBJECT. ...

Developing an Application That Uses an Adapter Class

This section explains how to develop a program that uses an adapter class.

Outline

The flow of program processing using the adapter class is as follows:
1. Initialization of the Java VM.
2. In the case of a multithreaded application, connection of the current thread to the Java VM .
3. Generation of the object.
4. Calling the method.
5. In the case of a multithreaded application, disconnection from the Java VM .
6. Termination of the Java VM.
Also, be careful when performing the following operations:
Manipulating a variable
Comparing object references
Assignment to a subclass
Mapping java.lang.String into PIC X.
End control of character string
Exception processing

Initializing the Java VM

To use an adapter class, the Java virtual machine (VM) must first be initialized . Use the JVM-INIT method or the JVM-ATTACH method of the FJ-JAVA-CONTROL class to initialize the Java VM.
A coding sample is shown below:
... REPOSITORY. CLASS FJ-JAVA-CONTROL ... PROCEDURE DIVISION. ... INVOKE FJ-JAVA-CONTROL "JVM-INIT". ...
Chapter 3. Developing Programs 23

Terminating the Java VM

When an adapter class is no longer used, the Java VM must be terminated. Use the JVM-TERMINATE method of the FJ-JAVA-CONTROL class to terminate the Java VM.
A coding sample is shown below:
... REPOSITORY. CLASS FJ-JAVA-CONTROL ... PROCEDURE DIVISION. ... INVOKE FJ-JAVA-CONTROL "JVM-TERMINATE". ...

Developing a Multithread Application

A multithread application using an adapter class must connect the current thread to the Java virtual machine (VM). When the multithread application is terminated, the current thread must first be disconnected from the Java VM.
Use the JVM-INIT method or the JVM-ATTACH method of the FJ-JAVA-CONTROL class to connect the current thread to the Java VM.
To disconnect the current thread from the Java VM, use the JVM-TERMINATE method or the JVM-DETACH method of the FJ-JAVA-CONTROL class.
A multithread application sample is shown below:
Figure 3.2

Generating an Object

Generate an object by invoking the adapter class factory method corresponding to the constructor. Generate the factory method with the following name (see
Constructor
"
Create-JavaClassName-nn (nn is 01 to 99)
").
24 Chapter 3. Developing Programs
An example of generating a Date class object is shown below:
... REPOSITORY. CLASS J-Date AS "java-util-Date" ... WORKING-STORAGE SECTION 01 anDate OBJECT REFERENCE J-Date. ... PROCEDURE DIVISION. ... INVOKE J-Date "Create-Date-01" RETURNING anDate. ...
Note:
Since the adapter class name is very long, it is recommended that an alias be assigned by specifying AS in the REPOSITORY paragraph.

Invoking a Method

Invoke an instance method by invoking the corresponding adapter class object method. The method name is the same as that of Java. However, if more than one method is defined with the same name, append a numeric suffix to distinguish them
Class method"
(see "
and
"Instance method
").
An example of invoking the getTime method of the Date class is shown below:
... REPOSITORY. CLASS J-Date AS "java-util-Date" ... WORKING-STORAGE SECTION 01 anDate OBJECT REFERENCE J-Date. 01 currentTime PIC S9(9) COMP-5. ... PROCEDURE DIVISION. ... INVOKE anDate "getTime" RETURNING currentTime. ...

Manipulating a Variable

Manipulate a variable through the corresponding adapter class property. The
JF-
property name is a Java field name with the prefix " field is defined with the same name, append a numeric suffix to distinguish them
Class variable
(see "
" and "
Instance variable
").
". However, if more than one
Chapter 3. Developing Programs 25
An example of referencing the class variable AM_PM_FIELD (static field) of the DateFormat class is shown below:
... REPOSITORY. CLASS J-DateFormat AS "java-text-DateFormat" ... WORKING-STORAGE SECTION 01 FMT-Type PIC S9(9) COMP-5. ... PROCEDURE DIVISION. ... MOVE JF-AM_PM_FIELD OF J-DateFormat TO FMT-Type. ...

Comparing Object References

COBOL uses "=" to check whether multiple object references point to the same object. To check whether the Java objects pointed to by the adapter objects are the same, COBOL uses the J-EQUALS method of the adapter class instead of "=". The adapter class always has the J-EQUALS method.
An example of comparing two Date objects is shown below. The condition is met when Date-1 and Date-2 point to the same Java object.
... REPOSITORY. CLASS J-Date AS "java-util-Date" ... WORKING-STORAGE SECTION 01 Date-1 OBJECT REFERENCE J-Date. 01 Date-2 OBJECT REFERENCE J-Date. 01 rst PIC 1. ... PROCEDURE DIVISION. ... INVOKE Date-1 "J-EQUALS" USING CONTENT Date-2 RETURNING rst. IF rst = B"1" THEN Condition met ...

Assignment to a Subclass

COBOL uses AS to assign an object to a subclass. However, it uses the J-NARROW method instead of AS to assign an adapter object. The adapter class always has the J-NARROW method.
26 Chapter 3. Developing Programs
An example of assigning an object, which has been referenced with Object class data, into Data class data is shown below:
... REPOSITORY. CLASS J-Object AS "java-lang-Object" CLASS J-Date AS "java-util-Date" ... WORKING-STORAGE SECTION 01 anDate OBJECT REFERENCE J-Date. 01 anObject OBJECT REFERENCE J-Object. ... PROCEDURE DIVISION. ... INVOKE J-Date "J-NARROW" USING CONTENT anObject RETURNING anDate. ...

Mapping java.lang.String into PIC X

The java.lang.String is mapped into the java-lang-String class in the generation of the normal adapter class. In this case, creation of the user's application becomes somewhat complicated because conversion between the String object and the COBOL data items must be performed using the java-lang-String class method (such as NEW-STRING-X, GET-STRING-X).
When the adapter class is generated by specifying the -s option or by specifying the "Option String" parameter, the following items can be handled as alphanumeric items in the user's applications, since the java.lang.String type is mapped into PIC X ANY LENGTH:
Return values of the java.lang.String type in the method
Argument of the java.lang.String type in the constructor and method
Fields (class variables and instance variables) of the java.lang.String type
Example: When the -s option and "Option String" parameter are not specified, the conversion between the String object and the COBOL data items must be performed in the user's application using the java-lang-String class method (such as NEW­STRING-X and GET-STRING-X).
REPOSITORY.
CLASS J-Date AS "java-util-Date" CLASS J-String AS "java-lang-String" CLASS J-DateFormat AS "java-text-DateFormat"
WORKING-STORAGE SECTION
01 aDateFormat OBJECT REFERENCE J-DateFormat. 01 aDate OBJECT REFERENCE J-Date. 01 dateString OBJECT REFERENCE J-String. 01 dateValue PIC X(30).
PROCEDURE DIVISION.
MOVE "2000/01/01" & X"00" TO dateValue.
INVOKE J-String "NEW-STRING-X" USING dateValue RETURNING dateString. INVOKE aDateFormat "parse" USING dateString RETURNING aDate.
INVOKE aDate "toString" RETURNING dateString.
INVOKE dateString "GET-STRING-X" RETURNING dateValue.
Chapter 3. Developing Programs 27
When the -s option or the "Option String" parameter is specified, the conversion between the String object and the COBOL data items is not necessary since an alphanumeric item can be specified as the String type argument and returns a value directly.
REPOSITORY.
CLASS J-Date AS "java-util-Date" CLASS J-DateFormat AS "java-text-DateFormat"
WORKING-STORAGE SECTION 01 aDateFormat OBJECT REFERENCE J-DateFormat.
01 aDate OBJECT REFERENCE J-Date. 01 dateValue PIC X(30).
PROCEDURE DIVISION.
MOVE "2000/01/01" & X"00" TO dateValue.
INVOKE aDateFormat "parse" USING dateValue RETURNING aDate.
INVOKE aDate "toString" RETURNING dateValue.
Notes:
The return value of the java.lang.String class constructor is the java.lang.String class
When the String object method is used, the creation of the object (calling the String constructor or calling the NEW-STRING-X method) is necessary.
To refer/set the java.lang.String type field (class variable or instance variable), specify its size using -s option or "Option String" parameter.
When you want to handle the String type NULL object, do not use the -s option and "Option String" parameter.

End Control of Character String

When passing a character string that is shorter than the data item length to an ordinary adapter class, the end of string (X”00”) must be set. The following example shows that "ABC" is copied to alphanumeric item initialValue having length of 50 characters and is passed to the NEW-STRING-X method:
REPOSITORY.
CLASS J-String AS "java-lang-String"
WORKING-STORAGE SECTION. 01 initialValue PIC X(50). 01 aString OBJECT REFERENCE J-String.
PROCEDURE DIVISION.
MOVE "ABC" & X"00" TO initialValue.
INVOKE J-String "NEW-STRING-X" USING initialValue RETURNING aString.
28 Chapter 3. Developing Programs
If an adapter class is generated by specifying the -t option or the "Option Terminal" parameter, the character string that is shorter than the data item length can be passed to a method without setting the end of string, since the end (X "00") of the character string is set in the adapter class.
The following example shows that "ABC" is copied to alphanumeric item initialValue having the length of 50 characters and is passed to the NEW-STRING-X method:
REPOSITORY.
CLASS J-String AS "java-lang-String"
WORKING-STORAGE SECTION. 01 initialValue PIC X(50). 01 aString OBJECT REFERENCE J-String.
PROCEDURE DIVISION.
MOVE "ABC" TO initialValue.
INVOKE J-String "NEW-STRING-X" USING initialValue RETURNING aString.

Exception Processing

When an adapter class detects an error during processing, the exception object is generated. FJ-JAVA-ERROR class is the class of the exception object.
In order to detect an exception generated in the adapter class, using the "exception object", the "exception handling" needs be described in the declaratives of the procedure division of the program, using the USE statement. When the method of the FJ-JAVA-ERROR class is used in the exception handling, the exception message, exception type and Java exception information can be extracted. For the details of the exception handling using the USE statement, refer to "Defining Exception Processes" of the "Fujitsu NetCOBOL User's Guide".
Example of coding of the exception handling is shown as follows:
REPOSITORY.
CLASS FJ-JAVA-ERROR
WORKING-STORAGE SECTION 01 errMessage PIC X(256). 01 expMessage PIC X(1024). 01 expClass PIC X(256). 01 errCode PIC S9(9) COMP-5. 01 errMessageLen PIC S9(9) COMP-5. 01 expMessageLen PIC S9(9) COMP-5. 01 expClassLen PIC S9(9) COMP-5. 01 rc PIC S9(9) COMP-5.
PROCEDURE DIVISION.
DECLARATIVES. ERR SECTION. USE AFTER EXCEPTION FJ-JAVA-ERROR. INVOKE EXCEPTION-OBJECT "GET-CODE" RETURNING errCode. INVOKE EXCEPTION-OBJECT "GET-MESSAGE" USING errMessage RETURNING errMessageLen. INVOKE EXCEPTION-OBJECT "GET-EXCEPTION" USING expMessage expMessageLen expClass expClassLen RETURNING rc.
Chapter 3. Developing Programs 29
DISPLAY "Error Code: " errCode. DISPLAY "Error Message: " errMessage(1:errMessageLen). IF rc NOT = -1 THEN DISPLAY "Java Class Name: " expClass(1:expClassLen) DISPLAY "Java Exception Message: " expMessage(1:expMessageLen) END-IF. END DECLARATIVES.
Note: When the exception handling is not described in a program, the program runtime error (JMP0104I-U) occurs due to the occurrence of the exception object.

Constructing a Program

This section explains how to construct a program that uses an adapter class, by using the COBOL project manager.
The following files generated from the adapter class are required to construct a program:
Adapter class LIB file (for linkage)
Adapter class repository file (for compilation)
Construct a program as follows:
1. Create a new project using the project manager.
2. Register the target executable program (EXE).
3. Create a COBOL source file folder and store the program source in it.
4. Create a library file folder, and store the adapter class LIB file and J adapter class generator runtime library F3BIJART.LIB in it. F3BIJART.LIB exists in the LIB folder of the install folder.
5. Specify compiler and link options:
- For REPIN, specify XXX\REP (XXX is the J adapter class generator install
folder) and the folder containing the adapter class repository.
- Specify ALPHAL (WORD) or NOALPHAL.
- Refer to the
6. Execute "
build

Running a Program

The following file generated from the adapter class is required to run a program:
Fujitsu NetCOBOL User's Guide
."
for other options.
Adapter class DLL file
Before running the program, add the folder containing the adapter class DLL file to environment variable PATH.
The program can be run in the same manner as any other COBOL application. Refer
Fujitsu NetCOBOL User's Guide
to the
for details.
Note: The Java VM operating environment can be customized by specifying environment variables (see ”JVM-INIT method (factory method)”).
30 Chapter 3. Developing Programs

Conversion to Java2

When using the resources (execute-form programs (EXE), DLLs, adapter class source, and program source using adapter classes) created by JDK1.1.x, note the following:
Adapter class source and DLLs created by JDK 1.1.x can be used as they are in the Java2 environment.
If an adapter class is recreated by Java2, a method name different from one created by JDK 1.1.x may be generated (see " the COBOL program using the Java class must be modified. To prevent this problem, recreate an adapter class with Java2 by using the generation name management file generated by JDK 1.1.x.
Numbering names
"). In this case,
Loading...
+ 68 hidden pages