The built-in functions in the JavaObject package provide the ability to access Java classes and services from OScript. The major functionalities offered in the JavaObject package are the following:
OScript |
Java |
---|---|
Assoc |
java.util.Map
|
Boolean |
boolean,
Boolean |
Integer |
short,
Short int, Integer long, Long |
JavaObject |
Passed as the
wrapped value |
List |
java.util.List
|
Long |
short,
Short
int, Integer long, Long |
Object or Frame (Since
10.0.0) |
com.opentext.livelink.oml.OScriptObject |
Real |
float,
Float double, Double |
Record |
com.opentext.util.Record |
RecArray |
com.opentext.util.RecArray |
String |
String |
Undefined |
null |
Java types not
listed in this table (Since 10.0.0) |
com.opentext.livelink.oml.OPeer |
Java |
OScript |
---|---|
boolean,
Boolean |
Boolean |
byte
char, Character short, Short int, Integer |
Integer |
float,
Float double, Double |
Real |
long,
Long |
Long |
java.util.List (Since 10.0.0) [1] | List |
java.util.Map
(Since 10.0.0) [1] |
Assoc |
com.opentext.util.RecArray (Since 10.0.0) [1] | RecArray |
com.opentext.util.Record
(Since 10.0.0) [1] |
Record |
String |
String |
null |
Undefined |
Java types not
listed in this table |
JavaObject |
1. This conversion is not backward compatible with the earlier versions of Livelink which convert this type to JavaObject. To switch to the old behavior, you can set "ReturnAsCollectionType=false" in the [JavaObject] section of opentext.ini file. But we strongly recommend that you update your code to comply with the new conversion.
JavaObject New( String className, List parameters)
Creates a new instance of a Java class.
className | - | The name of the class to instantiate. |
parameters | - | The parameter list to pass to the constructor. |
Here is an example:
JavaObject dateFormat = JavaObject.New( "com.opentext.util.DateFormat", {} )
Dynamic InvokeStaticMethod( String className, String methodName, List parameters)
Invokes a static method defined for a Java class.
className | - | The name of the class that defines the method. |
methodName | - | The name of the method to invoke. |
parameters | - | The parameter list to pass to the method. |
Here is an example:
Dynamic result = JavaObject.InvokeStaticMethod( "com.opentext.util.DateFormat", "GetDefaultMonthFormat", {} )
Dynamic GetStaticField( String className, String fieldName)
Returns the value of a static field.
className | - | The name of the class that defines the field. |
fieldName | - | The name of the field to get the value of. |
Here is an example:
Dynamic result = JavaObject.GetStaticField( "com.opentext.util.DateFormat", "fDefaultMonthFormat" )
Dynamic SetStaticField( String className, String fieldName, Dynamic value)
Sets the value of a static field.
className | - | The name of the class that defines the field. |
methodName | - | The name of the field to set the value of. |
value | - | The value to set the static field. |
Here is an example:
Dynamic result = JavaObject.SetStaticField( "com.opentext.util.DateFormat", "fDefaultMonthFormat", { "mm" } )
String GetError()
Returns the JNI exception error message from the last operation.
Here is an example:
Dynamic result = JavaObject.SetStaticField( "com.opentext.util.DateFormat", "fDefaultMonthFormat", { "mm" } ) if IsError( result ) echo( JavaObject.GetError() ) end
List GetErrorStack()
Returns a List for the stack trace associated with an exception in the last JNI operation.
Here is an example:
List errStack String s JavaObject fileStream = JavaObject.New( "java.io.FileInputStream", { 'c:\badfile' } ) if IsError( fileStream ) errStack = JavaObject.GetErrorStack() for s in errStack echo( s ) end end
Dynamic InvokeMethod( String methodName, List parameters)
Invokes an instance method defined for a Java class.
methodName | - | The name of the method to invoke. |
parameters | - | The parameter list to pass to the method. |
Here is an example:
Dynamic result = dateFormat.InvokeMethod( "GetMonthFormat", {} )
Dynamic GetField( String fieldName)
Returns the value of an instance field.
fieldName | - | The name of the field to get the value of. |
Here is an example:
Dynamic result = dateFormat.GetField( "fMonthFormat" )
Dynamic SetField( String fieldName, Dynamic value)
Sets the value of an instance field.
fieldName | - | The name of the field to set the value of. |
value | - | The value to set the field. |
Here is an example:
Dynamic result = dateFormat.SetField( "fMonthFormat", { "mm" } )