Types
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's off 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), and pass it to other public static 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 }
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' }