org.apache.bsf.engines.rexx
Class RexxAndJava

java.lang.Object
  |
  +--org.apache.bsf.engines.rexx.RexxAndJava

class RexxAndJava
extends java.lang.Object

This class manages the calls from Rexx or Object Rexx into Java.

Added ability to invoke Java methods without giving type of arguments! (On the way from the 2003 International Rexx symposium back home to Vienna.)

  RexxAndJava.java - this class relays Java and (Object) Rexx
  Copyright (C) 2001-2003 Rony G. Flatscher

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

  The following URL may be available for further information:

     http://www.gnu.org/copyleft/lesser.html

Since:
2001-03-01 by Rony G. Flatscher
Version:
2.0.1, 2003-05-30
Author:
Rony G. Flatscher (University of Essen & WU Wien University & University of Augsburg), Peter Kalender (Oct 2000 to Feb 2001, University of Essen)

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
private static int ADD_EVENT_LISTENER
           
private static int ARRAY_AT
           
private static int ARRAY_LENGTH
           
private static int ARRAY_PUT
           
private static int ARRAY_PUT_STRICT
           
(package private) static boolean bMethodHasSetAccessible
          true if setting accessibility rights is available, false else.
private static int CREATE_ARRAY_OBJECT
           
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_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.
private static int EXIT
           
private static int GET_FIELD_VALUE
           
private static int GET_PROPERTY_VALUE
           
private static int GET_STATIC_VALUE
           
private static int GET_VERSION
           
(package private)  org.apache.bsf.util.type.TypeConvertorRegistry glob_tcr
          To store the default TypeConvertorRegistry, if needed.
private static int INVOKE
           
private static int INVOKE_STRICT
           
private static int LOOKUP_BEAN
           
(package private)  java.util.Hashtable methodReferences
          Allows storing successfully reflected methods.
(package private)  org.apache.bsf.BSFManager mgr
          Stores the BSF manager.
protected static java.lang.String null4Rexx
          Defines the string which represents null, by default ".NIL".
(package private)  java.util.Hashtable orxReferences
          Stores the number of references from Object Rexx to Java objects using beanName as the key.
private static int POLL_EVENT_TEXT
           
private static int POST_EVENT_TEXT
           
private static int REGISTER_BEAN
           
private static int REGISTER_BEAN_STRICT
           
(package private)  org.apache.bsf.BSFEngine RexxEngine
          Stores the Rexx engine.
private static int SET_FIELD_VALUE
           
private static int SET_FIELD_VALUE_STRICT
           
private static int SET_PROPERTY_VALUE
           
private static int SET_PROPERTY_VALUE_STRICT
           
private static int SET_REXX_NULL_STRING
           
private static int SLEEP
           
private static java.lang.String STRING_ADD_EVENT_LISTENER
           
private static java.lang.String STRING_ARRAY_AT
           
private static java.lang.String STRING_ARRAY_LENGTH
           
private static java.lang.String STRING_ARRAY_PUT
           
private static java.lang.String STRING_ARRAY_PUT_STRICT
           
private static java.lang.String STRING_CREATE_ARRAY_OBJECT
           
private static java.lang.String STRING_EXIT
           
private static java.lang.String STRING_GET_FIELD_VALUE
           
private static java.lang.String STRING_GET_PROPERTY_VALUE
           
private static java.lang.String STRING_GET_STATIC_VALUE
           
private static java.lang.String STRING_GET_VERSION
           
private static java.lang.String STRING_INVOKE
           
private static java.lang.String STRING_INVOKE_STRICT
           
private static java.lang.String STRING_LOOKUP_BEAN
           
private static java.lang.String STRING_POLL_EVENT_TEXT
           
private static java.lang.String STRING_POST_EVENT_TEXT
           
private static java.lang.String STRING_REGISTER_BEAN
           
private static java.lang.String STRING_REGISTER_BEAN_STRICT
           
private static java.lang.String STRING_SET_FIELD_VALUE
           
private static java.lang.String STRING_SET_FIELD_VALUE_STRICT
           
private static java.lang.String STRING_SET_PROPERTY_VALUE
           
private static java.lang.String STRING_SET_PROPERTY_VALUE_STRICT
           
private static java.lang.String STRING_SET_REXX_NULL_STRING
           
private static java.lang.String STRING_SLEEP
           
private static java.lang.String STRING_UNREGISTER_BEAN
           
private static java.lang.String STRING_WRAP_ARRAY_OBJECT
           
private static java.lang.String STRING_WRAP_ENUMERATION_OBJECT
           
private static int UNREGISTER_BEAN
           
private static int WRAP_ARRAY_OBJECT
           
private static int WRAP_ENUMERATION_OBJECT
           
 
Constructor Summary
(package private) 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.
private  java.lang.Object convFromRexx(java.lang.String value)
          Replaces a reference to a Java object with the Java object.
private  java.lang.Object convFromRexx(java.lang.String type, java.lang.String value)
          Converts the string from Rexx to the indicated type.
 java.lang.String javaCallBSF(java.lang.String[] args)
          Entry point for Rexx calls into Java.
 int jniInitialize4Rexx()
          rgf, 2003-01-15, used for allowing the BSF4Rexx-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.
 int jniRexxDidRexxTerminate()
          This native method indicates whether the Object Rexx is still running or not. (2002-12-13, ---rgf)
 java.lang.String jniRexxStart(java.lang.String script, java.lang.String[] args)
          This native method Calls the Rexx interpreter, having it execute the passed in script with the given array of arguments.
 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. (2002-12-07, ---rgf)
protected  java.lang.String makeString4Rexx(java.lang.Object o)
          This method determines what String content to return.
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

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

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.


eventTextList

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


bMethodHasSetAccessible

static boolean bMethodHasSetAccessible
true if setting accessibility rights is available, false else.


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.


methodReferences

java.util.Hashtable methodReferences
Allows storing successfully reflected methods. If a method is invoked on a bean, it is being retrieved via reflection, a relatively slow process. This Hashtable allows re-usage of method objects for invocation purposes. The format is: "className"+" "+"methodname"+" "+nr_of_method_args, the stored object is a vector of arrays of class-objects representing the needed argument types. (It is possible that there are different signatures for a method, although the number of arguments is the same.) If this is too slow, one could use a different scheme.


glob_tcr

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


ADD_EVENT_LISTENER

private static final int ADD_EVENT_LISTENER
See Also:
Constant Field Values

ARRAY_AT

private static final int ARRAY_AT
See Also:
Constant Field Values

ARRAY_LENGTH

private static final int ARRAY_LENGTH
See Also:
Constant Field Values

ARRAY_PUT

private static final int ARRAY_PUT
See Also:
Constant Field Values

ARRAY_PUT_STRICT

private static final int ARRAY_PUT_STRICT
See Also:
Constant Field Values

CREATE_ARRAY_OBJECT

private static final int CREATE_ARRAY_OBJECT
See Also:
Constant Field Values

EXIT

private static final int EXIT
See Also:
Constant Field Values

GET_FIELD_VALUE

private static final int GET_FIELD_VALUE
See Also:
Constant Field Values

GET_PROPERTY_VALUE

private static final int GET_PROPERTY_VALUE
See Also:
Constant Field Values

GET_STATIC_VALUE

private static final int GET_STATIC_VALUE
See Also:
Constant Field Values

GET_VERSION

private static final int GET_VERSION
See Also:
Constant Field Values

INVOKE

private static final int INVOKE
See Also:
Constant Field Values

INVOKE_STRICT

private static final int INVOKE_STRICT
See Also:
Constant Field Values

LOOKUP_BEAN

private static final int LOOKUP_BEAN
See Also:
Constant Field Values

POLL_EVENT_TEXT

private static final int POLL_EVENT_TEXT
See Also:
Constant Field Values

POST_EVENT_TEXT

private static final int POST_EVENT_TEXT
See Also:
Constant Field Values

REGISTER_BEAN

private static final int REGISTER_BEAN
See Also:
Constant Field Values

REGISTER_BEAN_STRICT

private static final int REGISTER_BEAN_STRICT
See Also:
Constant Field Values

SET_FIELD_VALUE

private static final int SET_FIELD_VALUE
See Also:
Constant Field Values

SET_FIELD_VALUE_STRICT

private static final int SET_FIELD_VALUE_STRICT
See Also:
Constant Field Values

SET_PROPERTY_VALUE

private static final int SET_PROPERTY_VALUE
See Also:
Constant Field Values

SET_PROPERTY_VALUE_STRICT

private static final int SET_PROPERTY_VALUE_STRICT
See Also:
Constant Field Values

SET_REXX_NULL_STRING

private static final int SET_REXX_NULL_STRING
See Also:
Constant Field Values

SLEEP

private static final int SLEEP
See Also:
Constant Field Values

UNREGISTER_BEAN

private static final int UNREGISTER_BEAN
See Also:
Constant Field Values

WRAP_ARRAY_OBJECT

private static final int WRAP_ARRAY_OBJECT
See Also:
Constant Field Values

WRAP_ENUMERATION_OBJECT

private static final int WRAP_ENUMERATION_OBJECT
See Also:
Constant Field Values

STRING_ADD_EVENT_LISTENER

private static final java.lang.String STRING_ADD_EVENT_LISTENER
See Also:
Constant Field Values

STRING_ARRAY_AT

private static final java.lang.String STRING_ARRAY_AT
See Also:
Constant Field Values

STRING_ARRAY_LENGTH

private static final java.lang.String STRING_ARRAY_LENGTH
See Also:
Constant Field Values

STRING_ARRAY_PUT

private static final java.lang.String STRING_ARRAY_PUT
See Also:
Constant Field Values

STRING_ARRAY_PUT_STRICT

private static final java.lang.String STRING_ARRAY_PUT_STRICT
See Also:
Constant Field Values

STRING_CREATE_ARRAY_OBJECT

private static final java.lang.String STRING_CREATE_ARRAY_OBJECT
See Also:
Constant Field Values

STRING_EXIT

private static final java.lang.String STRING_EXIT
See Also:
Constant Field Values

STRING_GET_FIELD_VALUE

private static final java.lang.String STRING_GET_FIELD_VALUE
See Also:
Constant Field Values

STRING_GET_PROPERTY_VALUE

private static final java.lang.String STRING_GET_PROPERTY_VALUE
See Also:
Constant Field Values

STRING_GET_STATIC_VALUE

private static final java.lang.String STRING_GET_STATIC_VALUE
See Also:
Constant Field Values

STRING_GET_VERSION

private static final java.lang.String STRING_GET_VERSION
See Also:
Constant Field Values

STRING_INVOKE

private static final java.lang.String STRING_INVOKE
See Also:
Constant Field Values

STRING_INVOKE_STRICT

private static final java.lang.String STRING_INVOKE_STRICT
See Also:
Constant Field Values

STRING_LOOKUP_BEAN

private static final java.lang.String STRING_LOOKUP_BEAN
See Also:
Constant Field Values

STRING_POLL_EVENT_TEXT

private static final java.lang.String STRING_POLL_EVENT_TEXT
See Also:
Constant Field Values

STRING_POST_EVENT_TEXT

private static final java.lang.String STRING_POST_EVENT_TEXT
See Also:
Constant Field Values

STRING_REGISTER_BEAN

private static final java.lang.String STRING_REGISTER_BEAN
See Also:
Constant Field Values

STRING_REGISTER_BEAN_STRICT

private static final java.lang.String STRING_REGISTER_BEAN_STRICT
See Also:
Constant Field Values

STRING_SET_FIELD_VALUE

private static final java.lang.String STRING_SET_FIELD_VALUE
See Also:
Constant Field Values

STRING_SET_FIELD_VALUE_STRICT

private static final java.lang.String STRING_SET_FIELD_VALUE_STRICT
See Also:
Constant Field Values

STRING_SET_PROPERTY_VALUE

private static final java.lang.String STRING_SET_PROPERTY_VALUE
See Also:
Constant Field Values

STRING_SET_PROPERTY_VALUE_STRICT

private static final java.lang.String STRING_SET_PROPERTY_VALUE_STRICT
See Also:
Constant Field Values

STRING_SET_REXX_NULL_STRING

private static final java.lang.String STRING_SET_REXX_NULL_STRING
See Also:
Constant Field Values

STRING_SLEEP

private static final java.lang.String STRING_SLEEP
See Also:
Constant Field Values

STRING_UNREGISTER_BEAN

private static final java.lang.String STRING_UNREGISTER_BEAN
See Also:
Constant Field Values

STRING_WRAP_ARRAY_OBJECT

private static final java.lang.String STRING_WRAP_ARRAY_OBJECT
See Also:
Constant Field Values

STRING_WRAP_ENUMERATION_OBJECT

private static final java.lang.String STRING_WRAP_ENUMERATION_OBJECT
See Also:
Constant Field Values
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

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.


jniRexxStart

public java.lang.String jniRexxStart(java.lang.String script,
                                     java.lang.String[] args)
This native method Calls the Rexx interpreter, having it execute the passed in script with the given array of arguments.

Parameters:
script - a String consisting of Rexx statements separated by by line-end characters (';' or CR-LF).
args - an array of Strings representing the arguments or null, if no arguments are available.
Returns:
a String containing the result or null, if no result is returned or the Rexx interpreter stopped execution due to a runtime error.

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. (2002-12-07, ---rgf)

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 is still running or not. (2002-12-13, ---rgf)

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

jniInitialize4Rexx

public int jniInitialize4Rexx()
rgf, 2003-01-15, used for allowing the BSF4Rexx-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).
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.

idx2 Integer indicating the position in dimension 2 ...
"createArray" 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. 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.
"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.
"getFieldValue" Looks up a public field of the registered object.
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.
"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.
"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).
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.
"invoke" Invokes (calls) the method with the given arguments on the bean.
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.
arg # 1 Argument # 1 (if given).
... arg # n Argument # n (if given).
"invokeStrict" Invokes (calls) the method with the given arguments on the bean. 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, 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.
"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.
"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,
"registerBean" 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; the code to create the unique name is the same as the documented "Object.hashCode()":
o.getClass().getName() + "@" + Integer.toHexString(o.hashCode()).
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).
"registerBeanStrict" 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; the code to create the unique name is the same as the documented "Object.hashCode()":
o.getClass().getName() + "@" + Integer.toHexString(o.hashCode()).
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.
"setFieldValue" 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, 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, name of the public field of the object.
typeIndicator Type indicator for the immediately following argument (newValue).
newValue The new value the field gets set to.
"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.
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", e.g. "200.20030416 com.ibm.bsf.engines.rexx" for IBM's BSF or "200.20030416 org.apache.bsf.engines.rexx" for Apache's BSF.
There exists no argument for this subfunction.
"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 restriction under program control).
enumerationObject Mandatory, name of a registered enumerationObject (received by Java).

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

convFromRexx

private java.lang.Object convFromRexx(java.lang.String type,
                                      java.lang.String value)
                               throws org.apache.bsf.BSFException
Converts the string from Rexx to the indicated type. If a type 'O' is indicated and the value for it is an empty string, then null is returned for it.

Parameters:
type - one of "BOolean" (i.e. '0' or '1'), "BYte", "Char", "Double", "Float", "Int", "Long", "Object" (Object, i.e. a registered bean), "SHort", and "STring".
value - the value from Rexx (a string) to be converted to the Java type.
Returns:
the converted value.
org.apache.bsf.BSFException

convFromRexx

private 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
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.

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.

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.