Top
NetCOBOL V11.0 J Adapter Class GeneratorUser's Guide
FUJITSU Software

5.5.3 Constructor

Explanation

A public constructor is mapped to a COBOL factory method.

Expansion format

METHOD-ID internal-method-name AS "external-method-name".
    ...
DATA DIVISION.
LINKAGE SECTION.
01 generated-object OBJECT REFERENCE SELF.
[parameter ...]
PROCEDURE DIVISION [USING parameter ...] RETURNING generated-object
                               [RAISING exception-class-name].
END METHOD internal-method-name.

Generation rules

  1. The internal method name is internally used by the J class method generator and are not viewed from the class user.

  2. The external method name is used to identify the method. The class user can identify the method with the external method name.

  3. An external method name is generated according to the following rules:

    Create-JavaClassName-nn
    • "Create-" is followed by a Java class name with a hyphen "-" followed by a two-digit number (nn).

    • The Java class name does not include the package name.

    • nn is a serial number assigned in order from 01 to 99 to methods having the same Java class name.

    • If a super class has classes having the same Java class names, serial numbers are assigned to such classes in order from the super class. (see "5.8 Numbering Names".)

    • A name exceeding 160 characters is truncated after the 160th character.

  4. When a parameter is declared for the constructor, the corresponding parameter is generated. See "5.5.1 Data types" for the correspondence between parameter data types.

  5. The generated object is the unique object reference name used to store the object reference to the generated adapter object.

  6. When an exception is declared for the constructor, the RAISING specification is generated.

Generation example

The factory method corresponding to constructor Date() of the java.util.Date class is generated as shown below:

METHOD-ID. CREATE-01 AS "Create-Date-01".                    [1]
    ...
LINKAGE SECTION.
01  CREATED-OBJECT  OBJECT REFERENCE SELF.
PROCEDURE DIVISION RETURNING CREATED-OBJECT.
    ...
END METHOD CREATE-01.

The factory method corresponding to the constructor Date (long) of the java.sql.Date class (java.util.Date subclass) is generated as shown below:

METHOD-ID. CREATE-08 AS "Create-Date-08".                    [1]
    ...
LINKAGE SECTION.
01  CREATED-OBJECT  OBJECT REFERENCE SELF.
01  PARA-1  PIC S9(18) COMP-5.
PROCEDURE DIVISION USING PARA-1 RETURNING CREATED-OBJECT.
    ...
END METHOD CREATE-08.

Supplement

A factory method name is generated from a constructor, a number is assigned to the name to secure the uniqueness of the name. The class browser or method name cross-reference list file can be used to check the correspondence between constructors and factory methods. In the case of class browser, it can be identified from the parameter that appears during method selection. In the case of 4.3.3 Method Name Cross-Reference List File, it can be identified from the type of argument of the constructor.