/Users/lyon/j4p/src/net/rmi/rmiSynth/lex/Generator.java

1    package net.rmi.rmiSynth.lex; 
2     
3    // target: 
4    // rmi.rmiSynth.lex.Generator 
5     
6     
7    import graphics.raytracers.rmiRaytracer.raytracer.DoImage; 
8    import graphics.raytracers.rmiRaytracer.raytracer.Main; 
9    import net.rmi.rmiSynth.LocalClient; 
10   import net.compute.Hello; 
11    
12   import java.awt.*; 
13    
14   /** 
15    * Class rmi.rmiSynth.Generator generates classes 
16    * for accessing remote server 
17    * 
18    * @author Roman Yedokov 
19    * @version 1.1, D. Lyon 
20    */ 
21    
22   public class Generator { 
23    
24       private boolean onlyPublic = true;      //Output only public members 
25       private boolean withMain = false;       //Provide main method 
26       private boolean noMain = true;          //Do not provide main method 
27       private boolean withDelegate = true;    //Include cutils.delegate 
28       private boolean noDelegate = false;     //Do not include cutils.delegate 
29       private String s;                       //Output string 
30       private FileSaver fs = new FileSaver(); 
31    
32       public static void test1() { 
33           String serverClassName = "DoImageServer";       //RMI Server class name 
34           String serverInterfaceName = "DoImageInterface";        //RMI Interface name 
35           String exampleClientName = "DoImageClient";     //RMI Client class name 
36           LocalClient sequentialClass = 
37                   new LocalClient(); 
38           DoImage serverClass = 
39                   new DoImage(new Dimension()); 
40           synthesizeSource(serverInterfaceName, 
41                            serverClass, 
42                            serverClassName, 
43                            exampleClientName, 
44                            sequentialClass); 
45       } 
46    
47       public static void main(String args[]) { 
48           String serverClassName = "DoHelloServer"; 
49           //RMI Server class name 
50           String serverInterfaceName = "DoHelloInterface"; 
51           //RMI Interface name 
52           String exampleClientName = "DoHelloClient"; 
53           //RMI Client class name 
54           Hello h = new Hello(); 
55           Main clientClass = new Main(); 
56           synthesizeSource(serverInterfaceName, 
57                            h, 
58                            serverClassName, 
59                            exampleClientName, 
60                            h); 
61       } 
62    
63       private static void synthesizeSource( 
64               String serverInterfaceName, 
65               Object serverClass, 
66               String serverClassName, 
67               String exampleClientName, 
68               Object sequentialClass) { 
69           Generator g = new Generator(); 
70           g.createInterface( 
71                   serverInterfaceName, 
72                   serverClass); 
73           g.createServer( 
74                   serverInterfaceName, 
75                   serverClassName, 
76                   serverClass); 
77           //Comment out next line if you don't need to generate client 
78           g.createClient( 
79                   serverInterfaceName, 
80                   serverClassName, 
81                   exampleClientName, 
82                   sequentialClass); 
83       } 
84    
85       /** 
86        * Generates RMI interface out of a class 
87        * 
88        * @param newServerInter  Designates that 
89        *                        output source file 
90        *                        will be an interface 
91        * @param newServerInter  Name for new interface 
92        * @param sequentialClass Source class out of 
93        *                        which RMI interface 
94        *                        will be generated 
95        */ 
96       public void createInterface( 
97               String newServerInter, 
98               Object sequentialClass) { 
99           boolean isInterface = true; 
100          LexBase lb = new LexBase(isInterface, 
101                                   newServerInter, 
102                                   sequentialClass); 
103          Transform.toRMIInterface(lb); 
104          s = 
105          lb.toString(onlyPublic, 
106                      withMain, 
107                      withDelegate); 
108          System.out.println(s); 
109          fs.createFile(s, newServerInter); 
110      } 
111   
112      /** 
113       * Generates RMI server class out of a class 
114       * 
115       * @param newServerInter  Designates that 
116       *                        output source file 
117       *                        will be a class 
118       * @param newServerInter  Interface name 
119       *                        output class should 
120       *                        implement 
121       * @param newServerClass  Name for new class 
122       * @param sequentialClass Source class out of 
123       *                        which RMI server 
124       *                        class will be generated 
125       */ 
126      public void createServer( 
127              String newServerInter, 
128              String newServerClass, 
129              Object sequentialClass) { 
130          boolean isClass = true; 
131          LexBase lb = new LexBase(isClass, 
132                                   newServerClass, 
133                                   sequentialClass); 
134          Transform.toRMIServer(lb, 
135                                newServerInter, 
136                                newServerClass); 
137          s = 
138          lb.toString(onlyPublic, 
139                      withMain, 
140                      withDelegate); 
141          System.out.println(s); 
142          fs.createFile(s, newServerClass); 
143      } 
144   
145      /** 
146       * Generates template for RMI client class out 
147       * of a class 
148       * 
149       * @param newServerInter  Designates that 
150       *                        output source file 
151       *                        will be a class 
152       * @param newServerInter  Interface name 
153       *                        output class should 
154       *                        instanciate 
155       * @param newServerClass  Class name output 
156       *                        class should connect 
157       *                        to 
158       * @param newClientClass  Name for new class 
159       * @param sequentialClass Source class out of 
160       *                        which RMI client 
161       *                        class will be generated 
162       */ 
163      public void createClient( 
164              String newServerInter, 
165              String newServerClass, 
166              String newClientClass, 
167              Object sequentialClass) { 
168          boolean isClass = true; 
169          LexBase lb = new LexBase(isClass, 
170                                   newClientClass, 
171                                   sequentialClass); 
172          Transform.toRMIClient(lb, 
173                                newServerInter, 
174                                newServerClass, 
175                                newClientClass, 
176                                "\"localhost\""); 
177          s = 
178          lb.toString(onlyPublic, 
179                      noMain, 
180                      noDelegate); 
181          System.out.println(s); 
182          fs.createFile(s, newClientClass); 
183      } 
184   
185  }