KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > Connector > EEG > CodeWriter > IDLWriter


1 /*
2  * IDLWriter.java
3  *
4  * Created on 7. duben 2002, 10:23
5  */

6
7 package SOFA.Connector.EEG.CodeWriter;
8
9 import SOFA.SOFAnode.Made.TIR.Contained;
10 import SOFA.SOFAnode.Made.TIR.InterfaceDef;
11 import SOFA.SOFAnode.Made.TIR.OperationDef;
12 import SOFA.SOFAnode.Made.TIR.Access.TIRAccessMethods;
13
14 /**
15  *
16  * @author ghort
17  * @version
18  */

19 public class IDLWriter {
20
21     protected InterfaceDef inIface;
22     
23     protected String JavaDoc outFile;
24     protected String JavaDoc outInterface;
25     protected String JavaDoc outPackage;
26
27     /** Creates new IDLWriter */
28     public IDLWriter(String JavaDoc iface) throws CodeWriterException {
29         try {
30             inIface=(InterfaceDef)TIRAccessMethods.lookupCDLContained(SOFA.Connector.TIRAccess.TIRAccess.repository,iface);
31         } catch (Exception JavaDoc e) {
32             throw new CodeWriterException("Can't access interface '"+iface+"'.",e);
33         }
34     }
35
36     public void setOut(String JavaDoc outFile, String JavaDoc outPackage, String JavaDoc outInterface) {
37         this.outFile=outFile;
38         this.outInterface=outInterface;
39         this.outPackage=outPackage;
40     }
41
42     public void write(IDLWriterDirector director) throws CodeWriterException {
43         java.io.PrintWriter JavaDoc out;
44         try {
45             out=new java.io.PrintWriter JavaDoc(new java.io.BufferedWriter JavaDoc(new java.io.FileWriter JavaDoc(outFile)));
46         } catch (Exception JavaDoc e) {
47             throw new CodeWriterException("Can't open output file.",e);
48         }
49
50         try {
51             int i;
52             Contained[] mts=TIRAccessMethods.getOperAttrOfInterface(inIface);
53
54             java.util.StringTokenizer JavaDoc mods=new java.util.StringTokenizer JavaDoc(outPackage,".");
55             int modsCount=mods.countTokens();
56             while (mods.hasMoreTokens()) {
57                 out.println("module "+mods.nextToken()+" {");
58             }
59             
60             out.println();
61             out.print("interface "+outInterface);
62             
63             String JavaDoc[] exts=director.getExtends();
64             if (exts!=null) {
65                 out.print(": ");
66                 for (i=0;i<exts.length;i++) {
67                     if (i>0) {
68                         out.print(", ");
69                     }
70                     out.print(exts[i]);
71                 }
72             }
73             
74             out.println(" {");
75             out.println();
76
77             String JavaDoc ifaceBody=director.getInterfaceBody();
78             if (ifaceBody!=null) {
79                 out.println(ifaceBody);
80             }
81             
82             for (i=0;i<mts.length;i++) {
83                 String JavaDoc operationDef=director.getOperation((OperationDef)mts[i]);
84                 
85                 if (operationDef!=null) {
86                     out.println("\t"+operationDef+";");
87                 }
88             }
89             
90             out.println("};");
91             out.println();
92
93             while (modsCount-->0) {
94                 out.println("};");
95             }
96             
97         } catch (IDLWriterDirectorException e) {
98             throw new CodeWriterException("Troubles with IDL writer director.",e);
99         } catch (java.rmi.RemoteException JavaDoc e) {
100             throw new CodeWriterException("Can't access TIR.",e);
101         } catch (SOFA.SOFAnode.Made.TIR.TIRExceptLock e) {
102             throw new CodeWriterException("TIR is locked.",e);
103         }
104
105         out.close();
106     }
107 }
108
Popular Tags