Home | History | Annotate | Download | only in reflect
      1 package sample.reflect;
      2 
      3 import javassist.tools.reflect.Loader;
      4 
      5 /*
      6   The "verbose metaobject" example (JDK 1.2 or later only).
      7 
      8   Since this program registers class Person as a reflective class
      9   (in a more realistic demonstration, what classes are reflective
     10   would be specified by some configuration file), the class loader
     11   modifies Person.class when loading into the JVM so that the class
     12   Person is changed into a reflective class and a Person object is
     13   controlled by a VerboseMetaobj.
     14 
     15   To run,
     16 
     17   % java javassist.tools.reflect.Loader sample.reflect.Main Joe
     18 
     19   Compare this result with that of the regular execution without reflection:
     20 
     21   % java sample.reflect.Person Joe
     22 */
     23 public class Main {
     24     public static void main(String[] args) throws Throwable {
     25         Loader cl = (Loader)Main.class.getClassLoader();
     26         cl.makeReflective("sample.reflect.Person",
     27                           "sample.reflect.VerboseMetaobj",
     28                           "javassist.tools.reflect.ClassMetaobject");
     29 
     30         cl.run("sample.reflect.Person", args);
     31     }
     32 }
     33