Thu, 31 Aug 2017 18:10:36 +0800
merge
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 | // -D57067 <klr> suppress default init if an emit init explicitly specified. |
aoqi@0 | 41 | // -D59071 <daz> Clone method entries when their content needs modification. |
aoqi@0 | 42 | // -D59092 <klr> Valuetype supporting interfaces should implement interface. |
aoqi@0 | 43 | // -D59418 <klr> Custom values implement org.omg.CORBA.CustomMarshal |
aoqi@0 | 44 | // -D59418 <klr> Invert read/read_Value, write/write_Value for Simon |
aoqi@0 | 45 | // -D60929 <klr> Update for RTF2.4 changes |
aoqi@0 | 46 | // -D62018 <klr> write_value for value with value field x calls xHelper.write. |
aoqi@0 | 47 | // -D62062 <klr> Add _write to value Helper to marshal state. |
aoqi@0 | 48 | // write_value for value subclass calls parent._write |
aoqi@0 | 49 | // -D61650<daz> Remove '\n' from generated strings; use println()'s. |
aoqi@0 | 50 | |
aoqi@0 | 51 | import java.io.File; |
aoqi@0 | 52 | import java.io.PrintWriter; |
aoqi@0 | 53 | import java.util.Hashtable; |
aoqi@0 | 54 | import java.util.Enumeration; |
aoqi@0 | 55 | import java.util.Vector; |
aoqi@0 | 56 | |
aoqi@0 | 57 | import com.sun.tools.corba.se.idl.GenFileStream; |
aoqi@0 | 58 | import com.sun.tools.corba.se.idl.InterfaceEntry; |
aoqi@0 | 59 | import com.sun.tools.corba.se.idl.SymtabEntry; |
aoqi@0 | 60 | import com.sun.tools.corba.se.idl.TypedefEntry; |
aoqi@0 | 61 | import com.sun.tools.corba.se.idl.ValueEntry; |
aoqi@0 | 62 | import com.sun.tools.corba.se.idl.ValueBoxEntry; |
aoqi@0 | 63 | import com.sun.tools.corba.se.idl.InterfaceState; |
aoqi@0 | 64 | import com.sun.tools.corba.se.idl.MethodEntry; |
aoqi@0 | 65 | import com.sun.tools.corba.se.idl.PrimitiveEntry; |
aoqi@0 | 66 | import com.sun.tools.corba.se.idl.SequenceEntry; |
aoqi@0 | 67 | import com.sun.tools.corba.se.idl.StringEntry; |
aoqi@0 | 68 | import com.sun.tools.corba.se.idl.StructEntry; |
aoqi@0 | 69 | |
aoqi@0 | 70 | /** |
aoqi@0 | 71 | * |
aoqi@0 | 72 | **/ |
aoqi@0 | 73 | public class ValueGen implements com.sun.tools.corba.se.idl.ValueGen, JavaGenerator |
aoqi@0 | 74 | { |
aoqi@0 | 75 | /** |
aoqi@0 | 76 | * Public zero-argument constructor. |
aoqi@0 | 77 | **/ |
aoqi@0 | 78 | public ValueGen () |
aoqi@0 | 79 | { |
aoqi@0 | 80 | } // ctor |
aoqi@0 | 81 | |
aoqi@0 | 82 | /** |
aoqi@0 | 83 | * |
aoqi@0 | 84 | **/ |
aoqi@0 | 85 | public void generate (Hashtable symbolTable, ValueEntry v, PrintWriter str) |
aoqi@0 | 86 | { |
aoqi@0 | 87 | this.symbolTable = symbolTable; |
aoqi@0 | 88 | this.v = v; |
aoqi@0 | 89 | init (); |
aoqi@0 | 90 | |
aoqi@0 | 91 | openStream (); |
aoqi@0 | 92 | if (stream == null) |
aoqi@0 | 93 | return; |
aoqi@0 | 94 | generateTie (); |
aoqi@0 | 95 | generateHelper (); |
aoqi@0 | 96 | generateHolder (); |
aoqi@0 | 97 | writeHeading (); |
aoqi@0 | 98 | writeBody (); |
aoqi@0 | 99 | writeClosing (); |
aoqi@0 | 100 | closeStream (); |
aoqi@0 | 101 | } // generate |
aoqi@0 | 102 | |
aoqi@0 | 103 | /** |
aoqi@0 | 104 | * Initialize members unique to this generator. |
aoqi@0 | 105 | **/ |
aoqi@0 | 106 | protected void init () |
aoqi@0 | 107 | { |
aoqi@0 | 108 | emit = ((Arguments)Compile.compiler.arguments).emit; |
aoqi@0 | 109 | factories = (Factories)Compile.compiler.factories (); |
aoqi@0 | 110 | } // init |
aoqi@0 | 111 | |
aoqi@0 | 112 | /** |
aoqi@0 | 113 | * |
aoqi@0 | 114 | **/ |
aoqi@0 | 115 | protected void openStream () |
aoqi@0 | 116 | { |
aoqi@0 | 117 | stream = Util.stream (v, ".java"); |
aoqi@0 | 118 | } // openStream |
aoqi@0 | 119 | |
aoqi@0 | 120 | /** |
aoqi@0 | 121 | * Generate a Tie class only when the user specifies the TIE option |
aoqi@0 | 122 | * and the valuetype does support an interface. |
aoqi@0 | 123 | **/ |
aoqi@0 | 124 | protected void generateTie () |
aoqi@0 | 125 | { |
aoqi@0 | 126 | boolean tie = ((Arguments)Compile.compiler.arguments).TIEServer; |
aoqi@0 | 127 | if (v.supports ().size () > 0 && tie) |
aoqi@0 | 128 | { |
aoqi@0 | 129 | Factories factories = (Factories)Compile.compiler.factories (); |
aoqi@0 | 130 | factories.skeleton ().generate (symbolTable, v); |
aoqi@0 | 131 | } |
aoqi@0 | 132 | } // generateTie |
aoqi@0 | 133 | |
aoqi@0 | 134 | /** |
aoqi@0 | 135 | * |
aoqi@0 | 136 | **/ |
aoqi@0 | 137 | protected void generateHelper () |
aoqi@0 | 138 | { |
aoqi@0 | 139 | ((Factories)Compile.compiler.factories ()).helper ().generate (symbolTable, v); |
aoqi@0 | 140 | } // generateHelper |
aoqi@0 | 141 | |
aoqi@0 | 142 | /** |
aoqi@0 | 143 | * |
aoqi@0 | 144 | **/ |
aoqi@0 | 145 | protected void generateHolder () |
aoqi@0 | 146 | { |
aoqi@0 | 147 | ((Factories)Compile.compiler.factories ()).holder ().generate (symbolTable, v); |
aoqi@0 | 148 | } // generateHolder |
aoqi@0 | 149 | |
aoqi@0 | 150 | /** |
aoqi@0 | 151 | * |
aoqi@0 | 152 | **/ |
aoqi@0 | 153 | protected void writeHeading () |
aoqi@0 | 154 | { |
aoqi@0 | 155 | Util.writePackage (stream, v); |
aoqi@0 | 156 | Util.writeProlog (stream, ((GenFileStream)stream).name ()); |
aoqi@0 | 157 | |
aoqi@0 | 158 | if (v.comment () != null) |
aoqi@0 | 159 | v.comment ().generate ("", stream); |
aoqi@0 | 160 | |
aoqi@0 | 161 | if (v.isAbstract ()) |
aoqi@0 | 162 | { |
aoqi@0 | 163 | writeAbstract (); |
aoqi@0 | 164 | return; |
aoqi@0 | 165 | } |
aoqi@0 | 166 | else |
aoqi@0 | 167 | stream.print ("public class " + v.name ()); |
aoqi@0 | 168 | |
aoqi@0 | 169 | // There should always be at least one parent: ValueBase |
aoqi@0 | 170 | SymtabEntry parent = (SymtabEntry) v.derivedFrom ().elementAt (0); |
aoqi@0 | 171 | |
aoqi@0 | 172 | // If parent is ValueBase, it's mapped to java.io.Serializable |
aoqi@0 | 173 | String parentName = Util.javaName (parent); |
aoqi@0 | 174 | boolean impl = false; |
aoqi@0 | 175 | |
aoqi@0 | 176 | if (parentName.equals ("java.io.Serializable")) |
aoqi@0 | 177 | { |
aoqi@0 | 178 | // stream.print (" implements org.omg.CORBA.portable.ValueBase, org.omg.CORBA.portable.Streamable"); |
aoqi@0 | 179 | stream.print (" implements org.omg.CORBA.portable.ValueBase"); // <d60929> |
aoqi@0 | 180 | impl = true; |
aoqi@0 | 181 | } |
aoqi@0 | 182 | else if ( !((ValueEntry)parent).isAbstract ()) |
aoqi@0 | 183 | stream.print (" extends " + parentName); |
aoqi@0 | 184 | |
aoqi@0 | 185 | // if inheriting from abstract values |
aoqi@0 | 186 | for (int i = 0; i < v.derivedFrom ().size (); i++) { |
aoqi@0 | 187 | parent = (SymtabEntry) v.derivedFrom ().elementAt (i); |
aoqi@0 | 188 | if ( ((ValueEntry)parent).isAbstract ()) |
aoqi@0 | 189 | { |
aoqi@0 | 190 | if (!impl) |
aoqi@0 | 191 | { |
aoqi@0 | 192 | stream.print (" implements "); |
aoqi@0 | 193 | impl = true; |
aoqi@0 | 194 | } |
aoqi@0 | 195 | else |
aoqi@0 | 196 | stream.print (", "); |
aoqi@0 | 197 | stream.print (Util.javaName (parent)); |
aoqi@0 | 198 | } |
aoqi@0 | 199 | } |
aoqi@0 | 200 | // <d59092-klr> Valuetype supporting interface implement Operations interface |
aoqi@0 | 201 | // for supported IDL interface |
aoqi@0 | 202 | if (((ValueEntry)v).supports ().size () > 0) { |
aoqi@0 | 203 | if (!impl) |
aoqi@0 | 204 | { |
aoqi@0 | 205 | stream.print (" implements "); |
aoqi@0 | 206 | impl = true; |
aoqi@0 | 207 | } |
aoqi@0 | 208 | else |
aoqi@0 | 209 | stream.print (", "); |
aoqi@0 | 210 | |
aoqi@0 | 211 | InterfaceEntry s =(InterfaceEntry)((ValueEntry)v).supports().elementAt(0); |
aoqi@0 | 212 | // abstract supported classes don't have "Operations" |
aoqi@0 | 213 | if (s.isAbstract ()) |
aoqi@0 | 214 | stream.print (Util.javaName (s)); |
aoqi@0 | 215 | else |
aoqi@0 | 216 | stream.print (Util.javaName (s) + "Operations"); |
aoqi@0 | 217 | } |
aoqi@0 | 218 | |
aoqi@0 | 219 | // <d59418> Custom valuetypes implement org.omg.CORBA.CustomMarshal. |
aoqi@0 | 220 | if ( ((ValueEntry)v).isCustom ()) { |
aoqi@0 | 221 | if (!impl) |
aoqi@0 | 222 | { |
aoqi@0 | 223 | stream.print (" implements "); |
aoqi@0 | 224 | impl = true; |
aoqi@0 | 225 | } |
aoqi@0 | 226 | else |
aoqi@0 | 227 | stream.print (", "); |
aoqi@0 | 228 | |
aoqi@0 | 229 | stream.print ("org.omg.CORBA.CustomMarshal "); |
aoqi@0 | 230 | } |
aoqi@0 | 231 | |
aoqi@0 | 232 | stream.println (); |
aoqi@0 | 233 | stream.println ("{"); |
aoqi@0 | 234 | } // writeHeading |
aoqi@0 | 235 | |
aoqi@0 | 236 | /** |
aoqi@0 | 237 | * |
aoqi@0 | 238 | **/ |
aoqi@0 | 239 | protected void writeBody () |
aoqi@0 | 240 | { |
aoqi@0 | 241 | writeMembers (); |
aoqi@0 | 242 | writeInitializers (); |
aoqi@0 | 243 | writeConstructor (); // <d57067> |
aoqi@0 | 244 | writeTruncatable (); // <d60929> |
aoqi@0 | 245 | writeMethods (); |
aoqi@0 | 246 | } // writeBody |
aoqi@0 | 247 | |
aoqi@0 | 248 | /** |
aoqi@0 | 249 | * |
aoqi@0 | 250 | **/ |
aoqi@0 | 251 | protected void writeClosing () |
aoqi@0 | 252 | { |
aoqi@0 | 253 | if (v.isAbstract ()) |
aoqi@0 | 254 | stream.println ("} // interface " + v.name ()); |
aoqi@0 | 255 | else |
aoqi@0 | 256 | stream.println ("} // class " + v.name ()); |
aoqi@0 | 257 | } // writeClosing |
aoqi@0 | 258 | |
aoqi@0 | 259 | /** |
aoqi@0 | 260 | * |
aoqi@0 | 261 | **/ |
aoqi@0 | 262 | protected void closeStream () |
aoqi@0 | 263 | { |
aoqi@0 | 264 | stream.close (); |
aoqi@0 | 265 | } // closeStream |
aoqi@0 | 266 | |
aoqi@0 | 267 | /** |
aoqi@0 | 268 | * |
aoqi@0 | 269 | **/ |
aoqi@0 | 270 | protected void writeConstructor () |
aoqi@0 | 271 | { |
aoqi@0 | 272 | // Per Simon, 9/3/98, emit a protected default constructor |
aoqi@0 | 273 | if (!v.isAbstract () && !explicitDefaultInit) { // <d57067 - klr> |
aoqi@0 | 274 | stream.println (" protected " + v.name () + " () {}"); |
aoqi@0 | 275 | stream.println (); |
aoqi@0 | 276 | } |
aoqi@0 | 277 | } // writeConstructor |
aoqi@0 | 278 | |
aoqi@0 | 279 | /** |
aoqi@0 | 280 | * |
aoqi@0 | 281 | **/ |
aoqi@0 | 282 | protected void writeTruncatable () // <d60929> |
aoqi@0 | 283 | { |
aoqi@0 | 284 | // Per Simon, 4/6/98, emit _truncatable_ids() |
aoqi@0 | 285 | if (!v.isAbstract ()) { |
aoqi@0 | 286 | stream.println (" public String[] _truncatable_ids() {"); |
aoqi@0 | 287 | stream.println (" return " + Util.helperName(v, true) + ".get_instance().get_truncatable_base_ids();"); // <d61056> |
aoqi@0 | 288 | stream.println (" }"); |
aoqi@0 | 289 | stream.println (); |
aoqi@0 | 290 | } |
aoqi@0 | 291 | } // writeTruncatable |
aoqi@0 | 292 | |
aoqi@0 | 293 | /** |
aoqi@0 | 294 | * |
aoqi@0 | 295 | **/ |
aoqi@0 | 296 | protected void writeMembers () |
aoqi@0 | 297 | { |
aoqi@0 | 298 | // if the value type contains no data members, a null return is expected |
aoqi@0 | 299 | if (v.state () == null) |
aoqi@0 | 300 | return; |
aoqi@0 | 301 | |
aoqi@0 | 302 | for (int i = 0; i < v.state ().size (); i ++) |
aoqi@0 | 303 | { |
aoqi@0 | 304 | InterfaceState member = (InterfaceState) v.state ().elementAt (i); |
aoqi@0 | 305 | SymtabEntry entry = (SymtabEntry) member.entry; |
aoqi@0 | 306 | Util.fillInfo (entry); |
aoqi@0 | 307 | |
aoqi@0 | 308 | if (entry.comment () != null) |
aoqi@0 | 309 | entry.comment ().generate (" ", stream); |
aoqi@0 | 310 | |
aoqi@0 | 311 | String modifier = " "; |
aoqi@0 | 312 | if (member.modifier == InterfaceState.Public) |
aoqi@0 | 313 | modifier = " public "; |
aoqi@0 | 314 | Util.writeInitializer (modifier, entry.name (), "", entry, stream); |
aoqi@0 | 315 | } |
aoqi@0 | 316 | } // writeMembers |
aoqi@0 | 317 | |
aoqi@0 | 318 | /** |
aoqi@0 | 319 | * |
aoqi@0 | 320 | **/ |
aoqi@0 | 321 | protected void writeInitializers () |
aoqi@0 | 322 | { |
aoqi@0 | 323 | Vector init = v.initializers (); |
aoqi@0 | 324 | if (init != null) |
aoqi@0 | 325 | { |
aoqi@0 | 326 | stream.println (); |
aoqi@0 | 327 | for (int i = 0; i < init.size (); i++) |
aoqi@0 | 328 | { |
aoqi@0 | 329 | MethodEntry element = (MethodEntry) init.elementAt (i); |
aoqi@0 | 330 | element.valueMethod (true); |
aoqi@0 | 331 | ((MethodGen) element.generator ()). interfaceMethod (symbolTable, element, stream); |
aoqi@0 | 332 | if (element.parameters ().isEmpty ()) // <d57067-klr> |
aoqi@0 | 333 | explicitDefaultInit = true; |
aoqi@0 | 334 | } |
aoqi@0 | 335 | } |
aoqi@0 | 336 | } // writeInitializers |
aoqi@0 | 337 | |
aoqi@0 | 338 | /** |
aoqi@0 | 339 | * |
aoqi@0 | 340 | **/ |
aoqi@0 | 341 | protected void writeMethods () |
aoqi@0 | 342 | { |
aoqi@0 | 343 | // contained vector contains methods, attributes, const, enums, exceptions, |
aoqi@0 | 344 | // structs, unions, or typedefs that are declared inside the value object. |
aoqi@0 | 345 | // State members of the nested types are also included in this vector. |
aoqi@0 | 346 | // Thus, if the declaration of a constructed type is nested in the decl. |
aoqi@0 | 347 | // of a state member, e.g struct x {boolean b;} memberx; |
aoqi@0 | 348 | // the generation of the nested type must be handled here. |
aoqi@0 | 349 | Enumeration e = v.contained ().elements (); |
aoqi@0 | 350 | while (e.hasMoreElements ()) |
aoqi@0 | 351 | { |
aoqi@0 | 352 | SymtabEntry contained = (SymtabEntry)e.nextElement (); |
aoqi@0 | 353 | if (contained instanceof MethodEntry) |
aoqi@0 | 354 | { |
aoqi@0 | 355 | MethodEntry element = (MethodEntry)contained; |
aoqi@0 | 356 | ((MethodGen)element.generator ()).interfaceMethod (symbolTable, element, stream); |
aoqi@0 | 357 | } |
aoqi@0 | 358 | else |
aoqi@0 | 359 | { |
aoqi@0 | 360 | // Generate the type referenced by the typedef. |
aoqi@0 | 361 | if (contained instanceof TypedefEntry) |
aoqi@0 | 362 | contained.type ().generate (symbolTable, stream); |
aoqi@0 | 363 | |
aoqi@0 | 364 | // Note that we also need to generate the typedef itself if |
aoqi@0 | 365 | // contained is a typedef. |
aoqi@0 | 366 | contained.generate (symbolTable, stream); |
aoqi@0 | 367 | } |
aoqi@0 | 368 | } |
aoqi@0 | 369 | |
aoqi@0 | 370 | // Abstract values are mapped to interfaces. There is no need to generate |
aoqi@0 | 371 | // the bindings for inheriting methods in case of inheritance from other |
aoqi@0 | 372 | // abstract values or supporting interface |
aoqi@0 | 373 | if (v.isAbstract ()) |
aoqi@0 | 374 | return; |
aoqi@0 | 375 | |
aoqi@0 | 376 | // workaround: if the value type doesnot support any interfaces, a null |
aoqi@0 | 377 | // return is expected instead of an empty vector |
aoqi@0 | 378 | |
aoqi@0 | 379 | // if supporting an interfaces, generate bindings for inheriting methods |
aoqi@0 | 380 | if (v.supports ().size () > 0) |
aoqi@0 | 381 | { |
aoqi@0 | 382 | InterfaceEntry intf = (InterfaceEntry) v.supports ().elementAt (0); |
aoqi@0 | 383 | Enumeration el = intf.allMethods ().elements (); |
aoqi@0 | 384 | while (el.hasMoreElements ()) |
aoqi@0 | 385 | { |
aoqi@0 | 386 | MethodEntry m = (MethodEntry) el.nextElement (); |
aoqi@0 | 387 | // <d59071> Don't alter the symbol table/emit list elements! |
aoqi@0 | 388 | //m.container (v); |
aoqi@0 | 389 | //((MethodGen)m.generator ()).interfaceMethod (symbolTable, m, stream); |
aoqi@0 | 390 | MethodEntry mClone = (MethodEntry)m.clone (); |
aoqi@0 | 391 | mClone.container (v); |
aoqi@0 | 392 | ((MethodGen)mClone.generator ()).interfaceMethod (symbolTable, mClone, stream); |
aoqi@0 | 393 | } |
aoqi@0 | 394 | } |
aoqi@0 | 395 | |
aoqi@0 | 396 | // if inheriting from abstract values, generating bindings for all |
aoqi@0 | 397 | // inheriting methods |
aoqi@0 | 398 | for (int i = 0; i < v.derivedFrom ().size (); i++) { |
aoqi@0 | 399 | ValueEntry parentValue = (ValueEntry) v.derivedFrom ().elementAt (i); |
aoqi@0 | 400 | if (parentValue.isAbstract ()) |
aoqi@0 | 401 | { |
aoqi@0 | 402 | Enumeration el = parentValue.allMethods ().elements (); |
aoqi@0 | 403 | while (el.hasMoreElements ()) |
aoqi@0 | 404 | { |
aoqi@0 | 405 | MethodEntry m = (MethodEntry) el.nextElement (); |
aoqi@0 | 406 | // <d59071> Don't alter the symbol table/emit list elements! |
aoqi@0 | 407 | //m.container (v); |
aoqi@0 | 408 | //((MethodGen)m.generator ()).interfaceMethod (symbolTable, m, stream); |
aoqi@0 | 409 | MethodEntry mClone = (MethodEntry)m.clone (); |
aoqi@0 | 410 | mClone.container (v); |
aoqi@0 | 411 | ((MethodGen)mClone.generator ()).interfaceMethod (symbolTable, mClone, stream); |
aoqi@0 | 412 | } |
aoqi@0 | 413 | } |
aoqi@0 | 414 | } |
aoqi@0 | 415 | |
aoqi@0 | 416 | //writeStreamableMethods (); |
aoqi@0 | 417 | } // writeMethods |
aoqi@0 | 418 | |
aoqi@0 | 419 | /** |
aoqi@0 | 420 | * |
aoqi@0 | 421 | **/ |
aoqi@0 | 422 | protected void writeStreamableMethods () |
aoqi@0 | 423 | { |
aoqi@0 | 424 | stream.println (" public void _read (org.omg.CORBA.portable.InputStream istream)"); |
aoqi@0 | 425 | stream.println (" {"); |
aoqi@0 | 426 | read (0, " ", "this", v, stream); |
aoqi@0 | 427 | stream.println (" }"); |
aoqi@0 | 428 | stream.println (); |
aoqi@0 | 429 | stream.println (" public void _write (org.omg.CORBA.portable.OutputStream ostream)"); |
aoqi@0 | 430 | stream.println (" {"); |
aoqi@0 | 431 | write (0, " ", "this", v, stream); |
aoqi@0 | 432 | stream.println (" }"); |
aoqi@0 | 433 | stream.println (); |
aoqi@0 | 434 | stream.println (" public org.omg.CORBA.TypeCode _type ()"); |
aoqi@0 | 435 | stream.println (" {"); |
aoqi@0 | 436 | stream.println (" return " + Util.helperName (v, false) + ".type ();"); // <d61056> |
aoqi@0 | 437 | stream.println (" }"); |
aoqi@0 | 438 | } // writeStreamableMethods |
aoqi@0 | 439 | |
aoqi@0 | 440 | /////////////// |
aoqi@0 | 441 | // From JavaGenerator |
aoqi@0 | 442 | |
aoqi@0 | 443 | public int helperType (int index, String indent, TCOffsets tcoffsets, String name, SymtabEntry entry, PrintWriter stream) |
aoqi@0 | 444 | { |
aoqi@0 | 445 | ValueEntry vt = (ValueEntry) entry; |
aoqi@0 | 446 | Vector state = vt.state (); |
aoqi@0 | 447 | int noOfMembers = state == null ? 0 : state.size (); |
aoqi@0 | 448 | String members = "_members" + index++; |
aoqi@0 | 449 | String tcOfMembers = "_tcOf" + members; |
aoqi@0 | 450 | |
aoqi@0 | 451 | stream.println (indent + "org.omg.CORBA.ValueMember[] " |
aoqi@0 | 452 | + members + " = new org.omg.CORBA.ValueMember[" |
aoqi@0 | 453 | + noOfMembers |
aoqi@0 | 454 | + "];"); |
aoqi@0 | 455 | stream.println (indent + "org.omg.CORBA.TypeCode " + tcOfMembers + " = null;"); |
aoqi@0 | 456 | //stream.println (""); // <d61650> |
aoqi@0 | 457 | |
aoqi@0 | 458 | String definedInrepId = "_id"; |
aoqi@0 | 459 | String repId, version; |
aoqi@0 | 460 | |
aoqi@0 | 461 | for (int k=0; k<noOfMembers; k++) |
aoqi@0 | 462 | { |
aoqi@0 | 463 | InterfaceState valueMember = (InterfaceState)state.elementAt (k); |
aoqi@0 | 464 | TypedefEntry member = (TypedefEntry)valueMember.entry; |
aoqi@0 | 465 | SymtabEntry mType = Util.typeOf (member); |
aoqi@0 | 466 | if (hasRepId (member)) |
aoqi@0 | 467 | { |
aoqi@0 | 468 | repId = Util.helperName (mType, true) + ".id ()"; // <d61056> |
aoqi@0 | 469 | if (mType instanceof ValueEntry || mType instanceof ValueBoxEntry) |
aoqi@0 | 470 | // OBV spec is silent on defining VersionSpec for valuetype RepIds |
aoqi@0 | 471 | version = "\"\""; |
aoqi@0 | 472 | else |
aoqi@0 | 473 | { |
aoqi@0 | 474 | String id = mType.repositoryID ().ID (); |
aoqi@0 | 475 | version = '"' + id.substring (id.lastIndexOf (':')+1) + '"'; |
aoqi@0 | 476 | } |
aoqi@0 | 477 | } |
aoqi@0 | 478 | else |
aoqi@0 | 479 | { |
aoqi@0 | 480 | repId = "\"\""; |
aoqi@0 | 481 | version = "\"\""; |
aoqi@0 | 482 | } |
aoqi@0 | 483 | |
aoqi@0 | 484 | // Get TypeCode for valuetype member and store it var. name given by tcOfMembers |
aoqi@0 | 485 | stream.println (indent + "// ValueMember instance for " + member.name ()); |
aoqi@0 | 486 | index = ((JavaGenerator)member.generator ()).type (index, indent, tcoffsets, tcOfMembers, member, stream); |
aoqi@0 | 487 | stream.println (indent + members + "[" + k + "] = new org.omg.CORBA.ValueMember (" // <d61650> |
aoqi@0 | 488 | + '"' + member.name () + "\", "); // name |
aoqi@0 | 489 | stream.println (indent + " " + repId + ", "); // id |
aoqi@0 | 490 | stream.println (indent + " " + definedInrepId + ", "); // defined_in |
aoqi@0 | 491 | stream.println (indent + " " + version + ", "); // version |
aoqi@0 | 492 | stream.println (indent + " " + tcOfMembers + ", "); // type |
aoqi@0 | 493 | stream.println (indent + " " + "null, "); // type_def |
aoqi@0 | 494 | stream.println (indent + " " + "org.omg.CORBA." + |
aoqi@0 | 495 | (valueMember.modifier == InterfaceState.Public ? |
aoqi@0 | 496 | "PUBLIC_MEMBER" : "PRIVATE_MEMBER") + ".value" + ");"); // access |
aoqi@0 | 497 | } // end for |
aoqi@0 | 498 | |
aoqi@0 | 499 | stream.println (indent + name + " = org.omg.CORBA.ORB.init ().create_value_tc (" |
aoqi@0 | 500 | + "_id, " |
aoqi@0 | 501 | + '"' + entry.name () + "\", " |
aoqi@0 | 502 | + getValueModifier (vt) + ", " |
aoqi@0 | 503 | + getConcreteBaseTypeCode (vt) + ", " |
aoqi@0 | 504 | + members |
aoqi@0 | 505 | + ");"); |
aoqi@0 | 506 | |
aoqi@0 | 507 | return index; |
aoqi@0 | 508 | } // helperType |
aoqi@0 | 509 | |
aoqi@0 | 510 | public int type (int index, String indent, TCOffsets tcoffsets, String name, SymtabEntry entry, PrintWriter stream) { |
aoqi@0 | 511 | stream.println (indent + name + " = " + Util.helperName (entry, true) + ".type ();"); // <d61056> |
aoqi@0 | 512 | return index; |
aoqi@0 | 513 | } // type |
aoqi@0 | 514 | |
aoqi@0 | 515 | // Check for types which don't have a Repository ID: primitive, |
aoqi@0 | 516 | // string, arrays and sequences. |
aoqi@0 | 517 | |
aoqi@0 | 518 | private static boolean hasRepId (SymtabEntry member) |
aoqi@0 | 519 | { |
aoqi@0 | 520 | SymtabEntry mType = Util.typeOf (member); |
aoqi@0 | 521 | return !( mType instanceof PrimitiveEntry || |
aoqi@0 | 522 | mType instanceof StringEntry || |
aoqi@0 | 523 | ( mType instanceof TypedefEntry && |
aoqi@0 | 524 | !(((TypedefEntry)mType).arrayInfo ().isEmpty ()) ) || |
aoqi@0 | 525 | ( mType instanceof TypedefEntry && member.type () instanceof SequenceEntry) ); |
aoqi@0 | 526 | } // hasRepId |
aoqi@0 | 527 | |
aoqi@0 | 528 | private static String getValueModifier (ValueEntry vt) |
aoqi@0 | 529 | { |
aoqi@0 | 530 | String mod = "NONE"; |
aoqi@0 | 531 | if (vt.isCustom ()) |
aoqi@0 | 532 | mod = "CUSTOM"; |
aoqi@0 | 533 | else if (vt.isAbstract ()) |
aoqi@0 | 534 | mod = "ABSTRACT"; |
aoqi@0 | 535 | else if (vt.isSafe ()) |
aoqi@0 | 536 | mod = "TRUNCATABLE"; |
aoqi@0 | 537 | return "org.omg.CORBA.VM_" + mod + ".value"; |
aoqi@0 | 538 | } // getValueModifier |
aoqi@0 | 539 | |
aoqi@0 | 540 | private static String getConcreteBaseTypeCode (ValueEntry vt) |
aoqi@0 | 541 | { |
aoqi@0 | 542 | Vector v = vt.derivedFrom (); |
aoqi@0 | 543 | if (!vt.isAbstract ()) |
aoqi@0 | 544 | { |
aoqi@0 | 545 | SymtabEntry base = (SymtabEntry)vt.derivedFrom ().elementAt (0); |
aoqi@0 | 546 | if (!"ValueBase".equals (base.name ())) |
aoqi@0 | 547 | return Util.helperName (base, true) + ".type ()"; // <d61056> |
aoqi@0 | 548 | } |
aoqi@0 | 549 | return "null"; |
aoqi@0 | 550 | } // getConcreteBaseTypeCode |
aoqi@0 | 551 | |
aoqi@0 | 552 | public void helperRead (String entryName, SymtabEntry entry, PrintWriter stream) |
aoqi@0 | 553 | { |
aoqi@0 | 554 | // <d59418 - KLR> per Simon, make "static" read call istream.read_value. |
aoqi@0 | 555 | // put real marshalling code in read_value. |
aoqi@0 | 556 | |
aoqi@0 | 557 | if (((ValueEntry)entry).isAbstract ()) |
aoqi@0 | 558 | { |
aoqi@0 | 559 | stream.println (" throw new org.omg.CORBA.BAD_OPERATION (\"abstract value cannot be instantiated\");"); |
aoqi@0 | 560 | } |
aoqi@0 | 561 | else |
aoqi@0 | 562 | { |
aoqi@0 | 563 | stream.println (" return (" + entryName +") ((org.omg.CORBA_2_3.portable.InputStream) istream).read_value (get_instance());"); // <d60929> |
aoqi@0 | 564 | } |
aoqi@0 | 565 | stream.println (" }"); |
aoqi@0 | 566 | stream.println (); |
aoqi@0 | 567 | |
aoqi@0 | 568 | // done with "read", now do "read_value with real marshalling code. |
aoqi@0 | 569 | |
aoqi@0 | 570 | stream.println (" public java.io.Serializable read_value (org.omg.CORBA.portable.InputStream istream)"); // <d60929> |
aoqi@0 | 571 | stream.println (" {"); |
aoqi@0 | 572 | |
aoqi@0 | 573 | // per Simon, 3/3/99, read_value for custom values throws an exception |
aoqi@0 | 574 | if (((ValueEntry)entry).isAbstract ()) |
aoqi@0 | 575 | { |
aoqi@0 | 576 | stream.println (" throw new org.omg.CORBA.BAD_OPERATION (\"abstract value cannot be instantiated\");"); |
aoqi@0 | 577 | } |
aoqi@0 | 578 | else |
aoqi@0 | 579 | if (((ValueEntry)entry).isCustom ()) |
aoqi@0 | 580 | { |
aoqi@0 | 581 | stream.println (" throw new org.omg.CORBA.BAD_OPERATION (\"custom values should use unmarshal()\");"); |
aoqi@0 | 582 | } |
aoqi@0 | 583 | else |
aoqi@0 | 584 | { |
aoqi@0 | 585 | stream.println (" " + entryName + " value = new " + entryName + " ();"); |
aoqi@0 | 586 | read (0, " ", "value", entry, stream); |
aoqi@0 | 587 | stream.println (" return value;"); |
aoqi@0 | 588 | } |
aoqi@0 | 589 | stream.println (" }"); |
aoqi@0 | 590 | stream.println (); |
aoqi@0 | 591 | // End of normal read method |
aoqi@0 | 592 | |
aoqi@0 | 593 | // Per Simon, 8/26/98 - Value helpers get an additional overloaded |
aoqi@0 | 594 | // read method where the value is passed in instead of "new'd" up. This is |
aoqi@0 | 595 | // used for reading parent value state. |
aoqi@0 | 596 | |
aoqi@0 | 597 | // Per Simon, 3/3/99 - Don't change this "read" for custom marshalling |
aoqi@0 | 598 | stream.println (" public static void read (org.omg.CORBA.portable.InputStream istream, " + entryName + " value)"); |
aoqi@0 | 599 | stream.println (" {"); |
aoqi@0 | 600 | read (0, " ", "value", entry, stream); |
aoqi@0 | 601 | } // helperRead |
aoqi@0 | 602 | |
aoqi@0 | 603 | public int read (int index, String indent, String name, SymtabEntry entry, PrintWriter stream) |
aoqi@0 | 604 | { |
aoqi@0 | 605 | // First do the state members from concrete parent hierarchy |
aoqi@0 | 606 | Vector vParents = ((ValueEntry) entry).derivedFrom (); |
aoqi@0 | 607 | if (vParents != null && vParents.size() != 0) |
aoqi@0 | 608 | { |
aoqi@0 | 609 | ValueEntry parent = (ValueEntry) vParents.elementAt (0); |
aoqi@0 | 610 | if (parent == null) |
aoqi@0 | 611 | return index; |
aoqi@0 | 612 | // Per Simon, 4/6/99 - call parent read. <d60929> |
aoqi@0 | 613 | if (! Util.javaQualifiedName(parent).equals ("java.io.Serializable")) // <d60929> |
aoqi@0 | 614 | stream.println(indent + Util.helperName (parent, true) + ".read (istream, value);"); // <d60929> // <d61056> |
aoqi@0 | 615 | } |
aoqi@0 | 616 | |
aoqi@0 | 617 | Vector vMembers = ((ValueEntry) entry).state (); |
aoqi@0 | 618 | int noOfMembers = vMembers == null ? 0 : vMembers.size (); |
aoqi@0 | 619 | |
aoqi@0 | 620 | for (int k = 0; k < noOfMembers; k++) |
aoqi@0 | 621 | { |
aoqi@0 | 622 | TypedefEntry member = (TypedefEntry)((InterfaceState)vMembers.elementAt (k)).entry; |
aoqi@0 | 623 | String memberName = member.name (); |
aoqi@0 | 624 | SymtabEntry mType = member.type (); |
aoqi@0 | 625 | |
aoqi@0 | 626 | if (mType instanceof PrimitiveEntry || |
aoqi@0 | 627 | mType instanceof TypedefEntry || |
aoqi@0 | 628 | mType instanceof SequenceEntry || |
aoqi@0 | 629 | mType instanceof StringEntry || |
aoqi@0 | 630 | !member.arrayInfo ().isEmpty ()) |
aoqi@0 | 631 | index = ((JavaGenerator)member.generator ()).read (index, indent, name + '.' + memberName, member, stream); |
aoqi@0 | 632 | else if (mType instanceof ValueEntry) |
aoqi@0 | 633 | { |
aoqi@0 | 634 | String returnType = Util.javaQualifiedName (mType); |
aoqi@0 | 635 | if (mType instanceof ValueBoxEntry) |
aoqi@0 | 636 | // <f46082.51> Remove -stateful. |
aoqi@0 | 637 | //returnType = Util.javaStatefulName (mType); |
aoqi@0 | 638 | returnType = Util.javaName (mType); |
aoqi@0 | 639 | stream.println (" " + name + '.' + memberName + " = (" + returnType + |
aoqi@0 | 640 | ") ((org.omg.CORBA_2_3.portable.InputStream)istream).read_value (" + Util.helperName (mType, true) + // <d61056> |
aoqi@0 | 641 | ".get_instance ());"); // <d61056> |
aoqi@0 | 642 | } |
aoqi@0 | 643 | else |
aoqi@0 | 644 | stream.println (indent + name + '.' + memberName + " = " + |
aoqi@0 | 645 | Util.helperName (mType, true) + ".read (istream);"); // <d61056> |
aoqi@0 | 646 | } |
aoqi@0 | 647 | |
aoqi@0 | 648 | return index; |
aoqi@0 | 649 | } // read |
aoqi@0 | 650 | |
aoqi@0 | 651 | public void helperWrite (SymtabEntry entry, PrintWriter stream) |
aoqi@0 | 652 | { |
aoqi@0 | 653 | // <d59418 - KLR> per Simon, make "static" write call istream.write_value. |
aoqi@0 | 654 | // put real marshalling code in write_value. |
aoqi@0 | 655 | stream.println (" ((org.omg.CORBA_2_3.portable.OutputStream) ostream).write_value (value, get_instance());"); // <d60929> |
aoqi@0 | 656 | stream.println (" }"); |
aoqi@0 | 657 | stream.println (); |
aoqi@0 | 658 | |
aoqi@0 | 659 | // <d62062> |
aoqi@0 | 660 | // per Simon, 4/27/99, add static _write that marshals the state of this |
aoqi@0 | 661 | // value for non-custom valuetypes |
aoqi@0 | 662 | if (!((ValueEntry)entry).isCustom ()) |
aoqi@0 | 663 | { |
aoqi@0 | 664 | stream.println (" public static void _write (org.omg.CORBA.portable.OutputStream ostream, " + Util.javaName (entry) + " value)"); |
aoqi@0 | 665 | stream.println (" {"); |
aoqi@0 | 666 | write (0, " ", "value", entry, stream); |
aoqi@0 | 667 | stream.println (" }"); |
aoqi@0 | 668 | stream.println (); |
aoqi@0 | 669 | } |
aoqi@0 | 670 | |
aoqi@0 | 671 | // done with "_write", now do "write_value |
aoqi@0 | 672 | stream.println (" public void write_value (org.omg.CORBA.portable.OutputStream ostream, java.io.Serializable obj)"); // <d60929> |
aoqi@0 | 673 | stream.println (" {"); |
aoqi@0 | 674 | |
aoqi@0 | 675 | // per Simon, 3/3/99, write_value for custom values throws an exception |
aoqi@0 | 676 | if (((ValueEntry)entry).isCustom ()) |
aoqi@0 | 677 | { |
aoqi@0 | 678 | stream.println (" throw new org.omg.CORBA.BAD_OPERATION (\"custom values should use marshal()\");"); |
aoqi@0 | 679 | } |
aoqi@0 | 680 | else { |
aoqi@0 | 681 | String entryName = Util.javaName(entry); |
aoqi@0 | 682 | stream.println (" _write (ostream, (" + entryName + ") obj);"); // <d62062> |
aoqi@0 | 683 | // write (0, " ", "value", entry, stream); <d62062> |
aoqi@0 | 684 | } |
aoqi@0 | 685 | } // helperWrite |
aoqi@0 | 686 | |
aoqi@0 | 687 | public int write (int index, String indent, String name, SymtabEntry entry, PrintWriter stream) |
aoqi@0 | 688 | { |
aoqi@0 | 689 | // First do the state members from concrete parent hierarchy |
aoqi@0 | 690 | Vector vParents = ((ValueEntry)entry).derivedFrom (); |
aoqi@0 | 691 | if (vParents != null && vParents.size () != 0) |
aoqi@0 | 692 | { |
aoqi@0 | 693 | ValueEntry parent = (ValueEntry)vParents.elementAt (0); |
aoqi@0 | 694 | if (parent == null) |
aoqi@0 | 695 | return index; |
aoqi@0 | 696 | // Per Simon, 4/06/99 - call parent write. <d60929> |
aoqi@0 | 697 | // Per Simon, 4/27/99 - call parent _write. <d62062> |
aoqi@0 | 698 | if (! Util.javaQualifiedName(parent).equals ("java.io.Serializable")) // <d60929> |
aoqi@0 | 699 | stream.println(indent + Util.helperName (parent, true) + "._write (ostream, value);"); // <d60929> <d61056> <d62062> |
aoqi@0 | 700 | } |
aoqi@0 | 701 | |
aoqi@0 | 702 | Vector vMembers = ((ValueEntry) entry ).state (); |
aoqi@0 | 703 | int noOfMembers = vMembers == null ? 0 : vMembers.size (); |
aoqi@0 | 704 | for (int k = 0; k < noOfMembers; k++) |
aoqi@0 | 705 | { |
aoqi@0 | 706 | TypedefEntry member = (TypedefEntry)((InterfaceState)vMembers.elementAt (k)).entry; |
aoqi@0 | 707 | String memberName = member.name (); |
aoqi@0 | 708 | SymtabEntry mType = member.type (); |
aoqi@0 | 709 | |
aoqi@0 | 710 | if (mType instanceof PrimitiveEntry || |
aoqi@0 | 711 | mType instanceof TypedefEntry || |
aoqi@0 | 712 | mType instanceof SequenceEntry || |
aoqi@0 | 713 | mType instanceof StringEntry || |
aoqi@0 | 714 | !member.arrayInfo ().isEmpty ()) |
aoqi@0 | 715 | index = ((JavaGenerator)member.generator ()).write (index, indent, name + '.' + memberName, member, stream); |
aoqi@0 | 716 | else |
aoqi@0 | 717 | stream.println (indent + Util.helperName (mType, true) + // <d61056> |
aoqi@0 | 718 | ".write (ostream, " + name + '.' + memberName + ");"); |
aoqi@0 | 719 | } |
aoqi@0 | 720 | |
aoqi@0 | 721 | return index; |
aoqi@0 | 722 | } // write |
aoqi@0 | 723 | |
aoqi@0 | 724 | /** |
aoqi@0 | 725 | * |
aoqi@0 | 726 | **/ |
aoqi@0 | 727 | protected void writeAbstract () |
aoqi@0 | 728 | { |
aoqi@0 | 729 | stream.print ("public interface " + v.name ()); |
aoqi@0 | 730 | |
aoqi@0 | 731 | // workaround: if the abstract value type does not have any parent, a vector |
aoqi@0 | 732 | // containing ValueBase should be returned instead of an empty vector |
aoqi@0 | 733 | if (v.derivedFrom ().size () == 0) |
aoqi@0 | 734 | stream.print (" extends org.omg.CORBA.portable.ValueBase"); // <d60929> |
aoqi@0 | 735 | else |
aoqi@0 | 736 | { |
aoqi@0 | 737 | SymtabEntry parent; |
aoqi@0 | 738 | // list the values the abstract value type inherits |
aoqi@0 | 739 | for (int i = 0; i < v.derivedFrom ().size (); i++) |
aoqi@0 | 740 | { |
aoqi@0 | 741 | if (i == 0) |
aoqi@0 | 742 | stream.print (" extends "); |
aoqi@0 | 743 | else |
aoqi@0 | 744 | stream.print (", "); |
aoqi@0 | 745 | parent = (SymtabEntry) v.derivedFrom ().elementAt (i); |
aoqi@0 | 746 | stream.print (Util.javaName (parent)); |
aoqi@0 | 747 | } |
aoqi@0 | 748 | } |
aoqi@0 | 749 | |
aoqi@0 | 750 | // list the interface the abstract value type supports |
aoqi@0 | 751 | if (v.supports ().size () > 0) |
aoqi@0 | 752 | { |
aoqi@0 | 753 | stream.print (", "); |
aoqi@0 | 754 | SymtabEntry intf = (SymtabEntry) v.supports ().elementAt (0); |
aoqi@0 | 755 | stream.print (Util.javaName (intf)); |
aoqi@0 | 756 | } |
aoqi@0 | 757 | stream.println (); |
aoqi@0 | 758 | stream.println ("{"); |
aoqi@0 | 759 | } |
aoqi@0 | 760 | |
aoqi@0 | 761 | protected int emit = 0; |
aoqi@0 | 762 | protected Factories factories = null; |
aoqi@0 | 763 | protected Hashtable symbolTable = null; |
aoqi@0 | 764 | protected ValueEntry v = null; |
aoqi@0 | 765 | protected PrintWriter stream = null; |
aoqi@0 | 766 | protected boolean explicitDefaultInit = false; // <d57067 - klr> |
aoqi@0 | 767 | } // class ValueGen |