summaryrefslogtreecommitdiffstats
path: root/sample/reflect/Main.java
blob: 6086d9f8b47a292214e2fab589d271d87c70978c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package sample.reflect;

import javassist.reflect.ClassMetaobject;
import javassist.reflect.Loader;

/*
  The "verbose metaobject" example (JDK 1.2 or later only).

  Since this program registers class Person as a reflective class
  (in a more realistic demonstration, what classes are reflective
  would be specified by some configuration file), the class loader
  modifies Person.class when loading into the JVM so that the class
  Person is changed into a reflective class and a Person object is
  controlled by a VerboseMetaobj.

  To run,

  % java javassist.reflect.Loader sample.reflect.Main Joe

  Compare this result with that of the regular execution without reflection:

  % java sample.reflect.Person Joe
*/
public class Main {
    public static void main(String[] args) throws Throwable {
	Loader cl = (Loader)Main.class.getClassLoader();
	cl.makeReflective("sample.reflect.Person",
			  "sample.reflect.VerboseMetaobj",
			  "javassist.reflect.ClassMetaobject");

	cl.run("sample.reflect.Person", args);
    }
}