src/share/classes/sun/rmi/rmic/iiop/IDLGenerator.java

Thu, 31 Aug 2017 18:10:36 +0800

author
aoqi
date
Thu, 31 Aug 2017 18:10:36 +0800
changeset 748
6845b95cba6b
parent 158
91006f157c46
parent 0
7ef37b2cdcad
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1998, 2007, 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 * Licensed Materials - Property of IBM
aoqi@0 27 * RMI-IIOP v1.0
aoqi@0 28 * Copyright IBM Corp. 1998 1999 All Rights Reserved
aoqi@0 29 *
aoqi@0 30 */
aoqi@0 31
aoqi@0 32 package sun.rmi.rmic.iiop;
aoqi@0 33
aoqi@0 34 import java.io.File;
aoqi@0 35 import java.io.IOException;
aoqi@0 36 import java.text.DateFormat;
aoqi@0 37 import java.util.Date;
aoqi@0 38 import java.util.Enumeration;
aoqi@0 39 import java.util.Hashtable;
aoqi@0 40 import java.util.Locale;
aoqi@0 41 import java.util.StringTokenizer;
aoqi@0 42 import java.util.Vector;
aoqi@0 43 import sun.tools.java.Identifier;
aoqi@0 44 import sun.tools.java.ClassDefinition;
aoqi@0 45 import sun.tools.java.CompilerError;
aoqi@0 46 import sun.rmi.rmic.IndentingWriter;
aoqi@0 47 import java.util.HashSet;
aoqi@0 48 import sun.rmi.rmic.Main;
aoqi@0 49
aoqi@0 50 /**
aoqi@0 51 * An IDL generator for rmic.
aoqi@0 52 *
aoqi@0 53 * @author Steve Newberry, Bryan Atsatt
aoqi@0 54 */
aoqi@0 55 public class IDLGenerator extends sun.rmi.rmic.iiop.Generator {
aoqi@0 56
aoqi@0 57 private boolean valueMethods = true;
aoqi@0 58 private boolean factory = true; //init==!factory
aoqi@0 59 private Hashtable ifHash = new Hashtable(); //IDL file Hashtable
aoqi@0 60 private Hashtable imHash = new Hashtable(); //IDL module Hashtable
aoqi@0 61
aoqi@0 62 private boolean isThrown = true; //flag for writeInclude
aoqi@0 63 private boolean isException = true; //flag for writeBanner, writeIfndef
aoqi@0 64 private boolean isForward = true; //flag for writeIfndef
aoqi@0 65 private boolean forValuetype = true; //flag for writeInherits
aoqi@0 66
aoqi@0 67 /**
aoqi@0 68 * Default constructor for Main to use.
aoqi@0 69 */
aoqi@0 70 public IDLGenerator() {
aoqi@0 71 }
aoqi@0 72
aoqi@0 73
aoqi@0 74 /**
aoqi@0 75 * Return true if a new instance should be created for each
aoqi@0 76 * class on the command line. Subclasses which return true
aoqi@0 77 * should override newInstance() to return an appropriately
aoqi@0 78 * constructed instance.
aoqi@0 79 */
aoqi@0 80 protected boolean requireNewInstance() {
aoqi@0 81 return false;
aoqi@0 82 }
aoqi@0 83
aoqi@0 84 /**
aoqi@0 85 * Return true if non-conforming types should be parsed.
aoqi@0 86 * @param stack The context stack.
aoqi@0 87 */
aoqi@0 88 protected boolean parseNonConforming(ContextStack stack) {
aoqi@0 89 return valueMethods;
aoqi@0 90 }
aoqi@0 91
aoqi@0 92 /**
aoqi@0 93 * Create and return a top-level type.
aoqi@0 94 * @param env The compiler environment.
aoqi@0 95 * @param cdef The top-level class definition.
aoqi@0 96 * @return An RemoteType or null if is non-conforming.
aoqi@0 97 */
aoqi@0 98 protected sun.rmi.rmic.iiop.CompoundType getTopType(ClassDefinition cdef,
aoqi@0 99 ContextStack stack) {
aoqi@0 100 return CompoundType.forCompound(cdef,stack);
aoqi@0 101 }
aoqi@0 102
aoqi@0 103
aoqi@0 104 /**
aoqi@0 105 * Return an Identifier which contains the fully-qualified IDL filename
aoqi@0 106 * for the given OutputType.
aoqi@0 107 * The OutputType contains a filename string (not directory) and Type.
aoqi@0 108 * @param ot the OutputType for which directory nesting is to be defined.
aoqi@0 109 * @return the new identifier.
aoqi@0 110 */
aoqi@0 111 protected Identifier getOutputId (
aoqi@0 112 OutputType ot ) {
aoqi@0 113 Identifier id = super.getOutputId( ot );
aoqi@0 114
aoqi@0 115 Type t = ot.getType();
aoqi@0 116 String fName = ot.getName();
aoqi@0 117
aoqi@0 118 if ( id == idJavaLangClass ) //java.lang.Class and array of
aoqi@0 119 if ( t.isArray() )
aoqi@0 120 return Identifier.lookup(
aoqi@0 121 "org.omg.boxedRMI.javax.rmi.CORBA." + fName );
aoqi@0 122 else return idClassDesc;
aoqi@0 123
aoqi@0 124 if ( id == idJavaLangString && //array of java.lang.String
aoqi@0 125 t.isArray() )
aoqi@0 126 return Identifier.lookup( "org.omg.boxedRMI.CORBA." + fName );
aoqi@0 127
aoqi@0 128 if ( "org.omg.CORBA.Object".equals( t.getQualifiedName() ) &&
aoqi@0 129 t.isArray() ) //array of org.omg.CORBA.Object
aoqi@0 130 return Identifier.lookup( "org.omg.boxedRMI." + fName );
aoqi@0 131
aoqi@0 132 if ( t.isArray()) { //array
aoqi@0 133 ArrayType at = (ArrayType)t;
aoqi@0 134 Type et = at.getElementType();
aoqi@0 135 if ( et.isCompound() ) {
aoqi@0 136 CompoundType ct = (CompoundType)et;
aoqi@0 137 String qName = ct.getQualifiedName();
aoqi@0 138 if ( ct.isIDLEntity() )
aoqi@0 139 return Identifier.lookup( getQualifiedName( at ) );
aoqi@0 140 }
aoqi@0 141 return Identifier.lookup( idBoxedRMI,id );
aoqi@0 142 }
aoqi@0 143
aoqi@0 144 if ( t.isCompound() ) { //boxed IDLEntity
aoqi@0 145 CompoundType ct = (CompoundType)t;
aoqi@0 146 String qName = ct.getQualifiedName();
aoqi@0 147 if ( ct.isBoxed() )
aoqi@0 148 return Identifier.lookup( getQualifiedName( ct ) );
aoqi@0 149 }
aoqi@0 150
aoqi@0 151 return id;
aoqi@0 152 }
aoqi@0 153
aoqi@0 154
aoqi@0 155
aoqi@0 156 /**
aoqi@0 157 * Return the file name extension for the given file name (e.g. ".java").
aoqi@0 158 * All files generated with the ".java" extension will be compiled. To
aoqi@0 159 * change this behavior for ".java" files, override the compileJavaSourceFile
aoqi@0 160 * method to return false.
aoqi@0 161 * @param outputType One of the items returned by getOutputTypesFor(...)
aoqi@0 162 */
aoqi@0 163 protected String getFileNameExtensionFor(OutputType outputType) {
aoqi@0 164 return IDL_FILE_EXTENSION;
aoqi@0 165 }
aoqi@0 166
aoqi@0 167
aoqi@0 168 /**
aoqi@0 169 * Examine and consume command line arguments.
aoqi@0 170 * @param argv The command line arguments. Ignore null
aoqi@0 171 * and unknown arguments. Set each consumed argument to null.
aoqi@0 172 * @param error Report any errors using the main.error() methods.
aoqi@0 173 * @return true if no errors, false otherwise.
aoqi@0 174 */
aoqi@0 175 public boolean parseArgs(String argv[], Main main) {
aoqi@0 176 boolean result = super.parseArgs(argv,main);
aoqi@0 177 String idlFrom;
aoqi@0 178 String idlTo;
aoqi@0 179 if (result) {
aoqi@0 180 nextArg:
aoqi@0 181 for (int i = 0; i < argv.length; i++) {
aoqi@0 182 if (argv[i] != null) {
aoqi@0 183 if (argv[i].equalsIgnoreCase("-idl")) {
aoqi@0 184 idl = true;
aoqi@0 185 argv[i] = null;
aoqi@0 186 }
aoqi@0 187 else if ( argv[i].equalsIgnoreCase( "-valueMethods" ) ) {
aoqi@0 188 valueMethods = true;
aoqi@0 189 argv[i] = null;
aoqi@0 190 }
aoqi@0 191 else if ( argv[i].equalsIgnoreCase( "-noValueMethods" ) ) {
aoqi@0 192 valueMethods = false;
aoqi@0 193 argv[i] = null;
aoqi@0 194 }
aoqi@0 195 else if ( argv[i].equalsIgnoreCase( "-init" ) ) {
aoqi@0 196 factory = false;
aoqi@0 197 argv[i] = null;
aoqi@0 198 }
aoqi@0 199 else if ( argv[i].equalsIgnoreCase( "-factory" ) ) {
aoqi@0 200 factory = true;
aoqi@0 201 argv[i] = null;
aoqi@0 202 }
aoqi@0 203 else if ( argv[i].equalsIgnoreCase( "-idlfile" ) ) {
aoqi@0 204 argv[i] = null;
aoqi@0 205 if ( ++i < argv.length && argv[i] != null && !argv[i].startsWith("-") ) {
aoqi@0 206 idlFrom = argv[i];
aoqi@0 207 argv[i] = null;
aoqi@0 208 if ( ++i < argv.length && argv[i] != null && !argv[i].startsWith("-") ) {
aoqi@0 209 idlTo = argv[i];
aoqi@0 210 argv[i] = null;
aoqi@0 211 ifHash.put( idlFrom,idlTo );
aoqi@0 212 continue nextArg;
aoqi@0 213 }
aoqi@0 214 }
aoqi@0 215 main.error("rmic.option.requires.argument", "-idlfile");
aoqi@0 216 result = false;
aoqi@0 217 }
aoqi@0 218 else if ( argv[i].equalsIgnoreCase( "-idlmodule" ) ) {
aoqi@0 219 argv[i] = null;
aoqi@0 220 if ( ++i < argv.length && argv[i] != null && !argv[i].startsWith("-") ) {
aoqi@0 221 idlFrom = argv[i];
aoqi@0 222 argv[i] = null;
aoqi@0 223 if ( ++i < argv.length && argv[i] != null && !argv[i].startsWith("-") ) {
aoqi@0 224 idlTo = argv[i];
aoqi@0 225 argv[i] = null;
aoqi@0 226 imHash.put( idlFrom,idlTo );
aoqi@0 227 continue nextArg;
aoqi@0 228 }
aoqi@0 229 }
aoqi@0 230 main.error("rmic.option.requires.argument", "-idlmodule");
aoqi@0 231 result = false;
aoqi@0 232 }
aoqi@0 233
aoqi@0 234
aoqi@0 235 }
aoqi@0 236 }
aoqi@0 237 }
aoqi@0 238 return result;
aoqi@0 239 }
aoqi@0 240
aoqi@0 241
aoqi@0 242
aoqi@0 243 /**
aoqi@0 244 * Return an array of OutputTypes for the IDL files that need to be
aoqi@0 245 * generated for the given top-level type.
aoqi@0 246 * OutputTypes contain filename string (not directory) and Type.
aoqi@0 247 * @param topType The type returned by getTopType().
aoqi@0 248 * @param alreadyChecked A set of Types which have already been checked.
aoqi@0 249 * @return Array of OutputTypes to generate
aoqi@0 250 */
aoqi@0 251 protected OutputType[] getOutputTypesFor(
aoqi@0 252 CompoundType topType,
aoqi@0 253 HashSet alreadyChecked ) {
aoqi@0 254 Vector refVec = getAllReferencesFor( topType );
aoqi@0 255 Vector outVec = new Vector();
aoqi@0 256 for ( int i1 = 0; i1 < refVec.size(); i1++ ) { //forall references
aoqi@0 257 Type t = (Type)refVec.elementAt( i1 );
aoqi@0 258 if ( t.isArray() ) {
aoqi@0 259 ArrayType at = (ArrayType)t;
aoqi@0 260 int dim = at.getArrayDimension();
aoqi@0 261 Type et = at.getElementType();
aoqi@0 262 String fName = unEsc( et.getIDLName() ).replace( ' ','_' );
aoqi@0 263 for ( int i2 = 0; i2 < dim; i2++ ) { //foreach dimension
aoqi@0 264 String fileName = "seq" + ( i2 + 1 ) + "_" + fName;
aoqi@0 265 outVec.addElement( new OutputType( fileName,at ) );
aoqi@0 266 }
aoqi@0 267 }
aoqi@0 268 else if ( t.isCompound() ) {
aoqi@0 269 String fName = unEsc( t.getIDLName() );
aoqi@0 270 outVec.addElement( new OutputType( fName.replace( ' ','_' ),t ) );
aoqi@0 271 if ( t.isClass() ) {
aoqi@0 272 ClassType ct = (ClassType)t;
aoqi@0 273 if ( ct.isException() ) { //exception file
aoqi@0 274 fName = unEsc( ct.getIDLExceptionName() );
aoqi@0 275 outVec.addElement( new OutputType( fName.replace( ' ','_' ),t ) );
aoqi@0 276 }
aoqi@0 277 }
aoqi@0 278 }
aoqi@0 279 }
aoqi@0 280 OutputType[] outArr = new OutputType[outVec.size()];
aoqi@0 281 outVec.copyInto( outArr );
aoqi@0 282 return outArr;
aoqi@0 283 }
aoqi@0 284
aoqi@0 285 /**
aoqi@0 286 * Get all referenced types of a given tyoe for which an IDL file needs
aoqi@0 287 * to be generated.
aoqi@0 288 * @param ct The given type.
aoqi@0 289 * @return Vector of Types for which IDL must be generated.
aoqi@0 290 */
aoqi@0 291 protected Vector getAllReferencesFor(
aoqi@0 292 CompoundType ct ) {
aoqi@0 293 Hashtable refHash = new Hashtable();
aoqi@0 294 Hashtable spcHash = new Hashtable();
aoqi@0 295 Hashtable arrHash = new Hashtable();
aoqi@0 296 int refSize;
aoqi@0 297 refHash.put( ct.getQualifiedName(),ct ); //put the given type
aoqi@0 298 accumulateReferences( refHash,spcHash,arrHash );
aoqi@0 299 do {
aoqi@0 300 refSize = refHash.size();
aoqi@0 301 accumulateReferences( refHash,spcHash,arrHash );
aoqi@0 302 }
aoqi@0 303 while ( refSize < refHash.size() ); //till hashtable stays same size
aoqi@0 304
aoqi@0 305 Vector outVec = new Vector();
aoqi@0 306 Enumeration e = refHash.elements(); //ordinary references
aoqi@0 307 while ( e.hasMoreElements() ) {
aoqi@0 308 CompoundType t = (CompoundType)e.nextElement();
aoqi@0 309 outVec.addElement( t );
aoqi@0 310 }
aoqi@0 311 e = spcHash.elements(); //special references
aoqi@0 312 while ( e.hasMoreElements() ) {
aoqi@0 313 CompoundType t = (CompoundType)e.nextElement();
aoqi@0 314 outVec.addElement( t );
aoqi@0 315 }
aoqi@0 316 e = arrHash.elements(); //array references
aoqi@0 317 nextSequence:
aoqi@0 318 while ( e.hasMoreElements() ) {
aoqi@0 319 ArrayType at = (ArrayType)e.nextElement();
aoqi@0 320 int dim = at.getArrayDimension();
aoqi@0 321 Type et = at.getElementType();
aoqi@0 322 Enumeration e2 = arrHash.elements();
aoqi@0 323 while ( e2.hasMoreElements() ) { //eliminate duplicates
aoqi@0 324 ArrayType at2 = (ArrayType)e2.nextElement();
aoqi@0 325 if ( et == at2.getElementType() && //same element type &
aoqi@0 326 dim < at2.getArrayDimension() ) //smaller dimension?
aoqi@0 327 continue nextSequence; //ignore this one
aoqi@0 328 }
aoqi@0 329 outVec.addElement( at );
aoqi@0 330 }
aoqi@0 331 return outVec;
aoqi@0 332 }
aoqi@0 333
aoqi@0 334
aoqi@0 335 /**
aoqi@0 336 * Accumulate and filter all those types that are referenced by the given
aoqi@0 337 * referenced types.
aoqi@0 338 * Keep only those for which IDL is to be generated.
aoqi@0 339 * @param refHash Hashtable containing the given types
aoqi@0 340 * @param spcHash Hashtable containing referenced specials (IDL typedefs)
aoqi@0 341 * @param arrHash Hashtable containing referenced arrays (dimensioned)
aoqi@0 342 */
aoqi@0 343 protected void accumulateReferences(
aoqi@0 344 Hashtable refHash,
aoqi@0 345 Hashtable spcHash,
aoqi@0 346 Hashtable arrHash ) {
aoqi@0 347 Enumeration e = refHash.elements();
aoqi@0 348 while ( e.hasMoreElements() ) {
aoqi@0 349 CompoundType t = (CompoundType)e.nextElement();
aoqi@0 350 Vector datVec = getData( t ); //collect and sort data
aoqi@0 351 Vector mthVec = getMethods( t ); //collect and filter methods
aoqi@0 352 getInterfaces( t,refHash ); //collect interfaces
aoqi@0 353 getInheritance( t,refHash ); //add inheritance
aoqi@0 354 getMethodReferences( mthVec,refHash,spcHash,arrHash,refHash );
aoqi@0 355 getMemberReferences( datVec,refHash,spcHash,arrHash );
aoqi@0 356 }
aoqi@0 357 e = arrHash.elements(); //add array element references
aoqi@0 358 while ( e.hasMoreElements() ) {
aoqi@0 359 ArrayType at = (ArrayType)e.nextElement();
aoqi@0 360 Type et = at.getElementType();
aoqi@0 361 addReference( et,refHash,spcHash,arrHash );
aoqi@0 362 }
aoqi@0 363 e = refHash.elements();
aoqi@0 364 while ( e.hasMoreElements() ) {
aoqi@0 365 CompoundType t = (CompoundType)e.nextElement();
aoqi@0 366 if ( !isIDLGeneratedFor( t ) ) //remove if no IDL generation
aoqi@0 367 refHash.remove( t.getQualifiedName() );
aoqi@0 368 }
aoqi@0 369 }
aoqi@0 370
aoqi@0 371
aoqi@0 372
aoqi@0 373 /**
aoqi@0 374 * Determine if IDL should be generated for a referenced type.
aoqi@0 375 * Do not generate IDL for a CORBA Object reference. It gets mapped
aoqi@0 376 * to the original IDL or to Object (if exactly org.omg.CORBA.Object)
aoqi@0 377 * Generate (boxed) IDL for an IDL Entity unless it is an IDL user
aoqi@0 378 * exception, a ValueBase, an AbstractBase (or a CORBA Object).
aoqi@0 379 * Do not generate IDL for Implementation classes..unless they inherit
aoqi@0 380 * from multiple distinct remote interfaces
aoqi@0 381 * @param t The type to check.
aoqi@0 382 * @return true or false
aoqi@0 383 */
aoqi@0 384 protected boolean isIDLGeneratedFor(
aoqi@0 385 CompoundType t ) {
aoqi@0 386 if ( t.isCORBAObject() ) return false;
aoqi@0 387 if ( t.isIDLEntity() )
aoqi@0 388 if ( t.isBoxed() ) return true;
aoqi@0 389 else if ( "org.omg.CORBA.portable.IDLEntity"
aoqi@0 390 .equals( t.getQualifiedName() ) ) return true;
aoqi@0 391 else if ( t.isCORBAUserException() ) return true;
aoqi@0 392 else return false;
aoqi@0 393 Hashtable inhHash = new Hashtable();
aoqi@0 394 getInterfaces( t,inhHash );
aoqi@0 395 if ( t.getTypeCode() == TYPE_IMPLEMENTATION )
aoqi@0 396 if ( inhHash.size() < 2 ) return false; //no multiple inheritance
aoqi@0 397 else return true;
aoqi@0 398 return true; //generate IDL for this type
aoqi@0 399 }
aoqi@0 400
aoqi@0 401
aoqi@0 402 /**
aoqi@0 403 * Write the output for the given OutputFileName into the output stream.
aoqi@0 404 * (The IDL mapping for java.lang.Class is generated from
aoqi@0 405 * javax.rmi.CORBA.ClassDesc in the tools workspace)
aoqi@0 406 * @param OutputType ot One of the items returned by getOutputTypesFor(...)
aoqi@0 407 * @param alreadyChecked A set of Types which have already been checked.
aoqi@0 408 * Intended to be passed to Type.collectMatching(filter,alreadyChecked).
aoqi@0 409 * @param p The output stream.
aoqi@0 410 */
aoqi@0 411 protected void writeOutputFor(
aoqi@0 412 OutputType ot,
aoqi@0 413 HashSet alreadyChecked,
aoqi@0 414 IndentingWriter p )
aoqi@0 415 throws IOException {
aoqi@0 416 Type t = ot.getType();
aoqi@0 417 if ( t.isArray() ) { //specialcase: sequence
aoqi@0 418 writeSequence( ot,p );
aoqi@0 419 return;
aoqi@0 420 }
aoqi@0 421 if ( isSpecialReference( t ) ) { //specialcase: IDL typecode
aoqi@0 422 writeSpecial( t,p );
aoqi@0 423 return;
aoqi@0 424 }
aoqi@0 425 if ( t.isCompound() ) { //specialcase: boxed IDL
aoqi@0 426 CompoundType ct = (CompoundType)t;
aoqi@0 427 if ( ct.isIDLEntity() && ct.isBoxed() ) {
aoqi@0 428 writeBoxedIDL( ct,p );
aoqi@0 429 return;
aoqi@0 430 }
aoqi@0 431 }
aoqi@0 432 if ( t.isClass() ) { //specialcase: exception
aoqi@0 433 ClassType ct = (ClassType)t;
aoqi@0 434 if ( ct.isException() ) {
aoqi@0 435 String eName = unEsc( ct.getIDLExceptionName() );
aoqi@0 436 String fName = ot.getName();
aoqi@0 437 if ( fName.equals( eName.replace( ' ','_' ) ) ) {
aoqi@0 438 writeException( ct,p );
aoqi@0 439 return;
aoqi@0 440 }
aoqi@0 441 }
aoqi@0 442 }
aoqi@0 443 switch ( t.getTypeCode() ) { //general case
aoqi@0 444 case TYPE_IMPLEMENTATION:
aoqi@0 445 writeImplementation( (ImplementationType)t,p );
aoqi@0 446 break;
aoqi@0 447 case TYPE_NC_CLASS:
aoqi@0 448 case TYPE_NC_INTERFACE:
aoqi@0 449 writeNCType( (CompoundType)t,p );
aoqi@0 450 break;
aoqi@0 451 case TYPE_ABSTRACT: //AbstractType is a RemoteType
aoqi@0 452 case TYPE_REMOTE:
aoqi@0 453 writeRemote( (RemoteType)t,p );
aoqi@0 454 break;
aoqi@0 455 case TYPE_VALUE:
aoqi@0 456 writeValue( (ValueType)t,p );
aoqi@0 457 break;
aoqi@0 458 default:
aoqi@0 459 throw new CompilerError(
aoqi@0 460 "IDLGenerator got unexpected type code: "
aoqi@0 461 + t.getTypeCode());
aoqi@0 462 }
aoqi@0 463 }
aoqi@0 464
aoqi@0 465
aoqi@0 466 /**
aoqi@0 467 * Write an IDL interface definition for a Java implementation class
aoqi@0 468 * @param t The current ImplementationType
aoqi@0 469 * @param p The output stream.
aoqi@0 470 */
aoqi@0 471 protected void writeImplementation(
aoqi@0 472 ImplementationType t,
aoqi@0 473 IndentingWriter p )
aoqi@0 474 throws IOException {
aoqi@0 475 Hashtable inhHash = new Hashtable();
aoqi@0 476 Hashtable refHash = new Hashtable();
aoqi@0 477 getInterfaces( t,inhHash ); //collect interfaces
aoqi@0 478
aoqi@0 479 writeBanner( t,0,!isException,p );
aoqi@0 480 writeInheritedIncludes( inhHash,p );
aoqi@0 481 writeIfndef( t,0,!isException,!isForward,p );
aoqi@0 482 writeIncOrb( p );
aoqi@0 483 writeModule1( t,p );
aoqi@0 484 p.pln();p.pI();
aoqi@0 485 p.p( "interface " + t.getIDLName() );
aoqi@0 486 writeInherits( inhHash,!forValuetype,p );
aoqi@0 487
aoqi@0 488 p.pln( " {" );
aoqi@0 489 p.pln( "};" );
aoqi@0 490
aoqi@0 491 p.pO();p.pln();
aoqi@0 492 writeModule2( t,p );
aoqi@0 493 writeEpilog( t,refHash,p );
aoqi@0 494 }
aoqi@0 495
aoqi@0 496
aoqi@0 497 /**
aoqi@0 498 * Write an IDL valuetype definition for
aoqi@0 499 * 1) a nonconforming Java class
aoqi@0 500 * 2) a nonconforming Java interface (that is not an AbstractType)
aoqi@0 501 * @param t The current NC Type (NCClassType or NCInterfaceType)
aoqi@0 502 * @param p The output stream.
aoqi@0 503 */
aoqi@0 504 protected void writeNCType(
aoqi@0 505 CompoundType t,
aoqi@0 506 IndentingWriter p )
aoqi@0 507 throws IOException {
aoqi@0 508 Vector conVec = getConstants( t ); //collect constants
aoqi@0 509 Vector mthVec = getMethods( t ); //collect methods
aoqi@0 510 Hashtable inhHash = new Hashtable();
aoqi@0 511 Hashtable refHash = new Hashtable();
aoqi@0 512 Hashtable spcHash = new Hashtable();
aoqi@0 513 Hashtable arrHash = new Hashtable();
aoqi@0 514 Hashtable excHash = new Hashtable();
aoqi@0 515 getInterfaces( t,inhHash ); //collect interfaces
aoqi@0 516 getInheritance( t,inhHash ); //add inheritance
aoqi@0 517 getMethodReferences( mthVec,refHash,spcHash,arrHash,excHash );
aoqi@0 518
aoqi@0 519 writeProlog( t,refHash,spcHash,arrHash,excHash,inhHash,p );
aoqi@0 520 writeModule1( t,p );
aoqi@0 521 p.pln();p.pI();
aoqi@0 522 p.p( "abstract valuetype " + t.getIDLName() );
aoqi@0 523 writeInherits( inhHash,!forValuetype,p );
aoqi@0 524
aoqi@0 525 p.pln( " {" );
aoqi@0 526 if ( conVec.size() + mthVec.size() > 0 ) { //any content?
aoqi@0 527 p.pln();p.pI();
aoqi@0 528 for ( int i1 = 0; i1 < conVec.size(); i1++ ) //write constants
aoqi@0 529 writeConstant( (CompoundType.Member)conVec.elementAt( i1 ),p );
aoqi@0 530 for ( int i1 = 0; i1 < mthVec.size(); i1++ ) //write methods
aoqi@0 531 writeMethod( (CompoundType.Method)mthVec.elementAt( i1 ),p );
aoqi@0 532 p.pO();p.pln();
aoqi@0 533 }
aoqi@0 534 p.pln( "};" );
aoqi@0 535
aoqi@0 536 p.pO();p.pln();
aoqi@0 537 writeModule2( t,p );
aoqi@0 538 writeEpilog( t,refHash,p );
aoqi@0 539 }
aoqi@0 540
aoqi@0 541
aoqi@0 542 /**
aoqi@0 543 * Write an IDL interface definition for either:
aoqi@0 544 * 1) a conforming Java remote interface (RemoteType)..or
aoqi@0 545 * 2) a non-conforming Java interface whose methods all throw
aoqi@0 546 * java.rmi.RemoteException (AbstractType)
aoqi@0 547 * @param t The current RemoteType
aoqi@0 548 * @param p The output stream.
aoqi@0 549 */
aoqi@0 550 protected void writeRemote(
aoqi@0 551 RemoteType t,
aoqi@0 552 IndentingWriter p )
aoqi@0 553 throws IOException {
aoqi@0 554 Vector conVec = getConstants( t ); //collect constants
aoqi@0 555 Vector mthVec = getMethods( t ); //collect methods
aoqi@0 556 Hashtable inhHash = new Hashtable();
aoqi@0 557 Hashtable refHash = new Hashtable();
aoqi@0 558 Hashtable spcHash = new Hashtable();
aoqi@0 559 Hashtable arrHash = new Hashtable();
aoqi@0 560 Hashtable excHash = new Hashtable();
aoqi@0 561 getInterfaces( t,inhHash ); //collect interfaces
aoqi@0 562 getMethodReferences( mthVec,refHash,spcHash,arrHash,excHash );
aoqi@0 563
aoqi@0 564 writeProlog( t,refHash,spcHash,arrHash,excHash,inhHash,p );
aoqi@0 565 writeModule1( t,p );
aoqi@0 566 p.pln();p.pI();
aoqi@0 567 if ( t.getTypeCode() == TYPE_ABSTRACT ) p.p( "abstract " );
aoqi@0 568 p.p( "interface " + t.getIDLName() );
aoqi@0 569 writeInherits( inhHash,!forValuetype,p );
aoqi@0 570
aoqi@0 571 p.pln( " {" );
aoqi@0 572 if ( conVec.size() + mthVec.size() > 0 ) { //any constants or methods?
aoqi@0 573 p.pln();p.pI();
aoqi@0 574 for ( int i1 = 0; i1 < conVec.size(); i1++ ) //constants
aoqi@0 575 writeConstant( (CompoundType.Member)conVec.elementAt( i1 ),p );
aoqi@0 576 for ( int i1 = 0; i1 < mthVec.size(); i1++ ) //methods, attributes
aoqi@0 577 writeMethod( (CompoundType.Method)mthVec.elementAt( i1 ),p );
aoqi@0 578 p.pO();p.pln();
aoqi@0 579 }
aoqi@0 580 p.pln( "};" );
aoqi@0 581
aoqi@0 582 p.pO();p.pln();
aoqi@0 583 writeRepositoryID ( t,p );
aoqi@0 584 p.pln();
aoqi@0 585 writeModule2( t,p );
aoqi@0 586 writeEpilog( t,refHash,p );
aoqi@0 587 }
aoqi@0 588
aoqi@0 589
aoqi@0 590 /**
aoqi@0 591 * Write an IDL valuetype definition for a conforming Java class.
aoqi@0 592 * Methods and constructors are optional..controlled by -valueMethods flag
aoqi@0 593 * @param t The current ValueType
aoqi@0 594 * @param p The output stream.
aoqi@0 595 */
aoqi@0 596 protected void writeValue(
aoqi@0 597 ValueType t,
aoqi@0 598 IndentingWriter p )
aoqi@0 599 throws IOException {
aoqi@0 600 Vector datVec = getData( t ); //collect and sort data
aoqi@0 601 Vector conVec = getConstants( t ); //collect constants
aoqi@0 602 Vector mthVec = getMethods( t ); //collect and filter methods
aoqi@0 603 Hashtable inhHash = new Hashtable();
aoqi@0 604 Hashtable refHash = new Hashtable();
aoqi@0 605 Hashtable spcHash = new Hashtable();
aoqi@0 606 Hashtable arrHash = new Hashtable();
aoqi@0 607 Hashtable excHash = new Hashtable();
aoqi@0 608 getInterfaces( t,inhHash ); //collect interfaces
aoqi@0 609 getInheritance( t,inhHash ); //add inheritance
aoqi@0 610 getMethodReferences( mthVec,refHash,spcHash,arrHash,excHash );
aoqi@0 611 getMemberReferences( datVec,refHash,spcHash,arrHash );
aoqi@0 612
aoqi@0 613 writeProlog( t,refHash,spcHash,arrHash,excHash,inhHash,p );
aoqi@0 614 writeModule1( t,p );
aoqi@0 615 p.pln();p.pI();
aoqi@0 616 if ( t.isCustom() ) p.p( "custom " );
aoqi@0 617 p.p( "valuetype " + t.getIDLName() );
aoqi@0 618 writeInherits( inhHash,forValuetype,p );
aoqi@0 619
aoqi@0 620 p.pln( " {" );
aoqi@0 621 if ( conVec.size() + datVec.size() + mthVec.size() > 0 ) { //any content?
aoqi@0 622 p.pln();p.pI();
aoqi@0 623 for ( int i1 = 0; i1 < conVec.size(); i1++ ) //write constants
aoqi@0 624 writeConstant( (CompoundType.Member)conVec.elementAt( i1 ),p );
aoqi@0 625 for ( int i1 = 0; i1 < datVec.size(); i1++ ) {
aoqi@0 626 CompoundType.Member mem = (CompoundType.Member)datVec.elementAt( i1 );
aoqi@0 627 if ( mem.getType().isPrimitive() )
aoqi@0 628 writeData( mem,p ); //write primitive data
aoqi@0 629 }
aoqi@0 630 for ( int i1 = 0; i1 < datVec.size(); i1++ ) {
aoqi@0 631 CompoundType.Member mem = (CompoundType.Member)datVec.elementAt( i1 );
aoqi@0 632 if ( !mem.getType().isPrimitive() )
aoqi@0 633 writeData( mem,p ); //write non-primitive data
aoqi@0 634 }
aoqi@0 635 for ( int i1 = 0; i1 < mthVec.size(); i1++ ) //write methods
aoqi@0 636 writeMethod( (CompoundType.Method)mthVec.elementAt( i1 ),p );
aoqi@0 637 p.pO();p.pln();
aoqi@0 638 }
aoqi@0 639 p.pln( "};" );
aoqi@0 640
aoqi@0 641 p.pO();p.pln();
aoqi@0 642 writeRepositoryID ( t,p );
aoqi@0 643 p.pln();
aoqi@0 644 writeModule2( t,p );
aoqi@0 645 writeEpilog( t,refHash,p );
aoqi@0 646 }
aoqi@0 647
aoqi@0 648
aoqi@0 649 /**
aoqi@0 650 * Write IDL prolog for a CompoundType.
aoqi@0 651 * @param t The CompoundType.
aoqi@0 652 * @param refHash Hashtable loaded with type references.
aoqi@0 653 * @param spcHash Hashtable loaded with special type references.
aoqi@0 654 * @param arrHash Hashtable loaded with array references.
aoqi@0 655 * @param excHash Hashtable loaded with exceptions thrown.
aoqi@0 656 * @param inhHash Hashtable loaded with inherited types.
aoqi@0 657 * @param p The output stream.
aoqi@0 658 */
aoqi@0 659 protected void writeProlog(
aoqi@0 660 CompoundType t,
aoqi@0 661 Hashtable refHash,
aoqi@0 662 Hashtable spcHash,
aoqi@0 663 Hashtable arrHash,
aoqi@0 664 Hashtable excHash,
aoqi@0 665 Hashtable inhHash,
aoqi@0 666 IndentingWriter p )
aoqi@0 667 throws IOException {
aoqi@0 668 writeBanner( t,0,!isException,p );
aoqi@0 669 writeForwardReferences( refHash,p );
aoqi@0 670 writeIncludes( excHash,isThrown,p ); //#includes for exceptions thrown
aoqi@0 671 writeInheritedIncludes( inhHash,p );
aoqi@0 672 writeIncludes( spcHash,!isThrown,p ); //#includes for special types
aoqi@0 673 writeBoxedRMIIncludes( arrHash,p );
aoqi@0 674 writeIDLEntityIncludes( refHash,p );
aoqi@0 675 writeIncOrb( p );
aoqi@0 676 writeIfndef( t,0,!isException,!isForward,p );
aoqi@0 677 }
aoqi@0 678
aoqi@0 679
aoqi@0 680 /**
aoqi@0 681 * Write IDL epilog for a CompoundType.
aoqi@0 682 * @param t The CompoundType.
aoqi@0 683 * @param refHash Hashtable loaded with type references.
aoqi@0 684 * @param p The output stream.
aoqi@0 685 */
aoqi@0 686 protected void writeEpilog(
aoqi@0 687 CompoundType t,
aoqi@0 688 Hashtable refHash,
aoqi@0 689 IndentingWriter p )
aoqi@0 690 throws IOException {
aoqi@0 691 writeIncludes( refHash,!isThrown,p ); //#includes for forward dcl types
aoqi@0 692 writeEndif( p );
aoqi@0 693 }
aoqi@0 694
aoqi@0 695
aoqi@0 696
aoqi@0 697 /**
aoqi@0 698 * Write special typedef
aoqi@0 699 * @param t A special Type.
aoqi@0 700 * @param p The output stream.
aoqi@0 701 */
aoqi@0 702 protected void writeSpecial(
aoqi@0 703 Type t,
aoqi@0 704 IndentingWriter p )
aoqi@0 705 throws IOException {
aoqi@0 706 String spcName = t.getQualifiedName();
aoqi@0 707 if ( "java.io.Serializable".equals( spcName ) )
aoqi@0 708 writeJavaIoSerializable( t,p );
aoqi@0 709 else if ( "java.io.Externalizable".equals( spcName ) )
aoqi@0 710 writeJavaIoExternalizable( t,p );
aoqi@0 711 else if ( "java.lang.Object".equals( spcName) )
aoqi@0 712 writeJavaLangObject( t,p );
aoqi@0 713 else if ( "java.rmi.Remote".equals( spcName) )
aoqi@0 714 writeJavaRmiRemote( t,p );
aoqi@0 715 else if ( "org.omg.CORBA.portable.IDLEntity".equals( spcName) )
aoqi@0 716 writeIDLEntity( t,p );
aoqi@0 717 }
aoqi@0 718
aoqi@0 719
aoqi@0 720
aoqi@0 721 /**
aoqi@0 722 * Write a hard-coded IDL typedef definition for the special case
aoqi@0 723 * java.io.Serializable.
aoqi@0 724 * @param t The current Type
aoqi@0 725 * @param p The output stream.
aoqi@0 726 */
aoqi@0 727 protected void writeJavaIoSerializable(
aoqi@0 728 Type t,
aoqi@0 729 IndentingWriter p )
aoqi@0 730 throws IOException {
aoqi@0 731 writeBanner( t,0,!isException,p );
aoqi@0 732 writeIfndef( t,0,!isException,!isForward,p );
aoqi@0 733 writeModule1( t,p );
aoqi@0 734 p.pln();p.pI();
aoqi@0 735 p.pln( "typedef any Serializable;" );
aoqi@0 736 p.pO();p.pln();
aoqi@0 737 writeModule2( t,p );
aoqi@0 738 writeEndif( p );
aoqi@0 739 }
aoqi@0 740
aoqi@0 741
aoqi@0 742 /**
aoqi@0 743 * Write a hard-coded IDL typedef definition for the special case
aoqi@0 744 * java.io.Externalizable.
aoqi@0 745 * @param t The current Type
aoqi@0 746 * @param p The output stream.
aoqi@0 747 */
aoqi@0 748 protected void writeJavaIoExternalizable(
aoqi@0 749 Type t,
aoqi@0 750 IndentingWriter p )
aoqi@0 751 throws IOException {
aoqi@0 752 writeBanner( t,0,!isException,p );
aoqi@0 753 writeIfndef( t,0,!isException,!isForward,p );
aoqi@0 754 writeModule1( t,p );
aoqi@0 755 p.pln();p.pI();
aoqi@0 756 p.pln( "typedef any Externalizable;" );
aoqi@0 757 p.pO();p.pln();
aoqi@0 758 writeModule2( t,p );
aoqi@0 759 writeEndif( p );
aoqi@0 760 }
aoqi@0 761
aoqi@0 762
aoqi@0 763 /**
aoqi@0 764 * Write a hard-coded IDL typedef definition for the special case
aoqi@0 765 * java.lang.Object.
aoqi@0 766 * @param t The current Type
aoqi@0 767 * @param p The output stream.
aoqi@0 768 */
aoqi@0 769 protected void writeJavaLangObject(
aoqi@0 770 Type t,
aoqi@0 771 IndentingWriter p )
aoqi@0 772 throws IOException {
aoqi@0 773 writeBanner( t,0,!isException,p );
aoqi@0 774 writeIfndef( t,0,!isException,!isForward,p );
aoqi@0 775 writeModule1( t,p );
aoqi@0 776 p.pln();p.pI();
aoqi@0 777 p.pln( "typedef any _Object;" );
aoqi@0 778 p.pO();p.pln();
aoqi@0 779 writeModule2( t,p );
aoqi@0 780 writeEndif( p );
aoqi@0 781 }
aoqi@0 782
aoqi@0 783
aoqi@0 784 /**
aoqi@0 785 * Write a hard-coded IDL typedef definition for the special case
aoqi@0 786 * java.rmi.Remote.
aoqi@0 787 * @param t The current Type
aoqi@0 788 * @param p The output stream.
aoqi@0 789 */
aoqi@0 790 protected void writeJavaRmiRemote(
aoqi@0 791 Type t,
aoqi@0 792 IndentingWriter p )
aoqi@0 793 throws IOException {
aoqi@0 794 writeBanner( t,0,!isException,p );
aoqi@0 795 writeIfndef( t,0,!isException,!isForward,p );
aoqi@0 796 writeModule1( t,p );
aoqi@0 797 p.pln();p.pI();
aoqi@0 798 p.pln( "typedef Object Remote;" );
aoqi@0 799 p.pO();p.pln();
aoqi@0 800 writeModule2( t,p );
aoqi@0 801 writeEndif( p );
aoqi@0 802 }
aoqi@0 803
aoqi@0 804
aoqi@0 805
aoqi@0 806 /**
aoqi@0 807 * Write a hard-coded IDL typedef definition for the special case
aoqi@0 808 * org.omg.CORBA.portable.IDLEntity
aoqi@0 809 * @param t The current Type
aoqi@0 810 * @param p The output stream.
aoqi@0 811 */
aoqi@0 812 protected void writeIDLEntity(
aoqi@0 813 Type t,
aoqi@0 814 IndentingWriter p )
aoqi@0 815 throws IOException {
aoqi@0 816 writeBanner( t,0,!isException,p );
aoqi@0 817 writeIfndef( t,0,!isException,!isForward,p );
aoqi@0 818 writeModule1( t,p );
aoqi@0 819 p.pln();p.pI();
aoqi@0 820 p.pln( "typedef any IDLEntity;" );
aoqi@0 821 p.pO();p.pln();
aoqi@0 822 writeModule2( t,p );
aoqi@0 823 writeEndif( p );
aoqi@0 824 }
aoqi@0 825
aoqi@0 826
aoqi@0 827 /**
aoqi@0 828 * Filter and collect non-duplicate inherited interfaces for a type
aoqi@0 829 * @param ct The current CompoundType
aoqi@0 830 * @param inhHash Hashtable containing the inherited interfaces
aoqi@0 831 */
aoqi@0 832 protected void getInterfaces(
aoqi@0 833 CompoundType ct,
aoqi@0 834 Hashtable inhHash ) {
aoqi@0 835 InterfaceType[] infs = ct.getInterfaces();
aoqi@0 836 nextInterface:
aoqi@0 837 for ( int i1 = 0; i1 < infs.length; i1++ ) { //forall inherited interfaces
aoqi@0 838 String inhName = infs[i1].getQualifiedName();
aoqi@0 839 switch ( ct.getTypeCode() ) {
aoqi@0 840 case TYPE_NC_CLASS:
aoqi@0 841 case TYPE_VALUE: //filter for classes
aoqi@0 842 if ( "java.io.Externalizable".equals( inhName ) ||
aoqi@0 843 "java.io.Serializable".equals( inhName ) ||
aoqi@0 844 "org.omg.CORBA.portable.IDLEntity".equals( inhName ) )
aoqi@0 845 continue nextInterface;
aoqi@0 846 break;
aoqi@0 847 default: //filter for all others
aoqi@0 848 if ( "java.rmi.Remote".equals( inhName ) )
aoqi@0 849 continue nextInterface;
aoqi@0 850 break;
aoqi@0 851 }
aoqi@0 852 inhHash.put( inhName,infs[i1] ); //add this one
aoqi@0 853 }
aoqi@0 854 }
aoqi@0 855
aoqi@0 856
aoqi@0 857 /**
aoqi@0 858 * Filter and add base class inheritance for a class type
aoqi@0 859 * @param ct The current CompoundType
aoqi@0 860 * @param inhHash Hashtable containing inherited types
aoqi@0 861 */
aoqi@0 862 protected void getInheritance(
aoqi@0 863 CompoundType ct,
aoqi@0 864 Hashtable inhHash ) {
aoqi@0 865 ClassType par = ct.getSuperclass(); //get parent
aoqi@0 866 if ( par == null ) return;
aoqi@0 867 String parName = par.getQualifiedName();
aoqi@0 868 switch ( ct.getTypeCode() ) {
aoqi@0 869 case TYPE_NC_CLASS:
aoqi@0 870 case TYPE_VALUE:
aoqi@0 871 if ( "java.lang.Object".equals( parName ) ) //this is implicit
aoqi@0 872 return;
aoqi@0 873 break;
aoqi@0 874 default: return; //ignore other types
aoqi@0 875 }
aoqi@0 876 inhHash.put( parName,par ); //add valid base class
aoqi@0 877 }
aoqi@0 878
aoqi@0 879
aoqi@0 880 /**
aoqi@0 881 * Collect and filter type and array references from methods
aoqi@0 882 * @param mthVec Given Vector of methods
aoqi@0 883 * @param refHash Hashtable for type references
aoqi@0 884 * @param spcHash Hashtable for special type references
aoqi@0 885 * @param arrHash Hashtable for array references
aoqi@0 886 * @param excHash Hashtable for exceptions thrown
aoqi@0 887 */
aoqi@0 888 protected void getMethodReferences(
aoqi@0 889 Vector mthVec,
aoqi@0 890 Hashtable refHash,
aoqi@0 891 Hashtable spcHash,
aoqi@0 892 Hashtable arrHash,
aoqi@0 893 Hashtable excHash ) {
aoqi@0 894 for ( int i1 = 0; i1 < mthVec.size(); i1++ ) { //forall methods
aoqi@0 895 CompoundType.Method mth = (CompoundType.Method)mthVec.elementAt( i1 );
aoqi@0 896 Type[] args = mth.getArguments();
aoqi@0 897 Type ret = mth.getReturnType();
aoqi@0 898 getExceptions( mth,excHash ); //collect exceptions thrown
aoqi@0 899 for ( int i2 = 0; i2 < args.length; i2++ ) //forall arguments
aoqi@0 900 addReference( args[i2],refHash,spcHash,arrHash );
aoqi@0 901 addReference( ret,refHash,spcHash,arrHash );
aoqi@0 902 }
aoqi@0 903 }
aoqi@0 904
aoqi@0 905
aoqi@0 906 /**
aoqi@0 907 * Collect and filter type and array references from data members
aoqi@0 908 * @param datVec Given Vector of data members
aoqi@0 909 * @param refHash Hashtable for type references
aoqi@0 910 * @param spcHash Hashtable for special type references
aoqi@0 911 * @param arrHash Hashtable for array references
aoqi@0 912 */
aoqi@0 913 protected void getMemberReferences(
aoqi@0 914 Vector datVec,
aoqi@0 915 Hashtable refHash,
aoqi@0 916 Hashtable spcHash,
aoqi@0 917 Hashtable arrHash ) {
aoqi@0 918 for ( int i1 = 0; i1 < datVec.size(); i1++ ) { //forall datamembers
aoqi@0 919 CompoundType.Member mem = (CompoundType.Member)datVec.elementAt( i1 );
aoqi@0 920 Type dat = mem.getType();
aoqi@0 921 addReference( dat,refHash,spcHash,arrHash );
aoqi@0 922 }
aoqi@0 923 }
aoqi@0 924
aoqi@0 925
aoqi@0 926 /**
aoqi@0 927 * Add reference for given type avoiding duplication.
aoqi@0 928 * Sort into specials, arrays and regular references.
aoqi@0 929 * Filter out types which are not required.
aoqi@0 930 * @param t Given Type
aoqi@0 931 * @param refHash Hashtable for type references
aoqi@0 932 * @param spcHash Hashtable for special type references
aoqi@0 933 * @param arrHash Hashtable for array references
aoqi@0 934 */
aoqi@0 935 protected void addReference(
aoqi@0 936 Type ref,
aoqi@0 937 Hashtable refHash,
aoqi@0 938 Hashtable spcHash,
aoqi@0 939 Hashtable arrHash ) {
aoqi@0 940 String rName = ref.getQualifiedName();
aoqi@0 941 switch ( ref.getTypeCode() ) {
aoqi@0 942 case TYPE_ABSTRACT:
aoqi@0 943 case TYPE_REMOTE:
aoqi@0 944 case TYPE_NC_CLASS:
aoqi@0 945 case TYPE_NC_INTERFACE:
aoqi@0 946 case TYPE_VALUE:
aoqi@0 947 refHash.put( rName,ref );
aoqi@0 948 return;
aoqi@0 949 case TYPE_CORBA_OBJECT:
aoqi@0 950 if ( "org.omg.CORBA.Object".equals( rName ) ) return; //don't want
aoqi@0 951 refHash.put( rName,ref );
aoqi@0 952 return;
aoqi@0 953 case TYPE_ARRAY: //array?
aoqi@0 954 arrHash.put( rName + ref.getArrayDimension(),ref );
aoqi@0 955 return;
aoqi@0 956 default:
aoqi@0 957 if ( isSpecialReference( ref ) ) //special IDL typedef?
aoqi@0 958 spcHash.put( rName,ref );
aoqi@0 959 }
aoqi@0 960 }
aoqi@0 961
aoqi@0 962
aoqi@0 963
aoqi@0 964 /**
aoqi@0 965 * Determine whether given Type is a special reference.
aoqi@0 966 * Special cases are: java.io.Serializable, java.io.Externalizable,
aoqi@0 967 * java.lang.Object, java.rmi.Remote and org.omg.CORBA.portable.IDLEntity
aoqi@0 968 * They are special because they have a hard-coded typedef defined in the
aoqi@0 969 * spec.
aoqi@0 970 * @param ref A referenced Type
aoqi@0 971 * @return boolean indicating whether it's a special reference
aoqi@0 972 */
aoqi@0 973 protected boolean isSpecialReference(
aoqi@0 974 Type ref ) {
aoqi@0 975 String rName = ref.getQualifiedName();
aoqi@0 976 if ( "java.io.Serializable".equals( rName ) ) return true;
aoqi@0 977 if ( "java.io.Externalizable".equals( rName ) ) return true;
aoqi@0 978 if ( "java.lang.Object".equals( rName) ) return true;
aoqi@0 979 if ( "java.rmi.Remote".equals( rName) ) return true;
aoqi@0 980 if ( "org.omg.CORBA.portable.IDLEntity".equals( rName) ) return true;
aoqi@0 981 return false;
aoqi@0 982 }
aoqi@0 983
aoqi@0 984
aoqi@0 985 /**
aoqi@0 986 * Collect and filter thrown exceptions for a given pre-filtered method.
aoqi@0 987 * Keep only 'checked' exception classes minus java.rmi.RemoteException
aoqi@0 988 * and its subclasses
aoqi@0 989 * @param method The current method
aoqi@0 990 * @param excHash Hashtable containing non-duplicate thrown exceptions
aoqi@0 991 */
aoqi@0 992 protected void getExceptions(
aoqi@0 993 CompoundType.Method mth,
aoqi@0 994 Hashtable excHash ) {
aoqi@0 995 ClassType[] excs = mth.getExceptions();
aoqi@0 996 for ( int i1 = 0; i1 < excs.length; i1++ ) { //forall exceptions
aoqi@0 997 ClassType exc = excs[i1];
aoqi@0 998 if ( exc.isCheckedException() &&
aoqi@0 999 !exc.isRemoteExceptionOrSubclass() ) {
aoqi@0 1000 excHash.put( exc.getQualifiedName(),exc );
aoqi@0 1001 }
aoqi@0 1002 }
aoqi@0 1003 }
aoqi@0 1004
aoqi@0 1005
aoqi@0 1006 /**
aoqi@0 1007 * Collect and filter methods for a type.
aoqi@0 1008 * Remove any private or inherited methods.
aoqi@0 1009 * @param ct The current CompoundType
aoqi@0 1010 * @return Vector containing the methods
aoqi@0 1011 */
aoqi@0 1012 protected Vector getMethods(
aoqi@0 1013 CompoundType ct ) {
aoqi@0 1014 Vector vec = new Vector();
aoqi@0 1015 int ctType = ct.getTypeCode();
aoqi@0 1016 switch ( ctType ) {
aoqi@0 1017 case TYPE_ABSTRACT:
aoqi@0 1018 case TYPE_REMOTE: break;
aoqi@0 1019 case TYPE_NC_CLASS:
aoqi@0 1020 case TYPE_NC_INTERFACE:
aoqi@0 1021 case TYPE_VALUE: if ( valueMethods ) break;
aoqi@0 1022 default: return vec;
aoqi@0 1023 }
aoqi@0 1024 Identifier ctId = ct.getIdentifier();
aoqi@0 1025 CompoundType.Method[] mths = ct.getMethods();
aoqi@0 1026 nextMethod:
aoqi@0 1027 for ( int i1 = 0; i1 < mths.length; i1++ ) { //forall methods
aoqi@0 1028 if ( mths[i1].isPrivate() || //private method?
aoqi@0 1029 mths[i1].isInherited() ) //inherited method?
aoqi@0 1030 continue nextMethod; //yes..ignore it
aoqi@0 1031 if ( ctType == TYPE_VALUE ) {
aoqi@0 1032 String mthName = mths[i1].getName();
aoqi@0 1033 if ( "readObject" .equals( mthName ) ||
aoqi@0 1034 "writeObject" .equals( mthName ) ||
aoqi@0 1035 "readExternal".equals( mthName ) ||
aoqi@0 1036 "writeExternal".equals( mthName ) )
aoqi@0 1037 continue nextMethod; //ignore this one
aoqi@0 1038 }
aoqi@0 1039 if ( ( ctType == TYPE_NC_CLASS ||
aoqi@0 1040 ctType == TYPE_NC_INTERFACE ) &&
aoqi@0 1041 mths[i1].isConstructor() ) //init not valid for abstract valuetype
aoqi@0 1042 continue nextMethod; //ignore this one
aoqi@0 1043 vec.addElement( mths[i1] ); //add this one
aoqi@0 1044 }
aoqi@0 1045 return vec;
aoqi@0 1046 }
aoqi@0 1047
aoqi@0 1048
aoqi@0 1049 /**
aoqi@0 1050 * Collect constants for a type.
aoqi@0 1051 * A valid constant is a "public final static" field with a compile-time
aoqi@0 1052 * constant value for a primitive type or String
aoqi@0 1053 * @param ct The current CompoundType
aoqi@0 1054 * @return Vector containing the constants
aoqi@0 1055 */
aoqi@0 1056 protected Vector getConstants(
aoqi@0 1057 CompoundType ct ) {
aoqi@0 1058 Vector vec = new Vector();
aoqi@0 1059 CompoundType.Member[] mems = ct.getMembers();
aoqi@0 1060 for ( int i1 = 0; i1 < mems.length; i1++ ) { //forall members
aoqi@0 1061 Type memType = mems[i1].getType();
aoqi@0 1062 String memValue = mems[i1].getValue();
aoqi@0 1063 if ( mems[i1].isPublic() &&
aoqi@0 1064 mems[i1].isFinal() &&
aoqi@0 1065 mems[i1].isStatic() &&
aoqi@0 1066 ( memType.isPrimitive() || "String".equals( memType.getName() ) ) &&
aoqi@0 1067 memValue != null )
aoqi@0 1068 vec.addElement( mems[i1] ); //add this one
aoqi@0 1069 }
aoqi@0 1070 return vec;
aoqi@0 1071 }
aoqi@0 1072
aoqi@0 1073
aoqi@0 1074 /**
aoqi@0 1075 * Collect and sort data fields for a ValueType.
aoqi@0 1076 * Sort in Java (not IDL) Unicode name string lexicographic increasing
aoqi@0 1077 * order.
aoqi@0 1078 * Non-static, non-transient fields are mapped.
aoqi@0 1079 * If the type is a custom valuetype, only public fields are mapped.
aoqi@0 1080 * @param ct The current CompoundType
aoqi@0 1081 * @return Vector containing the data fields
aoqi@0 1082 */
aoqi@0 1083 protected Vector getData(
aoqi@0 1084 CompoundType t ) {
aoqi@0 1085 Vector vec = new Vector();
aoqi@0 1086 if ( t.getTypeCode() != TYPE_VALUE ) return vec;
aoqi@0 1087 ValueType vt = (ValueType)t;
aoqi@0 1088 CompoundType.Member[] mems = vt.getMembers();
aoqi@0 1089 boolean notCust = !vt.isCustom();
aoqi@0 1090 for ( int i1 = 0; i1 < mems.length; i1++ ) { //forall members
aoqi@0 1091 if ( !mems[i1].isStatic() &&
aoqi@0 1092 !mems[i1].isTransient() &&
aoqi@0 1093 ( mems[i1].isPublic() || notCust ) ) {
aoqi@0 1094 int i2;
aoqi@0 1095 String memName = mems[i1].getName();
aoqi@0 1096 for ( i2 = 0; i2 < vec.size(); i2++ ) { //insert in java lex order
aoqi@0 1097 CompoundType.Member aMem = (CompoundType.Member)vec.elementAt( i2 );
aoqi@0 1098 if ( memName.compareTo( aMem.getName() ) < 0 ) break;
aoqi@0 1099 }
aoqi@0 1100 vec.insertElementAt( mems[i1],i2 ); //insert this one
aoqi@0 1101 }
aoqi@0 1102 }
aoqi@0 1103 return vec;
aoqi@0 1104 }
aoqi@0 1105
aoqi@0 1106
aoqi@0 1107 /**
aoqi@0 1108 * Write forward references for referenced interfaces and valuetypes
aoqi@0 1109 * ...but not if the reference is to a boxed IDLEntity,
aoqi@0 1110 * @param refHash Hashtable loaded with referenced types
aoqi@0 1111 * @param p The output stream.
aoqi@0 1112 */
aoqi@0 1113 protected void writeForwardReferences(
aoqi@0 1114 Hashtable refHash,
aoqi@0 1115 IndentingWriter p )
aoqi@0 1116 throws IOException {
aoqi@0 1117 Enumeration refEnum = refHash.elements();
aoqi@0 1118 nextReference:
aoqi@0 1119 while ( refEnum.hasMoreElements() ) {
aoqi@0 1120 Type t = (Type)refEnum.nextElement();
aoqi@0 1121 if ( t.isCompound() ) {
aoqi@0 1122 CompoundType ct = (CompoundType)t;
aoqi@0 1123 if ( ct.isIDLEntity() )
aoqi@0 1124 continue nextReference; //ignore IDLEntity reference
aoqi@0 1125 }
aoqi@0 1126 writeForwardReference( t,p );
aoqi@0 1127 }
aoqi@0 1128 }
aoqi@0 1129
aoqi@0 1130
aoqi@0 1131 /**
aoqi@0 1132 * Write forward reference for given type
aoqi@0 1133 * @param t Given type
aoqi@0 1134 * @param p The output stream.
aoqi@0 1135 */
aoqi@0 1136 protected void writeForwardReference(
aoqi@0 1137 Type t,
aoqi@0 1138 IndentingWriter p )
aoqi@0 1139 throws IOException {
aoqi@0 1140 String qName = t.getQualifiedName();
aoqi@0 1141 if ( "java.lang.String".equals( qName ) ) ;
aoqi@0 1142 else if ( "org.omg.CORBA.Object".equals( qName ) ) return ; //no fwd dcl
aoqi@0 1143
aoqi@0 1144 writeIfndef( t,0,!isException,isForward,p );
aoqi@0 1145 writeModule1( t,p );
aoqi@0 1146 p.pln();p.pI();
aoqi@0 1147 switch ( t.getTypeCode() ) {
aoqi@0 1148 case TYPE_NC_CLASS:
aoqi@0 1149 case TYPE_NC_INTERFACE: p.p( "abstract valuetype " ); break;
aoqi@0 1150 case TYPE_ABSTRACT: p.p( "abstract interface " ); break;
aoqi@0 1151 case TYPE_VALUE: p.p( "valuetype " ); break;
aoqi@0 1152 case TYPE_REMOTE:
aoqi@0 1153 case TYPE_CORBA_OBJECT: p.p( "interface " ); break;
aoqi@0 1154 default: ; //all other types were filtered
aoqi@0 1155 }
aoqi@0 1156 p.pln( t.getIDLName() + ";" );
aoqi@0 1157 p.pO();p.pln();
aoqi@0 1158 writeModule2( t,p );
aoqi@0 1159 writeEndif( p );
aoqi@0 1160 }
aoqi@0 1161
aoqi@0 1162
aoqi@0 1163 /**
aoqi@0 1164 * Write forward reference for boxed valuetype for single dimension of IDL
aoqi@0 1165 * sequence.
aoqi@0 1166 * If the dimension is <1 and the element is a CompoundType, write a
aoqi@0 1167 * forward declare for the element
aoqi@0 1168 * @param at ArrayType for forward declare
aoqi@0 1169 * @param dim The dimension to write
aoqi@0 1170 * @param p The output stream.
aoqi@0 1171 */
aoqi@0 1172 protected void writeForwardReference(
aoqi@0 1173 ArrayType at,
aoqi@0 1174 int dim,
aoqi@0 1175 IndentingWriter p)
aoqi@0 1176 throws IOException {
aoqi@0 1177 Type et = at.getElementType();
aoqi@0 1178 if ( dim < 1 ) {
aoqi@0 1179 if ( et.isCompound() ) {
aoqi@0 1180 CompoundType ct = (CompoundType)et;
aoqi@0 1181 writeForwardReference( et,p);
aoqi@0 1182 }
aoqi@0 1183 return;
aoqi@0 1184 }
aoqi@0 1185 String fName = unEsc( et.getIDLName() ).replace( ' ','_' );
aoqi@0 1186
aoqi@0 1187 writeIfndef( at,dim,!isException,isForward,p );
aoqi@0 1188 writeModule1( at,p );
aoqi@0 1189 p.pln();p.pI();
aoqi@0 1190 switch ( et.getTypeCode() ) {
aoqi@0 1191 case TYPE_NC_CLASS:
aoqi@0 1192 case TYPE_NC_INTERFACE: p.p( "abstract valuetype " ); break;
aoqi@0 1193 case TYPE_ABSTRACT: p.p( "abstract interface " ); break;
aoqi@0 1194 case TYPE_VALUE: p.p( "valuetype " ); break;
aoqi@0 1195 case TYPE_REMOTE:
aoqi@0 1196 case TYPE_CORBA_OBJECT: p.p( "interface " ); break;
aoqi@0 1197 default: ; //all other types were filtered
aoqi@0 1198 }
aoqi@0 1199 p.pln( "seq" + dim + "_" + fName + ";" );
aoqi@0 1200 p.pO();p.pln();
aoqi@0 1201 writeModule2( at,p );
aoqi@0 1202 writeEndif( p );
aoqi@0 1203 }
aoqi@0 1204
aoqi@0 1205
aoqi@0 1206 /**
aoqi@0 1207 * Write #includes for boxed IDLEntity references.
aoqi@0 1208 * @param refHash Hashtable loaded with referenced types
aoqi@0 1209 * @param p The output stream.
aoqi@0 1210 */
aoqi@0 1211 protected void writeIDLEntityIncludes(
aoqi@0 1212 Hashtable refHash,
aoqi@0 1213 IndentingWriter p )
aoqi@0 1214 throws IOException {
aoqi@0 1215 Enumeration refEnum = refHash.elements();
aoqi@0 1216 while ( refEnum.hasMoreElements() ) {
aoqi@0 1217 Type t = (Type)refEnum.nextElement();
aoqi@0 1218 if ( t.isCompound() ) {
aoqi@0 1219 CompoundType ct = (CompoundType)t;
aoqi@0 1220 if ( ct.isIDLEntity() ) { //select IDLEntities
aoqi@0 1221 writeInclude( ct,0,!isThrown,p );
aoqi@0 1222 refHash.remove( ct.getQualifiedName() ); //avoid another #include
aoqi@0 1223 }
aoqi@0 1224 }
aoqi@0 1225 }
aoqi@0 1226 }
aoqi@0 1227
aoqi@0 1228
aoqi@0 1229 /**
aoqi@0 1230 * Write #includes
aoqi@0 1231 * @param incHash Hashtable loaded with Types to include
aoqi@0 1232 * @param isThrown true if Types are thrown exceptions
aoqi@0 1233 * @param p The output stream.
aoqi@0 1234 */
aoqi@0 1235 protected void writeIncludes(
aoqi@0 1236 Hashtable incHash,
aoqi@0 1237 boolean isThrown,
aoqi@0 1238 IndentingWriter p )
aoqi@0 1239 throws IOException {
aoqi@0 1240 Enumeration incEnum = incHash.elements();
aoqi@0 1241 while ( incEnum.hasMoreElements() ) {
aoqi@0 1242 CompoundType t = (CompoundType)incEnum.nextElement();
aoqi@0 1243 writeInclude( t,0,isThrown,p );
aoqi@0 1244 }
aoqi@0 1245 }
aoqi@0 1246
aoqi@0 1247
aoqi@0 1248 /**
aoqi@0 1249 * Write includes for boxedRMI valuetypes for IDL sequences.
aoqi@0 1250 * Write only the maximum dimension found for an ArrayType.
aoqi@0 1251 * @param arrHash Hashtable loaded with array types
aoqi@0 1252 * @param p The output stream.
aoqi@0 1253 */
aoqi@0 1254 protected void writeBoxedRMIIncludes(
aoqi@0 1255 Hashtable arrHash,
aoqi@0 1256 IndentingWriter p)
aoqi@0 1257 throws IOException {
aoqi@0 1258 Enumeration e1 = arrHash.elements();
aoqi@0 1259 nextSequence:
aoqi@0 1260 while ( e1.hasMoreElements() ) {
aoqi@0 1261 ArrayType at = (ArrayType)e1.nextElement();
aoqi@0 1262 int dim = at.getArrayDimension();
aoqi@0 1263 Type et = at.getElementType();
aoqi@0 1264
aoqi@0 1265 Enumeration e2 = arrHash.elements();
aoqi@0 1266 while ( e2.hasMoreElements() ) { //eliminate duplicates
aoqi@0 1267 ArrayType at2 = (ArrayType)e2.nextElement();
aoqi@0 1268 if ( et == at2.getElementType() && //same element type &
aoqi@0 1269 dim < at2.getArrayDimension() ) //smaller dimension?
aoqi@0 1270 continue nextSequence; //ignore this one
aoqi@0 1271 }
aoqi@0 1272 writeInclude( at,dim,!isThrown,p );
aoqi@0 1273 }
aoqi@0 1274 }
aoqi@0 1275
aoqi@0 1276
aoqi@0 1277 /**
aoqi@0 1278 * Write #includes
aoqi@0 1279 * @param incHash Hashtable loaded with Types to include
aoqi@0 1280 * @param p The output stream.
aoqi@0 1281 */
aoqi@0 1282 protected void writeInheritedIncludes(
aoqi@0 1283 Hashtable inhHash,
aoqi@0 1284 IndentingWriter p )
aoqi@0 1285 throws IOException {
aoqi@0 1286 Enumeration inhEnum = inhHash.elements();
aoqi@0 1287 while ( inhEnum.hasMoreElements() ) {
aoqi@0 1288 CompoundType t = (CompoundType)inhEnum.nextElement();
aoqi@0 1289 writeInclude( t,0,!isThrown,p );
aoqi@0 1290 }
aoqi@0 1291 }
aoqi@0 1292
aoqi@0 1293
aoqi@0 1294 /**
aoqi@0 1295 * Write a #include.
aoqi@0 1296 * @param t Type to include
aoqi@0 1297 * @param dim The dimension to write if t is an array.
aoqi@0 1298 * @param isThrown boolean indicating if include is for thrown exception.
aoqi@0 1299 * @param p The output stream.
aoqi@0 1300 */
aoqi@0 1301 protected void writeInclude(
aoqi@0 1302 Type t,
aoqi@0 1303 int dim,
aoqi@0 1304 boolean isThrown,
aoqi@0 1305 IndentingWriter p)
aoqi@0 1306 throws IOException {
aoqi@0 1307 CompoundType ct;
aoqi@0 1308 String tName;
aoqi@0 1309 String[] modNames;
aoqi@0 1310 if ( t.isCompound() ) {
aoqi@0 1311 ct = (CompoundType)t;
aoqi@0 1312 String qName = ct.getQualifiedName();
aoqi@0 1313 if ( "java.lang.String".equals( qName ) ) {
aoqi@0 1314 writeIncOrb( p ); //#include orb.idl for String
aoqi@0 1315 return;
aoqi@0 1316 }
aoqi@0 1317 if ( "org.omg.CORBA.Object".equals( qName ) )
aoqi@0 1318 return; //Object treated like primitive
aoqi@0 1319 modNames = getIDLModuleNames( ct ); //module name array
aoqi@0 1320 tName = unEsc( ct.getIDLName() ); //file name default
aoqi@0 1321
aoqi@0 1322 if ( ct.isException() )
aoqi@0 1323 if ( ct.isIDLEntityException() )
aoqi@0 1324 if ( ct.isCORBAUserException() )
aoqi@0 1325 if ( isThrown ) tName = unEsc( ct.getIDLExceptionName() );
aoqi@0 1326 else ;
aoqi@0 1327 else tName = ct.getName(); //use original IDL name
aoqi@0 1328 else if ( isThrown )
aoqi@0 1329 tName = unEsc( ct.getIDLExceptionName() );
aoqi@0 1330 }
aoqi@0 1331 else if ( t.isArray() ) {
aoqi@0 1332 Type et = t.getElementType(); //file name for sequence
aoqi@0 1333 if ( dim > 0 ) {
aoqi@0 1334 modNames = getIDLModuleNames( t ); //module name array
aoqi@0 1335 tName = "seq" + dim + "_" + unEsc( et.getIDLName().replace( ' ','_' ) );
aoqi@0 1336 }
aoqi@0 1337 else{ //#include element
aoqi@0 1338 if ( !et.isCompound() ) return; //no include needed for primitive
aoqi@0 1339 ct = (CompoundType) et;
aoqi@0 1340 modNames = getIDLModuleNames( ct ); //no boxedRMI for element
aoqi@0 1341 tName = unEsc( ct.getIDLName() );
aoqi@0 1342 writeInclude( ct,modNames,tName,p );
aoqi@0 1343 return;
aoqi@0 1344 }
aoqi@0 1345 }
aoqi@0 1346 else return; //no include needed for primitive
aoqi@0 1347 writeInclude( t,modNames,tName,p );
aoqi@0 1348 }
aoqi@0 1349
aoqi@0 1350
aoqi@0 1351 /**
aoqi@0 1352 * Write a #include doing user specified -idlFile translation (if any) for
aoqi@0 1353 * IDLEntities.
aoqi@0 1354 * @param t Type to include.
aoqi@0 1355 * @param modNames Preprocessed module names (default).
aoqi@0 1356 * @param tName Preprocessed Type name (default).
aoqi@0 1357 * @param p The output stream.
aoqi@0 1358 */
aoqi@0 1359 protected void writeInclude(
aoqi@0 1360 Type t,
aoqi@0 1361 String[] modNames,
aoqi@0 1362 String tName,
aoqi@0 1363 IndentingWriter p)
aoqi@0 1364 throws IOException {
aoqi@0 1365 if ( t.isCompound() ) {
aoqi@0 1366 CompoundType it = (CompoundType)t;
aoqi@0 1367
aoqi@0 1368 if ( ifHash.size() > 0 && //any -idlFile translation to apply
aoqi@0 1369 it.isIDLEntity() ) { //..for this IDLEntity?
aoqi@0 1370 String qName = t.getQualifiedName(); //fully qualified orig Java name
aoqi@0 1371
aoqi@0 1372 Enumeration k = ifHash.keys();
aoqi@0 1373 while ( k.hasMoreElements() ) { //loop thro user-defined -idlFiles
aoqi@0 1374 String from = (String)k.nextElement();
aoqi@0 1375 if ( qName.startsWith( from ) ) { //found a match?
aoqi@0 1376 String to = (String)ifHash.get( from );
aoqi@0 1377 p.pln( "#include \"" + to + "\"" ); //user-specified idl filename
aoqi@0 1378 return; //don't look for any more
aoqi@0 1379 }
aoqi@0 1380 }
aoqi@0 1381 }
aoqi@0 1382 }
aoqi@0 1383 else if ( t.isArray() ) ; //no -idlFile translation needed for array
aoqi@0 1384 else return; //no #include needed for primitive
aoqi@0 1385
aoqi@0 1386 p.p( "#include \"" ); //no -idlFile translation required
aoqi@0 1387 for ( int i1 = 0; i1 < modNames.length; i1++ ) p.p( modNames[i1] + "/" );
aoqi@0 1388 p.p( tName + ".idl\"" );
aoqi@0 1389 p.pln();
aoqi@0 1390 }
aoqi@0 1391
aoqi@0 1392
aoqi@0 1393 /**
aoqi@0 1394 * Return the fully qualified Java Name for a Type.
aoqi@0 1395 * IDLEntity preprocessing done by getIDLModuleNames(t)
aoqi@0 1396 * @param t Given Type
aoqi@0 1397 * @return Array containing the original module nesting.
aoqi@0 1398 */
aoqi@0 1399 protected String getQualifiedName(
aoqi@0 1400 Type t ) {
aoqi@0 1401 String[] modNames = getIDLModuleNames( t );
aoqi@0 1402 int len = modNames.length;
aoqi@0 1403 StringBuffer buf = new StringBuffer();
aoqi@0 1404 for ( int i1 = 0; i1 < len; i1++ )
aoqi@0 1405 buf.append( modNames[i1] + "." );
aoqi@0 1406 buf.append( t.getIDLName() );
aoqi@0 1407 return buf.toString();
aoqi@0 1408 }
aoqi@0 1409
aoqi@0 1410
aoqi@0 1411 /**
aoqi@0 1412 * Return the global fully qualified IDL Name for a Type.
aoqi@0 1413 * IDLEntity preprocessing done by getIDLModuleNames(t)
aoqi@0 1414 * @param t Given Type
aoqi@0 1415 * @return Array containing the original module nesting.
aoqi@0 1416 */
aoqi@0 1417 protected String getQualifiedIDLName(Type t) {
aoqi@0 1418 if ( t.isPrimitive() )
aoqi@0 1419 return t.getIDLName();
aoqi@0 1420 if ( !t.isArray() &&
aoqi@0 1421 "org.omg.CORBA.Object".equals( t.getQualifiedName() ) )
aoqi@0 1422 return t.getIDLName();
aoqi@0 1423
aoqi@0 1424 String[] modNames = getIDLModuleNames( t );
aoqi@0 1425 int len = modNames.length;
aoqi@0 1426 if (len > 0) {
aoqi@0 1427 StringBuffer buf = new StringBuffer();
aoqi@0 1428 for ( int i1 = 0; i1 < len; i1++ )
aoqi@0 1429 buf.append( IDL_NAME_SEPARATOR + modNames[i1] );
aoqi@0 1430 buf.append( IDL_NAME_SEPARATOR + t.getIDLName() );
aoqi@0 1431 return buf.toString();
aoqi@0 1432 } else {
aoqi@0 1433 return t.getIDLName();
aoqi@0 1434 }
aoqi@0 1435 }
aoqi@0 1436
aoqi@0 1437
aoqi@0 1438 /**
aoqi@0 1439 * Return the IDL module nesting of the given Type.
aoqi@0 1440 * For IDLEntity CompoundTypes (or their arrays) apply any user specified
aoqi@0 1441 * -idlModule translation or, if none applicable, strip any package
aoqi@0 1442 * prefix.
aoqi@0 1443 * Add boxedIDL or boxedRMI modules if required.
aoqi@0 1444 * @param t Given Type
aoqi@0 1445 * @return Array containing the original module nesting.
aoqi@0 1446 */
aoqi@0 1447 protected String[] getIDLModuleNames(Type t) {
aoqi@0 1448 String[] modNames = t.getIDLModuleNames(); //default module name array
aoqi@0 1449 CompoundType ct;
aoqi@0 1450 if ( t.isCompound() ) {
aoqi@0 1451 ct = (CompoundType)t;
aoqi@0 1452 if ( !ct.isIDLEntity ) return modNames; //normal (non-IDLEntity) case
aoqi@0 1453 if ( "org.omg.CORBA.portable.IDLEntity"
aoqi@0 1454 .equals( t.getQualifiedName() ) )
aoqi@0 1455 return modNames;
aoqi@0 1456 }
aoqi@0 1457 else if ( t.isArray() ) {
aoqi@0 1458 Type et = t.getElementType();
aoqi@0 1459 if ( et.isCompound() ) {
aoqi@0 1460 ct = (CompoundType)et;
aoqi@0 1461 if ( !ct.isIDLEntity ) return modNames; //normal (non-IDLEntity) case
aoqi@0 1462 if ( "org.omg.CORBA.portable.IDLEntity"
aoqi@0 1463 .equals( t.getQualifiedName() ) )
aoqi@0 1464 return modNames;
aoqi@0 1465 }
aoqi@0 1466 else return modNames;
aoqi@0 1467 }
aoqi@0 1468 else return modNames; //no preprocessing needed for primitives
aoqi@0 1469
aoqi@0 1470 //it's an IDLEntity or an array of...
aoqi@0 1471 Vector mVec = new Vector();
aoqi@0 1472 if ( !translateJavaPackage( ct,mVec ) ) //apply -idlModule translation
aoqi@0 1473 stripJavaPackage( ct,mVec ); //..or strip prefixes (not both)
aoqi@0 1474
aoqi@0 1475 if ( ct.isBoxed() ) { //add boxedIDL if required
aoqi@0 1476 mVec.insertElementAt( "org",0 );
aoqi@0 1477 mVec.insertElementAt( "omg",1 );
aoqi@0 1478 mVec.insertElementAt( "boxedIDL",2 );
aoqi@0 1479 }
aoqi@0 1480 if ( t.isArray() ) { //add boxedRMI if required
aoqi@0 1481 mVec.insertElementAt( "org",0 );
aoqi@0 1482 mVec.insertElementAt( "omg",1 );
aoqi@0 1483 mVec.insertElementAt( "boxedRMI",2 );
aoqi@0 1484 }
aoqi@0 1485 String[] outArr = new String[mVec.size()];
aoqi@0 1486 mVec.copyInto( outArr );
aoqi@0 1487 return outArr;
aoqi@0 1488 }
aoqi@0 1489
aoqi@0 1490
aoqi@0 1491 /**
aoqi@0 1492 * Apply user specified -idlModule translation to package names of given
aoqi@0 1493 * IDLEntity ct. Example:
aoqi@0 1494 * -idlModule foo.bar real::mod::nesting
aoqi@0 1495 * @param ct CompoundType containing given IDLEntity.
aoqi@0 1496 * @param vec Returned Vector of translated IDL module names.
aoqi@0 1497 * @return boolean true if any translation was done.
aoqi@0 1498 */
aoqi@0 1499 protected boolean translateJavaPackage(
aoqi@0 1500 CompoundType ct,
aoqi@0 1501 Vector vec ) {
aoqi@0 1502 vec.removeAllElements();
aoqi@0 1503 boolean ret = false;
aoqi@0 1504 String fc = null;
aoqi@0 1505 if ( ! ct.isIDLEntity() ) return ret;
aoqi@0 1506
aoqi@0 1507 String pName = ct.getPackageName(); //start from Java package names
aoqi@0 1508 if ( pName == null ) return ret;
aoqi@0 1509 StringTokenizer pt = new StringTokenizer( pName,"." );
aoqi@0 1510 while ( pt.hasMoreTokens() ) vec.addElement( pt.nextToken() );
aoqi@0 1511
aoqi@0 1512 if ( imHash.size() > 0 ) { //any -idlModule translation to apply?
aoqi@0 1513 Enumeration k = imHash.keys();
aoqi@0 1514
aoqi@0 1515 nextModule:
aoqi@0 1516 while ( k.hasMoreElements() ) { //loop thro user-defined -idlModules
aoqi@0 1517 String from = (String)k.nextElement(); //from String..
aoqi@0 1518 StringTokenizer ft = new StringTokenizer( from,"." );
aoqi@0 1519 int vecLen = vec.size();
aoqi@0 1520 int ifr;
aoqi@0 1521 for ( ifr = 0; ifr < vecLen && ft.hasMoreTokens(); ifr++ )
aoqi@0 1522 if ( ! vec.elementAt(ifr).equals( ft.nextToken() ) )
aoqi@0 1523 continue nextModule; //..no match
aoqi@0 1524
aoqi@0 1525 if ( ft.hasMoreTokens() ) { //matched so far..
aoqi@0 1526 fc = ft.nextToken(); //a 'from' token remains
aoqi@0 1527 if ( ! ct.getName().equals( fc ) || //matches class name?
aoqi@0 1528 ft.hasMoreTokens() )
aoqi@0 1529 continue nextModule; //..no match
aoqi@0 1530 }
aoqi@0 1531
aoqi@0 1532 ret = true; //found a match
aoqi@0 1533 for ( int i4 = 0; i4 < ifr; i4++ )
aoqi@0 1534 vec.removeElementAt( 0 ); //remove 'from' package
aoqi@0 1535
aoqi@0 1536 String to = (String)imHash.get( from ); //..to String
aoqi@0 1537 StringTokenizer tt = new StringTokenizer( to,IDL_NAME_SEPARATOR );
aoqi@0 1538
aoqi@0 1539 int itoco = tt.countTokens();
aoqi@0 1540 int ito = 0;
aoqi@0 1541 if ( fc != null ) itoco--; //user may have given IDL type
aoqi@0 1542 for ( ito = 0; ito < itoco; ito++ )
aoqi@0 1543 vec.insertElementAt( tt.nextToken(),ito ); //insert 'to' modules
aoqi@0 1544 if ( fc != null ) {
aoqi@0 1545 String tc = tt.nextToken();
aoqi@0 1546 if ( ! ct.getName().equals( tc ) ) //not the IDL type, so..
aoqi@0 1547 vec.insertElementAt( tc,ito ); //insert final 'to' module
aoqi@0 1548 }
aoqi@0 1549 }
aoqi@0 1550 }
aoqi@0 1551 return ret;
aoqi@0 1552 }
aoqi@0 1553
aoqi@0 1554
aoqi@0 1555 /**
aoqi@0 1556 * Strip Java #pragma prefix and/or -pkgPrefix prefix package names from
aoqi@0 1557 * given IDLEntity ct.
aoqi@0 1558 * Strip any package prefix which may have been added by comparing with
aoqi@0 1559 * repository id. For example in Java package fake.omega:
aoqi@0 1560 * repid = IDL:phoney.pfix/omega/Juliet:1.0 gives { "omega" }
aoqi@0 1561 * @param ct CompoundType containing given IDLEntity.
aoqi@0 1562 * @param vec Returned Vector of stripped IDL module names.
aoqi@0 1563 */
aoqi@0 1564 protected void stripJavaPackage(
aoqi@0 1565 CompoundType ct,
aoqi@0 1566 Vector vec ) {
aoqi@0 1567 vec.removeAllElements();
aoqi@0 1568 if ( ! ct.isIDLEntity() ) return;
aoqi@0 1569
aoqi@0 1570 String repID = ct.getRepositoryID().substring( 4 );
aoqi@0 1571 StringTokenizer rept = new StringTokenizer( repID,"/" );
aoqi@0 1572 if ( rept.countTokens() < 2 ) return;
aoqi@0 1573
aoqi@0 1574 while ( rept.hasMoreTokens() )
aoqi@0 1575 vec.addElement( rept.nextToken() );
aoqi@0 1576 vec.removeElementAt( vec.size() - 1 );
aoqi@0 1577
aoqi@0 1578 String pName = ct.getPackageName(); //start from Java package names
aoqi@0 1579 if ( pName == null ) return;
aoqi@0 1580 Vector pVec = new Vector();
aoqi@0 1581 StringTokenizer pt = new StringTokenizer( pName,"." );
aoqi@0 1582 while ( pt.hasMoreTokens() ) pVec.addElement( pt.nextToken() );
aoqi@0 1583
aoqi@0 1584 int i1 = vec.size() - 1;
aoqi@0 1585 int i2 = pVec.size() - 1;
aoqi@0 1586 while ( i1 >= 0 && i2 >= 0 ) { //go R->L till mismatch
aoqi@0 1587 String rep = (String)( vec.elementAt( i1 ) );
aoqi@0 1588 String pkg = (String)( pVec.elementAt( i2 ) );
aoqi@0 1589 if ( ! pkg.equals( rep ) ) break;
aoqi@0 1590 i1--; i2--;
aoqi@0 1591 }
aoqi@0 1592 for ( int i3 = 0; i3 <= i1; i3++ )
aoqi@0 1593 vec.removeElementAt( 0 ); //strip prefix
aoqi@0 1594 }
aoqi@0 1595
aoqi@0 1596
aoqi@0 1597
aoqi@0 1598 /**
aoqi@0 1599 * Write boxedRMI valuetype for a single dimension of an IDL sequence
aoqi@0 1600 * indicated by the given OutputType.
aoqi@0 1601 * The filename for the OutputType is of the form "seqn_elemName" where n
aoqi@0 1602 * is the dimension required.
aoqi@0 1603 * @param ot Given OutputType.
aoqi@0 1604 * @param p The output stream.
aoqi@0 1605 */
aoqi@0 1606 protected void writeSequence(
aoqi@0 1607 OutputType ot,
aoqi@0 1608 IndentingWriter p)
aoqi@0 1609 throws IOException {
aoqi@0 1610 ArrayType at = (ArrayType)ot.getType();
aoqi@0 1611 Type et = at.getElementType();
aoqi@0 1612 String fName = ot.getName();
aoqi@0 1613 int dim = Integer.parseInt( fName.substring( 3,fName.indexOf( "_" ) ) );
aoqi@0 1614 String idlName = unEsc( et.getIDLName() ).replace( ' ','_' );
aoqi@0 1615 String qIdlName = getQualifiedIDLName( et );
aoqi@0 1616 String qName = et.getQualifiedName();
aoqi@0 1617
aoqi@0 1618 String repID = at.getRepositoryID();
aoqi@0 1619 int rix1 = repID.indexOf( '[' ); //edit repository id
aoqi@0 1620 int rix2 = repID.lastIndexOf( '[' ) + 1;
aoqi@0 1621 StringBuffer rid = new StringBuffer(
aoqi@0 1622 repID.substring( 0,rix1 ) +
aoqi@0 1623 repID.substring( rix2 ) );
aoqi@0 1624 for ( int i1 = 0; i1 < dim; i1++ ) rid.insert( rix1,'[' );
aoqi@0 1625
aoqi@0 1626 String vtName = "seq" + dim + "_" + idlName;
aoqi@0 1627 boolean isFromIDL = false;
aoqi@0 1628 if ( et.isCompound() ) {
aoqi@0 1629 CompoundType ct = (CompoundType)et;
aoqi@0 1630 isFromIDL = ct.isIDLEntity() || ct.isCORBAObject();
aoqi@0 1631 }
aoqi@0 1632 boolean isForwardInclude =
aoqi@0 1633 et.isCompound() &&
aoqi@0 1634 !isSpecialReference( et ) &&
aoqi@0 1635 dim == 1 &&
aoqi@0 1636 !isFromIDL &&
aoqi@0 1637 !"org.omg.CORBA.Object".equals(qName) &&
aoqi@0 1638 !"java.lang.String".equals(qName);
aoqi@0 1639
aoqi@0 1640 writeBanner( at,dim,!isException,p );
aoqi@0 1641 if ( dim == 1 && "java.lang.String".equals(qName) ) //special case
aoqi@0 1642 writeIncOrb( p );
aoqi@0 1643 if ( dim == 1 && "org.omg.CORBA.Object".equals(qName) ) ;
aoqi@0 1644 else if ( isSpecialReference( et ) || dim > 1 || isFromIDL )
aoqi@0 1645 writeInclude( at,dim-1,!isThrown,p ); //"trivial" include
aoqi@0 1646 writeIfndef( at,dim,!isException,!isForward,p );
aoqi@0 1647 if ( isForwardInclude )
aoqi@0 1648 writeForwardReference( at,dim-1,p ); //forward declare
aoqi@0 1649 writeModule1( at,p );
aoqi@0 1650 p.pln();p.pI();
aoqi@0 1651 p.p( "valuetype " + vtName );
aoqi@0 1652 p.p( " sequence<" );
aoqi@0 1653 if ( dim == 1 ) p.p( qIdlName );
aoqi@0 1654 else {
aoqi@0 1655 p.p( "seq" + ( dim - 1 ) + "_" );
aoqi@0 1656 p.p( idlName );
aoqi@0 1657 }
aoqi@0 1658 p.pln( ">;" );
aoqi@0 1659 p.pO();p.pln();
aoqi@0 1660 p.pln( "#pragma ID " + vtName + " \"" + rid + "\"" );
aoqi@0 1661 p.pln();
aoqi@0 1662 writeModule2( at,p );
aoqi@0 1663 if ( isForwardInclude )
aoqi@0 1664 writeInclude( at,dim-1,!isThrown,p ); //#include for forward declare
aoqi@0 1665 writeEndif( p );
aoqi@0 1666 }
aoqi@0 1667
aoqi@0 1668
aoqi@0 1669 /**
aoqi@0 1670 * Write valuetype for a boxed IDLEntity.
aoqi@0 1671 * @param t Given CompoundType representing the IDLEntity.
aoqi@0 1672 * @param p The output stream.
aoqi@0 1673 */
aoqi@0 1674 protected void writeBoxedIDL(
aoqi@0 1675 CompoundType t,
aoqi@0 1676 IndentingWriter p)
aoqi@0 1677 throws IOException {
aoqi@0 1678 String[] boxNames = getIDLModuleNames( t );
aoqi@0 1679 int len = boxNames.length;
aoqi@0 1680 String[] modNames = new String[len - 3]; //remove box modules
aoqi@0 1681 for ( int i1 = 0; i1 < len - 3; i1++ ) modNames[i1] = boxNames[i1 + 3];
aoqi@0 1682 String tName = unEsc( t.getIDLName() );
aoqi@0 1683
aoqi@0 1684 writeBanner( t,0,!isException,p );
aoqi@0 1685 writeInclude( t,modNames,tName,p );
aoqi@0 1686 writeIfndef( t,0,!isException,!isForward,p );
aoqi@0 1687 writeModule1( t,p );
aoqi@0 1688 p.pln();p.pI();
aoqi@0 1689
aoqi@0 1690 p.p( "valuetype " + tName + " " );
aoqi@0 1691 for ( int i1 = 0; i1 < modNames.length; i1++ )
aoqi@0 1692 p.p( IDL_NAME_SEPARATOR + modNames[i1] );
aoqi@0 1693 p.pln( IDL_NAME_SEPARATOR + tName + ";" );
aoqi@0 1694
aoqi@0 1695 p.pO();p.pln();
aoqi@0 1696 writeRepositoryID( t,p );
aoqi@0 1697 p.pln();
aoqi@0 1698 writeModule2( t,p );
aoqi@0 1699 writeEndif( p );
aoqi@0 1700 }
aoqi@0 1701
aoqi@0 1702
aoqi@0 1703 /**
aoqi@0 1704 * Write an exception.
aoqi@0 1705 * @param t Given ClassType representing the exception.
aoqi@0 1706 * @param p The output stream.
aoqi@0 1707 */
aoqi@0 1708 protected void writeException(
aoqi@0 1709 ClassType t,
aoqi@0 1710 IndentingWriter p)
aoqi@0 1711 throws IOException {
aoqi@0 1712 writeBanner( t,0,isException,p );
aoqi@0 1713 writeIfndef( t,0,isException,!isForward,p );
aoqi@0 1714 writeForwardReference( t,p );
aoqi@0 1715 writeModule1( t,p );
aoqi@0 1716 p.pln();p.pI();
aoqi@0 1717
aoqi@0 1718 p.pln( "exception " + t.getIDLExceptionName() + " {" );
aoqi@0 1719 p.pln();p.pI();
aoqi@0 1720 p.pln( t.getIDLName() + " value;" );
aoqi@0 1721 p.pO();p.pln();
aoqi@0 1722 p.pln( "};" );
aoqi@0 1723
aoqi@0 1724 p.pO();p.pln();
aoqi@0 1725 writeModule2( t,p );
aoqi@0 1726 writeInclude( t,0,!isThrown,p ); //include valuetype idl file
aoqi@0 1727 writeEndif( p );
aoqi@0 1728 }
aoqi@0 1729
aoqi@0 1730
aoqi@0 1731 /**
aoqi@0 1732 * Write #pragma to identify the repository ID of the given type
aoqi@0 1733 * @param t The given Type.
aoqi@0 1734 * @param p The output stream.
aoqi@0 1735 */
aoqi@0 1736 protected void writeRepositoryID(
aoqi@0 1737 Type t,
aoqi@0 1738 IndentingWriter p )
aoqi@0 1739 throws IOException {
aoqi@0 1740 String repid = t.getRepositoryID();
aoqi@0 1741 if ( t.isCompound() ) {
aoqi@0 1742 CompoundType ct = (CompoundType)t;
aoqi@0 1743 if ( ct.isBoxed() )
aoqi@0 1744 repid = ct.getBoxedRepositoryID();
aoqi@0 1745 }
aoqi@0 1746
aoqi@0 1747 p.pln( "#pragma ID " + t.getIDLName() + " \"" +
aoqi@0 1748 repid + "\"" );
aoqi@0 1749 }
aoqi@0 1750
aoqi@0 1751 /**
aoqi@0 1752 * Write inheritance for an IDL interface or valuetype. Any class
aoqi@0 1753 * inheritance precedes any interface inheritance.
aoqi@0 1754 * For a valutype any inheritance from abstract interfaces then
aoqi@0 1755 * follows the "supports" keyword.
aoqi@0 1756 * @param inhHash Hashtable loaded with inherited Types
aoqi@0 1757 * @param forValuetype true if writing inheritance for a valuetype
aoqi@0 1758 * @param p The output stream.
aoqi@0 1759 */
aoqi@0 1760 protected void writeInherits(
aoqi@0 1761 Hashtable inhHash,
aoqi@0 1762 boolean forValuetype,
aoqi@0 1763 IndentingWriter p )
aoqi@0 1764 throws IOException {
aoqi@0 1765 int itot = inhHash.size();
aoqi@0 1766 int iinh = 0;
aoqi@0 1767 int isup = 0;
aoqi@0 1768 if ( itot < 1 ) return; //any inheritance to write?
aoqi@0 1769 Enumeration inhEnum = inhHash.elements();
aoqi@0 1770 CompoundType ct;
aoqi@0 1771 if ( forValuetype )
aoqi@0 1772 while ( inhEnum.hasMoreElements() ) {
aoqi@0 1773 ct = (CompoundType)inhEnum.nextElement();
aoqi@0 1774 if ( ct.getTypeCode() == TYPE_ABSTRACT ) isup++;
aoqi@0 1775 }
aoqi@0 1776 iinh = itot - isup;
aoqi@0 1777
aoqi@0 1778 if ( iinh > 0 ) {
aoqi@0 1779 p.p( ": " );
aoqi@0 1780 inhEnum = inhHash.elements();
aoqi@0 1781 while ( inhEnum.hasMoreElements() ) { //write any class inheritance
aoqi@0 1782 ct = (CompoundType)inhEnum.nextElement();
aoqi@0 1783 if ( ct.isClass() ) {
aoqi@0 1784 p.p( getQualifiedIDLName( ct ) );
aoqi@0 1785 if ( iinh > 1 ) p.p( ", " ); //delimit them with commas
aoqi@0 1786 else if ( itot > 1 ) p.p( " " );
aoqi@0 1787 break; //only one parent
aoqi@0 1788 }
aoqi@0 1789 }
aoqi@0 1790 int i = 0;
aoqi@0 1791 inhEnum = inhHash.elements();
aoqi@0 1792 while ( inhEnum.hasMoreElements() ) { //write any interface inheritance
aoqi@0 1793 ct = (CompoundType)inhEnum.nextElement();
aoqi@0 1794 if ( !ct.isClass() &&
aoqi@0 1795 !( ct.getTypeCode() == TYPE_ABSTRACT ) ) {
aoqi@0 1796 if ( i++ > 0 ) p.p( ", " ); //delimit with commas
aoqi@0 1797 p.p( getQualifiedIDLName( ct ) );
aoqi@0 1798 }
aoqi@0 1799 }
aoqi@0 1800 }
aoqi@0 1801 if ( isup > 0 ) { //write abstract interface inheritance
aoqi@0 1802 p.p( " supports " );
aoqi@0 1803 int i = 0;
aoqi@0 1804 inhEnum = inhHash.elements();
aoqi@0 1805 while ( inhEnum.hasMoreElements() ) {
aoqi@0 1806 ct = (CompoundType)inhEnum.nextElement();
aoqi@0 1807 if ( ct.getTypeCode() == TYPE_ABSTRACT ) {
aoqi@0 1808 if ( i++ > 0 ) p.p( ", " ); //delimit with commas
aoqi@0 1809 p.p( getQualifiedIDLName( ct ) );
aoqi@0 1810 }
aoqi@0 1811 }
aoqi@0 1812 }
aoqi@0 1813 }
aoqi@0 1814
aoqi@0 1815
aoqi@0 1816 /**
aoqi@0 1817 * Write an IDL constant
aoqi@0 1818 * @param constant The current CompoundType.Member constant
aoqi@0 1819 * @param p The output stream.
aoqi@0 1820 */
aoqi@0 1821 protected void writeConstant(
aoqi@0 1822 CompoundType.Member constant,
aoqi@0 1823 IndentingWriter p )
aoqi@0 1824 throws IOException {
aoqi@0 1825 Type t = constant.getType();
aoqi@0 1826 p.p( "const " );
aoqi@0 1827 p.p( getQualifiedIDLName( t ) );
aoqi@0 1828 p.p( " " + constant.getIDLName() + " = " + constant.getValue() );
aoqi@0 1829 p.pln( ";" );
aoqi@0 1830 }
aoqi@0 1831
aoqi@0 1832
aoqi@0 1833
aoqi@0 1834 /**
aoqi@0 1835 * Write an IDL data member
aoqi@0 1836 * @param data The current CompoundType.Member data member
aoqi@0 1837 * @param p The output stream.
aoqi@0 1838 */
aoqi@0 1839 protected void writeData(
aoqi@0 1840 CompoundType.Member data,
aoqi@0 1841 IndentingWriter p )
aoqi@0 1842 throws IOException {
aoqi@0 1843 if ( data.isInnerClassDeclaration() ) return; //ignore
aoqi@0 1844 Type t = data.getType();
aoqi@0 1845 if ( data.isPublic() )
aoqi@0 1846 p.p( "public " );
aoqi@0 1847 else p.p( "private " );
aoqi@0 1848 p.pln( getQualifiedIDLName( t ) + " " +
aoqi@0 1849 data.getIDLName() + ";" );
aoqi@0 1850 }
aoqi@0 1851
aoqi@0 1852
aoqi@0 1853
aoqi@0 1854 /**
aoqi@0 1855 * Write an IDL Attribute
aoqi@0 1856 * @param attr The current CompoundType.Method attribute
aoqi@0 1857 * @param p The output stream.
aoqi@0 1858 */
aoqi@0 1859 protected void writeAttribute(
aoqi@0 1860 CompoundType.Method attr,
aoqi@0 1861 IndentingWriter p )
aoqi@0 1862 throws IOException {
aoqi@0 1863 if ( attr.getAttributeKind() == ATTRIBUTE_SET ) return; //use getters only
aoqi@0 1864 Type t = attr.getReturnType();
aoqi@0 1865 if ( !attr.isReadWriteAttribute() ) p.p( "readonly " );
aoqi@0 1866 p.p( "attribute " + getQualifiedIDLName( t ) + " " );
aoqi@0 1867 p.pln( attr.getAttributeName() + ";" );
aoqi@0 1868 }
aoqi@0 1869
aoqi@0 1870
aoqi@0 1871
aoqi@0 1872 /**
aoqi@0 1873 * Write an IDL method
aoqi@0 1874 * @param method The current CompoundType.Method
aoqi@0 1875 * @param p The output stream.
aoqi@0 1876 */
aoqi@0 1877 protected void writeMethod(
aoqi@0 1878 CompoundType.Method method,
aoqi@0 1879 IndentingWriter p )
aoqi@0 1880 throws IOException {
aoqi@0 1881 if ( method.isAttribute() ) {
aoqi@0 1882 writeAttribute( method,p );
aoqi@0 1883 return;
aoqi@0 1884 }
aoqi@0 1885 Type[] pts = method.getArguments();
aoqi@0 1886 String[] paramNames = method.getArgumentNames();
aoqi@0 1887 Type rt = method.getReturnType();
aoqi@0 1888 Hashtable excHash = new Hashtable();
aoqi@0 1889 getExceptions( method,excHash );
aoqi@0 1890
aoqi@0 1891 if ( method.isConstructor() )
aoqi@0 1892 if ( factory ) p.p( "factory " + method.getIDLName() + "(" );
aoqi@0 1893 else p.p( "init(" ); //IDL initializer
aoqi@0 1894 else {
aoqi@0 1895 p.p( getQualifiedIDLName( rt ) );
aoqi@0 1896 p.p( " " + method.getIDLName() + "(" );
aoqi@0 1897 }
aoqi@0 1898 p.pI();
aoqi@0 1899
aoqi@0 1900 for ( int i=0; i < pts.length; i++ ) {
aoqi@0 1901 if ( i > 0 ) p.pln( "," ); //delimit with comma and newline
aoqi@0 1902 else p.pln();
aoqi@0 1903 p.p( "in " );
aoqi@0 1904 p.p( getQualifiedIDLName( pts[i] ) );
aoqi@0 1905 p.p( " " + paramNames[i] );
aoqi@0 1906 }
aoqi@0 1907 p.pO();
aoqi@0 1908 p.p( " )" );
aoqi@0 1909
aoqi@0 1910 if ( excHash.size() > 0 ) { //any exceptions to write?
aoqi@0 1911 p.pln( " raises (" );
aoqi@0 1912 p.pI();
aoqi@0 1913 int i = 0;
aoqi@0 1914 Enumeration excEnum = excHash.elements();
aoqi@0 1915 while ( excEnum.hasMoreElements() ) {
aoqi@0 1916 ValueType exc = (ValueType)excEnum.nextElement();
aoqi@0 1917 if ( i > 0 ) p.pln( "," ); //delimit them with commas
aoqi@0 1918 if ( exc.isIDLEntityException() )
aoqi@0 1919 if ( exc.isCORBAUserException() )
aoqi@0 1920 p.p( "::org::omg::CORBA::UserEx" );
aoqi@0 1921 else {
aoqi@0 1922 String[] modNames = getIDLModuleNames( exc );
aoqi@0 1923 for ( int i2 = 0; i2 < modNames.length; i2++ )
aoqi@0 1924 p.p( IDL_NAME_SEPARATOR + modNames[i2] );
aoqi@0 1925 p.p( IDL_NAME_SEPARATOR + exc.getName() );
aoqi@0 1926 }
aoqi@0 1927 else p.p( exc.getQualifiedIDLExceptionName( true ) );
aoqi@0 1928 i++;
aoqi@0 1929 }
aoqi@0 1930 p.pO();
aoqi@0 1931 p.p( " )" );
aoqi@0 1932 }
aoqi@0 1933
aoqi@0 1934 p.pln( ";" );
aoqi@0 1935 }
aoqi@0 1936
aoqi@0 1937
aoqi@0 1938 /**
aoqi@0 1939 * Remove escape character ("_"), if any, from given String
aoqi@0 1940 * @param name Given String
aoqi@0 1941 * @return String with any escape character removed
aoqi@0 1942 */
aoqi@0 1943 protected String unEsc(
aoqi@0 1944 String name ) {
aoqi@0 1945 if ( name.startsWith( "_" ) ) return name.substring( 1 );
aoqi@0 1946 else return name;
aoqi@0 1947 }
aoqi@0 1948
aoqi@0 1949
aoqi@0 1950 /**
aoqi@0 1951 * Write IDL banner into the output stream for a given Type
aoqi@0 1952 * @param t The given Type.
aoqi@0 1953 * @param dim The dimension required if t is an ArrayType.
aoqi@0 1954 * @param isException true if writing an exception.
aoqi@0 1955 * @param p The output stream.
aoqi@0 1956 */
aoqi@0 1957 protected void writeBanner(
aoqi@0 1958 Type t,
aoqi@0 1959 int dim,
aoqi@0 1960 boolean isException,
aoqi@0 1961 IndentingWriter p )
aoqi@0 1962 throws IOException {
aoqi@0 1963 String[] modNames = getIDLModuleNames( t ); //module name array
aoqi@0 1964 String fName = unEsc( t.getIDLName() ); //file name default
aoqi@0 1965 if ( isException && t.isClass() ) {
aoqi@0 1966 ClassType ct = (ClassType)t; //file name for Exception
aoqi@0 1967 fName = unEsc( ct.getIDLExceptionName() );
aoqi@0 1968 }
aoqi@0 1969 if ( dim > 0 && t.isArray() ) {
aoqi@0 1970 Type et = t.getElementType(); //file name for sequence
aoqi@0 1971 fName = "seq" + dim + "_" + unEsc( et.getIDLName().replace( ' ','_' ) );
aoqi@0 1972 }
aoqi@0 1973
aoqi@0 1974 p.pln( "/**" );
aoqi@0 1975 p.p( " * " );
aoqi@0 1976 for ( int i1 = 0; i1 < modNames.length; i1++ )
aoqi@0 1977 p.p( modNames[i1] + "/" );
aoqi@0 1978 p.pln( fName + ".idl" );
aoqi@0 1979 p.pln( " * Generated by rmic -idl. Do not edit" );
aoqi@0 1980 String d = DateFormat.getDateTimeInstance(
aoqi@0 1981 DateFormat.FULL,DateFormat.FULL,Locale.getDefault() )
aoqi@0 1982 .format( new Date() );
aoqi@0 1983 String ocStr = "o'clock";
aoqi@0 1984 int ocx = d.indexOf( ocStr ); //remove unwanted o'clock, if any
aoqi@0 1985 p.p ( " * " );
aoqi@0 1986 if ( ocx > -1 )
aoqi@0 1987 p.pln( d.substring( 0,ocx ) + d.substring( ocx + ocStr.length() ) );
aoqi@0 1988 else p.pln( d );
aoqi@0 1989 p.pln( " */" );
aoqi@0 1990 p.pln();
aoqi@0 1991 }
aoqi@0 1992
aoqi@0 1993
aoqi@0 1994 /**
aoqi@0 1995 * Write #include for orb.idl
aoqi@0 1996 * @param p The output stream.
aoqi@0 1997 */
aoqi@0 1998 protected void writeIncOrb(
aoqi@0 1999 IndentingWriter p )
aoqi@0 2000 throws IOException {
aoqi@0 2001 p.pln( "#include \"orb.idl\"" );
aoqi@0 2002 }
aoqi@0 2003
aoqi@0 2004
aoqi@0 2005 /**
aoqi@0 2006 * Write #ifndef guard into the output stream for a given Type
aoqi@0 2007 * @param t The given Type.
aoqi@0 2008 * @param dim The dimension required if t is an ArrayType.
aoqi@0 2009 * @param isException true if writing an exception.
aoqi@0 2010 * @param isForward. No #define needed if it's a forward declare
aoqi@0 2011 * @param p The output stream.
aoqi@0 2012 */
aoqi@0 2013 protected void writeIfndef(
aoqi@0 2014 Type t,
aoqi@0 2015 int dim,
aoqi@0 2016 boolean isException,
aoqi@0 2017 boolean isForward,
aoqi@0 2018 IndentingWriter p )
aoqi@0 2019 throws IOException {
aoqi@0 2020 String[] modNames = getIDLModuleNames( t ); //module name array
aoqi@0 2021 String fName = unEsc( t.getIDLName() ); //file name default
aoqi@0 2022 if ( isException && t.isClass() ) {
aoqi@0 2023 ClassType ct = (ClassType)t; //file name for Exception
aoqi@0 2024 fName = unEsc( ct.getIDLExceptionName() );
aoqi@0 2025 }
aoqi@0 2026 if ( dim > 0 && t.isArray() ) {
aoqi@0 2027 Type et = t.getElementType(); //file name for sequence
aoqi@0 2028 fName = "seq" + dim + "_" + unEsc( et.getIDLName().replace( ' ','_' ) );
aoqi@0 2029 }
aoqi@0 2030 p.pln();
aoqi@0 2031 p.p( "#ifndef __" );
aoqi@0 2032 for ( int i = 0; i < modNames.length; i++ ) p.p( modNames[i] + "_" );
aoqi@0 2033 p.pln( fName + "__" );
aoqi@0 2034 if ( !isForward ) {
aoqi@0 2035 p.p( "#define __" );
aoqi@0 2036 for ( int i = 0; i < modNames.length; i++ ) p.p( modNames[i] + "_" );
aoqi@0 2037 p.pln( fName + "__" );
aoqi@0 2038 p.pln();
aoqi@0 2039 }
aoqi@0 2040 }
aoqi@0 2041
aoqi@0 2042
aoqi@0 2043 /**
aoqi@0 2044 * Write #endif bracket into the output stream
aoqi@0 2045 * @param p The output stream.
aoqi@0 2046 */
aoqi@0 2047 protected void writeEndif(
aoqi@0 2048 IndentingWriter p )
aoqi@0 2049 throws IOException {
aoqi@0 2050 p.pln("#endif");
aoqi@0 2051 p.pln();
aoqi@0 2052 }
aoqi@0 2053
aoqi@0 2054 /**
aoqi@0 2055 * Write Module start bracketing for the given type into the output stream
aoqi@0 2056 * @param t The given Type
aoqi@0 2057 * @param p The output stream.
aoqi@0 2058 */
aoqi@0 2059 protected void writeModule1(
aoqi@0 2060 Type t,
aoqi@0 2061 IndentingWriter p )
aoqi@0 2062 throws IOException {
aoqi@0 2063
aoqi@0 2064 String[] modNames = getIDLModuleNames( t );
aoqi@0 2065 p.pln();
aoqi@0 2066 for ( int i = 0; i < modNames.length; i++ )
aoqi@0 2067 p.pln( "module " + modNames[i] + " {" );
aoqi@0 2068 }
aoqi@0 2069
aoqi@0 2070 /**
aoqi@0 2071 * Write Module end bracketing for the given type into the output stream
aoqi@0 2072 * @param t The given Type
aoqi@0 2073 * @param p The output stream.
aoqi@0 2074 */
aoqi@0 2075 protected void writeModule2(
aoqi@0 2076 Type t,
aoqi@0 2077 IndentingWriter p )
aoqi@0 2078 throws IOException {
aoqi@0 2079 String[] modNames = getIDLModuleNames( t );
aoqi@0 2080 for ( int i=0; i < modNames.length; i++ ) p.pln( "};" );
aoqi@0 2081 p.pln();
aoqi@0 2082 }
aoqi@0 2083
aoqi@0 2084 }

mercurial