1 20 21 package org.jacorb.idl; 22 23 29 30 import java.io.PrintWriter ; 31 32 public class Method 33 implements Operation 34 { 35 public TypeSpec resultType; 36 public TypeSpec parameterType; 37 38 private String name; 39 private boolean pseudo; 40 41 42 public Method( TypeSpec res, TypeSpec params, String name, boolean pseudo ) 43 { 44 resultType = res; 45 parameterType = params; 46 this.name = name; 47 this.pseudo = pseudo; 48 } 49 50 public boolean isGetter() 51 { 52 return resultType != null; 53 } 54 55 public String name() 56 { 57 return name; 58 } 59 60 public String opName() 61 { 62 if( isGetter() ) 63 return "_get_" + name; 64 else 65 return "_set_" + name; 66 } 67 68 public String signature() 69 { 70 StringBuffer sb = new StringBuffer (); 71 sb.append( name + "(" ); 72 if( parameterType != null ) 73 { 74 sb.append( parameterType.toString() ); 75 } 76 sb.append( ")" ); 77 return sb.toString(); 78 } 79 80 public void printSignature( PrintWriter ps ) 81 { 82 printSignature( ps, pseudo ); 83 } 84 85 88 public void printSignature( PrintWriter ps, boolean printModifiers ) 89 { 90 ps.print( "\t" ); 91 if( printModifiers ) 92 ps.print( "public abstract " ); 93 94 if( isGetter() ) 95 { 96 ps.print( resultType.toString() ); 97 ps.println( " " + name + "();" ); 98 } 99 else 100 { 101 ps.print( "void " + name + "(" ); 102 ps.print( parameterType.toString() ); 103 ps.println( " arg);" ); 104 } 105 } 106 107 108 public void printMethod( PrintWriter ps, String classname, boolean is_local, boolean is_abstract ) 109 { 110 ps.print( "\tpublic " ); 111 112 if( isGetter() ) 113 { 114 ps.print( resultType.toString() ); 116 ps.println( " " + name + "()" ); 117 ps.println( "\t{" ); 118 ps.println( "\t\twhile(true)" ); 119 ps.println( "\t\t{" ); 120 121 if( !is_local ) 124 { 125 ps.println( "\t\tif(! this._is_local())" ); 126 ps.println( "\t\t{" ); 127 128 ps.println( "\t\t\torg.omg.CORBA.portable.InputStream _is = null;" ); 129 130 ps.println( "\t\t\ttry" ); 131 ps.println( "\t\t\t{" ); 132 ps.println( "\t\t\t\torg.omg.CORBA.portable.OutputStream _os = _request(\"_get_" + name + "\",true);" ); 133 ps.println( "\t\t\t\t_is = _invoke(_os);" ); 134 TypeSpec ts = resultType.typeSpec(); 135 ps.println( "\t\t\t\treturn " + ts.printReadExpression( "_is" ) + ";" ); 136 ps.println( "\t\t\t}" ); 137 ps.println( "\t\t\tcatch( org.omg.CORBA.portable.RemarshalException _rx ){}" ); 138 ps.println( "\t\t\tcatch( org.omg.CORBA.portable.ApplicationException _ax )" ); 139 ps.println( "\t\t\t{" ); 140 ps.println( "\t\t\t\tString _id = _ax.getId();" ); 141 ps.println( "\t\t\t\tthrow new RuntimeException(\"Unexpected exception \" + _id );" ); 142 ps.println( "\t\t\t}" ); 143 ps.println( "\t\t\tfinally" ); 144 ps.println( "\t\t\t{" ); 145 ps.println( "\t\t\t\tthis._releaseReply(_is);" ); 146 ps.println( "\t\t\t}" ); 147 ps.println( "\t\t}\n" ); 148 149 ps.println( "\t\telse" ); 151 ps.println( "\t\t{" ); 152 } 153 154 ps.println( "\t\torg.omg.CORBA.portable.ServantObject _so = _servant_preinvoke( \"_get_" + name + "\", _opsClass);" ); 155 156 ps.println( "\t\tif( _so == null )" ); 157 ps.println( "\t\t\tthrow new org.omg.CORBA.UNKNOWN(\"local invocations not supported!\");" ); 158 if( is_abstract ) 159 { 160 ps.println( "\t\t\t" + classname + " _localServant = (" + 161 classname + ")_so.servant;" ); 162 } 163 else 164 { 165 ps.println( "\t\t\t" + classname + "Operations _localServant = (" + 166 classname + "Operations)_so.servant;" ); 167 } 168 169 ps.println( "\t\t\t" + resultType + " _result;" ); 170 171 ps.println( "\t\ttry" ); 172 ps.println( "\t\t{" ); 173 ps.println( "\t\t\t_result = _localServant." + name + "();" ); 174 ps.println( "\t\t}" ); 175 ps.println( "\t\tfinally" ); 176 ps.println( "\t\t{" ); 177 ps.println( "\t\t\t_servant_postinvoke(_so);" ); 178 ps.println( "\t\t}" ); 179 ps.println( "\t\treturn _result;" ); 180 ps.println( "\t\t}" ); 181 if( !is_local ) ps.println( "\t\t}\n" ); 182 ps.println( "\t}\n" ); 183 } 184 else 185 { 186 187 188 ps.print( "void " + name + "(" + parameterType.toString() ); 189 ps.println( " a)" ); 190 ps.println( "\t{" ); 191 ps.println( "\t\twhile(true)" ); 192 ps.println( "\t\t{" ); 193 if( !is_local ) 196 { 197 ps.println( "\t\tif(! this._is_local())" ); 198 ps.println( "\t\t{" ); 199 ps.println( "\t\t\torg.omg.CORBA.portable.InputStream _is = null;" ); 200 201 ps.println( "\t\t\ttry" ); 202 ps.println( "\t\t\t{" ); 203 ps.println( "\t\t\t\torg.omg.CORBA.portable.OutputStream _os = _request(\"_set_" + name + "\",true);" ); 204 ps.println( "\t\t\t\t" + parameterType.typeSpec().printWriteStatement( "a", "_os" ) ); 205 ps.println( "\t\t\t\t_is = _invoke(_os);" ); 206 ps.println( "\t\t\t\treturn;" ); 207 ps.println( "\t\t\t}" ); 208 ps.println( "\t\t\tcatch( org.omg.CORBA.portable.RemarshalException _rx ){}" ); 209 ps.println( "\t\t\tcatch( org.omg.CORBA.portable.ApplicationException _ax )" ); 210 ps.println( "\t\t\t{" ); 211 ps.println( "\t\t\t\tString _id = _ax.getId();" ); 212 ps.println( "\t\t\t\tthrow new RuntimeException(\"Unexpected exception \" + _id );" ); 213 ps.println( "\t\t\t}" ); 214 ps.println( "\t\t\tfinally" ); 215 ps.println( "\t\t\t{" ); 216 ps.println( "\t\t\t\tthis._releaseReply(_is);" ); 217 ps.println( "\t\t\t}" ); 218 ps.println( "\t\t}\n" ); 219 220 ps.println( "\t\telse" ); 222 ps.println( "\t\t{" ); 223 224 } 225 ps.println( "\t\t\torg.omg.CORBA.portable.ServantObject _so = _servant_preinvoke( \"_set_" + name + "\", _opsClass);" ); 226 227 ps.println( "\t\t\tif( _so == null )" ); 228 ps.println( "\t\t\t\tthrow new org.omg.CORBA.UNKNOWN(\"local invocations not supported!\");" ); 229 ps.println( "\t\t\t" + classname + "Operations _localServant = (" + classname + "Operations)_so.servant;" ); 230 231 ps.println( "\t\t\t\ttry" ); 232 ps.println( "\t\t\t\t{" ); 233 ps.println( "\t\t\t\t\t_localServant." + name + "(a);" ); 234 ps.println( "\t\t\t\t}" ); 235 ps.println( "\t\t\t\tfinally" ); 236 ps.println( "\t\t\t\t{" ); 237 ps.println( "\t\t\t\t\t_servant_postinvoke(_so);" ); 238 ps.println( "\t\t\t\t}" ); 239 ps.println( "\t\t\t\treturn;" ); 240 ps.println( "\t\t\t}" ); 241 if( !is_local ) ps.println( "\t\t}\n" ); 242 ps.println( "\t}\n" ); 243 } 244 } 245 246 247 public void print_sendc_Method( PrintWriter ps, 248 String classname ) 249 { 250 ps.print( "\tpublic void sendc_" ); 251 252 if( isGetter() ) 253 { 254 ps.print ( "get_" + name ); 256 ps.println( "(AMI_" + classname + "Handler ami_handler)" ); 257 ps.println( "\t{" ); 258 ps.println( "\t\twhile(true)" ); 259 ps.println( "\t\t{" ); 260 261 ps.println( "\t\t\ttry" ); 262 ps.println( "\t\t\t{" ); 263 ps.println( "\t\t\t\torg.omg.CORBA.portable.OutputStream _os = _request(\"_get_" + name + "\",true);" ); 264 ps.println( "\t\t\t\t((org.jacorb.orb.Delegate)_get_delegate()).invoke(this, _os, ami_handler);" ); 265 ps.println( "\t\t\t\treturn;" ); 266 ps.println( "\t\t\t}" ); 267 ps.println( "\t\t\tcatch( org.omg.CORBA.portable.RemarshalException _rx ){}" ); 268 ps.println( "\t\t\tcatch( org.omg.CORBA.portable.ApplicationException _ax )" ); 269 ps.println( "\t\t\t{" ); 270 ps.println( "\t\t\t\tString _id = _ax.getId();" ); 271 ps.println( "\t\t\t\tthrow new RuntimeException(\"Unexpected exception \" + _id );" ); 272 ps.println( "\t\t\t}" ); 273 ps.println( "\t\t}" ); 274 ps.println( "\t}\n" ); 275 } 276 else 277 { 278 ps.print ( "set_" + name ); 280 ps.print ( "(AMI_" + classname + "Handler ami_handler, " ); 281 ps.println ( parameterType.toString() + " attr_" + name + ")"); 282 ps.println( "\t{" ); 283 ps.println( "\t\twhile(true)" ); 284 ps.println( "\t\t{" ); 285 ps.println( "\t\t\ttry" ); 286 ps.println( "\t\t\t{" ); 287 ps.println( "\t\t\t\torg.omg.CORBA.portable.OutputStream _os = _request(\"_set_" + name + "\",true);" ); 288 ps.println( "\t\t\t\t" + parameterType.typeSpec().printWriteStatement( "attr_" + name, "_os" ) ); 289 ps.println( "\t\t\t\t((org.jacorb.orb.Delegate)_get_delegate()).invoke(this, _os, ami_handler);" ); 290 ps.println( "\t\t\t\treturn;" ); 291 ps.println( "\t\t\t}" ); 292 ps.println( "\t\t\tcatch( org.omg.CORBA.portable.RemarshalException _rx ){}" ); 293 ps.println( "\t\t\tcatch( org.omg.CORBA.portable.ApplicationException _ax )" ); 294 ps.println( "\t\t\t{" ); 295 ps.println( "\t\t\t\tString _id = _ax.getId();" ); 296 ps.println( "\t\t\t\tthrow new RuntimeException(\"Unexpected exception \" + _id );" ); 297 ps.println( "\t\t\t}" ); 298 ps.println( "\t\t}" ); 299 ps.println( "\t}\n" ); 300 } 301 } 302 303 public void printDelegatedMethod( PrintWriter ps ) 304 { 305 ps.print( "\tpublic " ); 306 if( isGetter() ) 307 { 308 ps.print( resultType.toString() ); 309 ps.println( " " + name + "()" ); 310 ps.println( "\t{" ); 311 ps.println( "\t\treturn _delegate." + name + "();" ); 312 ps.println( "\t}\n" ); 313 } 314 else 315 { 316 317 318 ps.print( "void " + name + "(" + parameterType.toString() ); 319 ps.println( " a)" ); 320 ps.println( "\t{" ); 321 ps.println( "\t\t_delegate." + name + "(a);" ); 322 ps.println( "\t}\n" ); 323 } 324 } 325 326 public void printInvocation( PrintWriter ps ) 327 { 328 329 ps.println( "\t\t\t_out = handler.createReply();" ); 330 ps.print( "\t\t\t" ); 331 332 if( isGetter() ) 333 { 334 ps.println( resultType.typeSpec().printWriteStatement( name + "()", "_out" ) ); 335 } 336 else 337 { 338 ps.println( name + "(" + parameterType.printReadExpression( "_input" ) + ");" ); 339 } 340 } 341 342 public void accept( IDLTreeVisitor visitor ) 343 { 344 visitor.visitMethod( this ); 345 } 346 347 348 349 } 350 | Popular Tags |