diff --git a/Readme.html b/Readme.html index 4699d715..9c88637d 100644 --- a/Readme.html +++ b/Readme.html @@ -137,7 +137,7 @@
% javac sample/reflect/*.java -% java javassist.reflect.Loader sample.reflect.Main Joe +% java javassist.tools.reflect.Loader sample.reflect.Main Joe
Compare this result with that of the regular execution without reflection: @@ -151,7 +151,7 @@
-% java javassist.reflect.Compiler sample.reflect.Person -m sample.reflect.VerboseMetaobj +% java javassist.tools.reflect.Compiler sample.reflect.Person -m sample.reflect.VerboseMetaobj
Then, @@ -292,14 +292,18 @@
- version 3.1 - -
+
- version 3.1 RC2 in September 7, 2005
diff --git a/build.xml b/build.xml
index b7562364..1f78b28a 100644
--- a/build.xml
+++ b/build.xml
@@ -109,18 +109,18 @@ to ${build.classes.dir}.
excludepackagenames="javassist.compiler.*,javassist.convert.*"
sourcepath="src/main"
defaultexcludes="yes"
+ locale="en_US"
+ charset="iso-8859-1"
destdir="html"
author="true"
version="true"
use="true"
- Locale="en_US"
- charset="iso-8859-1"
- Public="true"
+ public="true"
nohelp="true"
windowtitle="Javassist API">
If you don't want to use a web browser, do as follows:
- Figure 1: Applet
Note that the Note that the With the Java RMI or Voyager, the applet programmer must define
an interface for every remote object class and access the remote object
through that interface.
-On the other hand, the This package provides low-level API for editing annotations attributes.
diff --git a/src/main/javassist/expr/MethodCall.java b/src/main/javassist/expr/MethodCall.java
index 7bc2c388..9fd29e2a 100644
--- a/src/main/javassist/expr/MethodCall.java
+++ b/src/main/javassist/expr/MethodCall.java
@@ -120,7 +120,7 @@ public CtMethod getMethod() throws NotFoundException {
* The method signature is represented by a character string
* called method descriptor, which is defined in the JVM specification.
*
- * @see javassist.CtBehavior.getSignature()
+ * @see javassist.CtBehavior#getSignature()
* @see javassist.bytecode.Descriptor
* @since 3.1
*/
diff --git a/src/main/javassist/tools/package.html b/src/main/javassist/tools/package.html
index 1566e121..bee6208d 100644
--- a/src/main/javassist/tools/package.html
+++ b/src/main/javassist/tools/package.html
@@ -1,6 +1,6 @@
This translator directly modifies class files on a local disk so that
* the classes represented by those class files are reflective.
* After the modification, the class files can be run with the standard JVM
- * without The modified class files are given as the command-line parameters,
@@ -63,9 +63,9 @@ class CompiledClass {
* Note that if the super class is also made reflective, it must be done
* before the sub class.
*
- * @see javassist.reflect.Metaobject
- * @see javassist.reflect.ClassMetaobject
- * @see javassist.reflect.Reflection
+ * @see javassist.tools.reflect.Metaobject
+ * @see javassist.tools.reflect.ClassMetaobject
+ * @see javassist.tools.reflect.Reflection
*/
public class Compiler {
@@ -100,12 +100,12 @@ private static void processClasses(CompiledClass[] entries, int n)
String metaobj, classobj;
if (entries[i].metaobject == null)
- metaobj = "javassist.reflect.Metaobject";
+ metaobj = "javassist.tools.reflect.Metaobject";
else
metaobj = entries[i].metaobject;
if (entries[i].classobject == null)
- classobj = "javassist.reflect.ClassMetaobject";
+ classobj = "javassist.tools.reflect.ClassMetaobject";
else
classobj = entries[i].classobject;
@@ -156,7 +156,7 @@ else if (a.charAt(0) == '-')
}
private static void help(PrintStream out) {
- out.println("Usage: java javassist.reflect.Compiler");
+ out.println("Usage: java javassist.tools.reflect.Compiler");
out.println(" ( Then run this program as follows:
*
- * This command runs The difference from the former one is that the class Note:
*
- * To avoid this limitation, those classes should be statically
- * modified with To access the remote
* object, the applet first calls If you run a program with If you run a program with To run, you should type:
*
- * This command calls This factory generates a class that extends the given super class and implements
+ * the given interfaces. The calls of the methods inherited from the super class are
+ * forwarded and then For example, if the following code is executed,
+ *
+ * Then, the following method call will be forwarded to MethodHandler
+ * To change the method handler during runtime,
+ * execute the following code:
+ *
+ * Here is an example of method handler. It does not execute
+ * anything except invoking the original method:
+ *
+ * The default value is null.
+ */
+ public String writeDirectory;
+
+ private static final Class OBJECT_TYPE = Object.class;
+
+ private static final String HOLDER = "_methods_";
+ private static final String HOLDER_TYPE = "[Ljava/lang/reflect/Method;";
+ private static final String HANDLER = "handler";
+ private static final String DEFAULT_INTERCEPTOR = "default_interceptor";
+ private static final String HANDLER_TYPE
+ = 'L' + MethodHandler.class.getName().replace('.', '/') + ';';
+ private static final String HANDLER_SETTER = "setHandler";
+ private static final String HANDLER_SETTER_TYPE = "(" + HANDLER_TYPE + ")V";
+
+ /**
+ * Constructs a factory of proxy class.
+ */
+ public ProxyFactory() {
+ superClass = null;
+ interfaces = null;
+ methodFilter = null;
+ handler = new MethodHandler() {
+ public Object invoke(Object self, Method m,
+ Method proceed, Object[] args)
+ throws Exception
+ {
+ return proceed.invoke(self, args);
+ }
+ };
+ thisClass = null;
+ writeDirectory = null;
+ }
+
+ /**
+ * Sets the super class of a proxy class.
+ */
+ public void setSuperclass(Class clazz) {
+ superClass = clazz;
+ }
+
+ /**
+ * Sets the interfaces of a proxy class.
+ */
+ public void setInterfaces(Class[] ifs) {
+ interfaces = ifs;
+ }
+
+ /**
+ * Sets a filter that selects the methods that will be controlled by a handler.
+ */
+ public void setFilter(MethodFilter mf) {
+ methodFilter = mf;
+ }
+
+ /**
+ * Generates a proxy class.
+ */
+ public Class createClass() {
+ if (thisClass == null)
+ try {
+ ClassFile cf = make();
+ ClassLoader cl = getClassLoader();
+ if (writeDirectory != null)
+ FactoryHelper.writeFile(cf, writeDirectory);
+
+ thisClass = FactoryHelper.toClass(cf, cl);
+ setHandler();
+ }
+ catch (CannotCompileException e) {
+ throw new RuntimeException(e.getMessage(), e);
+ }
+
+ return thisClass;
+ }
+
+ protected ClassLoader getClassLoader() {
+ if (superClass != null && !superClass.getName().equals("java.lang.Object"))
+ return superClass.getClassLoader();
+ else if (interfaces != null && interfaces.length > 0)
+ return interfaces[0].getClassLoader();
+ else
+ return this.getClass().getClassLoader();
+ // return Thread.currentThread().getContextClassLoader();
+ }
+
+ /**
+ * Sets the default invocation handler. This invocation handler is shared
+ * among all the instances of a proxy class unless another is explicitly
+ * specified.
+ */
+ public void setHandler(MethodHandler mi) {
+ handler = mi;
+ setHandler();
+ }
+
+ private void setHandler() {
+ if (thisClass != null && handler != null)
+ try {
+ Field f = thisClass.getField(DEFAULT_INTERCEPTOR);
+ f.setAccessible(true);
+ f.set(null, handler);
+ f.setAccessible(false);
+ }
+ catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static int counter = 0;
+
+ private ClassFile make() throws CannotCompileException {
+ String superName, classname;
+ if (interfaces == null)
+ interfaces = new Class[0];
+
+ if (superClass == null) {
+ superClass = OBJECT_TYPE;
+ superName = superClass.getName();
+ classname = interfaces.length == 0 ? superName
+ : interfaces[0].getName();
+ }
+ else {
+ superName = superClass.getName();
+ classname = superName;
+ }
+
+ if (Modifier.isFinal(superClass.getModifiers()))
+ throw new CannotCompileException(superName + " is final");
+
+ // generate a proxy name.
+ classname = classname + "_$$_javassist_" + counter++;
+ if (classname.startsWith("java."))
+ classname = "org.javassist.tmp." + classname;
+
+ ClassFile cf = new ClassFile(false, classname, superName);
+ cf.setAccessFlags(AccessFlag.PUBLIC);
+ setInterfaces(cf, interfaces);
+ ConstPool pool = cf.getConstPool();
+ FieldInfo finfo = new FieldInfo(pool, DEFAULT_INTERCEPTOR, HANDLER_TYPE);
+ finfo.setAccessFlags(AccessFlag.PUBLIC | AccessFlag.STATIC);
+ cf.addField(finfo);
+
+ FieldInfo finfo2 = new FieldInfo(pool, HANDLER, HANDLER_TYPE);
+ finfo2.setAccessFlags(AccessFlag.PRIVATE);
+ cf.addField(finfo2);
+
+ HashMap allMethods = getMethods(superClass, interfaces);
+ int size = allMethods.size();
+ makeConstructors(classname, cf, pool, classname);
+ int s = overrideMethods(cf, pool, classname, allMethods);
+ addMethodsHolder(cf, pool, classname, s);
+ addSetter(classname, cf, pool);
+
+ thisClass = null;
+ return cf;
+ }
+
+ private static void setInterfaces(ClassFile cf, Class[] interfaces) {
+ String setterIntf = ProxyObject.class.getName();
+ String[] list;
+ if (interfaces == null || interfaces.length == 0)
+ list = new String[] { setterIntf };
+ else {
+ list = new String[interfaces.length + 1];
+ for (int i = 0; i < interfaces.length; i++)
+ list[i] = interfaces[i].getName();
+
+ list[interfaces.length] = setterIntf;
+ }
+
+ cf.setInterfaces(list);
+ }
+
+ private static void addMethodsHolder(ClassFile cf, ConstPool cp,
+ String classname, int size)
+ throws CannotCompileException
+ {
+ FieldInfo finfo = new FieldInfo(cp, HOLDER, HOLDER_TYPE);
+ finfo.setAccessFlags(AccessFlag.PRIVATE | AccessFlag.STATIC);
+ cf.addField(finfo);
+ MethodInfo minfo = new MethodInfo(cp, "
% java javassist.web.Viewer localhost 5001 sample.rmi.CountApplet
+% java javassist.tools.web.Viewer localhost 5001 sample.rmi.CountApplet
diff --git a/sample/rmi/webdemo.html b/sample/rmi/webdemo.html
index d313ec3c..a2b595ce 100644
--- a/sample/rmi/webdemo.html
+++ b/sample/rmi/webdemo.html
@@ -6,7 +6,7 @@ Remote Method Invocation
local object. The applet can communicate through a socket with the
host that executes the web server distributing that applet. However,
the applet cannot directly call a method on an object if the object is
-on a remote host. The javassist.rmi
package provides
+on a remote host. The javassist.tools.rmi
package provides
a mechanism for the applet to transparently access the remote object.
The rules that the applet must be subject to are simpler than the
standard Java RMI.
@@ -36,7 +36,7 @@ 1. Sample applet
-import javassist.rmi.ObjectImporter;
+import javassist.tools.rmi.ObjectImporter;
public class CountApplet extends Applet implements ActionListener {
private Font font;
@@ -106,7 +106,7 @@
-1. Sample applet
}
javassist.rmi
package does not require
+javassist.tools.rmi
package does not require
the Counter
class to be an interface unlike the Java RMI,
with which Counter
must be an interface and it must be
implemented by another class.
@@ -167,7 +167,7 @@ 2. Features
javassist.rmi
package does not
+On the other hand, the javassist.tools.rmi
package does not
require the programmer to follow that programming convention.
It is suitable for writing simple distributed programs like applets.
diff --git a/src/main/javassist/CtClass.java b/src/main/javassist/CtClass.java
index 74ab0d3e..d4178e7f 100644
--- a/src/main/javassist/CtClass.java
+++ b/src/main/javassist/CtClass.java
@@ -703,7 +703,7 @@ public CtMethod[] getMethods() {
*
* @param name method name
* @param desc method descriptor
- * @see CtBehavior.getSignature()
+ * @see CtBehavior#getSignature()
* @see javassist.bytecode.Descriptor
*/
public CtMethod getMethod(String name, String desc)
diff --git a/src/main/javassist/CtMethod.java b/src/main/javassist/CtMethod.java
index 043c8d3b..abb42b88 100644
--- a/src/main/javassist/CtMethod.java
+++ b/src/main/javassist/CtMethod.java
@@ -118,7 +118,7 @@ public CtMethod(CtMethod src, CtClass declaring, ClassMap map)
*
* @param src the source text.
* @param declaring the class to which the created method is added.
- * @see CtNewMethod.make(String, CtClass)
+ * @see CtNewMethod#make(String, CtClass)
*/
public static CtMethod make(String src, CtClass declaring)
throws CannotCompileException
diff --git a/src/main/javassist/bytecode/Bytecode.java b/src/main/javassist/bytecode/Bytecode.java
index a1f74c6d..b2a0ee23 100644
--- a/src/main/javassist/bytecode/Bytecode.java
+++ b/src/main/javassist/bytecode/Bytecode.java
@@ -1339,7 +1339,7 @@ public void addPutstatic(CtClass c, String name, String desc) {
* Appends PUTSTATIC.
*
* @param classname the fully-qualified name of the target class.
- * @param filedName the field name.
+ * @param fieldName the field name.
* @param desc the descriptor of the field type.
*/
public void addPutstatic(String classname, String fieldName, String desc) {
diff --git a/src/main/javassist/bytecode/Descriptor.java b/src/main/javassist/bytecode/Descriptor.java
index ef194b7f..39577ce2 100644
--- a/src/main/javassist/bytecode/Descriptor.java
+++ b/src/main/javassist/bytecode/Descriptor.java
@@ -717,7 +717,6 @@ public boolean hasNext() {
/**
* Returns the first character of the current element.
- * @return
*/
public char currentChar() { return desc.charAt(curPos); }
diff --git a/src/main/javassist/bytecode/annotation/package.html b/src/main/javassist/bytecode/annotation/package.html
index 6cf7e538..d0656db6 100644
--- a/src/main/javassist/bytecode/annotation/package.html
+++ b/src/main/javassist/bytecode/annotation/package.html
@@ -1,6 +1,6 @@
ClassMetaobject.newInstance()
fails.
diff --git a/src/main/javassist/reflect/CannotInvokeException.java b/src/main/javassist/tools/reflect/CannotInvokeException.java
similarity index 88%
rename from src/main/javassist/reflect/CannotInvokeException.java
rename to src/main/javassist/tools/reflect/CannotInvokeException.java
index c778e89d..d283d6d7 100644
--- a/src/main/javassist/reflect/CannotInvokeException.java
+++ b/src/main/javassist/tools/reflect/CannotInvokeException.java
@@ -13,7 +13,7 @@
* License.
*/
-package javassist.reflect;
+package javassist.tools.reflect;
import java.lang.reflect.InvocationTargetException;
import java.lang.IllegalAccessException;
@@ -22,9 +22,9 @@
* Thrown when method invocation using the reflection API has thrown
* an exception.
*
- * @see javassist.reflect.Metaobject#trapMethodcall(int, Object[])
- * @see javassist.reflect.ClassMetaobject#trapMethodcall(int, Object[])
- * @see javassist.reflect.ClassMetaobject#invoke(Object, int, Object[])
+ * @see javassist.tools.reflect.Metaobject#trapMethodcall(int, Object[])
+ * @see javassist.tools.reflect.ClassMetaobject#trapMethodcall(int, Object[])
+ * @see javassist.tools.reflect.ClassMetaobject#invoke(Object, int, Object[])
*/
public class CannotInvokeException extends RuntimeException {
diff --git a/src/main/javassist/reflect/CannotReflectException.java b/src/main/javassist/tools/reflect/CannotReflectException.java
similarity index 90%
rename from src/main/javassist/reflect/CannotReflectException.java
rename to src/main/javassist/tools/reflect/CannotReflectException.java
index 036ebf49..30c448b3 100644
--- a/src/main/javassist/reflect/CannotReflectException.java
+++ b/src/main/javassist/tools/reflect/CannotReflectException.java
@@ -13,7 +13,7 @@
* License.
*/
-package javassist.reflect;
+package javassist.tools.reflect;
import javassist.CannotCompileException;
@@ -24,7 +24,7 @@
* either ClassMetaobject or Metaobject.
*
* @author Brett Randall
- * @see javassist.reflect.Reflection#makeReflective(CtClass,CtClass,CtClass)
+ * @see javassist.tools.reflect.Reflection#makeReflective(CtClass,CtClass,CtClass)
* @see javassist.CannotCompileException
*/
public class CannotReflectException extends CannotCompileException {
diff --git a/src/main/javassist/reflect/ClassMetaobject.java b/src/main/javassist/tools/reflect/ClassMetaobject.java
similarity index 99%
rename from src/main/javassist/reflect/ClassMetaobject.java
rename to src/main/javassist/tools/reflect/ClassMetaobject.java
index 61328452..d0a645cc 100644
--- a/src/main/javassist/reflect/ClassMetaobject.java
+++ b/src/main/javassist/tools/reflect/ClassMetaobject.java
@@ -13,7 +13,7 @@
* License.
*/
-package javassist.reflect;
+package javassist.tools.reflect;
import java.lang.reflect.*;
import java.util.Arrays;
@@ -35,8 +35,8 @@
* ClassMetaobject cm = ((Metalevel)reflectiveObject)._getClass();
*
*
- * @see javassist.reflect.Metaobject
- * @see javassist.reflect.Metalevel
+ * @see javassist.tools.reflect.Metaobject
+ * @see javassist.tools.reflect.Metalevel
*/
public class ClassMetaobject implements Serializable {
/**
diff --git a/src/main/javassist/reflect/Compiler.java b/src/main/javassist/tools/reflect/Compiler.java
similarity index 92%
rename from src/main/javassist/reflect/Compiler.java
rename to src/main/javassist/tools/reflect/Compiler.java
index 734f598b..7e1fb943 100644
--- a/src/main/javassist/reflect/Compiler.java
+++ b/src/main/javassist/tools/reflect/Compiler.java
@@ -13,7 +13,7 @@
* License.
*/
-package javassist.reflect;
+package javassist.tools.reflect;
import javassist.CtClass;
import javassist.ClassPool;
@@ -31,7 +31,7 @@ class CompiledClass {
* javassist.reflect.Loader
+ * without javassist.tools.reflect.Loader
* or any other user-defined class loader.
*
*
* public class Main {
* public static void main(String[] args) throws Throwable {
- * javassist.reflect.Loader cl
- * = (javassist.reflect.Loader)Main.class.getClassLoader();
+ * javassist.tools.reflect.Loader cl
+ * = (javassist.tools.reflect.Loader)Main.class.getClassLoader();
* cl.makeReflective("Person", "MyMetaobject",
- * "javassist.reflect.ClassMetaobject");
+ * "javassist.tools.reflect.ClassMetaobject");
* cl.run("MyApp", args);
* }
* }
@@ -40,7 +40,7 @@
*
*
% java javassist.reflect.Loader Main arg1, ...
+ * % java javassist.tools.reflect.Loader Main arg1, ...
*
* Main.main()
with arg1
, ...
* and Main.main()
runs MyApp.main()
with
@@ -54,9 +54,9 @@
*
* public class Main2 {
* public static void main(String[] args) throws Throwable {
- * javassist.reflect.Loader cl = new javassist.reflect.Loader();
+ * javassist.tools.reflect.Loader cl = new javassist.tools.reflect.Loader();
* cl.makeReflective("Person", "MyMetaobject",
- * "javassist.reflect.ClassMetaobject");
+ * "javassist.tools.reflect.ClassMetaobject");
* cl.run("MyApp", args);
* }
* }
@@ -67,11 +67,11 @@
*
% java Main2 arg1, ...
*
* Main
- * is loaded by javassist.reflect.Loader
whereas the class
+ * is loaded by javassist.tools.reflect.Loader
whereas the class
* Main2
is not. Thus, Main
belongs
* to the same name space (security domain) as MyApp
* whereas Main2
does not; Main2
belongs
- * to the same name space as javassist.reflect.Loader
.
+ * to the same name space as javassist.tools.reflect.Loader
.
* For more details,
* see the notes in the manual page of javassist.Loader
.
*
@@ -84,7 +84,7 @@
* javassist.Loader cl
* = new javassist.Loader(ClassPool.getDefault(reflection));
* reflection.makeReflective("Person", "MyMetaobject",
- * "javassist.reflect.ClassMetaobject");
+ * "javassist.tools.reflect.ClassMetaobject");
* cl.run("MyApp", args);
* }
* }
@@ -92,18 +92,18 @@
*
* javassist.reflect.Loader
does not make a class reflective
+ * javassist.tools.reflect.Loader
does not make a class reflective
* if that class is in a java.*
or
* javax.*
pacakge because of the specifications
* on the class loading algorithm of Java. The JVM does not allow to
* load such a system class with a user class loader.
*
* javassist.reflect.Compiler
and the original
+ * modified with javassist.tools.reflect.Compiler
and the original
* class files should be replaced.
*
- * @see javassist.reflect.Reflection
- * @see javassist.reflect.Compiler
+ * @see javassist.tools.reflect.Reflection
+ * @see javassist.tools.reflect.Compiler
* @see javassist.Loader
*/
public class Loader extends javassist.Loader {
@@ -130,7 +130,7 @@ public static void main(String[] args) throws Throwable {
*/
public Loader() throws CannotCompileException, NotFoundException {
super();
- delegateLoadingOf("javassist.reflect.Loader");
+ delegateLoadingOf("javassist.tools.reflect.Loader");
reflection = new Reflection();
ClassPool pool = ClassPool.getDefault();
@@ -151,8 +151,8 @@ public Loader() throws CannotCompileException, NotFoundException {
* ClassMetaobject
.
* @return false
if the class is already reflective.
*
- * @see javassist.reflect.Metaobject
- * @see javassist.reflect.ClassMetaobject
+ * @see javassist.tools.reflect.Metaobject
+ * @see javassist.tools.reflect.ClassMetaobject
*/
public boolean makeReflective(String clazz,
String metaobject, String metaclass)
diff --git a/src/main/javassist/reflect/Metalevel.java b/src/main/javassist/tools/reflect/Metalevel.java
similarity index 97%
rename from src/main/javassist/reflect/Metalevel.java
rename to src/main/javassist/tools/reflect/Metalevel.java
index 8192267a..db45cad9 100644
--- a/src/main/javassist/reflect/Metalevel.java
+++ b/src/main/javassist/tools/reflect/Metalevel.java
@@ -13,7 +13,7 @@
* License.
*/
-package javassist.reflect;
+package javassist.tools.reflect;
/**
* An interface to access a metaobject and a class metaobject.
diff --git a/src/main/javassist/reflect/Metaobject.java b/src/main/javassist/tools/reflect/Metaobject.java
similarity index 97%
rename from src/main/javassist/reflect/Metaobject.java
rename to src/main/javassist/tools/reflect/Metaobject.java
index 8c3749aa..e89b5398 100644
--- a/src/main/javassist/reflect/Metaobject.java
+++ b/src/main/javassist/tools/reflect/Metaobject.java
@@ -13,7 +13,7 @@
* License.
*/
-package javassist.reflect;
+package javassist.tools.reflect;
import java.lang.reflect.Method;
import java.io.Serializable;
@@ -39,8 +39,8 @@
* Metaobject m = ((Metalevel)reflectiveObject)._getMetaobject();
*
*
- * @see javassist.reflect.ClassMetaobject
- * @see javassist.reflect.Metalevel
+ * @see javassist.tools.reflect.ClassMetaobject
+ * @see javassist.tools.reflect.Metalevel
*/
public class Metaobject implements Serializable {
protected ClassMetaobject classmetaobject;
@@ -88,7 +88,7 @@ private void readObject(ObjectInputStream in)
/**
* Obtains the class metaobject associated with this metaobject.
*
- * @see javassist.reflect.ClassMetaobject
+ * @see javassist.tools.reflect.ClassMetaobject
*/
public final ClassMetaobject getClassMetaobject() {
return classmetaobject;
diff --git a/src/main/javassist/reflect/Reflection.java b/src/main/javassist/tools/reflect/Reflection.java
similarity index 92%
rename from src/main/javassist/reflect/Reflection.java
rename to src/main/javassist/tools/reflect/Reflection.java
index cd4f441c..06ce2ccf 100644
--- a/src/main/javassist/reflect/Reflection.java
+++ b/src/main/javassist/tools/reflect/Reflection.java
@@ -13,7 +13,7 @@
* License.
*/
-package javassist.reflect;
+package javassist.tools.reflect;
import javassist.*;
import javassist.CtMethod.ConstParameter;
@@ -54,10 +54,10 @@
* }
*
*
- * @see javassist.reflect.ClassMetaobject
- * @see javassist.reflect.Metaobject
- * @see javassist.reflect.Loader
- * @see javassist.reflect.Compiler
+ * @see javassist.tools.reflect.ClassMetaobject
+ * @see javassist.tools.reflect.Metaobject
+ * @see javassist.tools.reflect.Loader
+ * @see javassist.tools.reflect.Compiler
*/
public class Reflection implements Translator {
@@ -69,9 +69,9 @@ public class Reflection implements Translator {
static final String readPrefix = "_r_";
static final String writePrefix = "_w_";
- static final String metaobjectClassName = "javassist.reflect.Metaobject";
+ static final String metaobjectClassName = "javassist.tools.reflect.Metaobject";
static final String classMetaobjectClassName
- = "javassist.reflect.ClassMetaobject";
+ = "javassist.tools.reflect.ClassMetaobject";
protected CtMethod trapMethod, trapStaticMethod;
protected CtMethod trapRead, trapWrite;
@@ -103,9 +103,9 @@ public Reflection() {
public void start(ClassPool pool) throws NotFoundException {
classPool = pool;
final String msg
- = "javassist.reflect.Sample is not found or broken.";
+ = "javassist.tools.reflect.Sample is not found or broken.";
try {
- CtClass c = classPool.get("javassist.reflect.Sample");
+ CtClass c = classPool.get("javassist.tools.reflect.Sample");
trapMethod = c.getDeclaredMethod("trap");
trapStaticMethod = c.getDeclaredMethod("trapStatic");
trapRead = c.getDeclaredMethod("trapRead");
@@ -139,8 +139,8 @@ public void onLoad(ClassPool pool, String classname)
* @param metaclass the class name of the class metaobject.
* @return false
if the class is already reflective.
*
- * @see javassist.reflect.Metaobject
- * @see javassist.reflect.ClassMetaobject
+ * @see javassist.tools.reflect.Metaobject
+ * @see javassist.tools.reflect.ClassMetaobject
*/
public boolean makeReflective(String classname,
String metaobject, String metaclass)
@@ -165,8 +165,8 @@ public boolean makeReflective(String classname,
* ClassMetaobject
.
* @return false
if the class is already reflective.
*
- * @see javassist.reflect.Metaobject
- * @see javassist.reflect.ClassMetaobject
+ * @see javassist.tools.reflect.Metaobject
+ * @see javassist.tools.reflect.ClassMetaobject
*/
public boolean makeReflective(Class clazz,
Class metaobject, Class metaclass)
@@ -191,8 +191,8 @@ public boolean makeReflective(Class clazz,
* ClassMetaobject
.
* @return false
if the class is already reflective.
*
- * @see javassist.reflect.Metaobject
- * @see javassist.reflect.ClassMetaobject
+ * @see javassist.tools.reflect.Metaobject
+ * @see javassist.tools.reflect.ClassMetaobject
*/
public boolean makeReflective(CtClass clazz,
CtClass metaobject, CtClass metaclass)
@@ -243,7 +243,7 @@ private boolean modifyClassfile(CtClass clazz, CtClass metaobject,
else
clazz.setAttribute("Reflective", new byte[0]);
- CtClass mlevel = classPool.get("javassist.reflect.Metalevel");
+ CtClass mlevel = classPool.get("javassist.tools.reflect.Metalevel");
boolean addMeta = !clazz.subtypeOf(mlevel);
if (addMeta)
clazz.addInterface(mlevel);
@@ -253,7 +253,7 @@ private boolean modifyClassfile(CtClass clazz, CtClass metaobject,
CtField f;
if (addMeta) {
- f = new CtField(classPool.get("javassist.reflect.Metaobject"),
+ f = new CtField(classPool.get("javassist.tools.reflect.Metaobject"),
metaobjectField, clazz);
f.setModifiers(Modifier.PROTECTED);
clazz.addField(f, CtField.Initializer.byNewWithParams(metaobject));
@@ -262,7 +262,7 @@ private boolean modifyClassfile(CtClass clazz, CtClass metaobject,
clazz.addMethod(CtNewMethod.setter(metaobjectSetter, f));
}
- f = new CtField(classPool.get("javassist.reflect.ClassMetaobject"),
+ f = new CtField(classPool.get("javassist.tools.reflect.ClassMetaobject"),
classobjectField, clazz);
f.setModifiers(Modifier.PRIVATE | Modifier.STATIC);
clazz.addField(f, CtField.Initializer.byNew(metaclass,
diff --git a/src/main/javassist/reflect/Sample.java b/src/main/javassist/tools/reflect/Sample.java
similarity index 98%
rename from src/main/javassist/reflect/Sample.java
rename to src/main/javassist/tools/reflect/Sample.java
index 81bad691..4e70236a 100644
--- a/src/main/javassist/reflect/Sample.java
+++ b/src/main/javassist/tools/reflect/Sample.java
@@ -13,7 +13,7 @@
* License.
*/
-package javassist.reflect;
+package javassist.tools.reflect;
/**
* A template used for defining a reflective class.
diff --git a/src/main/javassist/reflect/package.html b/src/main/javassist/tools/reflect/package.html
similarity index 100%
rename from src/main/javassist/reflect/package.html
rename to src/main/javassist/tools/reflect/package.html
diff --git a/src/main/javassist/rmi/AppletServer.java b/src/main/javassist/tools/rmi/AppletServer.java
similarity index 97%
rename from src/main/javassist/rmi/AppletServer.java
rename to src/main/javassist/tools/rmi/AppletServer.java
index 89cc92ab..5056e24c 100644
--- a/src/main/javassist/rmi/AppletServer.java
+++ b/src/main/javassist/tools/rmi/AppletServer.java
@@ -13,10 +13,11 @@
* License.
*/
-package javassist.rmi;
+package javassist.tools.rmi;
import java.io.*;
-import javassist.web.*;
+
+import javassist.tools.web.*;
import javassist.CannotCompileException;
import javassist.NotFoundException;
import javassist.ClassPool;
@@ -31,7 +32,7 @@
* If the classes of the exported objects are requested by the client-side
* JVM, this web server sends proxy classes for the requested classes.
*
- * @see javassist.rmi.ObjectImporter
+ * @see javassist.tools.rmi.ObjectImporter
*/
public class AppletServer extends Webserver {
private StubGenerator stubGen;
@@ -102,7 +103,7 @@ public void run() {
* @param obj the exported object.
* @return the object identifier
*
- * @see javassist.rmi.ObjectImporter#lookupObject(String)
+ * @see javassist.tools.rmi.ObjectImporter#lookupObject(String)
*/
public synchronized int exportObject(String name, Object obj)
throws CannotCompileException
diff --git a/src/main/javassist/rmi/ObjectImporter.java b/src/main/javassist/tools/rmi/ObjectImporter.java
similarity index 96%
rename from src/main/javassist/rmi/ObjectImporter.java
rename to src/main/javassist/tools/rmi/ObjectImporter.java
index adad468d..75f5aa60 100644
--- a/src/main/javassist/rmi/ObjectImporter.java
+++ b/src/main/javassist/tools/rmi/ObjectImporter.java
@@ -13,7 +13,7 @@
* License.
*/
-package javassist.rmi;
+package javassist.tools.rmi;
import java.io.*;
import java.net.*;
@@ -22,7 +22,8 @@
/**
* The object importer enables applets to call a method on a remote
- * object running on the Webserver
.
+ * object running on the Webserver
(the main class of this
+ * package).
*
* lookupObject()
and
@@ -66,9 +67,9 @@
* to catch the exception. However, good programs should catch
* the RuntimeException
.
*
- * @see javassist.rmi.AppletServer
- * @see javassist.rmi.RemoteException
- * @see javassist.web.Viewer
+ * @see javassist.tools.rmi.AppletServer
+ * @see javassist.tools.rmi.RemoteException
+ * @see javassist.tools.web.Viewer
*/
public class ObjectImporter implements java.io.Serializable {
private final byte[] endofline = { 0x0d, 0x0a };
@@ -95,7 +96,7 @@ public ObjectImporter(Applet applet) {
/**
* Constructs an object importer.
*
- * javassist.web.Viewer
,
+ * javassist.tools.web.Viewer
,
* you can construct an object importer as follows:
*
*
@@ -103,7 +104,7 @@ public ObjectImporter(Applet applet) {
* ObjectImporter oi = new ObjectImporter(v.getServer(), v.getPort());
*
*
- * @see javassist.web.Viewer
+ * @see javassist.tools.web.Viewer
*/
public ObjectImporter(String servername, int port) {
this.orgServername = this.servername = servername;
diff --git a/src/main/javassist/rmi/ObjectNotFoundException.java b/src/main/javassist/tools/rmi/ObjectNotFoundException.java
similarity index 97%
rename from src/main/javassist/rmi/ObjectNotFoundException.java
rename to src/main/javassist/tools/rmi/ObjectNotFoundException.java
index 85bc316e..e54a3257 100644
--- a/src/main/javassist/rmi/ObjectNotFoundException.java
+++ b/src/main/javassist/tools/rmi/ObjectNotFoundException.java
@@ -13,7 +13,7 @@
* License.
*/
-package javassist.rmi;
+package javassist.tools.rmi;
public class ObjectNotFoundException extends Exception {
public ObjectNotFoundException(String name) {
diff --git a/src/main/javassist/rmi/Proxy.java b/src/main/javassist/tools/rmi/Proxy.java
similarity index 91%
rename from src/main/javassist/rmi/Proxy.java
rename to src/main/javassist/tools/rmi/Proxy.java
index f627ac63..1512b87f 100644
--- a/src/main/javassist/rmi/Proxy.java
+++ b/src/main/javassist/tools/rmi/Proxy.java
@@ -13,12 +13,12 @@
* License.
*/
-package javassist.rmi;
+package javassist.tools.rmi;
/**
* An interface implemented by proxy classes.
*
- * @see javassist.rmi.StubGenerator
+ * @see javassist.tools.rmi.StubGenerator
*/
public interface Proxy {
int _getObjectId();
diff --git a/src/main/javassist/rmi/RemoteException.java b/src/main/javassist/tools/rmi/RemoteException.java
similarity index 97%
rename from src/main/javassist/rmi/RemoteException.java
rename to src/main/javassist/tools/rmi/RemoteException.java
index ceb04f9f..27ebe71e 100644
--- a/src/main/javassist/rmi/RemoteException.java
+++ b/src/main/javassist/tools/rmi/RemoteException.java
@@ -13,7 +13,7 @@
* License.
*/
-package javassist.rmi;
+package javassist.tools.rmi;
/**
* RemoteException
represents any exception thrown
diff --git a/src/main/javassist/rmi/RemoteRef.java b/src/main/javassist/tools/rmi/RemoteRef.java
similarity index 97%
rename from src/main/javassist/rmi/RemoteRef.java
rename to src/main/javassist/tools/rmi/RemoteRef.java
index fbd93add..edbf349f 100644
--- a/src/main/javassist/rmi/RemoteRef.java
+++ b/src/main/javassist/tools/rmi/RemoteRef.java
@@ -13,7 +13,7 @@
* License.
*/
-package javassist.rmi;
+package javassist.tools.rmi;
/**
* Remote reference. This class is internally used for sending a remote
diff --git a/src/main/javassist/rmi/Sample.java b/src/main/javassist/tools/rmi/Sample.java
similarity index 97%
rename from src/main/javassist/rmi/Sample.java
rename to src/main/javassist/tools/rmi/Sample.java
index b632cd03..a65b908d 100644
--- a/src/main/javassist/rmi/Sample.java
+++ b/src/main/javassist/tools/rmi/Sample.java
@@ -13,7 +13,7 @@
* License.
*/
-package javassist.rmi;
+package javassist.tools.rmi;
/**
* A template used for defining a proxy class.
diff --git a/src/main/javassist/rmi/StubGenerator.java b/src/main/javassist/tools/rmi/StubGenerator.java
similarity index 95%
rename from src/main/javassist/rmi/StubGenerator.java
rename to src/main/javassist/tools/rmi/StubGenerator.java
index eac40916..7681bd6d 100644
--- a/src/main/javassist/rmi/StubGenerator.java
+++ b/src/main/javassist/tools/rmi/StubGenerator.java
@@ -13,7 +13,7 @@
* License.
*/
-package javassist.rmi;
+package javassist.tools.rmi;
import javassist.*;
import java.lang.reflect.Method;
@@ -43,7 +43,7 @@ public class StubGenerator implements Translator {
private static final String fieldImporter = "importer";
private static final String fieldObjectId = "objectId";
private static final String accessorObjectId = "_getObjectId";
- private static final String sampleClass = "javassist.rmi.Sample";
+ private static final String sampleClass = "javassist.tools.rmi.Sample";
private ClassPool classPool;
private Hashtable proxyClasses;
@@ -74,13 +74,13 @@ public void start(ClassPool pool) throws NotFoundException {
forwardStaticMethod = c.getDeclaredMethod("forwardStatic");
proxyConstructorParamTypes
- = pool.get(new String[] { "javassist.rmi.ObjectImporter",
+ = pool.get(new String[] { "javassist.tools.rmi.ObjectImporter",
"int" });
interfacesForProxy
= pool.get(new String[] { "java.io.Serializable",
- "javassist.rmi.Proxy" });
+ "javassist.tools.rmi.Proxy" });
exceptionForProxy
- = new CtClass[] { pool.get("javassist.rmi.RemoteException") };
+ = new CtClass[] { pool.get("javassist.tools.rmi.RemoteException") };
}
/**
@@ -139,7 +139,7 @@ private CtClass produceProxyClass(CtClass orgclass, Class orgRtClass)
proxy.setInterfaces(interfacesForProxy);
CtField f
- = new CtField(classPool.get("javassist.rmi.ObjectImporter"),
+ = new CtField(classPool.get("javassist.tools.rmi.ObjectImporter"),
fieldImporter, proxy);
f.setModifiers(Modifier.PRIVATE);
proxy.addField(f, CtField.Initializer.byParameter(0));
diff --git a/src/main/javassist/rmi/package.html b/src/main/javassist/tools/rmi/package.html
similarity index 100%
rename from src/main/javassist/rmi/package.html
rename to src/main/javassist/tools/rmi/package.html
diff --git a/src/main/javassist/web/BadHttpRequest.java b/src/main/javassist/tools/web/BadHttpRequest.java
similarity index 97%
rename from src/main/javassist/web/BadHttpRequest.java
rename to src/main/javassist/tools/web/BadHttpRequest.java
index a1aee86a..606ce997 100644
--- a/src/main/javassist/web/BadHttpRequest.java
+++ b/src/main/javassist/tools/web/BadHttpRequest.java
@@ -13,7 +13,7 @@
* License.
*/
-package javassist.web;
+package javassist.tools.web;
/**
* Thrown when receiving an invalid HTTP request.
diff --git a/src/main/javassist/web/Viewer.java b/src/main/javassist/tools/web/Viewer.java
similarity index 95%
rename from src/main/javassist/web/Viewer.java
rename to src/main/javassist/tools/web/Viewer.java
index debc52af..6e737406 100644
--- a/src/main/javassist/web/Viewer.java
+++ b/src/main/javassist/tools/web/Viewer.java
@@ -13,7 +13,7 @@
* License.
*/
-package javassist.web;
+package javassist.tools.web;
import java.io.*;
import java.net.*;
@@ -27,7 +27,7 @@
*
*
+ * % java javassist.web.Viewer host port Main arg1, ...
*
* % java javassist.tools.web.Viewer host port Main arg1, ...
Main.main()
with arg1,...
* All classes including Main
are fetched from
@@ -63,7 +63,7 @@ public static void main(String[] args) throws Throwable {
}
else
System.err.println(
- "Usage: java javassist.web.Viewer ProxyFactory
.
+ * The users of ProxyFactory
do not have to see this class.
+ *
+ * @see ProxyFactory
+ */
+public class FactoryHelper {
+ /**
+ * Returns an index for accessing arrays in this class.
+ *
+ * @throws RuntimeException if a given type is not a primitive type.
+ */
+ public static final int typeIndex(Class type) {
+ Class[] list = primitiveTypes;
+ int n = list.length;
+ for (int i = 0; i < n; i++)
+ if (list[i] == type)
+ return i;
+
+ throw new RuntimeException("bad type:" + type.getName());
+ }
+
+ /**
+ * Class
objects representing primitive types.
+ */
+ public static final Class[] primitiveTypes = {
+ Boolean.TYPE, Byte.TYPE, Character.TYPE, Short.TYPE, Integer.TYPE,
+ Long.TYPE, Float.TYPE, Double.TYPE, Void.TYPE
+ };
+
+ /**
+ * The fully-qualified names of wrapper classes for primitive types.
+ */
+ public static final String[] wrapperTypes = {
+ "java.lang.Boolean", "java.lang.Byte", "java.lang.Character",
+ "java.lang.Short", "java.lang.Integer", "java.lang.Long",
+ "java.lang.Float", "java.lang.Double", "java.lang.Void"
+ };
+
+ /**
+ * The descriptors of the constructors of wrapper classes.
+ */
+ public static final String[] wrapperDesc = {
+ "(Z)V", "(B)V", "(C)V", "(S)V", "(I)V", "(J)V",
+ "(F)V", "(D)V"
+ };
+
+ /**
+ * The names of methods for obtaining a primitive value
+ * from a wrapper object. For example, intValue()
+ * is such a method for obtaining an integer value from a
+ * java.lang.Integer
object.
+ */
+ public static final String[] unwarpMethods = {
+ "booleanValue", "byteValue", "charValue", "shortValue",
+ "intValue", "longValue", "floatValue", "doubleValue"
+ };
+
+ /**
+ * The descriptors of the unwrapping methods contained
+ * in unwrapMethods
.
+ */
+ public static final String[] unwrapDesc = {
+ "()Z", "()B", "()C", "()S", "()I", "()J", "()F", "()D"
+ };
+
+ /**
+ * The data size of primitive types. long
+ * and double
are 2; the others are 1.
+ */
+ public static final int[] dataSize = {
+ 1, 1, 1, 1, 1, 2, 1, 2
+ };
+
+ /**
+ * Loads a class file by a given class loader.
+ */
+ public static Class toClass(ClassFile cf, ClassLoader loader)
+ throws CannotCompileException
+ {
+ try {
+ byte[] b = toBytecode(cf);
+ Class cl = Class.forName("java.lang.ClassLoader");
+ java.lang.reflect.Method method = cl.getDeclaredMethod(
+ "defineClass", new Class[] { String.class, byte[].class,
+ Integer.TYPE, Integer.TYPE });
+ method.setAccessible(true);
+ Object[] args = new Object[] { cf.getName(), b, new Integer(0),
+ new Integer(b.length) };
+ Class clazz = (Class)method.invoke(loader, args);
+ method.setAccessible(false);
+ return clazz;
+ }
+ catch (RuntimeException e) {
+ throw e;
+ }
+ catch (java.lang.reflect.InvocationTargetException e) {
+ throw new CannotCompileException(e.getTargetException());
+ }
+ catch (Exception e) {
+ throw new CannotCompileException(e);
+ }
+ }
+
+ private static byte[] toBytecode(ClassFile cf) throws IOException {
+ ByteArrayOutputStream barray = new ByteArrayOutputStream();
+ DataOutputStream out = new DataOutputStream(barray);
+ try {
+ cf.write(out);
+ }
+ finally {
+ out.close();
+ }
+
+ return barray.toByteArray();
+ }
+
+ /**
+ * Writes a class file.
+ */
+ public static void writeFile(ClassFile cf, String directoryName)
+ throws CannotCompileException {
+ try {
+ writeFile0(cf, directoryName);
+ }
+ catch (IOException e) {
+ throw new CannotCompileException(e);
+ }
+ }
+
+ private static void writeFile0(ClassFile cf, String directoryName)
+ throws CannotCompileException, IOException {
+ String classname = cf.getName();
+ String filename = directoryName + File.separatorChar
+ + classname.replace('.', File.separatorChar) + ".class";
+ int pos = filename.lastIndexOf(File.separatorChar);
+ if (pos > 0) {
+ String dir = filename.substring(0, pos);
+ if (!dir.equals("."))
+ new File(dir).mkdirs();
+ }
+
+ DataOutputStream out = new DataOutputStream(new BufferedOutputStream(
+ new FileOutputStream(filename)));
+ try {
+ cf.write(out);
+ }
+ catch (IOException e) {
+ throw e;
+ }
+ finally {
+ out.close();
+ }
+ }
+}
diff --git a/src/main/javassist/util/proxy/MethodFilter.java b/src/main/javassist/util/proxy/MethodFilter.java
new file mode 100644
index 00000000..67f9e409
--- /dev/null
+++ b/src/main/javassist/util/proxy/MethodFilter.java
@@ -0,0 +1,30 @@
+/*
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2005 Shigeru Chiba. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. Alternatively, the contents of this file may be used under
+ * the terms of the GNU Lesser General Public License Version 2.1 or later.
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ */
+
+package javassist.util.proxy;
+
+import java.lang.reflect.Method;
+
+/**
+ * Selector of the methods implemented by a handler.
+ *
+ * @see ProxyFactory#setFilter(MethodFilter)
+ */
+public interface MethodFilter {
+ /**
+ * Returns true if the given method is implemented by a handler.
+ */
+ boolean isHandled(Method m);
+}
diff --git a/src/main/javassist/util/proxy/MethodHandler.java b/src/main/javassist/util/proxy/MethodHandler.java
new file mode 100644
index 00000000..7bd28ba0
--- /dev/null
+++ b/src/main/javassist/util/proxy/MethodHandler.java
@@ -0,0 +1,48 @@
+/*
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2005 Shigeru Chiba. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. Alternatively, the contents of this file may be used under
+ * the terms of the GNU Lesser General Public License Version 2.1 or later.
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ */
+
+package javassist.util.proxy;
+
+import java.lang.reflect.Method;
+
+/**
+ * The interface implemented by the invocation handler of a proxy
+ * instance.
+ *
+ * @see ProxyFactory#setHandler(MethodHandler)
+ */
+public interface MethodHandler {
+ /**
+ * Is called when a method is invoked on a proxy instance associated
+ * with this handler. This method must process that method invocation.
+ *
+ * @param self the proxy instance.
+ * @param thisMethod the overridden method declared in the super
+ * class or interface.
+ * @param proceed the forwarder method for invoking the overridden
+ * method. It is null if the overridden mehtod is
+ * abstract or declared in the interface.
+ * @param args an array of objects containing the values of
+ * the arguments passed in the method invocation
+ * on the proxy instance. If a parameter type is
+ * a primitive type, the type of the array element
+ * is a wrapper class.
+ * @return the resulting value of the method invocation.
+ *
+ * @throws Exception if the method invocation fails.
+ */
+ Object invoke(Object self, Method thisMethod, Method proceed,
+ Object[] args) throws Exception;
+}
diff --git a/src/main/javassist/util/proxy/ProxyFactory.java b/src/main/javassist/util/proxy/ProxyFactory.java
new file mode 100644
index 00000000..356c23bf
--- /dev/null
+++ b/src/main/javassist/util/proxy/ProxyFactory.java
@@ -0,0 +1,699 @@
+/*
+ * Javassist, a Java-bytecode translator toolkit.
+ * Copyright (C) 1999-2005 Shigeru Chiba. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. Alternatively, the contents of this file may be used under
+ * the terms of the GNU Lesser General Public License Version 2.1 or later.
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ */
+
+package javassist.util.proxy;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Member;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javassist.CannotCompileException;
+import javassist.bytecode.*;
+
+/**
+ * Factory of dynamic proxy classes.
+ *
+ * invoke()
is called on the method handler
+ * associated with the generated class. The calls of the methods from the interfaces
+ * are also forwarded to the method handler.
+ *
+ *
+ * ProxyFactory f = new ProxyFactory();
+ * f.setSuperclass(Foo.class);
+ * MethodHandler mi = new MethodHandler() {
+ * public Object invoke(Object self, Method m, Method proceed,
+ * Object[] args) throws Exception {
+ * System.out.println("Name: " + m.getName());
+ * proceed.invoke(self, args); // execute the original method.
+ * }
+ * };
+ * f.setHandler(mi);
+ * Class c = f.createClass();
+ * Foo foo = (Foo)c.newInstance();
+ *
+ *
+ * mi
and prints a message before executing the originally called method
+ * bar()
in Foo
.
+ *
+ *
+ * foo.bar();
+ *
+ *
+ *
+ * MethodHandler mi2 = ... ; // another handler
+ * ((ProxyObject)foo).setHandler(mi2);
+ *
+ *
+ *
+ * class SimpleHandler implements MethodHandler {
+ * public Object invoke(Object self, Method m,
+ * Method proceed, Object[] args) throws Exception {
+ * return proceed.invoke(self, args);
+ * }
+ * }
+ *
+ *
+ * @see MethodHandler
+ * @since 3.1
+ */
+public class ProxyFactory {
+ private Class superClass;
+ private Class[] interfaces;
+ private MethodFilter methodFilter;
+ private MethodHandler handler;
+ private Class thisClass;
+
+ /**
+ * If the value of this variable is not null, the class file of
+ * the generated proxy class is written under the directory specified
+ * by this variable. For example, if the value is
+ * "."
, then the class file is written under the current
+ * directory. This method is for debugging.
+ *
+ * Enhancer
of cglib).
+
+