      *> ooctrl(+p) required for COM and Java classes
      *> ooctrl(-f) used to preserve case of method names for Java
      $set ooctrl(+p) ooctrl(-f) intlevel"4"

      ****************************************************************
      * Copyright (C) 1996 - 2000 Micro Focus International Ltd.     *
      * All Rights Reserved.                                         *
      ****************************************************************

       class-id. arraydemo inherits from javabase.
       class-control.
         javabase is class "javabase"
	 arraydemo is class "arraydemo"
	 arrayview is class "$JAVA$arrayview"
	 jarray is class "jarray"
         .

       class-object.

	method-id. initialise.
            exit method.
	end method initialise.
	
       end class-object.

       object.
       object-storage section.

       copy "javatypes.cpy".
      
      ****************************************************************
      * displayArray
      *
      * This methods receives a Java array as input and displays the
      * dimensions, mumber of elements in each dimension and the 
      * elements themselves. It also modifies the contents of the 
      * array before returning.
      *
      ****************************************************************
       method-id. "displayArray".
       local-storage section.
       01 theTotal	  pic 9(9).
       01 CDims 	  pic x(4) comp-5.
       01 Dims.
	 03 Dims-entry	  pic x(4) comp-5 occurs 256.
       01 Bounds.
	 03 Bounds-entry  pic x(4) comp-5 occurs 256.
       01 ind0		  pic x(4) comp-5.
       01 ind1		  pic x(4) comp-5.
       01 arrayElement	  pic x(4) comp-5.
       linkage section.
       01 lnkTable	  object reference.
       01 lnkResult	  pic x(4) comp-5.
       procedure division using by reference lnkTable
             returning lnkResult.

      *	find out the number of elements in the array	
		invoke lnkTable "getDimensions" returning CDims
		display "The array has " CDims " dimension(s)"

      * get the number of elements in each dimension
		display "dimensions are " with no advancing 
		invoke lnkTable "getBounds" using Bounds
		perform varying ind0 from 1 by 1 until ind0 > CDims
		     display Bounds-entry(ind0) with no advancing
		     if ind0 < CDims
			display " by " with no advancing
		     end-if
		end-perform
		display " "

      *	display each element in the array
		perform varying ind0 from 0 by 1 
			until ind0 = Bounds-entry(1)
		   move ind0 to Dims-entry(1)
		   perform varying ind1 from 0 by 1 
			   until ind1 = Bounds-entry(2)
		      move ind1 to Dims-entry(2)
		      invoke lnkTable "getElement" using 
					     by value CDims
					     by reference Dims
					     by reference arrayElement
		      display "Element " ind0 "," 
			      ind1 " is " arrayElement
      * modify the contents of the array		      
		      add 50 to arrayElement
		      invoke lnkTable "putElement" using 
					     by value CDims
					     by reference Dims
					     by reference arrayElement
		   end-perform
		end-perform
		
		move 0 to lnkResult.

         exit method.
       end method "displayArray".

      ****************************************************************
      * newArray
      *
      * This methods creates a Java array and invokes a Java method 
      * showArray in the arrayview class to display it.
      *
      ****************************************************************
       method-id. "newArray".
       local-storage section.
       01 CDims 	  pic x(4) comp-5.
       01 Dims.
	 03 Dims-entry	  pic x(4) comp-5 occurs 256.
       01 Bounds.
	 03 Bounds-entry  pic x(4) comp-5 occurs 256.
       01 ind0		  pic x(4) comp-5.
       01 ind1		  pic x(4) comp-5.
       01 arrayElement	  pic x(4) comp-5.
       01 newTable	  object reference.
       01 viewobj	  object reference.
       linkage section.
       procedure division.

      * create the array
		move 12 to Bounds-entry(1)
		move 5 to Bounds-entry(2)
		invoke jarray "new" using by value JT-INTEGER
					  by value 2
					  by reference Bounds
				    returning newTable
      
      *	check the number of elements in the array	
		invoke newTable "getDimensions" returning CDims
		display "The array has " CDims " dimension(s)"

      * check the number of elements in each dimension
		display "dimensions are " with no advancing 
		invoke newTable "getBounds" using Bounds
		perform varying ind0 from 1 by 1 until ind0 > CDims
		     display Bounds-entry(ind0) with no advancing
		     if ind0 < CDims
			display " by " with no advancing
		     end-if
		end-perform
		display " "

      * set the contents of the array		      
		perform varying ind0 from 0 by 1 
			until ind0 = Bounds-entry(1)
		   move ind0 to Dims-entry(1)
		   perform varying ind1 from 0 by 1 
			   until ind1 = Bounds-entry(2)
		      move ind1 to Dims-entry(2)
		      move ind0 to arrayElement
		      multiply 100 by arrayElement
		      add ind1 to arrayElement
		      invoke newTable "putElement" using 
					     by value CDims
					     by reference Dims
					     by reference arrayElement
		   end-perform
		end-perform
      * pass the array to Java
		invoke arrayview "new" returning viewobj
		invoke viewobj "showArray" using newTable
		
         exit method.
       end method "newArray".

       end object.
       end class arraydemo.
