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