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:

  • New() Creates a new instance of a Java class.
  • InvokeStaticMethod() Invokes a static method defined for a Java class.
  • GetStaticField() Returns the value of a static field.
  • SetStaticField() Sets the value of a static field.
  • GetError() Returns the JNI exception error message from the last operation.
  • GetErrorStack() Returns a List for the stack trace associated with an exception in the last JNI operation.
  • InvokeMethod() Invokes an instance method defined for a Java class.
  • GetField() Returns the value of an instance field.
  • SetField() Sets the value of an instance field.
  • Note:

    1. In order to use JavaObject, Livelink JVM has to be started. However, unlike Livelink service, Livelink Builder does not start the JVM by default. To start the JVM in Livelink Builder, add "-loadjavavm" in the Target field of the Livelink Builder's program shortcut.
    2. To deploy your jar files in Livelink JVM, added the jar files in OTHOME/ojlib/ or OTHOME/module/somemodule_1_0_0/ojlib/ directory (and their subdirectories) to be recognized by the JVM's application classloader.
    3. Since Livelink 10.0.0, Java methods invoked by InvokeMethod and InvokeStaticMethod can access OScript features. Please see the "Calling OScript from Java" section for details.

    OScript and Java Type Mappings

    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.


    Class Methods Index

     o New( String className, List parameters )
    Creates a new instance of a Java class.
     o InvokeStaticMethod( String className, String methodName, List parameters )
    Invokes a static method defined for a Java class.
     o GetStaticField( String className, String fieldName )
    Returns the value of a static field.
     o SetStaticField( String className, String fieldName, Dynmaic value )
    Sets the value of a static field.
     o GetError()
    Returns the JNI exception error message from the last operation.
     o GetErrorStack()
    Returns a List for the stack trace associated with an exception in the last JNI operation.

    Instance Methods Index

     o InvokeMethod( String methodName, List parameters )
    Invokes an instance method defined for a Java class.
     o GetField( String fieldName )
    Returns the value of an instance field.
     o SetField( String fieldName, Dynamic value )
    Sets the value of an instance field.

    Class Methods

     o New
     JavaObject New(
                   String className,
                   List parameters)

    Creates a new instance of a Java class.

    Parameters:
    className  -  The name of the class to instantiate.
    parameters  -  The parameter list to pass to the constructor.
    Returns:
    The return value can be either an Error object if it fails or a JavaObject if it succeeds.

    Here is an example:

    JavaObject dateFormat = JavaObject.New( "com.opentext.util.DateFormat", {} )
     o InvokeStaticMethod
     Dynamic InvokeStaticMethod(
                   String className,
                   String methodName,
                   List parameters)

    Invokes a static method defined for a Java class.

    Parameters:
    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.
    Returns:
     
    The return value can be either an Error object if it fails or a Dynamic if it succeeds.

    Here is an example:

    Dynamic result = JavaObject.InvokeStaticMethod( "com.opentext.util.DateFormat", "GetDefaultMonthFormat", {} )
     o GetStaticField
     Dynamic GetStaticField(
                   String className,
                   String fieldName)

    Returns the value of a static field.

    Parameters:
    className  -  The name of the class that defines the field.
    fieldName  -  The name of the field to get the value of.
    Returns:
     
    The return value can be either an Error object if it fails or a Dynamic if it succeeds.

    Here is an example:

    Dynamic result = JavaObject.GetStaticField( "com.opentext.util.DateFormat", "fDefaultMonthFormat" )
     o SetStaticField
     Dynamic SetStaticField(
                   String className,
                   String fieldName,
                   Dynamic value)

    Sets the value of a static field.

    Parameters:
    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.
    Returns:
     
    The return value can be either an Error object if it fails or a Undefined if it succeeds.

    Here is an example:

    Dynamic result = JavaObject.SetStaticField( "com.opentext.util.DateFormat", "fDefaultMonthFormat", { "mm" } )
     o GetError
     String GetError()

    Returns the JNI exception error message from the last operation.

    Returns:
     
    A string containing JNI exception error message from the last operation.
    If no exception occurs, an empty string is returned.

    Here is an example:

        Dynamic result = JavaObject.SetStaticField( "com.opentext.util.DateFormat", "fDefaultMonthFormat", { "mm" } )
        if IsError( result )
            echo( JavaObject.GetError() )
        end
     o GetErrorStack
     List GetErrorStack()

    Returns a List for the stack trace associated with an exception in the last JNI operation.

    Returns:
     
    A List of Strings from the Java stack trace elements at the time of an exception. Each String represents a single stack frame. As described in the Java API specification documentation for Class StackTraceElement, all stack frames except for the one at the top of the stack represent a method invocation. The frame at the top of the stack represents the the execution point at which the stack trace was generated.
    If no exception has occurred, an empty List is returned.

    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

    Instance Methods

     o InvokeMethod
     Dynamic InvokeMethod(
                   String methodName,
                   List parameters)

    Invokes an instance method defined for a Java class.

    Parameters:
    methodName  -  The name of the method to invoke.
    parameters  -  The parameter list to pass to the method.
    Returns:
     
    The return value can be either an Error object if it fails or a Dynamic if it succeeds.

    Here is an example:

    Dynamic result = dateFormat.InvokeMethod( "GetMonthFormat", {} )
     o GetField
     Dynamic GetField(
                   String fieldName)

    Returns the value of an instance field.

    Parameters:
    fieldName  -  The name of the field to get the value of.
    Returns:
     
    The return value can be either an Error object if it fails or a Dynamic if it succeeds.

    Here is an example:

    Dynamic result = dateFormat.GetField( "fMonthFormat" )
     o SetField
     Dynamic SetField(
                   String fieldName,
                   Dynamic value)

    Sets the value of an instance field.

    Parameters:
    fieldName  -  The name of the field to set the value of.
    value  -  The value to set the field.
    Returns:
     
    The return value can be either an Error object if it fails or a Undefined if it succeeds.

    Here is an example:

    Dynamic result = dateFormat.SetField( "fMonthFormat", { "mm" } )