20100210, rgf

org.rexxla.bsf.engines.rexx
Class RexxAndJava

java.lang.Object
  extended by org.rexxla.bsf.engines.rexx.RexxAndJava

 class RexxAndJava
extends java.lang.Object

This class manages the calls from Rexx or Object Rexx into Java. (Any scripting language being able to pass Strings to and from Java will be able to use this interface, making it really easy to interface with Java.)

------------------------ Apache Version 2.0 license -------------------------
    Copyright (C) 2001-2009 Rony G. Flatscher

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
 ----------------------------------------------------------------------------- 

Version:
4.0.0, 2009-10-31
Author:
Rony G. Flatscher (WU-Wien/Wirtschaftsuniversität Wien, http://www.wu-wien.ac.at/english)

Nested Class Summary
(package private)  class RexxAndJava.ExitDelayed
          Class to exit the JVM, will be executed concurrently, sleeps and then calls System.exit(exit_number).
protected  class RexxAndJava.SyncPutGet
          Inner class to implement a Synchronized ReaderWriter, where a read on an empty Vector blocks the read, until a write occurs (with optional timeout).
 
Field Summary
protected static boolean bsfPrefixReturnValue
          Determines whether the return value to Rexx will prepend the string "OBJECT" or "STRING" with a trailing tabulator character ("09"x in Rexx or the '\t' character in Java).
protected static java.lang.String DLL_NAME
          Defines the name of DLL to be used to resolve the native functions.
protected static java.lang.String EVENT_LISTENER_ARGUMENTS_LEADIN
          Defines the string that leads in the BSFRegistry key to the Object array containing the event object and additional information.
protected static java.lang.String EVENT_LISTENER_ARGUMENTS_LEADOUT
          Defines the string that leads out the BSFRegistry key to the Object array containing the event object and additional information.
protected static java.lang.String EVENT_TEXT
          Defines the string to indicate an 'eventText' is passed in: "<eventText>".
protected  RexxAndJava.SyncPutGet eventTextList
          Allows Synchronized access to the vector storing the text sent by the eventListeners.
(package private)  org.apache.bsf.util.type.TypeConvertorRegistry glob_tcr
          To store the default TypeConvertorRegistry, if needed.
(package private)  org.apache.bsf.BSFManager mgr
          Stores the BSF manager.
protected static java.lang.Class nlR_class
          Stores the "netrexx.lang.Rexx" class object, if available.
protected static java.lang.String null4Rexx
          Defines the string which represents null, by default ".NIL".
protected static java.lang.String OBJECT_INDICATOR_PREFIX
           
(package private)  java.util.Hashtable orxReferences
          Stores the number of references from Object Rexx to Java objects using beanName as the key.
(package private)  org.apache.bsf.BSFEngine rexxEngine
          Stores the Rexx engine.
protected static java.lang.String STRING_INDICATOR_PREFIX
           
static java.lang.String version
          Version string indicating version of this class (majorVersion*100+minorVersion concatenated with a dot and the sorted date of last change.
 
Constructor Summary
RexxAndJava(org.apache.bsf.BSFManager mgr, org.apache.bsf.BSFEngine rengine)
          Constructor to receive and store the BSF manager and the Rexx engine.
 
Method Summary
(package private)  java.lang.Object[] coerceArgs(java.lang.Object[] funcArgs, java.lang.Class[] paramTypes)
          Coerces the arguments from Rexx to the appropriate Java types.
protected  java.lang.Object convFromRexx(java.lang.String value)
          Replaces a reference to a Java object with the Java object.
protected  org.apache.bsf.BSFEngine getRexxEngine()
           
(package private)  java.lang.Object invokeMethod(java.lang.reflect.Method m, java.lang.Object o, java.lang.Object[] params)
          Invokes method and makes sure that any public method will get successfully invoked.
 java.lang.String javaCallBSF(java.lang.String[] args)
          Entry point for Rexx calls into Java.
 java.lang.String jniGetRexxInterpreterInstanceRoot()
          Returns the Rexx interpreter instance serving as the root of the linked list of Rexx interpreter using the ooRexx 4.0 API RexxCreateInterpreter().
 int jniInitialize4Rexx()
          rgf, 2003-01-15, used for allowing the BSF4ooRexx-DLL to get at *env, *obj and then to mid etc.
 int jniRegisterBSF()
          This native method makes sure that the function 'BSF' is registered with Rexx, making it thereby available to all Rexx and Object Rexx programs, called from Java.
 java.lang.String jniRexxCreateInterpreterInstance()
          Creates a new Rexx interpreter instance using the ooRexx 4.0 API RexxCreateInterpreter().
 int jniRexxDidRexxTerminate()
          This native method indicates whether the Object Rexx interpreter is still running or not.
 java.lang.String jniRexxGetTID()
          This native method returns the current thread id as seen by BSF4ooRexx encoded as a decimal value into a String.
 int jniRexxHaltInterpreterInstance(java.lang.String rii_ID)
          Uses the ooRexx 4.0 API Halt() to raise the HALT condition in all Rexx threads belonging to the given Rexx interpreter instance.
 java.lang.Object jniRexxRunProgram(java.lang.String rii_ID, int invocationType, java.lang.String fileName, java.lang.String programData, java.lang.Object[] args)
          Uses the ooRexx 4.0 API to execute a Rexx program or to execute a callback (sending a message to a given object).
 java.lang.Object jniRexxSendMessageToRexxObject(java.lang.String rii_ID, java.lang.String obj_ID, java.lang.String userData_ID, java.lang.String javaObjectBean, java.lang.String methodObjectBean, java.lang.String messageName, java.lang.String methodDescription, java.lang.Object[] args, java.lang.String returnType)
          Uses the ooRexx 4.0 API to execute a Rexx program or to execute a callback (sending a message to a given object).
 int jniRexxSetHalt(java.lang.String tid)
          This native method halts a Rexx interpreter instance or individual Rexx threads in the current process.
 int jniRexxTerminateInterpreterInstance(java.lang.String rii_ID)
          Uses the ooRexx 4.0 API Terminate() to wait on all Rexx threads belonging to the given Rexx interpreter instance to terminate.
 int jniRexxWaitForTermination()
          This native method waits for the Object Rexx interpreter to terminate and waits until all of the cleanup (e.g. of Object Rexx) is done.
 int jniUnregisterRexxObject(java.lang.String obj_ID)
          Unregisters the Rexx object denoted by 'obj_ID' from the JNI registry.
 java.lang.String makeBeanName(java.lang.Object o)
          This method creates a unique string value for the passed in object.
protected  java.lang.String makeString4Rexx(java.lang.Object o)
          This method determines what String content to return; if a non-primitive Java object a unique beanName is created and used to save the Java object in the BSFRegistry, returning the beanName.
(package private)  java.lang.String pp(java.lang.Object o)
          'Pretty print': returns string value of supplied object enclosed in square brackets.
protected  java.lang.String registerBean(java.lang.String beanName, java.lang.Object object)
          This method registers an object with the given beanName with the BSF registry, if not registered yet.
(package private)  java.lang.String truncString(java.lang.String s, int maxLength)
          Truncates string, if longer than given maxLength and append ellipsis (three dots: '...').
protected  boolean unregisterBean(java.lang.String beanName)
          This method allows for unregistering Beans, taking into account reference counters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

version

public static final java.lang.String version
Version string indicating version of this class (majorVersion*100+minorVersion concatenated with a dot and the sorted date of last change.

See Also:
Constant Field Values

DLL_NAME

protected static final java.lang.String DLL_NAME
Defines the name of DLL to be used to resolve the native functions.

See Also:
Constant Field Values

EVENT_TEXT

protected static final java.lang.String EVENT_TEXT
Defines the string to indicate an 'eventText' is passed in: "<eventText>".

See Also:
Constant Field Values

EVENT_LISTENER_ARGUMENTS_LEADIN

protected static final java.lang.String EVENT_LISTENER_ARGUMENTS_LEADIN
Defines the string that leads in the BSFRegistry key to the Object array containing the event object and additional information.

See Also:
Constant Field Values

EVENT_LISTENER_ARGUMENTS_LEADOUT

protected static final java.lang.String EVENT_LISTENER_ARGUMENTS_LEADOUT
Defines the string that leads out the BSFRegistry key to the Object array containing the event object and additional information. This concludes a sequence which represents at the same time a nested Rexx comment.

See Also:
Constant Field Values

null4Rexx

protected static java.lang.String null4Rexx
Defines the string which represents null, by default ".NIL". Arguments given by Rexx can in addition be indicated to be null by merely omitting them on the Rexx side.


bsfPrefixReturnValue

protected static boolean bsfPrefixReturnValue
Determines whether the return value to Rexx will prepend the string "OBJECT" or "STRING" with a trailing tabulator character ("09"x in Rexx or the '\t' character in Java). By default this is set to false to remain backwardly compatible with older BSF4ooRexx programs.


OBJECT_INDICATOR_PREFIX

protected static final java.lang.String OBJECT_INDICATOR_PREFIX
See Also:
Constant Field Values

STRING_INDICATOR_PREFIX

protected static final java.lang.String STRING_INDICATOR_PREFIX
See Also:
Constant Field Values

eventTextList

protected RexxAndJava.SyncPutGet eventTextList
Allows Synchronized access to the vector storing the text sent by the eventListeners.


nlR_class

protected static java.lang.Class nlR_class
Stores the "netrexx.lang.Rexx" class object, if available. Cf. http://www2.hursley.ibm.com/netrexx/.


mgr

org.apache.bsf.BSFManager mgr
Stores the BSF manager.


rexxEngine

org.apache.bsf.BSFEngine rexxEngine
Stores the Rexx engine.


orxReferences

java.util.Hashtable orxReferences
Stores the number of references from Object Rexx to Java objects using beanName as the key. This way it becomes possible for the Object Rexx implementation using "BSF.cls" to transparently create Object Rexx proxy objects, if objects are returned from Java method invocations and to transparently unregister them, when the Object Rexx proxy objects are garbage collected.


glob_tcr

org.apache.bsf.util.type.TypeConvertorRegistry glob_tcr
To store the default TypeConvertorRegistry, if needed.

Constructor Detail

RexxAndJava

RexxAndJava(org.apache.bsf.BSFManager mgr,
            org.apache.bsf.BSFEngine rengine)
Constructor to receive and store the BSF manager and the Rexx engine.

Preregisters the most important class objects. Referring to them is possible by using the following strings from Rexx (case *is* significant!):

Method Detail

getRexxEngine

protected org.apache.bsf.BSFEngine getRexxEngine()

jniRegisterBSF

public int jniRegisterBSF()
This native method makes sure that the function 'BSF' is registered with Rexx, making it thereby available to all Rexx and Object Rexx programs, called from Java.


jniRexxWaitForTermination

public int jniRexxWaitForTermination()
This native method waits for the Object Rexx interpreter to terminate and waits until all of the cleanup (e.g. of Object Rexx) is done. This is necessary for ooRexx 3.x.

Returns:
returns always 0. (Just there to allow future return codes, if necessary.)

jniRexxDidRexxTerminate

public int jniRexxDidRexxTerminate()
This native method indicates whether the Object Rexx interpreter is still running or not. This is necessary for ooRexx 3.x.

Returns:
returns always 0. (Just there to allow future return codes, if necessary.)

jniRexxGetTID

public java.lang.String jniRexxGetTID()
This native method returns the current thread id as seen by BSF4ooRexx encoded as a decimal value into a String. This value can be used as an argument for jniRexxSetHalt(String tid).

Returns:
returns the decimal value of the thread id (TID)

jniRexxSetHalt

public int jniRexxSetHalt(java.lang.String tid)
This native method halts a Rexx interpreter instance or individual Rexx threads in the current process. It uses the Rexx function "RexxSetHalt()" (cf. the documentation in the "rexxpg.pdf" book of Object REXX or ooRexx.

Parameters:
tid - a string containing either the thread id as returned by ( ) or the string ;"0", which causes the Rexx interpreter instance to halt (terminate) all its Rexx threads by raising the Rexx halt condition.
Returns:
returns the return code of the Rexx function (from the ooRexx documentation, rev. 4334):
0 RXARI_OK The function completed successfully.
1 RXARI_NOT_FOUND The target Rexx procedure was not found.
2 RXARI_PROCESSING_ERROR A failure in Rexx processing occurred.

jniRexxCreateInterpreterInstance

public java.lang.String jniRexxCreateInterpreterInstance()
Creates a new Rexx interpreter instance using the ooRexx 4.0 API RexxCreateInterpreter().

Returns:
a String representing the created Rexx interpreter instance ID or null, if no Rexx interpreter instance could be created
Since:
May 2009

jniGetRexxInterpreterInstanceRoot

public java.lang.String jniGetRexxInterpreterInstanceRoot()
Returns the Rexx interpreter instance serving as the root of the linked list of Rexx interpreter using the ooRexx 4.0 API RexxCreateInterpreter(). This will be needed in the context where Rexx loads Java, and the Java side needs to set up the BSF infrastructure accordingly.

Returns:
a String representing the root Rexx interpreter instance ID or null, if no Rexx interpreter instance is available at all
Since:
May 2009

jniRexxRunProgram

public java.lang.Object jniRexxRunProgram(java.lang.String rii_ID,
                                          int invocationType,
                                          java.lang.String fileName,
                                          java.lang.String programData,
                                          java.lang.Object[] args)
Uses the ooRexx 4.0 API to execute a Rexx program or to execute a callback (sending a message to a given object).

Parameters:
rii_ID - a String representing the Rexx interpreter instance as returned by ()
invocationType - determines the desired invocation
1
execute Rexx program from file, use the 4.0 API CallProgram
2
execute Rexx program from buffer, uses the 4.0 API NewRoutine and CallRoutine
3
load Rexx package (and run prolog) from file, use the 4.0 API LoadPackage
4
load Rexx package (and run prolog) from buffer, use the 4.0 API LoadPackageFromData
fileName - name (path) to file that contains the program to execute
programData - Rexx code to execute
args - an array of arguments to pass on
Returns:
Throws:
a - RexxException, if the argument does not denote an existing Rexx interpreter instance
Since:
May 2009

jniRexxSendMessageToRexxObject

public java.lang.Object jniRexxSendMessageToRexxObject(java.lang.String rii_ID,
                                                       java.lang.String obj_ID,
                                                       java.lang.String userData_ID,
                                                       java.lang.String javaObjectBean,
                                                       java.lang.String methodObjectBean,
                                                       java.lang.String messageName,
                                                       java.lang.String methodDescription,
                                                       java.lang.Object[] args,
                                                       java.lang.String returnType)
Uses the ooRexx 4.0 API to execute a Rexx program or to execute a callback (sending a message to a given object).

Parameters:
rii_ID - a String representing the Rexx interpreter instance as returned by ()
obj_ID - the object id that is used as a key on the JNI side, ()
userData_ID - optional RexxProxy, supplied either with the BsfCreateRexxProxy() as second argument or later set by programs
javaObjectBean - the Java object that invoked this very callback
methodObjectBean - java.lang.reflect.Method object that was invoked in the Java proxy
messageName - the name of the message to send to the Rexx object (the Rexx object will look for a method named like the message and invoke it)
methodDescription - string formated as internal Java string that describes a method's arguments and return value
args - an array of arguments to pass on
returnType - the primitive type signature (for primitive types or matching wrapper classes) or null for any object
Returns:
0
Throws:
a - RexxException, if the argument does not denote an existing Rexx interpreter instance
Since:
May 2009

jniUnregisterRexxObject

public int jniUnregisterRexxObject(java.lang.String obj_ID)
Unregisters the Rexx object denoted by 'obj_ID' from the JNI registry.

Parameters:
rii_ID - a String representing the Rexx interpreter instance as returned by ()
obj_ID - the object id that is used as a key on the JNI side
Returns:
number of references to the Rexx object in the JNI registry left; a number of '0' indicates that no references are left, a return value of '-1' indicates that the Rexx object was not registered (could not be found)

jniRexxHaltInterpreterInstance

public int jniRexxHaltInterpreterInstance(java.lang.String rii_ID)
Uses the ooRexx 4.0 API Halt() to raise the HALT condition in all Rexx threads belonging to the given Rexx interpreter instance.

Parameters:
rii_ID - a String representing the Rexx interpreter instance as returned by ()
Returns:
0
Throws:
a - RexxException, if the argument does not denote an existing Rexx interpreter instance
Since:
May 2009

jniRexxTerminateInterpreterInstance

public int jniRexxTerminateInterpreterInstance(java.lang.String rii_ID)
Uses the ooRexx 4.0 API Terminate() to wait on all Rexx threads belonging to the given Rexx interpreter instance to terminate.

Parameters:
rii_ID - a String representing the Rexx interpreter instance as returned by ()
Returns:
0
Throws:
a - RexxException, if the argument does not denote an existing Rexx interpreter instance
Since:
May 2009

jniInitialize4Rexx

public int jniInitialize4Rexx()
rgf, 2003-01-15, used for allowing the BSF4ooRexx-DLL to get at *env, *obj and then to mid etc.


javaCallBSF

public java.lang.String javaCallBSF(java.lang.String[] args)
                             throws org.apache.bsf.BSFException
Entry point for Rexx calls into Java. This method carries out all the necessary type conversions and finally calls/invokes the indicated Java method.


"typeIndicator": If a call needs to explicitly indicate the type of Rexx arguments meant for invoking a Java method (indicated by a trailing "Strict" in the subfunction name), than the following strings/characters must be used for defining the type of the argument immediately preceding the respective argument (minimum letters needed are uppercased and printed in bold):

TypeIndicator Following Argument is of Type:
"BOolean" "boolean" i.e. the value 0 (false) or 1 (true)
"BYte" "byte" a byte value
"Char" "char" i.e. a single (UTF8) character
"Double" "double" a double value
"Float" "float" a float value
"Int" "int" an integer value
"Long" "long" a long value
"Object" "Object" an Object which must be registered already
"SHort" "short" a short value
"STring" "String" a string value (UTF8)

Hence, for the "...Strict"-subfunctions the Rexx supplied arguments must be given in pairs by Rexx: first the type argument (from the above table) and then the argument itself.


The call syntax from Rexx looks like, e.g.:

    call BSF "SubFunctionName", "argument1", "argument2", "", ...
 or:
    a=BSF("SubFunctionName", "argument1", "argument2", ...)
 

The following BSF methods are made available to Rexx and can therefore be indicated as the first argument (the 'subfunction') to the 'BSF' call from Rexx:

SubFunctionName Argument Description
"addEventListener" Adds an event listener to a bean and defines the eventText to be generated. These generated texts can be retrieved with the function pollEventText.
beanName Mandatory, name of a registered bean which should get monitored.
eventSetName Mandatory, name of the set the event belongs to. This name is used to create an event adapter at runtime.
filter Mandatory, name of the actual event which should cause a notification.
eventText Mandatory, text which should be sent by this event listener, each time the event occurs.
"arrayAt" Allows accessing a Java array element.
Returns the Java object at the indicated array element, or null, if no object is stored there.
arrayObject Mandatory, name of a registered arrayObject (received by Java).
idx1 Mandatory, integer indicating the position in dimension 1.

Alternatively, a sole Java int-array containing the 0-based index-values.

idx2 Integer indicating the position in dimension 2 ...
"arrayLength" Returns the value of the 'length' field of the arrayObject.
arrayObject Mandatory, name of a registered arrayObject (received by Java).
"arrayPut" Allows to put a new value into a Java array element at the indicated position.
arrayObject Mandatory, name of a registered arrayObject (received by Java).
newValue The new value to be set at the indicated position in the array.
idx1 Mandatory, integer indicating the position in dimension 1.

Alternatively, a sole Java int-array containing the 0-based index-values.

...idxn Integer indicating the position in dimension n ...
"arrayPutStrict" Allows to put a new value into a Java array element at the indicated position.
arrayObject Mandatory, name of a registered arrayObject (received by Java).
typeIndicator Type indicator for newValue
newValue The new value to be set at the indicated position in the array.
idx1 Mandatory, integer indicating the position in dimension 1.

Alternatively, a sole Java int-array containing the 0-based index-values.

... idxn Integer indicating the position in dimension n ...
"bsfPrefixReturnValue" Allows to globally set RexxAndJava to prepend a type hint to the string that gets returned ('<O>' for a Java object in the BSFRegistry where the following string denotes the index value; '<S>' indicates that the remainder is to be interpreted as a plain string)
newSetting Optional. If omitted the current setting will be returned ("1" or quot;0"). If given, then it must be a boolean value, i.e. "1" (true) or quot;0" (false).
"createJavaArray"
"createArray" (deprecated)
Creates a Java array of the given componentType and number of dimensions.
Returns the created Java array object.
componentType Mandatory, name of a registered Java class object or a string fully qualifying a Java class. For convenience, you may use any of the pre-registered beans named (note case of first letter!):
"Class.class", "Object.class", "Method.class", "Array.class", "String.class", "System.class", "Boolean.class", "boolean.class" (primitive data type), "Byte.class", "byte.class" (primitive data type), "Character.class", "char.class" (primitive data type), "Double.class", "double.class" (primitive data type), "Integer.class", "int.class" (primitive data type), "Long.class", "long.class" (primitive data type), "Float.class", "float.class" (primitive data type), "Short.class", "short.class" (primitive data type).
capacity 1 Mandatory, integer indicating the number of elements in dimension 1.

Alternatively, a sole Java int-array containing the capacity per dimension. The first dimension is stored with index 0, the second with index 1, ...

capacity 2 Integer indicating the number of elements in dimension 2.
... capacity n Integer indicating the number of elements in dimension n.
"createJavaArrayOf"
"createArrayOf" (deprecated)
Creates a single dimensioned Java array of the given componentType and adds the supplied arguments to it. The length (size) is determined by the added arguments and can be 0, if only the componentType was given (an empty Java array object).
Returns the created Java array object.
componentType Mandatory, name of a registered Java class object or a string fully qualifying a Java class.
arg # 1 Argument # 1 (if given must be of the given componentType).
... arg # n Argument # n (if given must be of the given componentType).
"wrapArray" Wraps the given array up in a ArrayWrapper-object, allowing easy access to information about the array like dimensions, size and also getting and setting values in an easy manner.
arrayObject Mandatory, name of a registered arrayObject (received by Java).
"exit" Terminates the Java Virtual Machine. Allows Rexx to shut down the JVM (and thereby Rexx as well). In order for Rexx being able to shutdown properly itself, the termination of the JVM is delayed by time2wait.
Returns the string "SHUTDOWN, REXX !".
retVal Optional integer return value. If omitted, then "0" will be used as argument for the System.exit(n) call.
time2wait Optional number of milliseconds (msecs) to wait until the JVM will be terminated. This allows Rexx to shutdown (clean up) its side as well. Default value, if omitted: 100, i.e. 100 msecs, i.e. 1/10th second.
"getBSFManager" Returns the BSFManager object that dispatches this Rexx engine instance. This way one can get at the version of BSF in use, but also one gains the ability to dispatch scripts in any of the supported BSF languages sharing the BSF registry with this Rexx engine instance!
"getFieldValue" Looks up a public field of the registered object. The case of the characters of the field name does not matter.
Hint: If the field cannot be found, then this subfunction assumes that a getter method (field name prepended by "get") exists for the field and tries to invoke one. If you do not want this behaviour use subfunciton "getFieldValueStrict" instead.
Returns the value of the field.
beanName Mandatory, name of the object to be looked up.
fieldName Mandatory, name of the public field of the object.
"getFieldValueStrict" Looks up a public field of the registered object. The case of the characters of the field name must match exactly.
Returns the value of the field.
beanName Mandatory, name of the object to be looked up.
fieldName Mandatory, case sensitive name of the public field of the object.
"getPropertyValue" (untested!) Looks up a property of the registered Java Bean object.
Returns the value of the property.
beanName Mandatory, name of the Java Bean object to be looked up.
propertyName Mandatory, name of the Java Bean property.
index Mandatory, null, if Java Bean property is not indexed, a valid integer number else.
"getRexxAndJava" , synonym: "e;getRAJO"e; Returns the RexxAndJava object to which this Rexx program interfaces.
"getRexxEngine" Returns the RexxEngine object, that is used to run the Rexx program.
"getStaticValue" Looks up a public static field of the given class or interface. This function does not instantiate the class (would not be possible for abstract classes or interfaces). Case of fieldName is not relevant!
Returns the value of the public static field.
className Mandatory, name of the class, abstract class or interface to be looked up.
fieldName Mandatory, name of the public static field of the object.
"getStaticValueStrict" Looks up a public static field of the given class or interface. This function does not instantiate the class (would not be possible for abstract classes or interfaces). Case of fieldName is relevant!
Returns the value of the public static field.
className Mandatory, name of the class, abstract class or interface to be looked up.
fieldName Mandatory, case sensitive name of the public static field of the object.
"haltThread" Halts (terminates) the ooRexx thread with the given tid. A tid value of 0 will cause all ooRexx threads to be halted.
Returns the return value of RexxSetHalt(...): 0 (o.k.), 1 (not found), and 2 (failure).
tid Mandatory, the thread id as returned e.g. by BsfGetTID() or 0 to halt (terminate) all ooRexx threads.
"invoke" Invokes (calls) the method with the given arguments on the bean.
Hint: if the method could not be found and has no arguments, this subfunction assumes that the value of a field is sought. Therefore, it employs the subfunction "getFieldValue" using the methodName as the fieldName. If you do not want to use this feature, then employ the subfunction "invokeStrict" instead.
Returns the result of the method invocation or null.
beanName Mandatory, name of a registered bean on which the method (function) should get invoked.
methodName Mandatory, name of the method which should get invoked. methodName is not case sensitive!
arg # 1 Argument # 1 (if given).
... arg # n Argument # n (if given).
"invokeStrict" Invokes (calls) the method with the given arguments on the bean. The case of the characters of the method name must match exactly. Each Rexx argument must be preceeded by its Java type.
Returns the result of the method invocation or null.
beanName Mandatory, name of a registered bean on which the method (function) should get invoked.
methodName Mandatory, case sensitive name of the method which should get invoked.
typeIndicator # 1 Type indicator for argument # 1 (if given).
arg # 1 The argument # 1 itself (if given).
Any additional arguments must be given in pairs of "typeIndicator" and "arg" as well.
"loadClass" Loads a Java class with the given name.
Returns the object or null, if not found.
beanName Mandatory, fully qualified name of the Java class to be looked. Returns the class object rendered to a string or null, if not found.
"lookupBean" Looks up an object in the BSF manager object registry. (Allows for retrieving pre-declared beans as well.)
Returns the object or null, if not found.
beanName Mandatory, name of the object to be looked up. Returns the object rendered to a string or null, if not found.
"new" or
"registerBean" (a synonym)
Creates a new object (instantiating the given Java class with the given arguments) and registers it using the given beanName.
Returns beanName (always use this returned beanName for looking up the object in the registry).
beanName Name of the object to be created and registered. if no name is given (empty string or null) then a unique one will be created and returned; this is done in method makeBeanName(Object o).
beanType Mandatory, type (Java class name) of the bean (Java object) to be created and registered.
arg # 1 The argument # 1 (if given).
... arg # n The argument # n (if given).
"newStrict" or
"registerBeanStrict" (a synonym)
Creates a new object (instantiating the given Java class with the given arguments) and registers it using the given beanName.
Returns beanName (always use this returned beanName for looking up the object in the registry).
beanName Name of the object to be created and registered. if no name is given (empty string or null) then a unique one will be created and returned; this is done in method makeBeanName(Object o).
beanType Mandatory, type (Java class name) of the bean (Java object) to be created and registered.
typeIndicator # 1 Type indicator for argument # 1 (if given).
arg # 1 The argument # 1 (if given).
Any additional arguments must be given in pairs of "typeIndicator" and "arg" as well.
"pollEventText" Polls for the eventText defined in the above subfunction "addEventListener" placed into a queue by the appropriate event listeners, or posted via "postEventText" below.
If no timeout value is supplied, "0" will be used by default, which blocks the return of this function (forever) until some text is available for return.
Returns available eventText, or if a timeout occurred while waiting null.
timeOut Optional, timeout in milliseconds, i.e. time to wait for an eventText to appear, before returning.
"postEventText" Adds eventText to the eventText vector (list), can be retrieved via pollEventText.
Returns the received eventText
eventText Mandatory, text which should be put into the eventText vector.
priority Optional, priority level of eventText, can be one of:

  • "2": high ('alarm level') priority.
  • "1": normal (default) priority, and
  • "0": low ('batch level') priority,
"rawRegisterBean" or
"new" (a synonym)
Uses the supplied beanName to store the supplied object in the BSFRegistry. Creates a new object (instantiating the given Java class with the given arguments) and registers it using the given beanName.
Returns beanName (always use this returned beanName for looking up the object in the registry).
beanName Name of the object to be created and registered. if no name is given (empty string or null) then a unique one will be created and returned; this is done in method makeBeanName(Object o).
beanType Mandatory, type (Java class name) of the bean (Java object) to be created and registered.
arg # 1 The argument # 1 (if given).
... arg # n The argument # n (if given).
"setFieldValue" Looks up a public field of the registered object and sets it to the argument's value.
Hint: if the field could not be found, this subfunction automatically attempts to employ a setter method (fieldName prepended with the string "set"). If you do not want to use this feature, then employ the subfunction "setFieldValueStrict" instead.
Returns the new value of the field.
beanName Mandatory, name of the object to be looked up.
fieldName Mandatory, name of the public field of the object.
newValue The new value the field gets set to.
"setFieldValueStrict" Looks up a public field of the registered object and sets it to the argument's value.
Returns the new value of the field.
beanName Mandatory, name of the object to be looked up.
fieldName Mandatory, case sensitive name of the public field of the object.
typeIndicator optional type indicator for the immediately following argument (newValue) or newValue.
newValue The new value the field gets set to. (If this argument is given, then the previous argument is interpreted as a typeIndicator .)
"setPropertyValue" (untested!) Looks up a property of the registered Java Bean object and sets it to the argument's value.
Returns the new value of the property.
beanName Mandatory, name of the Java Bean object to be looked up.
propertyName Mandatory, name of the Java Bean property.
index Mandatory, null, if Java Bean property is not indexed, a valid integer number else.
newValue The new value the property gets set to.
"setPropertyValueStrict" (untested!) Looks up a property of the registered Java Bean object and sets it to the argument's value.
Returns the new value of the property.
beanName Mandatory, name of the Java Bean object to be looked up.
propertyName Mandatory, name of the Java Bean property.
index Mandatory, null, if Java Bean property is not indexed, a valid integer number else.
typeIndicator Type indicator for the immediately following argument (newValue).
newValue The new value the property gets set to.
"setRexxNullString" Sets the field null4Rexx to the string which serves as the representation for null.
  • The Java side will return this value to Rexx to indicate a Java null ("no value"). This conversion is done in method makeString4Rexx(Object o).
  • The Rexx side can use this string for an argument for which no value is supplied. This option is available in addition to the standard Rexx option of just leaving the missing argument empty. The conversion of Rexx arguments to Java is done in convFromRexx(String type, String value).
newString Mandatory, the new string to be used to indicate a Java null.
"sleep" Sleeps time2sleep seconds before returning.
time2sleep Mandatory, indicates seconds to sleep before returning. time2sleep. The sleeping occurs with an attempted resolution of milliseconds, being calculated like: (long) ((double)time2sleep*1000+0.5d), e.g.
  • 3 (three seconds, 3000 msec),
  • 600 (600 seconds, i.e. 10 minutes, 600000 msec),
  • 0.5 (5/10 second, i.e. half a second, 500 msec),
  • 0.01 (1/100 second, 10 msec),
  • 0.001 (1/1000 second, 1 msec),
  • 0.0005 (rounded up, ie. 1/1000 second, 1 msec),
  • 0.0004 (rounded down, ie. 0/1000 second, 0 msec).

Hint: If available, use Rexx' SysSleep() function instead (it is usually more exact).

"unregisterBean" Unregisters an object from the BSF manager's object registry.
Returns the former beanName of the just unregistered object.
If the object could not be unregistered, because the reference counter did not drop to 0, then .NIL is returned.
beanName Mandatory, name of bean (Java object) to be unregistered.
"version" Returns the version of this program in the form of "version.YYYYMMMDDD package-name-of-engine info", e.g. "272.20061210 org.rexxla.bsf.engines.rexx (org.apache.bsf)" for Apache's BSF, if no argument is given. Otherwise it returns the version of BSFManager or of the indicated class in the org.rexxla.bsf.engines.rexx package.
classIndicator Optional. If no argument is given the version of this program is returned in the long format: "version.YYYYMMMDDD package-name-of-engine info".
In the following list of arguments only the first uppercase characters need to be given:
"ALl" Returns a blank delimited string with pairs of fully qualified class names and their version number in the form of version.YYYYMMDD.
"ARrayWrapper" Returns the version number of the org.rexxla.bsf.engines.rexx.ArrayWrapper class.
"BSFManager" Returns the version number of the org.apache.bsf.BSFManager class.
"EnumerationWrapper" Returns the version number of the org.rexxla.bsf.engines.rexx.EnumerationWrapper class.
"Java4Rexx" Returns the version number of the org.rexxla.bsf.engines.rexx.Java4Rexx class.
"REXXAndJava" Returns the version number of the org.rexxla.bsf.engines.rexx.RexxAndJava class.
"REXXEngine" Returns the version number of the org.rexxla.bsf.engines.rexx.RexxEngine class.
"Supplier" Returns the version number of the org.rexxla.bsf.engines.rexx.Supplier class.
"wrapEnumeration" Wraps the given object up in a EnumerationWrapper-object, allowing Java 1.1 programs to use the methods of the Enumeration interface (the problem: Java 1.1 raises an IllegalAccessException, if accessing methods of inner classes; starting with 1.2 one can come by this bug under program control).
enumerationObject Mandatory, name of a registered enumerationObject (received by Java).

Returns:
A Rexx string or null.
Throws:
org.apache.bsf.BSFException

invokeMethod

java.lang.Object invokeMethod(java.lang.reflect.Method m,
                              java.lang.Object o,
                              java.lang.Object[] params)
                        throws java.lang.IllegalAccessException,
                               java.lang.reflect.InvocationTargetException
Invokes method and makes sure that any public method will get successfully invoked.

Parameters:
m - method object to use for invocation
o - object for which the method should get invoked
params - Object[] with parameters to supply
Returns:
the result of the method invocation
Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

convFromRexx

protected java.lang.Object convFromRexx(java.lang.String value)
                                 throws org.apache.bsf.BSFException
Replaces a reference to a Java object with the Java object.

Parameters:
value - this String is used to look up the BSF registry. If an entry is found (a Java object) it will get returned, if not (or the value is null) then null is returned.
Returns:
the Java object stored in the BSF registry, null else
Throws:
org.apache.bsf.BSFException

coerceArgs

java.lang.Object[] coerceArgs(java.lang.Object[] funcArgs,
                              java.lang.Class[] paramTypes)
Coerces the arguments from Rexx to the appropriate Java types.

Parameters:
funcArgs - an Object array (actually the Rexx arguments of type String)
paramTypes - an Class array, containing the Java class objects to which the Rexx arguments have to be converted to
Returns:
an array with the coerced arguments, if successful, null else.

registerBean

protected java.lang.String registerBean(java.lang.String beanName,
                                        java.lang.Object object)
This method registers an object with the given beanName with the BSF registry, if not registered yet. In addition a reference counting is carried out.

Parameters:
beanName - name of the object to be registered
object - to be registered
Returns:
returns the beanName

unregisterBean

protected boolean unregisterBean(java.lang.String beanName)
This method allows for unregistering Beans, taking into account reference counters. Only if the reference counter is 0, will the given Bean be unregistered. (2003-01-06, ---rgf)

Parameters:
beanName - name of the Bean to be unregistered
Returns:
returns true, if the Bean exists, false else.

makeString4Rexx

protected java.lang.String makeString4Rexx(java.lang.Object o)
This method determines what String content to return; if a non-primitive Java object a unique beanName is created and used to save the Java object in the BSFRegistry, returning the beanName.

Parameters:
o - the object which should get returned as a string to Rexx.
Returns:
a String rendering of the primitive types and String. Otherwise create a unique bean name, register the object under it and return the bean name. If null, then the string of null4Rexx is returned to Rexx.

makeBeanName

public java.lang.String makeBeanName(java.lang.Object o)
This method creates a unique string value for the passed in object. the code to create the unique name is the same as the documented "Object.hashCode()":
o.getClass().getName() + "@" + Integer.toHexString(o.hashCode()).

Parameters:
o - the object for which a unique string value should be created
Returns:
null, if the argument was null, else a String, uniquely denoting the object

pp

java.lang.String pp(java.lang.Object o)
'Pretty print': returns string value of supplied object enclosed in square brackets.


truncString

java.lang.String truncString(java.lang.String s,
                             int maxLength)
Truncates string, if longer than given maxLength and append ellipsis (three dots: '...').


20100210, rgf