Wed, 27 Apr 2016 01:21:28 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/corba/
changeset: 765:f46df0af2ca8
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | /* |
aoqi@0 | 26 | * COMPONENT_NAME: idl.toJava |
aoqi@0 | 27 | * |
aoqi@0 | 28 | * ORIGINS: 27 |
aoqi@0 | 29 | * |
aoqi@0 | 30 | * Licensed Materials - Property of IBM |
aoqi@0 | 31 | * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999 |
aoqi@0 | 32 | * RMI-IIOP v1.0 |
aoqi@0 | 33 | * |
aoqi@0 | 34 | */ |
aoqi@0 | 35 | |
aoqi@0 | 36 | package com.sun.tools.corba.se.idl.toJavaPortable; |
aoqi@0 | 37 | |
aoqi@0 | 38 | // NOTES: |
aoqi@0 | 39 | // -F46082.51<daz> Remove -stateful feature; javaStatefulName() obsolete. |
aoqi@0 | 40 | // -D57147 <klr> Make _Tie implement org.omg.CORBA.portable.InvokeHandler |
aoqi@0 | 41 | // -D58037 <klr> Make _Tie delegate to Operations interface |
aoqi@0 | 42 | // -D62739 <klr> no TIE for values that support abstract interfaces, etc. |
aoqi@0 | 43 | |
aoqi@0 | 44 | import java.io.File; |
aoqi@0 | 45 | import java.io.PrintWriter; |
aoqi@0 | 46 | |
aoqi@0 | 47 | import java.util.Enumeration; |
aoqi@0 | 48 | import java.util.Hashtable; |
aoqi@0 | 49 | import java.util.Vector; |
aoqi@0 | 50 | |
aoqi@0 | 51 | import com.sun.tools.corba.se.idl.AttributeEntry; |
aoqi@0 | 52 | import com.sun.tools.corba.se.idl.GenFileStream; |
aoqi@0 | 53 | |
aoqi@0 | 54 | import com.sun.tools.corba.se.idl.InterfaceEntry; |
aoqi@0 | 55 | import com.sun.tools.corba.se.idl.InterfaceState; |
aoqi@0 | 56 | import com.sun.tools.corba.se.idl.MethodEntry; |
aoqi@0 | 57 | import com.sun.tools.corba.se.idl.SymtabEntry; |
aoqi@0 | 58 | import com.sun.tools.corba.se.idl.TypedefEntry; |
aoqi@0 | 59 | import com.sun.tools.corba.se.idl.ValueEntry; |
aoqi@0 | 60 | |
aoqi@0 | 61 | /** |
aoqi@0 | 62 | * |
aoqi@0 | 63 | **/ |
aoqi@0 | 64 | public class Skeleton implements AuxGen |
aoqi@0 | 65 | { |
aoqi@0 | 66 | private NameModifier skeletonNameModifier ; |
aoqi@0 | 67 | private NameModifier tieNameModifier ; |
aoqi@0 | 68 | |
aoqi@0 | 69 | public Skeleton () |
aoqi@0 | 70 | { |
aoqi@0 | 71 | } |
aoqi@0 | 72 | |
aoqi@0 | 73 | public void generate (Hashtable symbolTable, SymtabEntry entry) |
aoqi@0 | 74 | { |
aoqi@0 | 75 | // <d62739-begin> |
aoqi@0 | 76 | // Per Simon, 5-12-99, don't generate TIE or Skeleton for |
aoqi@0 | 77 | // |
aoqi@0 | 78 | // 1) valuetypes supporting abstract interfaces |
aoqi@0 | 79 | // 2) valuetypes with no supports. |
aoqi@0 | 80 | // 3) abstract interfaces |
aoqi@0 | 81 | // |
aoqi@0 | 82 | if (entry instanceof ValueEntry) |
aoqi@0 | 83 | { |
aoqi@0 | 84 | ValueEntry v = (ValueEntry) entry; |
aoqi@0 | 85 | if ((v.supports ().size () == 0) || |
aoqi@0 | 86 | ((InterfaceEntry) v.supports ().elementAt (0)).isAbstract ()) { |
aoqi@0 | 87 | return; |
aoqi@0 | 88 | } |
aoqi@0 | 89 | } |
aoqi@0 | 90 | if (((InterfaceEntry) entry).isAbstract ()) { |
aoqi@0 | 91 | return; |
aoqi@0 | 92 | } |
aoqi@0 | 93 | // <d62739-end> |
aoqi@0 | 94 | |
aoqi@0 | 95 | this.symbolTable = symbolTable; |
aoqi@0 | 96 | |
aoqi@0 | 97 | this.i = (InterfaceEntry)entry; |
aoqi@0 | 98 | init (); |
aoqi@0 | 99 | openStream (); |
aoqi@0 | 100 | if (stream == null) |
aoqi@0 | 101 | return; |
aoqi@0 | 102 | writeHeading (); |
aoqi@0 | 103 | writeBody (); |
aoqi@0 | 104 | writeClosing (); |
aoqi@0 | 105 | closeStream (); |
aoqi@0 | 106 | } // generate |
aoqi@0 | 107 | |
aoqi@0 | 108 | /** |
aoqi@0 | 109 | * Initialize members unique to this generator. |
aoqi@0 | 110 | **/ |
aoqi@0 | 111 | protected void init () |
aoqi@0 | 112 | { |
aoqi@0 | 113 | tie = ((Arguments)Compile.compiler.arguments).TIEServer ; |
aoqi@0 | 114 | poa = ((Arguments)Compile.compiler.arguments).POAServer ; |
aoqi@0 | 115 | |
aoqi@0 | 116 | skeletonNameModifier = |
aoqi@0 | 117 | ((Arguments)Compile.compiler.arguments).skeletonNameModifier ; |
aoqi@0 | 118 | tieNameModifier = |
aoqi@0 | 119 | ((Arguments)Compile.compiler.arguments).tieNameModifier ; |
aoqi@0 | 120 | |
aoqi@0 | 121 | tieClassName = tieNameModifier.makeName( i.name() ) ; |
aoqi@0 | 122 | skeletonClassName = skeletonNameModifier.makeName( i.name() ) ; |
aoqi@0 | 123 | |
aoqi@0 | 124 | intfName = Util.javaName (i); |
aoqi@0 | 125 | // for valuetype, get the name of the interface the valuetype supports |
aoqi@0 | 126 | if (i instanceof ValueEntry) |
aoqi@0 | 127 | { |
aoqi@0 | 128 | ValueEntry v = (ValueEntry) i; |
aoqi@0 | 129 | InterfaceEntry intf = (InterfaceEntry) v.supports ().elementAt (0); |
aoqi@0 | 130 | intfName = Util.javaName (intf); |
aoqi@0 | 131 | } |
aoqi@0 | 132 | } // init |
aoqi@0 | 133 | |
aoqi@0 | 134 | protected void openStream () |
aoqi@0 | 135 | { |
aoqi@0 | 136 | if (tie) |
aoqi@0 | 137 | stream = Util.stream( i, tieNameModifier, ".java" ) ; |
aoqi@0 | 138 | else |
aoqi@0 | 139 | stream = Util.stream( i, skeletonNameModifier, ".java" ) ; |
aoqi@0 | 140 | } // openStream |
aoqi@0 | 141 | |
aoqi@0 | 142 | protected void writeHeading () |
aoqi@0 | 143 | { |
aoqi@0 | 144 | Util.writePackage (stream, i, Util.StubFile); |
aoqi@0 | 145 | Util.writeProlog (stream, ((GenFileStream)stream).name ()); |
aoqi@0 | 146 | if (i.comment () != null) |
aoqi@0 | 147 | i.comment ().generate ("", stream); |
aoqi@0 | 148 | writeClassDeclaration (); |
aoqi@0 | 149 | stream.println ('{'); |
aoqi@0 | 150 | stream.println (); |
aoqi@0 | 151 | } // writeHeading |
aoqi@0 | 152 | |
aoqi@0 | 153 | protected void writeClassDeclaration () |
aoqi@0 | 154 | { |
aoqi@0 | 155 | if (tie){ |
aoqi@0 | 156 | stream.println ("public class " + tieClassName + |
aoqi@0 | 157 | " extends " + skeletonClassName ) ; |
aoqi@0 | 158 | } else { |
aoqi@0 | 159 | if (poa) { |
aoqi@0 | 160 | stream.println ("public abstract class " + skeletonClassName + |
aoqi@0 | 161 | " extends org.omg.PortableServer.Servant"); |
aoqi@0 | 162 | stream.print (" implements " + intfName + "Operations, "); |
aoqi@0 | 163 | stream.println ("org.omg.CORBA.portable.InvokeHandler"); |
aoqi@0 | 164 | } else { |
aoqi@0 | 165 | stream.println ("public abstract class " + skeletonClassName + |
aoqi@0 | 166 | " extends org.omg.CORBA.portable.ObjectImpl"); |
aoqi@0 | 167 | stream.print (" implements " + intfName + ", "); |
aoqi@0 | 168 | stream.println ("org.omg.CORBA.portable.InvokeHandler"); |
aoqi@0 | 169 | } |
aoqi@0 | 170 | } |
aoqi@0 | 171 | } // writeClassDeclaration |
aoqi@0 | 172 | |
aoqi@0 | 173 | /** |
aoqi@0 | 174 | * |
aoqi@0 | 175 | **/ |
aoqi@0 | 176 | protected void writeBody () |
aoqi@0 | 177 | { |
aoqi@0 | 178 | // <f46082.51> Remove -stateful feature. ????? |
aoqi@0 | 179 | //if (i.state () != null) |
aoqi@0 | 180 | // writeState (); |
aoqi@0 | 181 | writeCtors (); |
aoqi@0 | 182 | if (i instanceof ValueEntry) |
aoqi@0 | 183 | { |
aoqi@0 | 184 | // use the interface the valuetype supports to generate the |
aoqi@0 | 185 | // tie class instead of using the valuetype itself |
aoqi@0 | 186 | ValueEntry v = (ValueEntry) i; |
aoqi@0 | 187 | this.i = (InterfaceEntry) v.supports ().elementAt (0); |
aoqi@0 | 188 | } |
aoqi@0 | 189 | buildMethodList (); |
aoqi@0 | 190 | //DispatchMethod and MethodTable |
aoqi@0 | 191 | if (tie){ //Concrete class implementing the remote interface |
aoqi@0 | 192 | //The logic is here for future use |
aoqi@0 | 193 | if (poa) { |
aoqi@0 | 194 | writeMethods (); |
aoqi@0 | 195 | stream.println (" private " + intfName + "Operations _impl;"); |
aoqi@0 | 196 | stream.println (" private org.omg.PortableServer.POA _poa;"); |
aoqi@0 | 197 | } else { |
aoqi@0 | 198 | writeMethods (); |
aoqi@0 | 199 | stream.println (" private " + intfName + "Operations _impl;"); |
aoqi@0 | 200 | } |
aoqi@0 | 201 | } else { //Both POA and ImplBase are abstract InvokeHandler |
aoqi@0 | 202 | //The logic is here for future use |
aoqi@0 | 203 | if (poa) { |
aoqi@0 | 204 | writeMethodTable (); |
aoqi@0 | 205 | writeDispatchMethod (); |
aoqi@0 | 206 | writeCORBAOperations (); |
aoqi@0 | 207 | } else { |
aoqi@0 | 208 | writeMethodTable (); |
aoqi@0 | 209 | writeDispatchMethod (); |
aoqi@0 | 210 | writeCORBAOperations (); |
aoqi@0 | 211 | } |
aoqi@0 | 212 | } |
aoqi@0 | 213 | //legacy !! |
aoqi@0 | 214 | writeOperations (); |
aoqi@0 | 215 | } // writeBody |
aoqi@0 | 216 | |
aoqi@0 | 217 | /** |
aoqi@0 | 218 | * Close the skeleton class. The singleton ORB member is |
aoqi@0 | 219 | * necessary only for portable skeletons. |
aoqi@0 | 220 | **/ |
aoqi@0 | 221 | protected void writeClosing () |
aoqi@0 | 222 | { |
aoqi@0 | 223 | stream.println (); |
aoqi@0 | 224 | if (tie){ |
aoqi@0 | 225 | stream.println ("} // class " + tieClassName); |
aoqi@0 | 226 | } else { |
aoqi@0 | 227 | stream.println ("} // class " + skeletonClassName); |
aoqi@0 | 228 | } |
aoqi@0 | 229 | } // writeClosing |
aoqi@0 | 230 | |
aoqi@0 | 231 | /** |
aoqi@0 | 232 | * Close the print stream, which flushes the stream to file. |
aoqi@0 | 233 | **/ |
aoqi@0 | 234 | protected void closeStream () |
aoqi@0 | 235 | { |
aoqi@0 | 236 | stream.close (); |
aoqi@0 | 237 | } // closeStream |
aoqi@0 | 238 | |
aoqi@0 | 239 | protected void writeCtors () |
aoqi@0 | 240 | { |
aoqi@0 | 241 | stream.println (" // Constructors"); |
aoqi@0 | 242 | // Empty argument constructors |
aoqi@0 | 243 | if (!poa) { |
aoqi@0 | 244 | if (tie){ |
aoqi@0 | 245 | stream.println (" public " + tieClassName + " ()"); |
aoqi@0 | 246 | stream.println (" {"); |
aoqi@0 | 247 | stream.println (" }"); |
aoqi@0 | 248 | } else { |
aoqi@0 | 249 | stream.println (" public " + skeletonClassName + " ()"); |
aoqi@0 | 250 | stream.println (" {"); |
aoqi@0 | 251 | stream.println (" }"); |
aoqi@0 | 252 | } |
aoqi@0 | 253 | } |
aoqi@0 | 254 | stream.println (); |
aoqi@0 | 255 | // Argumented constructors |
aoqi@0 | 256 | if (tie){ |
aoqi@0 | 257 | if (poa) { |
aoqi@0 | 258 | //Write constructors |
aoqi@0 | 259 | writePOATieCtors(); |
aoqi@0 | 260 | //Write state setters and getters |
aoqi@0 | 261 | writePOATieFieldAccessMethods(); |
aoqi@0 | 262 | } else { |
aoqi@0 | 263 | stream.println (" public " + tieClassName + |
aoqi@0 | 264 | " (" + intfName + "Operations impl)"); |
aoqi@0 | 265 | stream.println (" {"); |
aoqi@0 | 266 | // Does it derive from a interface having state, e.g., valuetype? |
aoqi@0 | 267 | if (((InterfaceEntry)i.derivedFrom ().firstElement ()).state () != null) |
aoqi@0 | 268 | stream.println (" super (impl);"); |
aoqi@0 | 269 | else |
aoqi@0 | 270 | stream.println (" super ();"); |
aoqi@0 | 271 | stream.println (" _impl = impl;"); |
aoqi@0 | 272 | stream.println (" }"); |
aoqi@0 | 273 | stream.println (); |
aoqi@0 | 274 | } |
aoqi@0 | 275 | } else { //Skeleton is not Tie so it has no constructors. |
aoqi@0 | 276 | if (poa) { |
aoqi@0 | 277 | } else { |
aoqi@0 | 278 | } |
aoqi@0 | 279 | } |
aoqi@0 | 280 | |
aoqi@0 | 281 | } // writeCtors |
aoqi@0 | 282 | |
aoqi@0 | 283 | |
aoqi@0 | 284 | private void writePOATieCtors(){ |
aoqi@0 | 285 | //First constructor |
aoqi@0 | 286 | stream.println (" public " + tieClassName + " ( " + intfName + "Operations delegate ) {"); |
aoqi@0 | 287 | stream.println (" this._impl = delegate;"); |
aoqi@0 | 288 | stream.println (" }"); |
aoqi@0 | 289 | //Second constructor specifying default poa. |
aoqi@0 | 290 | stream.println (" public " + tieClassName + " ( " + intfName + |
aoqi@0 | 291 | "Operations delegate , org.omg.PortableServer.POA poa ) {"); |
aoqi@0 | 292 | stream.println (" this._impl = delegate;"); |
aoqi@0 | 293 | stream.println (" this._poa = poa;"); |
aoqi@0 | 294 | stream.println (" }"); |
aoqi@0 | 295 | } |
aoqi@0 | 296 | |
aoqi@0 | 297 | private void writePOATieFieldAccessMethods(){ |
aoqi@0 | 298 | //Getting delegate |
aoqi@0 | 299 | stream.println (" public " + intfName+ "Operations _delegate() {"); |
aoqi@0 | 300 | stream.println (" return this._impl;"); |
aoqi@0 | 301 | stream.println (" }"); |
aoqi@0 | 302 | //Setting delegate |
aoqi@0 | 303 | stream.println (" public void _delegate (" + intfName + "Operations delegate ) {"); |
aoqi@0 | 304 | stream.println (" this._impl = delegate;"); |
aoqi@0 | 305 | stream.println (" }"); |
aoqi@0 | 306 | //Overriding default poa |
aoqi@0 | 307 | stream.println (" public org.omg.PortableServer.POA _default_POA() {"); |
aoqi@0 | 308 | stream.println (" if(_poa != null) {"); |
aoqi@0 | 309 | stream.println (" return _poa;"); |
aoqi@0 | 310 | stream.println (" }"); |
aoqi@0 | 311 | stream.println (" else {"); |
aoqi@0 | 312 | stream.println (" return super._default_POA();"); |
aoqi@0 | 313 | stream.println (" }"); |
aoqi@0 | 314 | stream.println (" }"); |
aoqi@0 | 315 | } |
aoqi@0 | 316 | |
aoqi@0 | 317 | /** |
aoqi@0 | 318 | * Build a list of all of the methods, keeping out duplicates. |
aoqi@0 | 319 | **/ |
aoqi@0 | 320 | protected void buildMethodList () |
aoqi@0 | 321 | { |
aoqi@0 | 322 | // Start from scratch |
aoqi@0 | 323 | methodList = new Vector (); |
aoqi@0 | 324 | |
aoqi@0 | 325 | buildMethodList (i); |
aoqi@0 | 326 | } // buildMethodList |
aoqi@0 | 327 | |
aoqi@0 | 328 | /** |
aoqi@0 | 329 | * |
aoqi@0 | 330 | **/ |
aoqi@0 | 331 | private void buildMethodList (InterfaceEntry entry) |
aoqi@0 | 332 | { |
aoqi@0 | 333 | // Add the local methods |
aoqi@0 | 334 | Enumeration locals = entry.methods ().elements (); |
aoqi@0 | 335 | while (locals.hasMoreElements ()) |
aoqi@0 | 336 | addMethod ((MethodEntry)locals.nextElement ()); |
aoqi@0 | 337 | |
aoqi@0 | 338 | // Add the inherited methods |
aoqi@0 | 339 | Enumeration parents = entry.derivedFrom ().elements (); |
aoqi@0 | 340 | while (parents.hasMoreElements ()) |
aoqi@0 | 341 | { |
aoqi@0 | 342 | InterfaceEntry parent = (InterfaceEntry)parents.nextElement (); |
aoqi@0 | 343 | if (!parent.name ().equals ("Object")) |
aoqi@0 | 344 | buildMethodList (parent); |
aoqi@0 | 345 | } |
aoqi@0 | 346 | } // buildMethodList |
aoqi@0 | 347 | |
aoqi@0 | 348 | /** |
aoqi@0 | 349 | * |
aoqi@0 | 350 | **/ |
aoqi@0 | 351 | private void addMethod (MethodEntry method) |
aoqi@0 | 352 | { |
aoqi@0 | 353 | if (!methodList.contains (method)) |
aoqi@0 | 354 | methodList.addElement (method); |
aoqi@0 | 355 | } // addMethod |
aoqi@0 | 356 | |
aoqi@0 | 357 | /** |
aoqi@0 | 358 | * |
aoqi@0 | 359 | **/ |
aoqi@0 | 360 | protected void writeDispatchMethod () |
aoqi@0 | 361 | { |
aoqi@0 | 362 | String indent = " "; |
aoqi@0 | 363 | stream.println (" public org.omg.CORBA.portable.OutputStream _invoke (String $method,"); |
aoqi@0 | 364 | stream.println (indent + "org.omg.CORBA.portable.InputStream in,"); |
aoqi@0 | 365 | stream.println (indent + "org.omg.CORBA.portable.ResponseHandler $rh)"); |
aoqi@0 | 366 | stream.println (" {"); |
aoqi@0 | 367 | |
aoqi@0 | 368 | // this is a special case code generation for cases servantLocator and |
aoqi@0 | 369 | // servantActivator, where OMG is taking too long to define them |
aoqi@0 | 370 | // as local objects |
aoqi@0 | 371 | |
aoqi@0 | 372 | boolean isLocalInterface = false; |
aoqi@0 | 373 | if (i instanceof InterfaceEntry) { |
aoqi@0 | 374 | isLocalInterface = i.isLocalServant(); |
aoqi@0 | 375 | } |
aoqi@0 | 376 | |
aoqi@0 | 377 | if (!isLocalInterface) { |
aoqi@0 | 378 | // Per Simon 8/26/98, create and return reply stream for all methods - KLR |
aoqi@0 | 379 | stream.println (" org.omg.CORBA.portable.OutputStream out = null;"); |
aoqi@0 | 380 | stream.println (" java.lang.Integer __method = (java.lang.Integer)_methods.get ($method);"); |
aoqi@0 | 381 | stream.println (" if (__method == null)"); |
aoqi@0 | 382 | stream.println (" throw new org.omg.CORBA.BAD_OPERATION (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);"); |
aoqi@0 | 383 | stream.println (); |
aoqi@0 | 384 | if (methodList.size () > 0) |
aoqi@0 | 385 | { |
aoqi@0 | 386 | stream.println (" switch (__method.intValue ())"); |
aoqi@0 | 387 | stream.println (" {"); |
aoqi@0 | 388 | |
aoqi@0 | 389 | // Write the method case statements |
aoqi@0 | 390 | int realI = 0; |
aoqi@0 | 391 | for (int i = 0; i < methodList.size (); ++i) |
aoqi@0 | 392 | { |
aoqi@0 | 393 | MethodEntry method = (MethodEntry)methodList.elementAt (i); |
aoqi@0 | 394 | ((MethodGen)method.generator ()).dispatchSkeleton (symbolTable, method, stream, realI); |
aoqi@0 | 395 | if (method instanceof AttributeEntry && !((AttributeEntry)method).readOnly ()) |
aoqi@0 | 396 | realI += 2; |
aoqi@0 | 397 | else |
aoqi@0 | 398 | ++realI; |
aoqi@0 | 399 | } |
aoqi@0 | 400 | |
aoqi@0 | 401 | indent = " "; |
aoqi@0 | 402 | stream.println (indent + "default:"); |
aoqi@0 | 403 | stream.println (indent + " throw new org.omg.CORBA.BAD_OPERATION (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);"); |
aoqi@0 | 404 | stream.println (" }"); |
aoqi@0 | 405 | stream.println (); |
aoqi@0 | 406 | } |
aoqi@0 | 407 | stream.println (" return out;"); |
aoqi@0 | 408 | } else { |
aoqi@0 | 409 | stream.println(" throw new org.omg.CORBA.BAD_OPERATION();"); |
aoqi@0 | 410 | } |
aoqi@0 | 411 | stream.println (" } // _invoke"); |
aoqi@0 | 412 | stream.println (); |
aoqi@0 | 413 | } // writeDispatchMethod |
aoqi@0 | 414 | |
aoqi@0 | 415 | /** |
aoqi@0 | 416 | * |
aoqi@0 | 417 | **/ |
aoqi@0 | 418 | protected void writeMethodTable () |
aoqi@0 | 419 | { |
aoqi@0 | 420 | // Write the methods hashtable |
aoqi@0 | 421 | stream.println (" private static java.util.Hashtable _methods = new java.util.Hashtable ();"); |
aoqi@0 | 422 | stream.println (" static"); |
aoqi@0 | 423 | stream.println (" {"); |
aoqi@0 | 424 | |
aoqi@0 | 425 | int count = -1; |
aoqi@0 | 426 | Enumeration e = methodList.elements (); |
aoqi@0 | 427 | while (e.hasMoreElements ()) |
aoqi@0 | 428 | { |
aoqi@0 | 429 | MethodEntry method = (MethodEntry)e.nextElement (); |
aoqi@0 | 430 | if (method instanceof AttributeEntry) |
aoqi@0 | 431 | { |
aoqi@0 | 432 | stream.println (" _methods.put (\"_get_" + Util.stripLeadingUnderscores (method.name ()) + "\", new java.lang.Integer (" + (++count) + "));"); |
aoqi@0 | 433 | if (!((AttributeEntry)method).readOnly ()) |
aoqi@0 | 434 | stream.println (" _methods.put (\"_set_" + Util.stripLeadingUnderscores (method.name ()) + "\", new java.lang.Integer (" + (++count) + "));"); |
aoqi@0 | 435 | } |
aoqi@0 | 436 | else |
aoqi@0 | 437 | stream.println (" _methods.put (\"" + Util.stripLeadingUnderscores (method.name ()) + "\", new java.lang.Integer (" + (++count) + "));"); |
aoqi@0 | 438 | } |
aoqi@0 | 439 | stream.println (" }"); |
aoqi@0 | 440 | stream.println (); |
aoqi@0 | 441 | } // writeMethodTable |
aoqi@0 | 442 | |
aoqi@0 | 443 | /** |
aoqi@0 | 444 | * |
aoqi@0 | 445 | **/ |
aoqi@0 | 446 | protected void writeMethods () |
aoqi@0 | 447 | { |
aoqi@0 | 448 | int realI = 0; |
aoqi@0 | 449 | for (int i = 0; i < methodList.size (); ++i) |
aoqi@0 | 450 | { |
aoqi@0 | 451 | MethodEntry method = (MethodEntry)methodList.elementAt (i); |
aoqi@0 | 452 | ((MethodGen)method.generator ()).skeleton |
aoqi@0 | 453 | (symbolTable, method, stream, realI); |
aoqi@0 | 454 | if (method instanceof AttributeEntry && |
aoqi@0 | 455 | !((AttributeEntry)method).readOnly ()) |
aoqi@0 | 456 | realI += 2; |
aoqi@0 | 457 | else |
aoqi@0 | 458 | ++realI; |
aoqi@0 | 459 | stream.println (); |
aoqi@0 | 460 | } |
aoqi@0 | 461 | } // writeMethods |
aoqi@0 | 462 | |
aoqi@0 | 463 | /** |
aoqi@0 | 464 | * |
aoqi@0 | 465 | **/ |
aoqi@0 | 466 | private void writeIDs () |
aoqi@0 | 467 | { |
aoqi@0 | 468 | Vector list = new Vector (); |
aoqi@0 | 469 | buildIDList (i, list); |
aoqi@0 | 470 | Enumeration e = list.elements (); |
aoqi@0 | 471 | boolean first = true; |
aoqi@0 | 472 | while (e.hasMoreElements ()) |
aoqi@0 | 473 | { |
aoqi@0 | 474 | if (first) |
aoqi@0 | 475 | first = false; |
aoqi@0 | 476 | else |
aoqi@0 | 477 | stream.println (", "); |
aoqi@0 | 478 | stream.print (" \"" + (String)e.nextElement () + '"'); |
aoqi@0 | 479 | } |
aoqi@0 | 480 | } // writeIDs |
aoqi@0 | 481 | |
aoqi@0 | 482 | /** |
aoqi@0 | 483 | * |
aoqi@0 | 484 | **/ |
aoqi@0 | 485 | private void buildIDList (InterfaceEntry entry, Vector list) |
aoqi@0 | 486 | { |
aoqi@0 | 487 | if (!entry.fullName ().equals ("org/omg/CORBA/Object")) |
aoqi@0 | 488 | { |
aoqi@0 | 489 | String id = Util.stripLeadingUnderscoresFromID (entry.repositoryID ().ID ()); |
aoqi@0 | 490 | if (!list.contains (id)) |
aoqi@0 | 491 | list.addElement (id); |
aoqi@0 | 492 | Enumeration e = entry.derivedFrom ().elements (); |
aoqi@0 | 493 | while (e.hasMoreElements ()) |
aoqi@0 | 494 | buildIDList ((InterfaceEntry)e.nextElement (), list); |
aoqi@0 | 495 | } |
aoqi@0 | 496 | } // buildIDList |
aoqi@0 | 497 | |
aoqi@0 | 498 | /** |
aoqi@0 | 499 | * |
aoqi@0 | 500 | **/ |
aoqi@0 | 501 | protected void writeCORBAOperations () |
aoqi@0 | 502 | { |
aoqi@0 | 503 | stream.println (" // Type-specific CORBA::Object operations"); |
aoqi@0 | 504 | |
aoqi@0 | 505 | stream.println (" private static String[] __ids = {"); |
aoqi@0 | 506 | writeIDs (); |
aoqi@0 | 507 | stream.println ("};"); |
aoqi@0 | 508 | stream.println (); |
aoqi@0 | 509 | if (poa) |
aoqi@0 | 510 | writePOACORBAOperations(); |
aoqi@0 | 511 | else |
aoqi@0 | 512 | writeNonPOACORBAOperations(); |
aoqi@0 | 513 | |
aoqi@0 | 514 | } // writeCORBAOperations |
aoqi@0 | 515 | |
aoqi@0 | 516 | protected void writePOACORBAOperations(){ |
aoqi@0 | 517 | stream.println (" public String[] _all_interfaces (org.omg.PortableServer.POA poa, byte[] objectId)"); |
aoqi@0 | 518 | //Right now, with our POA implementation, the same |
aoqi@0 | 519 | //implementation of _ids() type methods seem to work for both non-POA |
aoqi@0 | 520 | //as well as POA servers. We need to REVISIT since the equivalent |
aoqi@0 | 521 | //POA interface, i.e. _all_interfaces, has parameters which are not being |
aoqi@0 | 522 | //used in the _ids() implementation. |
aoqi@0 | 523 | stream.println (" {"); |
aoqi@0 | 524 | stream.println (" return (String[])__ids.clone ();"); |
aoqi@0 | 525 | stream.println (" }"); |
aoqi@0 | 526 | stream.println (); |
aoqi@0 | 527 | //_this() |
aoqi@0 | 528 | stream.println (" public "+ i.name() +" _this() "); |
aoqi@0 | 529 | stream.println (" {"); |
aoqi@0 | 530 | stream.println (" return "+ i.name() +"Helper.narrow(" ); |
aoqi@0 | 531 | stream.println (" super._this_object());"); |
aoqi@0 | 532 | stream.println (" }"); |
aoqi@0 | 533 | stream.println (); |
aoqi@0 | 534 | //_this(org.omg.CORBA.ORB orb) |
aoqi@0 | 535 | stream.println (" public "+ i.name() +" _this(org.omg.CORBA.ORB orb) "); |
aoqi@0 | 536 | stream.println (" {"); |
aoqi@0 | 537 | stream.println (" return "+ i.name() +"Helper.narrow(" ); |
aoqi@0 | 538 | stream.println (" super._this_object(orb));"); |
aoqi@0 | 539 | stream.println (" }"); |
aoqi@0 | 540 | stream.println (); |
aoqi@0 | 541 | } |
aoqi@0 | 542 | protected void writeNonPOACORBAOperations(){ |
aoqi@0 | 543 | stream.println (" public String[] _ids ()"); |
aoqi@0 | 544 | stream.println (" {"); |
aoqi@0 | 545 | stream.println (" return (String[])__ids.clone ();"); |
aoqi@0 | 546 | stream.println (" }"); |
aoqi@0 | 547 | stream.println (); |
aoqi@0 | 548 | } |
aoqi@0 | 549 | /** |
aoqi@0 | 550 | * |
aoqi@0 | 551 | **/ |
aoqi@0 | 552 | protected void writeOperations () |
aoqi@0 | 553 | { |
aoqi@0 | 554 | // _get_ids removed at Simon's request 8/26/98 - KLR |
aoqi@0 | 555 | } // writeOperations |
aoqi@0 | 556 | |
aoqi@0 | 557 | protected Hashtable symbolTable = null; |
aoqi@0 | 558 | protected InterfaceEntry i = null; |
aoqi@0 | 559 | protected PrintWriter stream = null; |
aoqi@0 | 560 | |
aoqi@0 | 561 | // Unique to this generator |
aoqi@0 | 562 | protected String tieClassName = null; |
aoqi@0 | 563 | protected String skeletonClassName = null; |
aoqi@0 | 564 | protected boolean tie = false; |
aoqi@0 | 565 | protected boolean poa = false; |
aoqi@0 | 566 | protected Vector methodList = null; |
aoqi@0 | 567 | protected String intfName = ""; |
aoqi@0 | 568 | } // class Skeleton |