Accessing Native Java Objects

Restriction: This applies to native code only.

Using the native OO COBOL Java domain means that you never access Java objects directly - you are always going through a proxy. You can obtain a pointer to the actual Java object using the "getJavaObject" method of the javasup class. You can use this in conjunction with the Java Native Interface (JNI) if you want access to Java functionality not provided by the native OO COBOL Java domain.

To get a JNI pointer invoke "getEnv" on the javasup class. The JNI pointer is a pointer to a table of functions; data type JNINativeInterface in copybook javatypes.cpy provides a structure that makes the JNI function table easier to use, as shown in the example below:

 working-storage section. 
 01 JEnv                        pointer.
 linkage section.
 01 lnk-JNINativeInterface      JNINativeInterface.

 procedure division.
     invoke javasup "getEnv" returning jEnv
*>   Map the pointer passed in JEnv to the
*>   JNINativeInterface structure so that we
*>   can call JNI functions.
     set address of lnk-JNINativeInterface to JEnv

You can now call JNI functions using the names provided by the JNINativeInterface type definition.

See the Java Run-time Class Library Reference, which is in docs/java/ in your COBOL development system installation.