1 21 package org.jacorb.idl; 22 23 import java.io.*; 24 import java.util.*; 25 26 34 public class ReplyHandler extends Interface 35 { 36 public ReplyHandler (Interface parent) 37 { 38 super (new_num()); 39 40 name = "AMI_" + parent.name + "Handler"; 41 pack_name = parent.pack_name; 42 43 createInheritanceSpec (parent.inheritanceSpec); 44 45 body = new InterfaceBody (new_num()); 46 body.set_name (name); 47 body.my_interface = this; 48 body.setEnclosingSymbol (this); 49 body.inheritance_spec = this.inheritanceSpec; 50 51 createOperations (parent); 52 } 53 54 58 private void createInheritanceSpec (SymbolList source) 59 { 60 inheritanceSpec = new SymbolList (new_num()); 61 if (source.v.isEmpty()) 62 { 63 ScopedName n = new ScopedName (new_num()); 64 n.pack_name = "org.omg.Messaging"; 65 n.typeName = "ReplyHandler"; 66 inheritanceSpec.v.add (n); 67 } 68 else 69 { 70 for (Iterator i = source.v.iterator(); i.hasNext();) 71 { 72 ScopedName n1 = (ScopedName)i.next(); 73 ScopedName n2 = new ScopedName (new_num()); 74 n2.pack_name = n1.pack_name; 75 n2.typeName = "AMI_" + n1.name + "Handler"; 76 inheritanceSpec.v.add (n2); 77 } 78 } 79 } 80 81 84 private void createOperations (Interface parent) 85 { 86 for (Iterator i = parent.body.v.iterator(); i.hasNext();) 87 { 88 Declaration d = ((Definition)i.next()).get_declaration(); 89 if (d instanceof OpDecl) 90 { 91 createOperationsFor ((OpDecl)d); 92 } 93 else if (d instanceof AttrDecl) 94 { 95 createOperationsFor ((AttrDecl)d); 96 } 97 } 98 } 99 100 104 private void createOperationsFor (OpDecl d) 105 { 106 List paramDecls = new ArrayList(); 108 if (!(d.opTypeSpec.type_spec instanceof VoidTypeSpec)) 109 { 110 paramDecls.add (new ParamDecl (ParamDecl.MODE_IN, 111 d.opTypeSpec, 112 "ami_return_val")); 113 } 114 for (Iterator i = d.paramDecls.iterator(); i.hasNext();) 115 { 116 ParamDecl p = (ParamDecl)i.next(); 117 if (p.paramAttribute != ParamDecl.MODE_IN) 118 { 119 paramDecls.add (new ParamDecl (ParamDecl.MODE_IN, 120 p.paramTypeSpec, 121 p.simple_declarator)); 122 } 123 } 124 body.addDefinition (new OpDecl (this, d.name, paramDecls)); 125 body.addDefinition 126 (new OpDecl (this, d.name + "_excep", excepParameterList())); 127 } 128 129 133 private void createOperationsFor (AttrDecl d) 134 { 135 for (Iterator i = d.declarators.v.iterator(); i.hasNext();) 136 { 137 SimpleDeclarator decl = (SimpleDeclarator)i.next(); 138 body.addDefinition 139 (new OpDecl (this, "get_" + decl.name, 140 parameterList (d.param_type_spec, "ami_return_val"))); 141 body.addDefinition 142 (new OpDecl (this, "get_" + decl.name + "_excep", 143 excepParameterList())); 144 if (!d.readOnly) 145 { 146 body.addDefinition 147 (new OpDecl (this, "set_" + decl.name, new ArrayList())); 148 body.addDefinition 149 (new OpDecl (this, "set_" + decl.name + "_excep", 150 excepParameterList())); 151 } 152 } 153 } 154 155 159 private List parameterList(TypeSpec type, String name) 160 { 161 List result = new ArrayList(); 162 result.add (new ParamDecl (ParamDecl.MODE_IN, type, name)); 163 return result; 164 } 165 166 private List excepParameterList() 167 { 168 return parameterList (new ExceptionHolderTypeSpec (new_num()), 169 "excep_holder"); 170 } 171 172 public String id() 173 { 174 return "IDL:" + full_name().replace('.', '/') + ":1.0"; 175 } 176 177 public void parse() 178 { 179 if (!NameTable.isDefined ("org.omg.Messaging.ReplyHandler")) 180 { 181 try 182 { 183 NameTable.define ("org.omg.Messaging.ReplyHandler", "type"); 184 TypeMap.typedef ("org.omg.Messaging.ReplyHandler", 185 new ReplyHandlerTypeSpec (IdlSymbol.new_num())); 186 } 187 catch (Exception e) 188 { 189 throw new RuntimeException (e.getMessage()); 190 } 191 } 192 193 ConstrTypeSpec ctspec = new ConstrTypeSpec (this); 194 try 195 { 196 NameTable.define (full_name(), "interface"); 197 TypeMap.typedef(full_name(), ctspec); 198 } 199 catch (NameAlreadyDefined e) 200 { 201 parser.error( "Interface " + typeName() + " already defined", token ); 202 } 203 204 body.parse(); 205 } 206 207 public void print (PrintWriter ps) 208 { 209 printInterface(); 210 printOperations(); 211 printStub(); 212 printHelper(); 213 printImplSkeleton(); 214 printTieSkeleton(); 215 } 216 217 218 } 219 220 221 222 | Popular Tags |