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