Initializing help system before first use

Types

Topics covered in this chapter:

The jvmobject type

You can use the jvmobject type to hold a Java object reference within your Mosel model. A jvmobject initially contains a null reference but can be populated as the return value of jvmcallobj, e.g.:

declarations
  myobj: jvmobject
end-decarations
myobj := jvmcallobj("com.fico.examples.ConfigOperations.getConfigFile","config.dat")

Once the jvmobject is populated, you can check it's populated using getisnull and check if it's of the expected class using getclass, e.g.:

declarations
  myobj: jvmobject
end-decarations
myobj := jvmcallobj("com.fico.examples.ConfigOperations.getConfigFile","config.dat")
if myobj.isnull then
  writeln('ERROR: Expected configuration File object, found null')
elif myobj.class<>'java.io.File' then
  writeln('ERROR: Expected configuration File object, found '+myobj.class)
end-if

You can also turn it to a string or text (which uses the Java toString() method), or pass it to other public Java functions, e.g.:

declarations
  myobj: jvmobject
  configfiles: array(range) of text
end-decarations
myobj := jvmcallobj("com.fico.examples.ConfigOperations.getConfigFile","config.dat")
configfiles(configfiles.size+1) := text(myobj)
writeln('About to read configuration from file ',myobj)
jvmcallvoid("com.fico.examples.ConfigOperations.loadConfigFromFile",myobj);

If the jvmobject contains a java.lang.Number, a java.lang.String or a java.lang.Boolean, you can read the value into a Mosel variable, e.g.:

declarations
  myobj: jvmobject
  b: boolean
  i: integer
  r: real
  t: text
end-decarations
myobj := jvmcallobj("com.fico.examples.ConfigOperations.getConfigValue","value1")
if myobj.class='java.lang.Integer' then
  i := myobj.intvalue
elif myobj.class='java.lang.Boolean' then
  b := myobj.boolvalue
elif myobj.class='java.lang.Double' then
  r := myobj.realvalue
elif myobj.class='java.lang.String' then
  t := myobj.textvalue
end-if

You can construct a new Java object and store it in a jvmobject by using the jvmnewobj function, e.g.:

declarations
  myobj: jvmobject
end-decarations
myobj := jvmnewobj("java.io.File","C:/myfiles/mydatafile.csv")

Finally, you can also populate a jvmobject with any of these basic types (the Java object will be created automatically based on the type of the value you provide), e.g.:

declarations
  i,b,r,t: jvmobject
end-decarations
i.value := 1
b.value := true
r.value := 9.1
t.value := 'hello world'

Attributes

The jvmobject type supports attributes allowing different types of object reference to be read/written:

Attribute Java type Mosel type
boolvalue java.lang.Boolean boolean
bytevalue java.lang.Byte integer
charvalue java.lang.Character text
floatvalue java.lang.Float real
intvalue java.lang.Integer integer
longvalue java.lang.Long real
realvalue java.lang.Double real
shortvalue java.lang.Short integer
strvalue java.lang.String string
textvalue java.lang.String text

The jvmmethod type

The jvmmethod type holds a Java object reference to a java.lang.reflect.Method or java.land.reflect.Constructor object. Typically jvmmethod values are created by jvmfindmethod, jvmfindstaticmethod or jvmfindconstructor calls and then passed to jvmcall* functions such as jvmcallvoid or jvmnewobjinstead of a class/method name, for those cases where the developer wants to specify exactly which overload of a method name should be called. For example:

model myModel
  uses 'mosjvm'

  declarations
    mth: jvmmethod
  end-declarations

  ! Look up method myMethod on class MyClass which takes a java.lang.Number as a parameter
  mth := jvmfindmethod('com.fico.MyClass', 'myMethod', ['java.lang.Number'])

  ! Call it
  jvmcall(mth, 123)
end-model

jvmmethod values can be converted to/from jvmobject; for example if you want to use the standard Java reflection API to look up a method to call:

model myModel
  uses 'mosjvm'

  declarations
    stringClass: jvmobject
    lengthMethod: jvmobject
    myString: jvmmethod
  end-declarations

  ! Populate with dummy data
  myString.string := 'hello world'

  ! Look up length method in String class
  stringClass := jvmcallobj('java.lang.class.forName', 'java.lang.String')
  lengthMethod := jvmmethod(jvmcallobj(stringClass, 'getDeclaredMethod', 'length'))

  ! Call the method
  writeln('Length of Java string = ', jvmcallint(myString, lengthMethod))
end-model

A jvmmethod initially contains a null reference; you can check it's populated using the isnull attribute.


© 2001-2026 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.