1 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 19 public class IDLWriter { 20 21 protected InterfaceDef inIface; 22 23 protected String outFile; 24 protected String outInterface; 25 protected String outPackage; 26 27 28 public IDLWriter(String iface) throws CodeWriterException { 29 try { 30 inIface=(InterfaceDef)TIRAccessMethods.lookupCDLContained(SOFA.Connector.TIRAccess.TIRAccess.repository,iface); 31 } catch (Exception e) { 32 throw new CodeWriterException("Can't access interface '"+iface+"'.",e); 33 } 34 } 35 36 public void setOut(String outFile, String outPackage, String 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 out; 44 try { 45 out=new java.io.PrintWriter (new java.io.BufferedWriter (new java.io.FileWriter (outFile))); 46 } catch (Exception 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 mods=new java.util.StringTokenizer (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 [] 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 ifaceBody=director.getInterfaceBody(); 78 if (ifaceBody!=null) { 79 out.println(ifaceBody); 80 } 81 82 for (i=0;i<mts.length;i++) { 83 String 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 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 |