Class RexxProxy

java.lang.Object
org.rexxla.bsf.engines.rexx.RexxProxy
All Implemented Interfaces:
InvocationHandler

public class RexxProxy extends Object implements InvocationHandler
This class allows RexxProxy objects to be created from native (JNI) code and will be registered in the BSFRegistry using the String retrievable by getBsfRegistryKey(). It allows ooRexx objects to be addressed by Java, as well as creating any number of java.lang.reflect.Proxy objects from it(cf. newJavaProxyInstance(Object[] interfaces)) which forward any method invocation to the proxied ooRexx object. The class is public, such that any Java program can define variables of type RexxProxy. However, only native code is capable of instantiating this class.
------------------------ Apache Version 2.0 license -------------------------
    Copyright (C) 2009-2022 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:
1.0.6, 2009-05-03 - 2022-08-11
Author:
Rony G. Flatscher
  • Field Details

    • version

      public static final String version
      Version information on this class.
      See Also:
    • rexxInterpreterID

      protected String rexxInterpreterID
      The string value of the RexxInstance C++ pointer. The RexxProxy object can only be deployed via the RexxInstance in which it got created; note: if the original Rexx interpreter instance was terminated in between its .local directory got garbage collected.
    • rexxObjectID

      protected String rexxObjectID
      The string value of the identity hash value of the ooRexx object, which is used as the key in the proxied ooRexx directory in the JNI code.
    • rexxUserDataID

      protected String rexxUserDataID
      The string value of the identity hash value of the optional "userData" ooRexx object, which - if it is not null - will be submitted as part of the callback directory argument to the Rexx object.
    • bsfRegistryKey

      protected String bsfRegistryKey
      The string value that was used as the key for storing this object in the BSFRegistry.
    • rexxEngine

      protected RexxEngine rexxEngine
      The RexxEngine instance that creates this proxy and which will be used for callbacks.
  • Method Details

    • proxyHashCode

      protected Integer proxyHashCode(Object proxy)
    • proxyEquals

      protected Boolean proxyEquals(Object proxy, Object other)
    • proxyToString

      protected String proxyToString(Object proxy)
    • getRexxInterpreterID

      public String getRexxInterpreterID()
      Getter method.
      Returns:
      the ooRexx Interpreter ID
    • getRexxObjectID

      public String getRexxObjectID()
      Getter method.
      Returns:
      the ooRexx object ID
    • getRexxUserDataID

      public String getRexxUserDataID()
      Getter method.
      Returns:
      the ooRexx object ID
    • getBsfRegistryKey

      public String getBsfRegistryKey()
      Getter method.
      Returns:
      string value that was used as the key for storing this object in the BSFRegistry
    • getRexxEngineInstance

      public RexxEngine getRexxEngineInstance()
      Getter method.
      Returns:
      the RexxEngine instance that gets used to dispatch methods to ooRexx objects
    • sendMessageScoped

      public Object sendMessageScoped(String messageName, Object scope, Object[] args) throws org.apache.bsf.BSFException
      Sends the given message, with the given scope and arguments using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      messageName - name of the method to invoke
      scope - a String or a RexxProxy denoting the Rexx object's superclass to start looking for the method by the name of messageName
      args - array of Objects serving as arguments
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessage

      public Object sendMessage(String messageName, Object[] args) throws org.apache.bsf.BSFException
      Sends the given message with the given arguments using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      messageName - name of the method to invoke
      args - array of Objects serving as arguments
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessage0

      public Object sendMessage0(String messageName) throws org.apache.bsf.BSFException
      Sends the given message using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      messageName - name of the method to invoke
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessage1

      public Object sendMessage1(String messageName, Object arg1) throws org.apache.bsf.BSFException
      Sends the given message with the given argument using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      messageName - name of the method to invoke
      arg1 - single argument
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessage2

      public Object sendMessage2(String messageName, Object arg1, Object arg2) throws org.apache.bsf.BSFException
      Sends the given message with the two given arguments using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      messageName - name of the method to invoke
      arg1 - argument
      arg2 - argument
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessage3

      public Object sendMessage3(String messageName, Object arg1, Object arg2, Object arg3) throws org.apache.bsf.BSFException
      Sends the given message with the three given arguments using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      messageName - name of the method to invoke
      arg1 - argument
      arg2 - argument
      arg3 - argument
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessage4

      public Object sendMessage4(String messageName, Object arg1, Object arg2, Object arg3, Object arg4) throws org.apache.bsf.BSFException
      Sends the given message with the four given arguments using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      messageName - name of the method to invoke
      arg1 - argument
      arg2 - argument
      arg3 - argument
      arg4 - argument
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessage5

      public Object sendMessage5(String messageName, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) throws org.apache.bsf.BSFException
      Sends the given message with the five given arguments using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      messageName - name of the method to invoke
      arg1 - argument
      arg2 - argument
      arg3 - argument
      arg4 - argument
      arg5 - argument
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessageScoped

      public Object sendMessageScoped(RexxEngine re, String messageName, Object scope, Object[] args) throws org.apache.bsf.BSFException
      Sends the given message with the given scope and arguments using a callback to ooRexx using the supplied RexxEngine instance.
      Parameters:
      re - RexxEngine object to use for the call, if null, using RexxEngine object that created this RexxProxy object
      messageName - name of the method to invoke
      scope - a String or a RexxProxy denoting the Rexx object's superclass to start looking for the method by the name of messageName
      args - array of Objects serving as arguments
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessage

      public Object sendMessage(RexxEngine re, String messageName, Object[] args) throws org.apache.bsf.BSFException
      Sends the given message with the given arguments using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      re - RexxEngine object to use for the call, if null, using RexxEngine object that created this RexxProxy object
      messageName - name of the method to invoke
      args - array of Objects serving as arguments
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessage0

      public Object sendMessage0(RexxEngine re, String messageName) throws org.apache.bsf.BSFException
      Sends the given message using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      re - RexxEngine object to use for the call, if null, using RexxEngine object that created this RexxProxy object
      messageName - name of the method to invoke
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessage1

      public Object sendMessage1(RexxEngine re, String messageName, Object arg1) throws org.apache.bsf.BSFException
      Sends the given message with the given argument using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      re - RexxEngine object to use for the call, if null, using RexxEngine object that created this RexxProxy object
      messageName - name of the method to invoke
      arg1 - single argument
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessage2

      public Object sendMessage2(RexxEngine re, String messageName, Object arg1, Object arg2) throws org.apache.bsf.BSFException
      Sends the given message with the two given arguments using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      re - RexxEngine object to use for the call, if null, using RexxEngine object that created this RexxProxy object
      messageName - name of the method to invoke
      arg1 - argument
      arg2 - argument
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessage3

      public Object sendMessage3(RexxEngine re, String messageName, Object arg1, Object arg2, Object arg3) throws org.apache.bsf.BSFException
      Sends the given message with the three given arguments using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      re - RexxEngine object to use for the call, if null, using RexxEngine object that created this RexxProxy object
      messageName - name of the method to invoke
      arg1 - argument
      arg2 - argument
      arg3 - argument
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessage4

      public Object sendMessage4(RexxEngine re, String messageName, Object arg1, Object arg2, Object arg3, Object arg4) throws org.apache.bsf.BSFException
      Sends the given message with the four given arguments using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      re - RexxEngine object to use for the call, if null, using RexxEngine object that created this RexxProxy object
      messageName - name of the method to invoke
      arg1 - argument
      arg2 - argument
      arg3 - argument
      arg4 - argument
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessage5

      public Object sendMessage5(RexxEngine re, String messageName, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) throws org.apache.bsf.BSFException
      Sends the given message with the five given arguments using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      re - RexxEngine object to use for the call, if null, using RexxEngine object that created this RexxProxy object
      messageName - name of the method to invoke
      arg1 - argument
      arg2 - argument
      arg3 - argument
      arg4 - argument
      arg5 - argument
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessageScoped

      public Object sendMessageScoped(org.rexxla.bsf.engines.rexx.RexxAndJava raj, String messageName, Object scope, Object[] args) throws org.apache.bsf.BSFException
      Sends the given message with the given scope and arguments using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      raj - RexxAndJava object which RexxEngine will be used for the call, if null, using RexxEngine object that created this RexxProxy object
      messageName - name of the method to invoke
      scope - a String or a RexxProxy denoting the Rexx object's superclass to start looking for the method by the name of messageName
      args - array of Objects serving as arguments
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessage

      public Object sendMessage(org.rexxla.bsf.engines.rexx.RexxAndJava raj, String messageName, Object[] args) throws org.apache.bsf.BSFException
      Sends the given message with the given arguments using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      raj - RexxAndJava object which RexxEngine will be used for the call, if null, using RexxEngine object that created this RexxProxy object
      messageName - name of the method to invoke
      args - array of Objects serving as arguments
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessage0

      public Object sendMessage0(org.rexxla.bsf.engines.rexx.RexxAndJava raj, String messageName) throws org.apache.bsf.BSFException
      Sends the given message using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      raj - RexxAndJava object which RexxEngine will be used for the call, if null, using RexxEngine object that created this RexxProxy object
      messageName - name of the method to invoke
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessage1

      public Object sendMessage1(org.rexxla.bsf.engines.rexx.RexxAndJava raj, String messageName, Object arg1) throws org.apache.bsf.BSFException
      Sends the given message with the given argument using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      raj - RexxAndJava object which RexxEngine will be used for the call, if null, using RexxEngine object that created this RexxProxy object
      messageName - name of the method to invoke
      arg1 - single argument
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessage2

      public Object sendMessage2(org.rexxla.bsf.engines.rexx.RexxAndJava raj, String messageName, Object arg1, Object arg2) throws org.apache.bsf.BSFException
      Sends the given message with the two given arguments using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      raj - RexxAndJava object which RexxEngine will be used for the call, if null, using RexxEngine object that created this RexxProxy object
      messageName - name of the method to invoke
      arg1 - argument
      arg2 - argument
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessage3

      public Object sendMessage3(org.rexxla.bsf.engines.rexx.RexxAndJava raj, String messageName, Object arg1, Object arg2, Object arg3) throws org.apache.bsf.BSFException
      Sends the given message with the three given arguments using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      raj - RexxAndJava object which RexxEngine will be used for the call, if null, using RexxEngine object that created this RexxProxy object
      messageName - name of the method to invoke
      arg1 - argument
      arg2 - argument
      arg3 - argument
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessage4

      public Object sendMessage4(org.rexxla.bsf.engines.rexx.RexxAndJava raj, String messageName, Object arg1, Object arg2, Object arg3, Object arg4) throws org.apache.bsf.BSFException
      Sends the given message with the four given arguments using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      raj - RexxAndJava object which RexxEngine will be used for the call, if null, using RexxEngine object that created this RexxProxy object
      messageName - name of the method to invoke
      arg1 - argument
      arg2 - argument
      arg3 - argument
      arg4 - argument
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • sendMessage5

      public Object sendMessage5(org.rexxla.bsf.engines.rexx.RexxAndJava raj, String messageName, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) throws org.apache.bsf.BSFException
      Sends the given message with the five given arguments using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      raj - RexxAndJava object which RexxEngine will be used for the call, if null, using RexxEngine object that created this RexxProxy object
      messageName - name of the method to invoke
      arg1 - argument
      arg2 - argument
      arg3 - argument
      arg4 - argument
      arg5 - argument
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • invoke

      public Object invoke(Method methodObject, Object[] args) throws org.apache.bsf.BSFException
      Invokes the given method with the given arguments using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      methodObject - for which we invoke a Rexx message
      args - array of Objects serving as arguments
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
    • invoke

      public Object invoke(Object javaObject, String methodName, String methodDescriptor, Object[] args) throws org.apache.bsf.BSFException
      Invokes the given method with the given arguments using a callback to ooRexx using the RexxEngine instance.
      Parameters:
      javaObject - object that invoked this callback, such that the Rexx side can get access to it and send additional messages to it
      methodName - this name is used as the message to be sent to the Rexx object
      methodDescriptor - the Java internal representation of the method's arguments and return type, if any
      args - array of Objects serving as arguments
      Returns:
      value that the ooRexx method returns, if any
      Throws:
      org.apache.bsf.BSFException
      Since:
      2009-07-11
    • invoke

      public Object invoke(Object proxy, Method method, Object[] args) throws org.apache.bsf.BSFException
      Implements the InvocationHandler's method.
      Specified by:
      invoke in interface InvocationHandler
      Throws:
      org.apache.bsf.BSFException
    • newJavaProxyInstance

      public Proxy newJavaProxyInstance(Object[] interfaces) throws IllegalArgumentException
      Creates an instance of java.lang.reflect.Proxy using the supplied list of interfaces; will use the RexxProxy as the target object.
      Parameters:
      interfaces - array of interfaces the java.lang.reflect.Proxy object should implement. Each element may be either a class object, a String which denotes a fully qualified class name which should be loaded instead, or any other object, whose implemented interfaces should be honored.
      Returns:
      java.lang.reflect.Proxy object which dispatches all messages to this RexxProxy instance, which itself will dispatch (forward) it to ooRexx via a callback
      Throws:
      IllegalArgumentException
    • newExtendedProxyInstance

      Creates a new class from a supplied abstract class on the fly with all abstract methods being implemented such that they forward their invocations to a RexxProxy. This method then instantiates the extended class supplying itself as the RexxProxy object to be the target of the dispatch. If more than one element gets supplied in the argument array, then they are taken as values for the constructor to invoke.
      Parameters:
      arguments - array of arguments, element at index 0 must be given and denotes an abstract class whose abstract methods should be implemented; remaining arguments are taken as arguments for the constructor of the extended class
      Returns:
      object which dispatches all method invocations to this RexxProxy instance, which itself will dispatch (forward) it to ooRexx via a callback
      Throws:
      IllegalArgumentException
      ClassNotFoundException
      NoSuchFieldException
      NoSuchMethodException
      org.apache.bsf.BSFException
      IllegalAccessException
      InvocationTargetException