KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sample > reflect > Main


1 package 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 public class Main {
25     public static void main(String JavaDoc[] args) throws Throwable JavaDoc {
26     Loader cl = (Loader)Main.class.getClassLoader();
27     cl.makeReflective("sample.reflect.Person",
28               "sample.reflect.VerboseMetaobj",
29               "javassist.reflect.ClassMetaobject");
30
31     cl.run("sample.reflect.Person", args);
32     }
33 }
34
Popular Tags