/Users/lyon/j4p/src/javassist/sample/evolve/DemoLoader.java

1    package javassist.sample.evolve; 
2     
3    import javassist.*; 
4     
5    import java.io.*; 
6    import java.util.Hashtable; 
7     
8    /** 
9     * DemoLoader is a class loader for running a program including 
10    * an updatable class.  This simple loader allows only a single 
11    * class to be updatable.  (Extending it for supporting multiple 
12    * updatable classes is easy.) 
13    * 
14    * To run, type as follows: 
15    * 
16    * % java sample.evolve.DemoLoader <port number> 
17    * 
18    * Then DemoLoader launches sample.evolve.DemoServer with <port number>. 
19    * It also translates sample.evolve.WebPage, which sample.evolve.DemoServer 
20    * uses, so that it is an updable class. 
21    * 
22    * Note: JDK 1.2 or later only. 
23    */ 
24   public class DemoLoader { 
25       private static final int initialVersion = 0; 
26       private String updatableClassName = null; 
27       private CtClass updatableClass = null; 
28    
29       /* Creates a <code>DemoLoader</code> for making class WebPage 
30        * updatable.  Then it runs main() in sample.evolve.DemoServer. 
31        */ 
32       public static void main(String[] args) throws Throwable { 
33           Evolution translator = new Evolution(); 
34           ClassPool cp = ClassPool.getDefault(translator); 
35           Loader cl = new Loader(); 
36           cl.setClassPool(cp); 
37    
38           translator.makeUpdatable("sample.evolve.WebPage"); 
39           cl.run("sample.evolve.DemoServer", args); 
40       } 
41   } 
42