Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

JCI_NewObject

This function generates a new Java object.
It is equivalent to the JNI function NewObject. However, it also offers the option of transferring strings directly.

Call

CALL 'JCI_NewObject' USING cObj mID arg res

cObj

Class object

mID

Method ID

arg

Constructor arguments

res

Result

Arguments

cObj

Data field of the type JCI-object

Class object for which an object is to be generated. It may not refer to an array class.

mID

Data field of the type JCI-handle
ID of the constructor method. The method ID must be obtained by calling the function JCI_GetMethodID with the name <init> and signature (...)V for the cObj class.

arg

A structure of the form MethodArg
Description of the arguments for the constructor call (see section "Arguments and event values of Java methods").

res

A structure of the form MethodRes
Return value (new object) and error information (output only, result in ResValObject). In the event of an error, JCI-NULL is returned.


Return value (RETURN-CODE)

JCI-RET-OK

The call was successful.

JCI-RET-ENULLOBJ

cObj is JCI-NULL.

JCI-RET-ENULLID

mId is JCI-NULL.

JCI-RET-EARGUMENT

cObj is not a class object or refers to an array.

JCI-RET-ENOVM

No Java VM has been started.

JCI-RET-EARGVERS

The statically generated version number in arg is invalid (possibly overwritten).

JCI-RET-ERESVERS

The statically generated version number in res is invalid (possibly overwritten).

JCI-RET-EARGNUM

The number of arguments transferred (CallArgNum) is less than 0 or greater than the value used for <max-arguments> (see section "JCI-METHODARGS - Function arguments").

JCI-RET-EARGTYPE

The value of the ArgType field is invalid. The ResErrIndex field contains the number of the faulty argument.

JCI-RET-EARGCONV

An error occurred while an argument was being converted.
The ResErrIndex field contains the number of the argument, the ResErrCode field a more precise error code.

JCI-RET-ERR

The object could not be generated.


Exceptions

All exceptions generated by the constructor.

The other exceptions generated by the function correspond to those of the JNI function NewObject.


Example

DATA DIVISION.
WORKING-STORAGE SECTION.
COPY JCI-TYPEDEFS.
01 JCIConstants.
COPY JCI-CONST.
...
01 className.
02 PIC S9(9) COMP-5 VALUE 30.
02 PIC X(30) VALUE 'myClass'.
01 methodName.
05 PIC S9(9) COMP-5 VALUE 9.
05 PIC X(10) VALUE '<init>'.
01 methodSig.
05 PIC S9(9) COMP-5 VALUE 80.
05 PIC X(80) VALUE
'(Ljava/lang/String;Ljava/lang/String;)V'.
01 nText.
05 PIC S9(9) COMP-5 VALUE 8.
05 PIC N(20) VALUE N'COBOL'.
01 aText.
05 PIC S9(9) COMP-5 VALUE 8.
05 PIC X(20) VALUE 'Java'.
01 classObj  TYPE JCI-object.
01 instanceObj TYPE JCI-object.
01 methodID  TYPE JCI-handle.
01 MethodArgs.
COPY JCI-METHODARGS REPLACING ==<max-arguments>== BY 2.
01 MethodRes.
COPY JCI-METHODRES.
...
PROCEDURE DIVISION.
...
CALL 'JCI_FindClass' USING className classObject
IF RETURN-CODE NOT = JCI-RET-OK
...
END-IF
CALL 'JCI_GetMethodID' USING classObj methodName
methodSig methodID
IF RETURN-CODE NOT = JCI-RET-OK
...
END-IF
MOVE 2 TO CallArgNum
SET ARG-NAT-STRING(1) IGNORE-TRAILING-SPACES(1) TO TRUE
SET ArgValAddr(1) TO ADDRESS OF nText
SET ARG-ANUM-STRING(2) IGNORE-TRAILING-SPACES(2) TO TRUE
SET ArgValAddr(2) TO ADDRESS OF aText

CALL 'JCI_NewObject' USING classObj methodId
MethodArgs MethodRes
IF RETURN-CODE NOT = JCI-RET-OK
...
END-IF
MOVE ResValObject TO instanceObject
...