public class ProxiedJavaClassTool
extends java.lang.Object
------------------------ Apache Version 2.0 license ------------------------- Copyright (C) 2010-2017 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. -----------------------------------------------------------------------------
Modifier and Type | Class and Description |
---|---|
(package private) static class |
ProxiedJavaClassTool.RunInfos
Inner class to make maintenance and access to management data structures easy.
|
Modifier and Type | Field and Description |
---|---|
static boolean |
bShowSource |
static boolean |
bTiming |
static java.lang.String |
version
Version information on this class.
|
Modifier and Type | Method and Description |
---|---|
(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 void |
createInterfaceMethods(java.lang.StringBuffer sb,
java.lang.String newClzName,
java.lang.Class ifClz,
ProxiedJavaClassTool.RunInfos ri,
java.lang.Class<?> tmpClz)
Controls the creation of interface methods (they are always public).
|
(package private) static void |
createInterfaceMethodsWorker(java.lang.StringBuffer sb,
java.lang.String newClzName,
java.lang.Class ifClz,
ProxiedJavaClassTool.RunInfos ri,
java.lang.Class<?> tmpClz) |
(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,
java.lang.Class[] interfaceClasses,
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,
java.lang.Class[] interfaceClasses)
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)
Allow using this class from the command line to create an extended Java class and displaying the generated source.
|
(package private) static java.lang.String[] |
parseMethod2Proxy(java.lang.String val)
Parses a string from Rexx that consists of "[Java_Class_Name ]method_name".
|
public static boolean bTiming
public static boolean bShowSource
public static final java.lang.String version
public static void main(java.lang.String[] args) throws org.apache.bsf.BSFException
java java org.rexxla.bsf.engines.rexx.ProxiedJavaClassTool javax.swing.AbstractAction ronysClass "*"
blankDelimitedStrings
- in the form of "fullJavaClassName [newClassName [methodToProxy [...]]". If there is
a single method to proxy with a value of "*" (asterisk), then all declared methods will get proxied.org.apache.bsf.BSFException
public static java.lang.Class createProxiedJavaClass(java.lang.Class javaClassToProxy, java.lang.String newClzName, java.lang.String[] methodNames2proxy, java.lang.Class[] interfaceClasses) throws org.apache.bsf.BSFException
javaClassToProxy
- Class object to use for proxyingnewClzName
- null
or name for proxy class to createmethodNames2proxy
- 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); if
this is null
or an empty String array no proxy methods will be created (may be useful
if supplying additional interface classes to mixin into the extended class for which proxy methods
should be created); if there is a String array with a single entry denoting the string "*"
(asterisk), then there will be proxy methods created for all declared methods, in effect allowing
all method invocations to be intercepted by Rexx, including its constructors;interfaceClasses
- the extended class should implement as wellorg.apache.bsf.BSFException
static void createProlog(java.lang.StringBuffer sb, java.lang.String newClzName, java.lang.Class javaClassToProxy, java.lang.Class[] interfaceClasses, ProxiedJavaClassTool.RunInfos ri) throws org.apache.bsf.BSFException
sb
- the StringBuffer to append the statements tonewClzName
- the new name of the new classjavaClassToProxy
- the Java (concrete, abstract, interface) class that gets extendedinterfaceClasses
- the extended class should implementri
- RunInfos runtime infos for managing the processorg.apache.bsf.BSFException
static void createEpilog(java.lang.StringBuffer sb)
sb
- the StringBuffer to append the statements tostatic void createConstructorsBase(java.lang.StringBuffer sb, java.lang.String newClzName, java.lang.Class<?> javaClassToProxy, boolean bProxyConstructors, ProxiedJavaClassTool.RunInfos ri)
sb
- the StringBuffer to append the statements tonewClzName
- the new name of the new classjavaClassToProxy
- the Java (abstract) class that gets extendedbProxyConstructors
- determines whether constructor invocations get proxied to the RexxProxy (true
)ri
- RunInfos runtime infos for managing the processstatic void createConstructors(java.lang.StringBuffer sb, java.lang.String newClzName, java.lang.Class javaClassToProxy, boolean bProxyConstructors, ProxiedJavaClassTool.RunInfos ri)
static void createInterfaceMethods(java.lang.StringBuffer sb, java.lang.String newClzName, java.lang.Class ifClz, ProxiedJavaClassTool.RunInfos ri, java.lang.Class<?> tmpClz)
sb
- the StringBuffer to append the statements tonewClzName
- the new name of the new classifClz
- an interface class which needs to processed together with its super interface classes if anyri
- RunInfos runtime infos for managing the processtmpClz
- null
(create all methods) or a class object which will be checked
(create proxy method only, if no concrete declaredMethod() of it exists)static void createInterfaceMethodsWorker(java.lang.StringBuffer sb, java.lang.String newClzName, java.lang.Class ifClz, ProxiedJavaClassTool.RunInfos ri, java.lang.Class<?> tmpClz)
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
methods2proxy
argument. As each method must have a
unique signature, hence no method with a unique signature is created more than once.sb
- the StringBuffer to append the statements tonewClzName
- the new name of the new classjavaClassToProxy
- the Java (abstract) class that gets extendedmethods2proxy
- String list of method names to create proxies for; a method name
may be prepended with the name of a superclass delimited with a blankri
- RunInfos runtime infos for managing the processorg.apache.bsf.BSFException
static void createMethod(java.lang.StringBuffer sb, java.lang.reflect.Method m, java.lang.String newClzName, ProxiedJavaClassTool.RunInfos ri)
sb
- the StringBuffer to append the statements tom
- a Method object which needs to get proxiednewClzName
- the new name of the new classri
- RunInfos runtime infos for managing the processstatic java.lang.String[] parseMethod2Proxy(java.lang.String val)
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.null
, if supplied argument is null or empty, else a
String array, containing
0
1
2
3
static java.lang.String[] createArgumentHead(java.lang.Class[] paramTypes, boolean bCreateForConstructor, boolean bCreateInvokeArg)
paramTypes
- array of Class objects representing the typesbCreateForConstructor
- first String should inject as first argument the RexxProxy to forward tobCreateInvokeArg
- determines whether the invocations of constructors get forwarded to the RexxProxy0
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 rexxProxystatic java.lang.String createReturnStatements(java.lang.Class returnType)
returnType
- the class object of the return typestatic java.lang.String createListOfClassNames(java.lang.Class[] paramTypes, int kind)
paramTypes
- array of Class objectskind
- static java.lang.String[] createThrowsClause(java.lang.Class[] excTypes)
excTypes
- array of Class objects representing the exceptions that may be thrownBSFException
static java.lang.String getEditedClassName(java.lang.Class clz)
clz
- the class to create a name for