Initializing help system before first use

Returning an object from a Java method


Description: Demonstrates calling a static Java function that returns a complex object.
File(s): passarray.mos


passarray.mos
(!*******************************************************
   file returnobject.mos
   `````````````````
   a model that demonstrates handling a Java object within Mosel

   This example requires an installation of Java, see
   the manual 'mosjvm Module for Mosel' for
   compatible versions and setup instructions.
   
   (c) 2017 Fair Isaac Corporation
       author: J. Farmer, 2017
  *******************************************************!)


model myModel
  uses 'mosjvm','mmsystem'
  
  declarations
    fileobj: jvmobject
    tempfile: text
  end-declarations
 
  ! Abort model if we encounter a Java exception
  setparam('jvmabortonexception',true)

  ! Create a temporary file from Java, using a public static method in the standard java.io.File class
  fileobj := jvmcallobj("java.io.File.createTempFile","xpress-example-",".dat")

  ! fileobj now contains reference to a java.io.File object representing our temporary file
  writeln("Java created temporary file ",fileobj)
  
  ! Store path in Mosel (as java.io.File.toString() returns path)
  tempfile := text(fileobj)
  
  ! Delete file from Mosel
  fdelete(tempfile)
  if getsysstat<>0 then
    writeln("FAILED to dete temporary file ",tempfile)
  else
    writeln("Mosel deleted temporary file ",tempfile)
  end-if
end-model

© 2001-2019 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.