KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sample > evolve > DemoLoader


1 package sample.evolve;
2
3 import javassist.*;
4 import java.io.*;
5 import java.util.Hashtable JavaDoc;
6
7 /**
8  * DemoLoader is a class loader for running a program including
9  * an updatable class. This simple loader allows only a single
10  * class to be updatable. (Extending it for supporting multiple
11  * updatable classes is easy.)
12  *
13  * To run, type as follows:
14  *
15  * % java sample.evolve.DemoLoader <port number>
16  *
17  * Then DemoLoader launches sample.evolve.DemoServer with <port number>.
18  * It also translates sample.evolve.WebPage, which sample.evolve.DemoServer
19  * uses, so that it is an updable class.
20  *
21  * Note: JDK 1.2 or later only.
22  */

23 public class DemoLoader {
24     private static final int initialVersion = 0;
25     private String JavaDoc updatableClassName = null;
26     private CtClass updatableClass = null;
27
28     /* Creates a <code>DemoLoader</code> for making class WebPage
29      * updatable. Then it runs main() in sample.evolve.DemoServer.
30      */

31     public static void main(String JavaDoc[] args) throws Throwable JavaDoc {
32         Evolution translator = new Evolution();
33         ClassPool cp = ClassPool.getDefault();
34         Loader cl = new Loader();
35         cl.addTranslator(cp, translator);
36
37         translator.makeUpdatable("sample.evolve.WebPage");
38         cl.run("sample.evolve.DemoServer", args);
39     }
40 }
41
Popular Tags