Java インスタンスをネイティブ オブジェクト COBOL に渡す JVM COBOL

以前の Micro Focus 製品では、COBOL と Java の相互運用性は、クラス com.microfocus.cobol.RuntimeObject とその対になる COBOL クラスを拡張する Java クラスを作成する、クラス ウィザードとメソッド ウィザードを使用して実現されていました。

現在では、生成されたクラスを JVM COBOL アプリケーションで使用し、com.microfocus.cobol.RuntimeObject のインスタンスを作成することで、ネイティブ オブジェクト COBOL に Java インスタンスを渡すことが可能になりました。ネイティブ COBOL は、それらのインスタンスをネイティブ オブジェクト参照として取得します。

以下の例では、Java クラス addressbookcom.microfocus.cobol.RuntimeObject を拡張し、インスタンスの作成に使用されます。

 working-storage section.
 01 ab    type addressbook.
 procedure division.
     set ab to type addressbook::new()
     call "useab_oon" using by value ab

受け取り側ネイティブ COBOL プログラム:

$set ooctrl(+p) ooctrl(-f) dialect(iso2002) mf warning(1)
 identification division.
 program-id. useab_con as "useab_oon".
 repository.
    class cls-sb as "$java$java.lang.StringBuffer".
 working-storage section.
 01 nameBuffer       object reference.
 01 nameBufferLength binary-long.
 01 nameBufferX       pic x(80).
 linkage section.
 01 ab                   object reference.
 procedure division using by value ab.
     invoke cls-sb "new" using
         by value 80 size 4
         returning nameBuffer
     invoke ab "getName" using nameBuffer
     invoke nameBuffer "length" returning nameBufferLength
     invoke nameBuffer "toString" returning nameBufferX
     display "Customer name : " nameBufferX(1:nameBufferLength)
     invoke nameBuffer "finalize" returning nameBuffer
     goback.

ネイティブ COBOL クラス:

$set ooctrl(+p) ooctrl(-f) dialect(iso2002) mf warning(1)
 identification division.
 class-id. addressBook as "addressbook" 
           inherits from javabase.
    
 repository.
     class javabase as "javabase"
 factory.
 working-storage section.
 end factory.
 object. 
 working-storage section.

 method-id.  getName .
 linkage Section.
 01 customerName           pic x(80).
 procedure division using by reference customerName.
     move "Mr Smith" to customerName
 exit method.
 end method getName.
 end object.

 end class addressBook.

自動生成される addressbook.java:

import com.microfocus.cobol.*;
// OCWIZARD start imports
// OCWIZARD end imports

public class addressbook extends com.microfocus.cobol.RuntimeObject
{
 /* static methods - the COBOL runtime will register these */
 public native static boolean cobinvokestatic_boolean (String methodName, Object[] params)
  throws CobolException, Exception;
 public native static byte cobinvokestatic_byte (String methodName, Object[] params)
  throws CobolException, Exception;
 public native static char cobinvokestatic_char (String methodName, Object[] params)
  throws CobolException, Exception;
 public native static short cobinvokestatic_short (String methodName, Object[] params)
  throws CobolException, Exception;
 public native static int cobinvokestatic_int (String methodName, Object[] params)
  throws CobolException, Exception;
 public native static long cobinvokestatic_long (String methodName, Object[] params)
  throws CobolException, Exception;
 public native static float cobinvokestatic_float (String methodName, Object[] params)
  throws CobolException, Exception;
 public native static double cobinvokestatic_double (String methodName, Object[] params)
  throws CobolException, Exception;
 public native static void cobinvokestatic_void (String methodName, Object[] params)
  throws CobolException, Exception; 
 public native static Object cobinvokestatic_Object (String methodName, Object[] params)
  throws CobolException, Exception;

 static private String javaClassName = "addressbook";
 static
 {
  /* Load the class */
  /* cobloadclass (libraryname, cobolname, fulljavaname); */
  cobloadclass ("addressbook", "addressbook", javaClassName);
 }

 // OCWIZARD - start java methods

 public  void getName (StringBuffer customerName) throws Exception, CobolException
 {
  // Parameters are passed to COBOL in an array
  Object[] params = {customerName};
  cobinvoke_void ("getName", params);
 }
 // OCWIZARD - end java methods
}