1 2 package SOFA.SOFAnode.Made.CodeGen; 3 4 import java.io.IOException ; 5 import java.rmi.RemoteException ; 6 7 import SOFA.SOFAnode.Made.TIR.Contained; 8 import SOFA.SOFAnode.Made.TIR.Identification; 9 10 15 public class ContainedGeneratedObject extends GeneratedObject { 16 17 18 Contained obj; 19 20 String generatedName; 21 22 String inRef; 23 String outRef; 24 25 31 public ContainedGeneratedObject(Contained obj, String generatedName) throws RemoteException { 32 this.obj = obj; 33 this.generatedName = generatedName; 34 key = createKey(obj); 35 inRef = generatedName; 36 outRef = generatedName+"Holder"; 37 } 38 39 46 public ContainedGeneratedObject(Contained obj, String inRefer, String outRefer) throws RemoteException { 47 this.obj = obj; 48 this.generatedName = inRefer; 49 key = createKey(obj); 50 inRef = inRefer; 51 outRef = outRefer; 52 } 53 54 61 public boolean isEqual(String absName, String ver) throws RemoteException { 62 Identification idl = obj.get_identification(); 63 return absName.compareTo(idl.absolute_name().name())==0 && ver.compareTo(idl.version())==0; 64 } 65 66 72 public boolean isEqual(Identification identification) throws RemoteException { 73 return obj.get_identification().is_equal(identification); 74 } 75 76 public String genReference(int kind) { 78 switch (kind) { 79 case INREF: return inRef; 80 case OUTREF: return outRef; 81 default: return null; 82 } 83 } 84 85 public void genReference(CGFileWriter out, int kind) throws IOException { 87 switch (kind) { 88 case INREF: out.iwrite(inRef); 89 case OUTREF: out.iwrite(outRef); 90 default: ; 91 } 92 } 93 94 public String genSpecReference(int kind, int specType) { 96 if (specType == 0) { 97 switch (kind) { 98 case INREF: return inRef; 99 case OUTREF: return outRef; 100 default: return null; 101 } 102 } else if (specType == 1) { int n = inRef.lastIndexOf('.'); 104 StringBuffer sb = new StringBuffer (inRef); 105 if (n != -1) { 106 sb.insert(n+1,"CN"); 107 } else { 108 sb.insert(inRef.lastIndexOf(":")+1,"CN"); 109 } 110 return sb.toString(); 111 } 112 return null; 113 } 114 115 public void genSpecReference(CGFileWriter out, int kind, int specType) throws IOException { 117 out.iwrite(genSpecReference(kind,specType)); 118 } 119 120 121 public void defaultValue(CGFileWriter out) throws IOException { 122 out.iwriteln("null"); 123 } 124 125 public String defaultValue() throws IOException { 126 return "null"; 127 } 128 129 public void genReadType(CGFileWriter out, String varName) throws IOException { 130 out.iwrite(varName+" = "+generatedName+"Helper.read("+defaultIstream+")"); 131 } 132 133 public String genReadType(String varName) throws IOException { 134 return varName+" = "+generatedName+"Helper.read("+defaultIstream+")"; 135 } 136 137 public void genWriteType(CGFileWriter out, String varName) throws IOException { 138 out.iwrite(generatedName+"Helper.write("+defaultOstream+", "+ varName+")"); 139 } 140 141 public String genWriteType(String varName) throws IOException { 142 return generatedName+"Helper.write("+defaultOstream+", "+ varName+")"; 143 } 144 145 public String toString() { 146 return inRef; 147 } 148 } 149 | Popular Tags |