169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalpackage sample.reflect;
269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalimport javassist.tools.reflect.Loader;
469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal/*
669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal  The "verbose metaobject" example (JDK 1.2 or later only).
769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal  Since this program registers class Person as a reflective class
969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal  (in a more realistic demonstration, what classes are reflective
1069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal  would be specified by some configuration file), the class loader
1169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal  modifies Person.class when loading into the JVM so that the class
1269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal  Person is changed into a reflective class and a Person object is
1369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal  controlled by a VerboseMetaobj.
1469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
1569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal  To run,
1669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
1769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal  % java javassist.tools.reflect.Loader sample.reflect.Main Joe
1869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
1969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal  Compare this result with that of the regular execution without reflection:
2069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
2169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal  % java sample.reflect.Person Joe
2269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal*/
2369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalpublic class Main {
2469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public static void main(String[] args) throws Throwable {
2569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        Loader cl = (Loader)Main.class.getClassLoader();
2669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        cl.makeReflective("sample.reflect.Person",
2769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                          "sample.reflect.VerboseMetaobj",
2869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal                          "javassist.tools.reflect.ClassMetaobject");
2969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
3069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        cl.run("sample.reflect.Person", args);
3169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
3269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal}
33