20120618, rgf

org.rexxla.bsf.engines.rexx
Class ProxiedJavaClassTool

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

public class ProxiedJavaClassTool
extends java.lang.Object

This class creates a proxied Java class on the fly, which has concrete implementations for all abstract (inherited or not) methods. Additionally it allows for creating proxy methods for concrete methods and matching <">_forwardToSuper<"> methods to allow ooRexx to forward proxied Java method invocations to their original target on the Java side.

------------------------ Apache Version 2.0 license -------------------------
    Copyright (C) 2010-2012 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:
0.6.0, 2010-03-27, 2010-04-14, 2010-04-17, 2010-04-18, 2010-11-30, 2011-05-31
Author:
Rony G. Flatscher (WU-Wien/Wirtschaftsuniversität Wien, http://www.wu.ac.at)

Nested Class Summary
(package private) static class ProxiedJavaClassTool.RunInfos
          Inner class to make maintenance and access to management data structures easy.
 
Field Summary
static boolean bDoNotProxySyntheticMethods
           
static boolean bss
           
static boolean bTiming
           
 
Method Summary
(package private) static java.lang.String[] createArgumentHead(java.lang.Class[] paramTypes, boolean bCreateForConstructor, boolean bCreateInvokeArg)
          Creates an argument list as a String from the supplied array of Classes representing the types.
(package private) static void createConstructors(java.lang.StringBuffer sb, java.lang.String newClzName, java.lang.Class javaClassToProxy, boolean bProxyConstructors, ProxiedJavaClassTool.RunInfos ri)
           
(package private) static void createConstructorsBase(java.lang.StringBuffer sb, java.lang.String newClzName, java.lang.Class javaClassToProxy, boolean bProxyConstructors, ProxiedJavaClassTool.RunInfos ri)
          Creates the base constructor (the default constructor and the default constructor with a RexxProxy argument) statements, if possible.
(package private) static void createEpilog(java.lang.StringBuffer sb)
          Creates the epilog statement.
(package private) static java.lang.String createListOfClassNames(java.lang.Class[] paramTypes, int kind)
          Create comma-separated list of parameter types, enclosed in round parenthesis.
(package private) static void createMethod(java.lang.StringBuffer sb, java.lang.reflect.Method m, java.lang.String newClzName, ProxiedJavaClassTool.RunInfos ri)
          Creates a public method proxy for the supplied Method object.
(package private) static void createMethods(java.lang.StringBuffer sb, java.lang.String newClzName, java.lang.Class javaClassToProxy, java.lang.String[] methods2proxy, ProxiedJavaClassTool.RunInfos ri)
          Controls which public methods get created on the fly.
(package private) static void createProlog(java.lang.StringBuffer sb, java.lang.String newClzName, java.lang.Class javaClassToProxy, ProxiedJavaClassTool.RunInfos ri)
          Creates the prolog statements (import, class definition, fields, getter/setter for default RexxProxy handlers.
static java.lang.Class createProxiedJavaClass(java.lang.Class javaClassToProxy, java.lang.String newClzName, java.lang.String[] methodNames2proxy)
          Creates and returns a proxy class in which Java method invocations get forwarded to a RexxProxy.
(package private) static java.lang.String createReturnStatements(java.lang.Class returnType)
          Creates the statements for returning the result of invoking the RexxProxy, possibly cast to primitive types.
(package private) static java.lang.String[] createThrowsClause(java.lang.Class[] excTypes)
          Create comma-separated list of parameter types, enclosed in round parenthesis.
(package private) static java.lang.String getEditedClassName(java.lang.Class clz)
          Creates and returns the name of the supplied class, taking array classes into consideration.
static void main(java.lang.String[] args)
           
(package private) static java.lang.String[] parseMethod2Proxy(java.lang.String val)
          Parses a string from Rexx that consists of "[Java_Class_Name ]method_name".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bTiming

public static boolean bTiming

bss

public static boolean bss

bDoNotProxySyntheticMethods

public static boolean bDoNotProxySyntheticMethods
Method Detail

main

public static void main(java.lang.String[] args)
                 throws org.apache.bsf.BSFException
Throws:
org.apache.bsf.BSFException

createProxiedJavaClass

public static java.lang.Class createProxiedJavaClass(java.lang.Class javaClassToProxy,
                                                     java.lang.String newClzName,
                                                     java.lang.String[] methodNames2proxy)
                                              throws org.apache.bsf.BSFException
Creates and returns a proxy class in which Java method invocations get forwarded to a RexxProxy.

Parameters:
javaClassToProxy - Class object to use for proxying
newClzName - null or name for proxy class to create
methodNames2proxy - null or array of Strings denoting the names of methods to proxy (each entry either the method name, or the class name blank-delimited with the method name)
Returns:
the class object representing the extended class
Throws:
org.apache.bsf.BSFException

createProlog

static void createProlog(java.lang.StringBuffer sb,
                         java.lang.String newClzName,
                         java.lang.Class javaClassToProxy,
                         ProxiedJavaClassTool.RunInfos ri)
                  throws org.apache.bsf.BSFException
Creates the prolog statements (import, class definition, fields, getter/setter for default RexxProxy handlers.

Parameters:
sb - the StringBuffer to append the statements to
newClzName - the new name of the new class
javaClassToProxy - the Java (abstract) class that gets extended
ri - RunInfos runtime infos for managing the process
Throws:
org.apache.bsf.BSFException

createEpilog

static void createEpilog(java.lang.StringBuffer sb)
Creates the epilog statement.

Parameters:
sb - the StringBuffer to append the statements to

createConstructorsBase

static void createConstructorsBase(java.lang.StringBuffer sb,
                                   java.lang.String newClzName,
                                   java.lang.Class javaClassToProxy,
                                   boolean bProxyConstructors,
                                   ProxiedJavaClassTool.RunInfos ri)
Creates the base constructor (the default constructor and the default constructor with a RexxProxy argument) statements, if possible.

Parameters:
sb - the StringBuffer to append the statements to
newClzName - the new name of the new class
javaClassToProxy - the Java (abstract) class that gets extended
bProxyConstructors - determines whether constructor invocations get proxied to the RexxProxy (true)
ri - RunInfos runtime infos for managing the process

createConstructors

static void createConstructors(java.lang.StringBuffer sb,
                               java.lang.String newClzName,
                               java.lang.Class javaClassToProxy,
                               boolean bProxyConstructors,
                               ProxiedJavaClassTool.RunInfos ri)

createMethods

static void createMethods(java.lang.StringBuffer sb,
                          java.lang.String newClzName,
                          java.lang.Class javaClassToProxy,
                          java.lang.String[] methods2proxy,
                          ProxiedJavaClassTool.RunInfos ri)
                   throws org.apache.bsf.BSFException
Controls which public methods get created on the fly. All abstract methods get implemented, optionally methods that are supplied in the methods2proxy argument. As each method must have a unique signature, hence no method with a unique signature is created more than once.

Parameters:
sb - the StringBuffer to append the statements to
newClzName - the new name of the new class
javaClassToProxy - the Java (abstract) class that gets extended
methods2proxy - String list of method names to create proxies for; a method name may be prepended with the name of a superclass delimited with a blank
ri - RunInfos runtime infos for managing the process
Throws:
org.apache.bsf.BSFException

createMethod

static void createMethod(java.lang.StringBuffer sb,
                         java.lang.reflect.Method m,
                         java.lang.String newClzName,
                         ProxiedJavaClassTool.RunInfos ri)
Creates a public method proxy for the supplied Method object.

Parameters:
sb - the StringBuffer to append the statements to
m - a Method object which needs to get proxied
newClzName - the new name of the new class
ri - RunInfos runtime infos for managing the process

parseMethod2Proxy

static java.lang.String[] parseMethod2Proxy(java.lang.String val)
Parses a string from Rexx that consists of "[Java_Class_Name ]method_name".

Parameters:
val - a String value which denotes an optional Java class name, followed by a blank, followed by a mandatory method name. All methods with the same name in the given class will get proxied. If no class name is given, the method name relates to the extended Java class.
Returns:
null, if supplied argument is null or empty, else a String array, containing
index 0
the mixed case Java class name or null, if missing
index 1
the upper case Java class name or null, if missing
index 2
the mixed case method name
index 3
the upper case Java method name

createArgumentHead

static java.lang.String[] createArgumentHead(java.lang.Class[] paramTypes,
                                             boolean bCreateForConstructor,
                                             boolean bCreateInvokeArg)
Creates an argument list as a String from the supplied array of Classes representing the types.

Parameters:
paramTypes - array of Class objects representing the types
bCreateForConstructor - first String should inject as first argument the RexxProxy to forward to
bCreateInvokeArg - determines whether the invocations of constructors get forwarded to the RexxProxy
Returns:
a String array, where index 0 represents the parenthized argument list, index 1 represents the parenthized argument list without the RexxProxy argument, index 2 is either null or defines an array of type Object to allow the received arguments to be forwarded to the rexxProxy

createReturnStatements

static java.lang.String createReturnStatements(java.lang.Class returnType)
Creates the statements for returning the result of invoking the RexxProxy, possibly cast to primitive types. This method assumes that the result of invoking a method on a RexxProxy will be stored in a local variable named "res".

Parameters:
returnType - the class object of the return type
Returns:
returns a string representing the necessary statements to return the return value with the proper type

createListOfClassNames

static java.lang.String createListOfClassNames(java.lang.Class[] paramTypes,
                                               int kind)
Create comma-separated list of parameter types, enclosed in round parenthesis.

Parameters:
paramTypes - array of Class objects
kind -

createThrowsClause

static java.lang.String[] createThrowsClause(java.lang.Class[] excTypes)
Create comma-separated list of parameter types, enclosed in round parenthesis.

Parameters:
excTypes - array of Class objects representing the exceptions that may be thrown
Returns:
a String array with two elements, the first entry representing the original list of exceptions, the second entry extends this list by the BSFException

getEditedClassName

static java.lang.String getEditedClassName(java.lang.Class clz)
Creates and returns the name of the supplied class, taking array classes into consideration.

Parameters:
clz - the class to create a name for
Returns:
the class name

20120618, rgf