corba/src/share/classes/sun/rmi/rmic/iiop/StubGenerator.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 4 02bb8761fcce
child 5555 b2b5ed3f0d0d
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
02bb8761fcce Initial load
duke
parents:
diff changeset
     2
 * Portions Copyright 1998-2007 Sun Microsystems, Inc.  All Rights Reserved.
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
02bb8761fcce Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
02bb8761fcce Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
02bb8761fcce Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
02bb8761fcce Initial load
duke
parents:
diff changeset
    23
 * have any questions.
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
/*
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
 * Licensed Materials - Property of IBM
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
 * RMI-IIOP v1.0
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
 * Copyright IBM Corp. 1998 1999  All Rights Reserved
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
package sun.rmi.rmic.iiop;
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import java.io.File;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import java.io.IOException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import java.util.Vector;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import java.util.Hashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import java.util.Enumeration;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import sun.tools.java.Identifier;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import sun.tools.java.ClassNotFound;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import sun.tools.java.ClassDefinition;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import sun.tools.java.ClassDeclaration;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import sun.tools.java.CompilerError;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import sun.rmi.rmic.IndentingWriter;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import java.util.HashSet;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import java.util.Arrays;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
import com.sun.corba.se.impl.util.Utility;
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
import com.sun.corba.se.impl.util.PackagePrefixChecker;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
import sun.rmi.rmic.Main;
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
 * An IIOP stub/tie generator for rmic.
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
 * @author      Bryan Atsatt
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
 * @author      Anil Vijendran
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
 * @author      M. Mortazavi
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
public class StubGenerator extends sun.rmi.rmic.iiop.Generator {
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
    private static final String DEFAULT_STUB_CLASS = "javax.rmi.CORBA.Stub";
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
    private static final String DEFAULT_TIE_CLASS = "org.omg.CORBA_2_3.portable.ObjectImpl";
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
    private static final String DEFAULT_POA_TIE_CLASS = "org.omg.PortableServer.Servant";
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
    protected boolean reverseIDs = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
    protected boolean localStubs = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
    protected boolean standardPackage = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
    protected boolean useHash = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
    protected String stubBaseClass = DEFAULT_STUB_CLASS;
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
    protected String tieBaseClass = DEFAULT_TIE_CLASS;
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
    protected HashSet namesInUse = new HashSet();
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
    protected Hashtable classesInUse = new Hashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
    protected Hashtable imports = new Hashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
    protected int importCount = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
    protected String currentPackage = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
    protected String currentClass = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
    protected boolean castArray = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
    protected Hashtable transactionalObjects = new Hashtable() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
    protected boolean POATie = false ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
     * Default constructor for Main to use.
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
    public StubGenerator() {
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
     * Overridden in order to set the standardPackage flag.
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
    public void generate(
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
            sun.rmi.rmic.BatchEnvironment env,
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
            ClassDefinition cdef, File destDir) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
        ((sun.rmi.rmic.iiop.BatchEnvironment)env).
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
                setStandardPackage(standardPackage);
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
        super.generate(env, cdef, destDir);
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
     * Return true if a new instance should be created for each
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
     * class on the command line. Subclasses which return true
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
     * should override newInstance() to return an appropriately
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
     * constructed instance.
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
    protected boolean requireNewInstance() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
        return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
     * Return true if non-conforming types should be parsed.
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
     * @param stack The context stack.
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
    protected boolean parseNonConforming(ContextStack stack) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
        // We let the environment setting decide so that
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
        // another generator (e.g. IDLGenerator) can change
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
        // it and we will just go with the flow...
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
        return stack.getEnv().getParseNonConforming();
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
     * Create and return a top-level type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
     * @param cdef The top-level class definition.
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
     * @param stack The context stack.
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
     * @return The compound type or null if is non-conforming.
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
    protected CompoundType getTopType(ClassDefinition cdef, ContextStack stack) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
        CompoundType result = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
        // Do we have an interface?
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
        if (cdef.isInterface()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
            // Yes, so first try Abstract...
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
            result = AbstractType.forAbstract(cdef,stack,true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
            if (result == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
                // Then try Remote...
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
                result = RemoteType.forRemote(cdef,stack,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
            // Not an interface, so try Implementation...
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
            result = ImplementationType.forImplementation(cdef,stack,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
        return result;
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
     * Examine and consume command line arguments.
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
     * @param argv The command line arguments. Ignore null
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
     * and unknown arguments. Set each consumed argument to null.
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
     * @param error Report any errors using the main.error() methods.
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
     * @return true if no errors, false otherwise.
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
    public boolean parseArgs(String argv[], Main main) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
        Object marker = new Object() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
        // Reset any cached options...
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
        reverseIDs = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
        localStubs = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
        useHash = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
        stubBaseClass = DEFAULT_STUB_CLASS;
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
        //       tieBaseClass = DEFAULT_TIE_CLASS;
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
        transactionalObjects = new Hashtable() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
        // Parse options...
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
        boolean result = super.parseArgs(argv,main);
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
        if (result) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
            for (int i = 0; i < argv.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
                if (argv[i] != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
                    String arg = argv[i].toLowerCase();
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
                    if (arg.equals("-iiop")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
                        argv[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
                    } else if (arg.equals("-xreverseids")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
                        reverseIDs = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
                        argv[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
                    } else if (arg.equals("-nolocalstubs")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
                        localStubs = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
                        argv[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
                    } else if (arg.equals("-xnohash")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
                        useHash = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
                        argv[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
                    } else if (argv[i].equals("-standardPackage")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
                        standardPackage = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
                        argv[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
                    } else if (arg.equals("-xstubbase")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
                        argv[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
                        if (++i < argv.length && argv[i] != null && !argv[i].startsWith("-")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
                            stubBaseClass = argv[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
                            argv[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
                        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
                            main.error("rmic.option.requires.argument", "-Xstubbase");
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
                            result = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
                    } else if (arg.equals("-xtiebase")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
                        argv[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
                        if (++i < argv.length && argv[i] != null && !argv[i].startsWith("-")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
                            tieBaseClass = argv[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
                            argv[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
                        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
                            main.error("rmic.option.requires.argument", "-Xtiebase");
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
                            result = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
                    } else if (arg.equals("-transactional" )) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
                        // Scan for the next non-flag argument.
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
                        // Assume that it is a class name and add it
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
                        // to the list of transactional classes.
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
                        for ( int ctr=i+1; ctr<argv.length; ctr++ ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
                            if (argv[ctr].charAt(1) != '-') {
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
                                transactionalObjects.put( argv[ctr], marker ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
                                break ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
                            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
                        argv[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
                    } else if (arg.equals( "-poa" )) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
                        POATie = true ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
                        argv[i] = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
        if(POATie){
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
            tieBaseClass = DEFAULT_POA_TIE_CLASS;
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
            tieBaseClass = DEFAULT_TIE_CLASS;
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
     * Return an array containing all the file names and types that need to be
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
     * generated for the given top-level type.  The file names must NOT have an
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
     * extension (e.g. ".java").
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
     * @param topType The type returned by getTopType().
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
     * @param alreadyChecked A set of Types which have already been checked.
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
     *  Intended to be passed to topType.collectMatching(filter,alreadyChecked).
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
    protected OutputType[] getOutputTypesFor(CompoundType topType,
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
                                             HashSet alreadyChecked) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
        // We want to generate stubs for all remote and implementation types,
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
        // so collect them up.
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
        // We use the form of collectMatching which allows us to pass in a set of
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
        // types which have previously been checked. By doing so, we ensure that if
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
        // the command line contains Hello and HelloImpl, we will only generate
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
        // output for Hello once...
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
        int filter = TYPE_REMOTE | TYPE_IMPLEMENTATION;
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
        Type[] genTypes = topType.collectMatching(filter,alreadyChecked);
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
        int count = genTypes.length;
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
        Vector list = new Vector(count+5);
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
        BatchEnvironment theEnv = topType.getEnv();
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
        // Now walk all types...
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
        for (int i = 0; i < genTypes.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
            Type type = genTypes[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
            String typeName = type.getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
            boolean createStub = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
            // Is it an implementation type?
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
            if (type instanceof ImplementationType) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
                // Yes, so add a tie for it...
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
                list.addElement(new OutputType(Utility.tieNameForCompiler(typeName), type));
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
                // Does it have more than 1 remote interface?  If so, we
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
                // want to create a stub for it...
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
                int remoteInterfaceCount = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
                InterfaceType[] interfaces = ((CompoundType)type).getInterfaces();
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
                for (int j = 0; j < interfaces.length; j++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
                    if (interfaces[j].isType(TYPE_REMOTE) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
                        !interfaces[j].isType(TYPE_ABSTRACT)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
                        remoteInterfaceCount++;
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
                if (remoteInterfaceCount <= 1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
                    // No, so do not create a stub for this type...
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
                    createStub = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
            // Is it an abstract interface type?
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
            if (type instanceof AbstractType) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
                // Do not create a stub for this type...
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
                createStub = false;  // d11141
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
            if (createStub) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
                // Add a stub for the type...
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
                list.addElement(new OutputType(Utility.stubNameForCompiler(typeName), type));
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
        // Copy list into array..
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
        OutputType[] outputTypes = new OutputType[list.size()];
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
        list.copyInto(outputTypes);
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
        return outputTypes;
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
     * Return the file name extension for the given file name (e.g. ".java").
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
     * All files generated with the ".java" extension will be compiled. To
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
     * change this behavior for ".java" files, override the compileJavaSourceFile
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
     * method to return false.
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
     * @param outputType One of the items returned by getOutputTypesFor(...)
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
    protected String getFileNameExtensionFor(OutputType outputType) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
        return SOURCE_FILE_EXTENSION;
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
     * Write the output for the given OutputFileName into the output stream.
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
     * @param name One of the items returned by getOutputTypesFor(...)
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
     * @param alreadyChecked A set of Types which have already been checked.
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
     *  Intended to be passed to Type.collectMatching(filter,alreadyChecked).
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
     * @param writer The output stream.
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
    protected void writeOutputFor(      OutputType outputType,
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
                                        HashSet alreadyChecked,
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
                                        IndentingWriter writer) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
        String fileName = outputType.getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
        CompoundType theType = (CompoundType) outputType.getType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
        // Are we doing a Stub or Tie?
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
        if (fileName.endsWith(Utility.RMI_STUB_SUFFIX)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
            // Stub.
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
            writeStub(outputType,writer);
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
            // Tie
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
            writeTie(outputType,writer);
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
     * Write a stub for the specified type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
    protected void writeStub(OutputType outputType,
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
                             IndentingWriter p) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
        CompoundType theType = (CompoundType) outputType.getType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
        RemoteType[] remoteInterfaces = getDirectRemoteInterfaces(theType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
        // Write comment.
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
        p.pln("// Stub class generated by rmic, do not edit.");
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
        p.pln("// Contents subject to change without notice.");
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
        p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
        // Set our standard classes...
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
        setStandardClassesInUse(theType,true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
        // Add classes for this type...
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
        addClassesInUse(theType,remoteInterfaces);
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
        // Write package and import statements...
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
        writePackageAndImports(p);
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
        // Declare the stub class; implement all remote interfaces.
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
        p.p("public class " + currentClass);
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
        p.p(" extends " + getName(stubBaseClass));
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
        p.p(" implements ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
        if (remoteInterfaces.length > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
            for(int i = 0; i < remoteInterfaces.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
                if (i > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
                    p.pln(",");
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
                String objName = testUtil(getName(remoteInterfaces[i]), theType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
                p.p(objName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
        // Add java.rmi.Remote if this type does not implement it.
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
        // This allows stubs for Abstract interfaces to be treated
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
        // uniformly...
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
        if (!implementsRemote(theType)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
            p.pln(",");
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
            p.p(getName("java.rmi.Remote"));
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
        p.plnI(" {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
        p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
        // Write the ids...
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
        writeIds( p, theType, false );
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
        p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
        // Write the _ids() method...
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
        p.plnI("public String[] _ids() { ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
        p.pln("return _type_ids;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
        p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
        // Get all the methods and write each stub method...
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
        CompoundType.Method[] remoteMethods = theType.getMethods();
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
        int methodCount = remoteMethods.length;
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
        if (methodCount > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
            boolean writeHeader = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
            for(int i = 0; i < methodCount; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
                if (!remoteMethods[i].isConstructor()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
                    if (writeHeader) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
                        writeHeader = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
                    p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
                    writeStubMethod(p, remoteMethods[i], theType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
        // Write the cast array hack...
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
        writeCastArray(p);
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
        p.pOln("}");            // end stub class
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
    void addClassInUse(String qualifiedName) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
        String unqualifiedName = qualifiedName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
        String packageName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
        int index = qualifiedName.lastIndexOf('.');
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
        if (index > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
            unqualifiedName = qualifiedName.substring(index+1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
            packageName = qualifiedName.substring(0,index);
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
        addClassInUse(unqualifiedName,qualifiedName,packageName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
    void addClassInUse(Type type) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
        if (!type.isPrimitive()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
            Identifier id = type.getIdentifier();
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
            String name = IDLNames.replace(id.getName().toString(),". ",".");
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
            String packageName = type.getPackageName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
            String qualifiedName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
            if (packageName != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
                qualifiedName = packageName+"."+name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
                qualifiedName = name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
            addClassInUse(name,qualifiedName,packageName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
    void addClassInUse(Type[] types) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
        for (int i = 0; i < types.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
            addClassInUse(types[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
    void addStubInUse(Type type) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
        if (type.getIdentifier() != idCorbaObject &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
            type.isType(TYPE_CORBA_OBJECT)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
            String stubName = getStubNameFor(type,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
            String packageName = type.getPackageName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
            String fullName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
            if (packageName == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
                fullName = stubName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
                fullName = packageName + "." + stubName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
            addClassInUse(stubName,fullName,packageName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
        if (type.isType(TYPE_REMOTE) ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
            type.isType(TYPE_JAVA_RMI_REMOTE)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
            addClassInUse("javax.rmi.PortableRemoteObject");
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
    String getStubNameFor(Type type, boolean qualified) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
        String stubName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
        String className;
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
        if (qualified) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
            className = type.getQualifiedName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
            className = type.getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
        if (((CompoundType)type).isCORBAObject()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
            stubName = Utility.idlStubName(className);
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
            stubName = Utility.stubNameForCompiler(className);
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
        return stubName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
02bb8761fcce Initial load
duke
parents:
diff changeset
   522
    void addStubInUse(Type[] types) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
        for (int i = 0; i < types.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
            addStubInUse(types[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   525
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
    private static final String NO_IMPORT = new String();
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
    void addClassInUse(String unqualifiedName, String qualifiedName, String packageName) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
        // Have we already got an entry for this qualifiedName?
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
        String currentName = (String)classesInUse.get(qualifiedName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
        if (currentName == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
            // No, never seen it before. Grab any existing import
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
            // name and then decide what to do...
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
            String importName = (String) imports.get(unqualifiedName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
            String nameToUse = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
            if (packageName == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
                // Default package, so doesn't matter which name to use...
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
                nameToUse = unqualifiedName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
            } else if (packageName.equals("java.lang")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
                // java.lang.*, so use unqualified name...
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
                nameToUse = unqualifiedName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
                // unless you want to be able to import things from the right place :--)
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
                if(nameToUse.endsWith("_Stub")) nameToUse = Util.packagePrefix()+qualifiedName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
            } else if (currentPackage != null && packageName.equals(currentPackage)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
                // Class in currentPackage, so use unqualified name...
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
                nameToUse = unqualifiedName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   565
02bb8761fcce Initial load
duke
parents:
diff changeset
   566
                // Do we already have a previous import under this
02bb8761fcce Initial load
duke
parents:
diff changeset
   567
                // unqualified name?
02bb8761fcce Initial load
duke
parents:
diff changeset
   568
02bb8761fcce Initial load
duke
parents:
diff changeset
   569
                if (importName != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   570
02bb8761fcce Initial load
duke
parents:
diff changeset
   571
                    // Yes, so we use qualifiedName...
02bb8761fcce Initial load
duke
parents:
diff changeset
   572
02bb8761fcce Initial load
duke
parents:
diff changeset
   573
                    nameToUse = qualifiedName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   574
02bb8761fcce Initial load
duke
parents:
diff changeset
   575
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   576
02bb8761fcce Initial load
duke
parents:
diff changeset
   577
            } else if (importName != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   578
02bb8761fcce Initial load
duke
parents:
diff changeset
   579
                // It is in some package for which we normally
02bb8761fcce Initial load
duke
parents:
diff changeset
   580
                // would import, but we have a previous import
02bb8761fcce Initial load
duke
parents:
diff changeset
   581
                // under this unqualified name. We must use
02bb8761fcce Initial load
duke
parents:
diff changeset
   582
                // the qualified name...
02bb8761fcce Initial load
duke
parents:
diff changeset
   583
02bb8761fcce Initial load
duke
parents:
diff changeset
   584
                nameToUse = qualifiedName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   585
02bb8761fcce Initial load
duke
parents:
diff changeset
   586
                /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   587
                  // Is the currentPackage the default package?
02bb8761fcce Initial load
duke
parents:
diff changeset
   588
02bb8761fcce Initial load
duke
parents:
diff changeset
   589
                  if (currentPackage == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   590
02bb8761fcce Initial load
duke
parents:
diff changeset
   591
                  // Yes, so undo the import so that all
02bb8761fcce Initial load
duke
parents:
diff changeset
   592
                  // uses for this name will be qualified...
02bb8761fcce Initial load
duke
parents:
diff changeset
   593
02bb8761fcce Initial load
duke
parents:
diff changeset
   594
                  String old = (String)imports.remove(unqualifiedName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   595
                  classesInUse.put(old,old);
02bb8761fcce Initial load
duke
parents:
diff changeset
   596
                  importCount--;
02bb8761fcce Initial load
duke
parents:
diff changeset
   597
02bb8761fcce Initial load
duke
parents:
diff changeset
   598
                  // Note that this name is in use but should
02bb8761fcce Initial load
duke
parents:
diff changeset
   599
                  // not be imported...
02bb8761fcce Initial load
duke
parents:
diff changeset
   600
02bb8761fcce Initial load
duke
parents:
diff changeset
   601
                  imports.put(nameToUse,NO_IMPORT);
02bb8761fcce Initial load
duke
parents:
diff changeset
   602
                  }
02bb8761fcce Initial load
duke
parents:
diff changeset
   603
                */
02bb8761fcce Initial load
duke
parents:
diff changeset
   604
            } else if (qualifiedName.equals("org.omg.CORBA.Object")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   605
02bb8761fcce Initial load
duke
parents:
diff changeset
   606
                // Always qualify this quy to avoid confusion...
02bb8761fcce Initial load
duke
parents:
diff changeset
   607
02bb8761fcce Initial load
duke
parents:
diff changeset
   608
                nameToUse = qualifiedName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   609
02bb8761fcce Initial load
duke
parents:
diff changeset
   610
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   611
02bb8761fcce Initial load
duke
parents:
diff changeset
   612
                // Default to using unqualified name, and add
02bb8761fcce Initial load
duke
parents:
diff changeset
   613
                // this guy to the imports...
02bb8761fcce Initial load
duke
parents:
diff changeset
   614
02bb8761fcce Initial load
duke
parents:
diff changeset
   615
                // Check for nested class in which case we use
02bb8761fcce Initial load
duke
parents:
diff changeset
   616
                // the fully qualified name instead of imports
02bb8761fcce Initial load
duke
parents:
diff changeset
   617
                if (unqualifiedName.indexOf('.') != -1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   618
                    nameToUse = qualifiedName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   619
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   620
                    nameToUse = unqualifiedName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   621
                    imports.put(unqualifiedName,qualifiedName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   622
                    importCount++;
02bb8761fcce Initial load
duke
parents:
diff changeset
   623
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   624
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   625
02bb8761fcce Initial load
duke
parents:
diff changeset
   626
            // Now add the name...
02bb8761fcce Initial load
duke
parents:
diff changeset
   627
02bb8761fcce Initial load
duke
parents:
diff changeset
   628
            classesInUse.put(qualifiedName,nameToUse);
02bb8761fcce Initial load
duke
parents:
diff changeset
   629
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   630
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   631
02bb8761fcce Initial load
duke
parents:
diff changeset
   632
    String getName(Type type) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   633
        if (type.isPrimitive()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   634
            return type.getName() + type.getArrayBrackets();
02bb8761fcce Initial load
duke
parents:
diff changeset
   635
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   636
        Identifier id = type.getIdentifier();
02bb8761fcce Initial load
duke
parents:
diff changeset
   637
        String name = IDLNames.replace(id.toString(),". ",".");
02bb8761fcce Initial load
duke
parents:
diff changeset
   638
        return getName(name) + type.getArrayBrackets();
02bb8761fcce Initial load
duke
parents:
diff changeset
   639
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   640
02bb8761fcce Initial load
duke
parents:
diff changeset
   641
    // Added for Bug 4818753
02bb8761fcce Initial load
duke
parents:
diff changeset
   642
    String getExceptionName(Type type) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   643
        Identifier id = type.getIdentifier();
02bb8761fcce Initial load
duke
parents:
diff changeset
   644
        return IDLNames.replace(id.toString(),". ",".");
02bb8761fcce Initial load
duke
parents:
diff changeset
   645
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   646
02bb8761fcce Initial load
duke
parents:
diff changeset
   647
    String getName(String qualifiedName) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   648
        return (String)classesInUse.get(qualifiedName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   649
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   650
02bb8761fcce Initial load
duke
parents:
diff changeset
   651
    String getName(Identifier id) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   652
        return getName(id.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   653
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   654
02bb8761fcce Initial load
duke
parents:
diff changeset
   655
    String getStubName(Type type) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   656
        String stubName = getStubNameFor(type,true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   657
        return getName(stubName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   658
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   659
02bb8761fcce Initial load
duke
parents:
diff changeset
   660
    void setStandardClassesInUse(CompoundType type,
02bb8761fcce Initial load
duke
parents:
diff changeset
   661
                                 boolean stub) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   662
02bb8761fcce Initial load
duke
parents:
diff changeset
   663
        // Reset our state...
02bb8761fcce Initial load
duke
parents:
diff changeset
   664
02bb8761fcce Initial load
duke
parents:
diff changeset
   665
        currentPackage = type.getPackageName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   666
        imports.clear();
02bb8761fcce Initial load
duke
parents:
diff changeset
   667
        classesInUse.clear();
02bb8761fcce Initial load
duke
parents:
diff changeset
   668
        namesInUse.clear();
02bb8761fcce Initial load
duke
parents:
diff changeset
   669
        importCount = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   670
        castArray = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   671
02bb8761fcce Initial load
duke
parents:
diff changeset
   672
        // Add the top-level type...
02bb8761fcce Initial load
duke
parents:
diff changeset
   673
02bb8761fcce Initial load
duke
parents:
diff changeset
   674
        addClassInUse(type);
02bb8761fcce Initial load
duke
parents:
diff changeset
   675
02bb8761fcce Initial load
duke
parents:
diff changeset
   676
        // Set current class name...
02bb8761fcce Initial load
duke
parents:
diff changeset
   677
02bb8761fcce Initial load
duke
parents:
diff changeset
   678
        if (stub) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   679
            currentClass = Utility.stubNameForCompiler(type.getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   680
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   681
            currentClass = Utility.tieNameForCompiler(type.getName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   682
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   683
02bb8761fcce Initial load
duke
parents:
diff changeset
   684
        // Add current class...
02bb8761fcce Initial load
duke
parents:
diff changeset
   685
02bb8761fcce Initial load
duke
parents:
diff changeset
   686
        if (currentPackage == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   687
            addClassInUse(currentClass,currentClass,currentPackage);
02bb8761fcce Initial load
duke
parents:
diff changeset
   688
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   689
            addClassInUse(currentClass,(currentPackage+"."+currentClass),currentPackage);
02bb8761fcce Initial load
duke
parents:
diff changeset
   690
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   691
02bb8761fcce Initial load
duke
parents:
diff changeset
   692
        // Add standard classes...
02bb8761fcce Initial load
duke
parents:
diff changeset
   693
02bb8761fcce Initial load
duke
parents:
diff changeset
   694
        addClassInUse("javax.rmi.CORBA.Util");
02bb8761fcce Initial load
duke
parents:
diff changeset
   695
        addClassInUse(idRemote.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   696
        addClassInUse(idRemoteException.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   697
        addClassInUse(idOutputStream.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   698
        addClassInUse(idInputStream.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   699
        addClassInUse(idSystemException.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   700
        addClassInUse(idJavaIoSerializable.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   701
        addClassInUse(idCorbaORB.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   702
        addClassInUse(idReplyHandler.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   703
02bb8761fcce Initial load
duke
parents:
diff changeset
   704
        // Add stub/tie specific imports...
02bb8761fcce Initial load
duke
parents:
diff changeset
   705
02bb8761fcce Initial load
duke
parents:
diff changeset
   706
        if (stub) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   707
            addClassInUse(stubBaseClass);
02bb8761fcce Initial load
duke
parents:
diff changeset
   708
            addClassInUse("java.rmi.UnexpectedException");
02bb8761fcce Initial load
duke
parents:
diff changeset
   709
            addClassInUse(idRemarshalException.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   710
            addClassInUse(idApplicationException.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   711
            if (localStubs) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   712
                addClassInUse("org.omg.CORBA.portable.ServantObject");
02bb8761fcce Initial load
duke
parents:
diff changeset
   713
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   714
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   715
            addClassInUse(type);
02bb8761fcce Initial load
duke
parents:
diff changeset
   716
            addClassInUse(tieBaseClass);
02bb8761fcce Initial load
duke
parents:
diff changeset
   717
            addClassInUse(idTieInterface.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   718
            addClassInUse(idBadMethodException.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   719
            addClassInUse(idPortableUnknownException.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   720
            addClassInUse(idJavaLangThrowable.toString());
02bb8761fcce Initial load
duke
parents:
diff changeset
   721
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   722
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   723
02bb8761fcce Initial load
duke
parents:
diff changeset
   724
    void addClassesInUse(CompoundType type, RemoteType[] interfaces) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   725
02bb8761fcce Initial load
duke
parents:
diff changeset
   726
        // Walk all methods and add types in use...
02bb8761fcce Initial load
duke
parents:
diff changeset
   727
02bb8761fcce Initial load
duke
parents:
diff changeset
   728
        CompoundType.Method[] methods = type.getMethods();
02bb8761fcce Initial load
duke
parents:
diff changeset
   729
        for (int i = 0; i < methods.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   730
            addClassInUse(methods[i].getReturnType());
02bb8761fcce Initial load
duke
parents:
diff changeset
   731
            addStubInUse(methods[i].getReturnType());
02bb8761fcce Initial load
duke
parents:
diff changeset
   732
            addClassInUse(methods[i].getArguments());
02bb8761fcce Initial load
duke
parents:
diff changeset
   733
            addStubInUse(methods[i].getArguments());
02bb8761fcce Initial load
duke
parents:
diff changeset
   734
            addClassInUse(methods[i].getExceptions());
02bb8761fcce Initial load
duke
parents:
diff changeset
   735
            // bug 4473859: Also include narrower subtypes for use
02bb8761fcce Initial load
duke
parents:
diff changeset
   736
            addClassInUse(methods[i].getImplExceptions());
02bb8761fcce Initial load
duke
parents:
diff changeset
   737
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   738
02bb8761fcce Initial load
duke
parents:
diff changeset
   739
        // If this is a stub, add all interfaces...
02bb8761fcce Initial load
duke
parents:
diff changeset
   740
02bb8761fcce Initial load
duke
parents:
diff changeset
   741
        if (interfaces != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   742
            addClassInUse(interfaces);
02bb8761fcce Initial load
duke
parents:
diff changeset
   743
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   744
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   745
02bb8761fcce Initial load
duke
parents:
diff changeset
   746
    void writePackageAndImports(IndentingWriter p) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   747
02bb8761fcce Initial load
duke
parents:
diff changeset
   748
        // Write package declaration...
02bb8761fcce Initial load
duke
parents:
diff changeset
   749
02bb8761fcce Initial load
duke
parents:
diff changeset
   750
        if (currentPackage != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   751
            p.pln("package " +
02bb8761fcce Initial load
duke
parents:
diff changeset
   752
                     Util.correctPackageName(
02bb8761fcce Initial load
duke
parents:
diff changeset
   753
                          currentPackage, false, standardPackage)
02bb8761fcce Initial load
duke
parents:
diff changeset
   754
                   + ";");
02bb8761fcce Initial load
duke
parents:
diff changeset
   755
            p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
   756
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   757
02bb8761fcce Initial load
duke
parents:
diff changeset
   758
        // Get imports into an array and sort them...
02bb8761fcce Initial load
duke
parents:
diff changeset
   759
02bb8761fcce Initial load
duke
parents:
diff changeset
   760
        String[] names = new String[importCount];
02bb8761fcce Initial load
duke
parents:
diff changeset
   761
        int index = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   762
        for (Enumeration e = imports.elements() ; e.hasMoreElements() ;) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   763
            String it = (String) e.nextElement();
02bb8761fcce Initial load
duke
parents:
diff changeset
   764
            if (it != NO_IMPORT) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   765
                names[index++] = it;
02bb8761fcce Initial load
duke
parents:
diff changeset
   766
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   767
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   768
02bb8761fcce Initial load
duke
parents:
diff changeset
   769
        Arrays.sort(names,new StringComparator());
02bb8761fcce Initial load
duke
parents:
diff changeset
   770
02bb8761fcce Initial load
duke
parents:
diff changeset
   771
        // Now dump them out...
02bb8761fcce Initial load
duke
parents:
diff changeset
   772
02bb8761fcce Initial load
duke
parents:
diff changeset
   773
        for (int i = 0; i < importCount; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   774
            if(
02bb8761fcce Initial load
duke
parents:
diff changeset
   775
               Util.isOffendingPackage(names[i])
02bb8761fcce Initial load
duke
parents:
diff changeset
   776
               && names[i].endsWith("_Stub")
02bb8761fcce Initial load
duke
parents:
diff changeset
   777
               && String.valueOf(names[i].charAt(names[i].lastIndexOf(".")+1)).equals("_")
02bb8761fcce Initial load
duke
parents:
diff changeset
   778
               ){
02bb8761fcce Initial load
duke
parents:
diff changeset
   779
                p.pln("import " + PackagePrefixChecker.packagePrefix()+names[i]+";");
02bb8761fcce Initial load
duke
parents:
diff changeset
   780
            } else{
02bb8761fcce Initial load
duke
parents:
diff changeset
   781
                p.pln("import " + names[i] + ";");
02bb8761fcce Initial load
duke
parents:
diff changeset
   782
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   783
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   784
        p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
   785
02bb8761fcce Initial load
duke
parents:
diff changeset
   786
        // Include offending packages . . .
02bb8761fcce Initial load
duke
parents:
diff changeset
   787
        if ( currentPackage!=null && Util.isOffendingPackage(currentPackage) ){
02bb8761fcce Initial load
duke
parents:
diff changeset
   788
            p.pln("import " + currentPackage +".*  ;");
02bb8761fcce Initial load
duke
parents:
diff changeset
   789
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   790
        p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
   791
02bb8761fcce Initial load
duke
parents:
diff changeset
   792
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   793
02bb8761fcce Initial load
duke
parents:
diff changeset
   794
    boolean implementsRemote(CompoundType theType) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   795
        boolean result = theType.isType(TYPE_REMOTE) && !theType.isType(TYPE_ABSTRACT);
02bb8761fcce Initial load
duke
parents:
diff changeset
   796
02bb8761fcce Initial load
duke
parents:
diff changeset
   797
        // If theType is not remote, look at all the interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
   798
        // until we find one that is...
02bb8761fcce Initial load
duke
parents:
diff changeset
   799
02bb8761fcce Initial load
duke
parents:
diff changeset
   800
        if (!result) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   801
            InterfaceType[] interfaces = theType.getInterfaces();
02bb8761fcce Initial load
duke
parents:
diff changeset
   802
            for (int i = 0; i < interfaces.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   803
                result = implementsRemote(interfaces[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   804
                if (result) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   805
                    break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   806
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   807
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   808
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   809
02bb8761fcce Initial load
duke
parents:
diff changeset
   810
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   811
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   812
02bb8761fcce Initial load
duke
parents:
diff changeset
   813
    void writeStubMethod (  IndentingWriter p,
02bb8761fcce Initial load
duke
parents:
diff changeset
   814
                            CompoundType.Method method,
02bb8761fcce Initial load
duke
parents:
diff changeset
   815
                            CompoundType theType) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   816
02bb8761fcce Initial load
duke
parents:
diff changeset
   817
        // Wtite the method declaration and opening brace...
02bb8761fcce Initial load
duke
parents:
diff changeset
   818
02bb8761fcce Initial load
duke
parents:
diff changeset
   819
        String methodName = method.getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   820
        String methodIDLName = method.getIDLName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   821
02bb8761fcce Initial load
duke
parents:
diff changeset
   822
        Type paramTypes[] = method.getArguments();
02bb8761fcce Initial load
duke
parents:
diff changeset
   823
        String paramNames[] = method.getArgumentNames();
02bb8761fcce Initial load
duke
parents:
diff changeset
   824
        Type returnType = method.getReturnType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   825
        ValueType[] exceptions = getStubExceptions(method,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   826
02bb8761fcce Initial load
duke
parents:
diff changeset
   827
        addNamesInUse(method);
02bb8761fcce Initial load
duke
parents:
diff changeset
   828
        addNameInUse("_type_ids");
02bb8761fcce Initial load
duke
parents:
diff changeset
   829
02bb8761fcce Initial load
duke
parents:
diff changeset
   830
        String objName = testUtil(getName(returnType), returnType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   831
        p.p("public " + objName + " " + methodName + "(");
02bb8761fcce Initial load
duke
parents:
diff changeset
   832
        for(int i = 0; i < paramTypes.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   833
            if (i > 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   834
                p.p(", ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   835
            p.p(getName(paramTypes[i]) + " " + paramNames[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   836
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   837
02bb8761fcce Initial load
duke
parents:
diff changeset
   838
        p.p(")");
02bb8761fcce Initial load
duke
parents:
diff changeset
   839
        if (exceptions.length > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   840
            p.p(" throws ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   841
            for(int i = 0; i < exceptions.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   842
                if (i > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   843
                    p.p(", ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   844
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   845
                // Added for Bug 4818753
02bb8761fcce Initial load
duke
parents:
diff changeset
   846
                p.p(getExceptionName(exceptions[i]));
02bb8761fcce Initial load
duke
parents:
diff changeset
   847
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   848
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   849
02bb8761fcce Initial load
duke
parents:
diff changeset
   850
        p.plnI(" {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   851
02bb8761fcce Initial load
duke
parents:
diff changeset
   852
        // Now create the method body...
02bb8761fcce Initial load
duke
parents:
diff changeset
   853
02bb8761fcce Initial load
duke
parents:
diff changeset
   854
        if (localStubs) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   855
            writeLocalStubMethodBody(p,method,theType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   856
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   857
            writeNonLocalStubMethodBody(p,method,theType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   858
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   859
02bb8761fcce Initial load
duke
parents:
diff changeset
   860
        // Close out the method...
02bb8761fcce Initial load
duke
parents:
diff changeset
   861
02bb8761fcce Initial load
duke
parents:
diff changeset
   862
        p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
   863
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   864
02bb8761fcce Initial load
duke
parents:
diff changeset
   865
02bb8761fcce Initial load
duke
parents:
diff changeset
   866
    void writeLocalStubMethodBody (IndentingWriter p,
02bb8761fcce Initial load
duke
parents:
diff changeset
   867
                                   CompoundType.Method method,
02bb8761fcce Initial load
duke
parents:
diff changeset
   868
                                   CompoundType theType) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   869
02bb8761fcce Initial load
duke
parents:
diff changeset
   870
        String objName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   871
        String paramNames[] = method.getArgumentNames();
02bb8761fcce Initial load
duke
parents:
diff changeset
   872
        Type returnType = method.getReturnType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   873
        ValueType[] exceptions = getStubExceptions(method,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   874
        String methodName = method.getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   875
        String methodIDLName = method.getIDLName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   876
02bb8761fcce Initial load
duke
parents:
diff changeset
   877
        p.plnI("if (!Util.isLocal(this)) {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   878
        writeNonLocalStubMethodBody(p,method,theType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   879
        p.pOlnI("} else {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   880
        String so = getVariableName("so");
02bb8761fcce Initial load
duke
parents:
diff changeset
   881
02bb8761fcce Initial load
duke
parents:
diff changeset
   882
        p.pln("ServantObject "+so+" = _servant_preinvoke(\""+methodIDLName+"\","+getName(theType)+".class);");
02bb8761fcce Initial load
duke
parents:
diff changeset
   883
        p.plnI("if ("+so+" == null) {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   884
        if (!returnType.isType(TYPE_VOID)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   885
            p.p("return ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   886
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   887
        p.p(methodName+"(");
02bb8761fcce Initial load
duke
parents:
diff changeset
   888
        for (int i = 0; i < paramNames.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   889
            if (i > 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   890
                p.p(", ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   891
            p.p(paramNames[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   892
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   893
        p.pln(");");
02bb8761fcce Initial load
duke
parents:
diff changeset
   894
        if (returnType.isType(TYPE_VOID)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   895
            p.pln( "return ;" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   896
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   897
02bb8761fcce Initial load
duke
parents:
diff changeset
   898
        p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
   899
        p.plnI("try {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   900
02bb8761fcce Initial load
duke
parents:
diff changeset
   901
        // Generate code to copy required arguments, and
02bb8761fcce Initial load
duke
parents:
diff changeset
   902
        // get back the names by which all arguments are known...
02bb8761fcce Initial load
duke
parents:
diff changeset
   903
02bb8761fcce Initial load
duke
parents:
diff changeset
   904
        String[] argNames = writeCopyArguments(method,p);
02bb8761fcce Initial load
duke
parents:
diff changeset
   905
02bb8761fcce Initial load
duke
parents:
diff changeset
   906
        // Now write the method...
02bb8761fcce Initial load
duke
parents:
diff changeset
   907
02bb8761fcce Initial load
duke
parents:
diff changeset
   908
        boolean copyReturn = mustCopy(returnType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   909
        String resultName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   910
        if (!returnType.isType(TYPE_VOID)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   911
            if (copyReturn) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   912
                resultName = getVariableName("result");
02bb8761fcce Initial load
duke
parents:
diff changeset
   913
                objName = testUtil(getName(returnType), returnType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   914
                p.p(objName+" "+resultName + " = ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   915
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   916
                p.p("return ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   917
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   918
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   919
        objName = testUtil(getName(theType), theType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   920
        p.p("(("+objName+")"+so+".servant)."+methodName+"(");
02bb8761fcce Initial load
duke
parents:
diff changeset
   921
02bb8761fcce Initial load
duke
parents:
diff changeset
   922
        for (int i = 0; i < argNames.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   923
            if (i > 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   924
                p.p(", ");
02bb8761fcce Initial load
duke
parents:
diff changeset
   925
            p.p(argNames[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   926
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   927
02bb8761fcce Initial load
duke
parents:
diff changeset
   928
        if (copyReturn) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   929
            p.pln(");");
02bb8761fcce Initial load
duke
parents:
diff changeset
   930
            objName = testUtil(getName(returnType), returnType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   931
            p.pln("return ("+objName+")Util.copyObject("+resultName+",_orb());");
02bb8761fcce Initial load
duke
parents:
diff changeset
   932
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   933
            p.pln(");");
02bb8761fcce Initial load
duke
parents:
diff changeset
   934
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   935
02bb8761fcce Initial load
duke
parents:
diff changeset
   936
        String e1 = getVariableName("ex");
02bb8761fcce Initial load
duke
parents:
diff changeset
   937
        String e2 = getVariableName("exCopy");
02bb8761fcce Initial load
duke
parents:
diff changeset
   938
        p.pOlnI("} catch (Throwable "+e1+") {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   939
02bb8761fcce Initial load
duke
parents:
diff changeset
   940
        p.pln("Throwable "+e2+" = (Throwable)Util.copyObject("+e1+",_orb());");
02bb8761fcce Initial load
duke
parents:
diff changeset
   941
        for(int i = 0; i < exceptions.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   942
            if (exceptions[i].getIdentifier() != idRemoteException &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   943
                exceptions[i].isType(TYPE_VALUE)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   944
                // Added for Bug 4818753
02bb8761fcce Initial load
duke
parents:
diff changeset
   945
                p.plnI("if ("+e2+" instanceof "+getExceptionName(exceptions[i])+") {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   946
                p.pln("throw ("+getExceptionName(exceptions[i])+")"+e2+";");
02bb8761fcce Initial load
duke
parents:
diff changeset
   947
                p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
   948
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   949
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   950
02bb8761fcce Initial load
duke
parents:
diff changeset
   951
        p.pln("throw Util.wrapException("+e2+");");
02bb8761fcce Initial load
duke
parents:
diff changeset
   952
        p.pOlnI("} finally {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   953
        p.pln("_servant_postinvoke("+so+");");
02bb8761fcce Initial load
duke
parents:
diff changeset
   954
        p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
   955
        p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
   956
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   957
02bb8761fcce Initial load
duke
parents:
diff changeset
   958
02bb8761fcce Initial load
duke
parents:
diff changeset
   959
    void writeNonLocalStubMethodBody (  IndentingWriter p,
02bb8761fcce Initial load
duke
parents:
diff changeset
   960
                                        CompoundType.Method method,
02bb8761fcce Initial load
duke
parents:
diff changeset
   961
                                        CompoundType theType) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   962
02bb8761fcce Initial load
duke
parents:
diff changeset
   963
        String methodName = method.getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   964
        String methodIDLName = method.getIDLName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   965
02bb8761fcce Initial load
duke
parents:
diff changeset
   966
        Type paramTypes[] = method.getArguments();
02bb8761fcce Initial load
duke
parents:
diff changeset
   967
        String paramNames[] = method.getArgumentNames();
02bb8761fcce Initial load
duke
parents:
diff changeset
   968
        Type returnType = method.getReturnType();
02bb8761fcce Initial load
duke
parents:
diff changeset
   969
        ValueType[] exceptions = getStubExceptions(method,true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   970
02bb8761fcce Initial load
duke
parents:
diff changeset
   971
        String in = getVariableName("in");
02bb8761fcce Initial load
duke
parents:
diff changeset
   972
        String out = getVariableName("out");
02bb8761fcce Initial load
duke
parents:
diff changeset
   973
        String ex = getVariableName("ex");
02bb8761fcce Initial load
duke
parents:
diff changeset
   974
02bb8761fcce Initial load
duke
parents:
diff changeset
   975
        // Decide if we need to use the new streams for
02bb8761fcce Initial load
duke
parents:
diff changeset
   976
        // any of the read calls...
02bb8761fcce Initial load
duke
parents:
diff changeset
   977
02bb8761fcce Initial load
duke
parents:
diff changeset
   978
        boolean needNewReadStreamClass = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   979
        for (int i = 0; i < exceptions.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   980
            if (exceptions[i].getIdentifier() != idRemoteException &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   981
                exceptions[i].isType(TYPE_VALUE) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   982
                needNewReadStreamClass(exceptions[i])) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   983
                needNewReadStreamClass = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   984
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   985
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   986
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   987
        if (!needNewReadStreamClass) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   988
            for (int i = 0; i < paramTypes.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   989
                if (needNewReadStreamClass(paramTypes[i])) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   990
                    needNewReadStreamClass = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   991
                    break;
02bb8761fcce Initial load
duke
parents:
diff changeset
   992
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   993
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   994
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   995
        if (!needNewReadStreamClass) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   996
            needNewReadStreamClass = needNewReadStreamClass(returnType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   997
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   998
02bb8761fcce Initial load
duke
parents:
diff changeset
   999
        // Decide if we need to use the new streams for
02bb8761fcce Initial load
duke
parents:
diff changeset
  1000
        // any of the write calls...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1001
02bb8761fcce Initial load
duke
parents:
diff changeset
  1002
        boolean needNewWriteStreamClass = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1003
        for (int i = 0; i < paramTypes.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1004
            if (needNewWriteStreamClass(paramTypes[i])) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1005
                needNewWriteStreamClass = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1006
                break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1007
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1008
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1009
02bb8761fcce Initial load
duke
parents:
diff changeset
  1010
        // Now write the method, inserting casts where needed...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1011
02bb8761fcce Initial load
duke
parents:
diff changeset
  1012
        p.plnI("try {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1013
        if (needNewReadStreamClass) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1014
            p.pln(idExtInputStream + " "+in+" = null;");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1015
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1016
            p.pln(idInputStream + " "+in+" = null;");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1017
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1018
        p.plnI("try {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1019
02bb8761fcce Initial load
duke
parents:
diff changeset
  1020
        String argStream = "null";
02bb8761fcce Initial load
duke
parents:
diff changeset
  1021
02bb8761fcce Initial load
duke
parents:
diff changeset
  1022
        if (needNewWriteStreamClass) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1023
            p.plnI(idExtOutputStream + " "+out+" = ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1024
            p.pln("(" + idExtOutputStream + ")");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1025
            p.pln("_request(\"" + methodIDLName + "\", true);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1026
            p.pO();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1027
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1028
            p.pln("OutputStream "+out+" = _request(\"" + methodIDLName + "\", true);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1029
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1030
02bb8761fcce Initial load
duke
parents:
diff changeset
  1031
        if (paramTypes.length > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1032
            writeMarshalArguments(p, out, paramTypes, paramNames);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1033
            p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1034
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1035
        argStream = out;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1036
02bb8761fcce Initial load
duke
parents:
diff changeset
  1037
        if (returnType.isType(TYPE_VOID)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1038
            p.pln("_invoke(" + argStream + ");" );
02bb8761fcce Initial load
duke
parents:
diff changeset
  1039
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1040
            if (needNewReadStreamClass) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1041
                p.plnI(in+" = (" + idExtInputStream + ")_invoke(" + argStream + ");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1042
                p.pO();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1043
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1044
                p.pln(in+" = _invoke(" + argStream + ");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1045
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1046
            p.p("return ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1047
            writeUnmarshalArgument(p, in, returnType, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1048
            p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1049
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1050
02bb8761fcce Initial load
duke
parents:
diff changeset
  1051
        // Handle ApplicationException...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1052
02bb8761fcce Initial load
duke
parents:
diff changeset
  1053
        p.pOlnI("} catch ("+getName(idApplicationException)+" "+ex+") {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1054
        if (needNewReadStreamClass) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1055
            p.pln(in + " = (" + idExtInputStream + ") "+ex+".getInputStream();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1056
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1057
            p.pln(in + " = "+ex+".getInputStream();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1058
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1059
02bb8761fcce Initial load
duke
parents:
diff changeset
  1060
        boolean idRead = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1061
        boolean idAllocated = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1062
        for(int i = 0; i < exceptions.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1063
            if (exceptions[i].getIdentifier() != idRemoteException) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1064
02bb8761fcce Initial load
duke
parents:
diff changeset
  1065
                // Is this our special-case IDLEntity exception?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1066
02bb8761fcce Initial load
duke
parents:
diff changeset
  1067
                if (exceptions[i].isIDLEntityException() && !exceptions[i].isCORBAUserException()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1068
02bb8761fcce Initial load
duke
parents:
diff changeset
  1069
                    // Yes.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1070
02bb8761fcce Initial load
duke
parents:
diff changeset
  1071
                    if (!idAllocated && !idRead) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1072
                        p.pln("String $_id = "+ex+".getId();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1073
                        idAllocated = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1074
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1075
02bb8761fcce Initial load
duke
parents:
diff changeset
  1076
                    String helperName = IDLNames.replace(exceptions[i].getQualifiedIDLName(false),"::",".");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1077
                    helperName += "Helper";
02bb8761fcce Initial load
duke
parents:
diff changeset
  1078
                    p.plnI("if ($_id.equals("+helperName+".id())) {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1079
                    p.pln("throw "+helperName+".read("+in+");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1080
02bb8761fcce Initial load
duke
parents:
diff changeset
  1081
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1082
02bb8761fcce Initial load
duke
parents:
diff changeset
  1083
                    // No.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1084
02bb8761fcce Initial load
duke
parents:
diff changeset
  1085
                    if (!idAllocated && !idRead) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1086
        p.pln("String $_id = "+in+".read_string();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1087
                        idAllocated = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1088
                        idRead = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1089
                    } else if (idAllocated && !idRead) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1090
                        p.pln("$_id = "+in+".read_string();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1091
                        idRead = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1092
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1093
                    p.plnI("if ($_id.equals(\""+getExceptionRepositoryID(exceptions[i])+"\")) {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1094
                    // Added for Bug 4818753
02bb8761fcce Initial load
duke
parents:
diff changeset
  1095
                    p.pln("throw ("+getExceptionName(exceptions[i])+") "+in+".read_value(" + getExceptionName(exceptions[i]) + ".class);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1096
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1097
                p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1098
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1099
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1100
        if (!idAllocated && !idRead) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1101
            p.pln("String $_id = "+in+".read_string();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1102
            idAllocated = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1103
            idRead = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1104
        } else if (idAllocated && !idRead) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1105
            p.pln("$_id = "+in+".read_string();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1106
            idRead = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1107
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1108
        p.pln("throw new UnexpectedException($_id);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1109
02bb8761fcce Initial load
duke
parents:
diff changeset
  1110
        // Handle RemarshalException...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1111
02bb8761fcce Initial load
duke
parents:
diff changeset
  1112
        p.pOlnI("} catch ("+getName(idRemarshalException)+" "+ex+") {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1113
        if (!returnType.isType(TYPE_VOID)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1114
            p.p("return ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1115
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1116
        p.p(methodName + "(");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1117
        for(int i = 0; i < paramTypes.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1118
            if (i > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1119
                p.p(",");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1120
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1121
            p.p(paramNames[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1122
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1123
        p.pln(");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1124
02bb8761fcce Initial load
duke
parents:
diff changeset
  1125
        // Ensure that we release the reply...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1126
02bb8761fcce Initial load
duke
parents:
diff changeset
  1127
        p.pOlnI("} finally {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1128
        p.pln("_releaseReply("+in+");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1129
02bb8761fcce Initial load
duke
parents:
diff changeset
  1130
        p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1131
02bb8761fcce Initial load
duke
parents:
diff changeset
  1132
        // Handle SystemException...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1133
02bb8761fcce Initial load
duke
parents:
diff changeset
  1134
        p.pOlnI("} catch (SystemException "+ex+") {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1135
        p.pln("throw Util.mapSystemException("+ex+");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1136
        p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1137
02bb8761fcce Initial load
duke
parents:
diff changeset
  1138
        // returnResult(p,returnType);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1139
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1140
02bb8761fcce Initial load
duke
parents:
diff changeset
  1141
    void allocateResult (IndentingWriter p,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1142
                         Type returnType) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1143
        if (!returnType.isType(TYPE_VOID)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1144
            String objName = testUtil(getName(returnType), returnType);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1145
            p.p(objName + " result = ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1146
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1147
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1148
02bb8761fcce Initial load
duke
parents:
diff changeset
  1149
    int getTypeCode(Type type) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1150
02bb8761fcce Initial load
duke
parents:
diff changeset
  1151
        int typeCode = type.getTypeCode();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1152
02bb8761fcce Initial load
duke
parents:
diff changeset
  1153
        // Handle late-breaking special case for
02bb8761fcce Initial load
duke
parents:
diff changeset
  1154
        // abstract IDL entities...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1155
02bb8761fcce Initial load
duke
parents:
diff changeset
  1156
        if ((type instanceof CompoundType) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  1157
            ((CompoundType)type).isAbstractBase()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1158
            typeCode = TYPE_ABSTRACT;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1159
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1160
02bb8761fcce Initial load
duke
parents:
diff changeset
  1161
        return typeCode;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1162
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1163
02bb8761fcce Initial load
duke
parents:
diff changeset
  1164
02bb8761fcce Initial load
duke
parents:
diff changeset
  1165
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1166
     * Write a snippet of Java code to marshal a value named "name" of
02bb8761fcce Initial load
duke
parents:
diff changeset
  1167
     * type "type" to the java.io.ObjectOutput stream named "stream".
02bb8761fcce Initial load
duke
parents:
diff changeset
  1168
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1169
    void writeMarshalArgument(IndentingWriter p,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1170
                              String streamName,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1171
                              Type type, String name) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1172
02bb8761fcce Initial load
duke
parents:
diff changeset
  1173
        int typeCode = getTypeCode(type);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1174
02bb8761fcce Initial load
duke
parents:
diff changeset
  1175
        switch (typeCode) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1176
        case TYPE_BOOLEAN:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1177
            p.p(streamName + ".write_boolean(" + name + ");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1178
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1179
        case TYPE_BYTE:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1180
            p.p(streamName + ".write_octet(" + name + ");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1181
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1182
        case TYPE_CHAR:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1183
            p.p(streamName + ".write_wchar(" + name + ");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1184
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1185
        case TYPE_SHORT:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1186
            p.p(streamName + ".write_short(" + name + ");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1187
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1188
        case TYPE_INT:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1189
            p.p(streamName + ".write_long(" + name + ");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1190
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1191
        case TYPE_LONG:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1192
            p.p(streamName + ".write_longlong(" + name + ");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1193
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1194
        case TYPE_FLOAT:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1195
            p.p(streamName + ".write_float(" + name + ");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1196
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1197
        case TYPE_DOUBLE:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1198
            p.p(streamName + ".write_double(" + name + ");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1199
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1200
        case TYPE_STRING:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1201
            p.p(streamName + ".write_value(" + name + "," + getName(type) + ".class);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1202
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1203
        case TYPE_ANY:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1204
            p.p("Util.writeAny("+ streamName + "," + name + ");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1205
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1206
        case TYPE_CORBA_OBJECT:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1207
            p.p(streamName + ".write_Object(" + name + ");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1208
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1209
        case TYPE_REMOTE:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1210
            p.p("Util.writeRemoteObject("+ streamName + "," + name + ");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1211
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1212
        case TYPE_ABSTRACT:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1213
            p.p("Util.writeAbstractObject("+ streamName + "," + name + ");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1214
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1215
        case TYPE_NC_INTERFACE:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1216
            p.p(streamName + ".write_value((Serializable)" + name + "," + getName(type) + ".class);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1217
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1218
        case TYPE_VALUE:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1219
            p.p(streamName + ".write_value(" + name + "," + getName(type) + ".class);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1220
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1221
        case TYPE_IMPLEMENTATION:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1222
            p.p(streamName + ".write_value((Serializable)" + name + "," + getName(type) + ".class);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1223
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1224
        case TYPE_NC_CLASS:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1225
            p.p(streamName + ".write_value((Serializable)" + name + "," + getName(type) + ".class);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1226
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1227
        case TYPE_ARRAY:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1228
            castArray = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1229
            p.p(streamName + ".write_value(cast_array(" + name + ")," + getName(type) + ".class);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1230
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1231
        case TYPE_JAVA_RMI_REMOTE:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1232
            p.p("Util.writeRemoteObject("+ streamName + "," + name + ");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1233
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1234
        default:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1235
            throw new Error("unexpected type code: " + typeCode);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1236
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1237
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1238
02bb8761fcce Initial load
duke
parents:
diff changeset
  1239
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1240
     * Write a snippet of Java code to unmarshal a value of type "type"
02bb8761fcce Initial load
duke
parents:
diff changeset
  1241
     * from the java.io.ObjectInput stream named "stream" into a variable
02bb8761fcce Initial load
duke
parents:
diff changeset
  1242
     * named "name" (if "name" is null, the value in unmarshalled and
02bb8761fcce Initial load
duke
parents:
diff changeset
  1243
     * discarded).
02bb8761fcce Initial load
duke
parents:
diff changeset
  1244
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1245
    void writeUnmarshalArgument(IndentingWriter p,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1246
                                String streamName,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1247
                                Type type,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1248
                                String name) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1249
02bb8761fcce Initial load
duke
parents:
diff changeset
  1250
        int typeCode = getTypeCode(type);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1251
02bb8761fcce Initial load
duke
parents:
diff changeset
  1252
        if (name != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1253
            p.p(name + " = ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1254
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1255
02bb8761fcce Initial load
duke
parents:
diff changeset
  1256
        switch (typeCode) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1257
        case TYPE_BOOLEAN:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1258
            p.p(streamName + ".read_boolean();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1259
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1260
        case TYPE_BYTE:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1261
            p.p(streamName + ".read_octet();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1262
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1263
        case TYPE_CHAR:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1264
            p.p(streamName + ".read_wchar();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1265
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1266
        case TYPE_SHORT:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1267
            p.p(streamName + ".read_short();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1268
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1269
        case TYPE_INT:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1270
            p.p(streamName + ".read_long();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1271
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1272
        case TYPE_LONG:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1273
            p.p(streamName + ".read_longlong();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1274
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1275
        case TYPE_FLOAT:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1276
            p.p(streamName + ".read_float();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1277
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1278
        case TYPE_DOUBLE:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1279
            p.p(streamName + ".read_double();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1280
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1281
        case TYPE_STRING:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1282
            p.p("(String) " + streamName + ".read_value(" + getName(type) + ".class);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1283
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1284
        case TYPE_ANY:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1285
            if (type.getIdentifier() != idJavaLangObject) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1286
                p.p("(" + getName(type) + ") ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1287
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1288
            p.p("Util.readAny(" + streamName + ");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1289
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1290
        case TYPE_CORBA_OBJECT:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1291
            if (type.getIdentifier() == idCorbaObject) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1292
                p.p("(" + getName(type) + ") " + streamName + ".read_Object();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1293
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1294
                p.p("(" + getName(type) + ") " + streamName + ".read_Object(" + getStubName(type) + ".class);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1295
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1296
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1297
        case TYPE_REMOTE:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1298
            String objName = testUtil(getName(type), type);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1299
            p.p("(" + objName + ") " +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1300
                "PortableRemoteObject.narrow(" + streamName + ".read_Object(), " + objName + ".class);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1301
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1302
        case TYPE_ABSTRACT:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1303
            p.p("(" + getName(type) + ") " + streamName + ".read_abstract_interface();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1304
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1305
        case TYPE_NC_INTERFACE:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1306
            p.p("(" + getName(type) + ") " + streamName + ".read_value(" + getName(type) + ".class);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1307
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1308
        case TYPE_VALUE:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1309
            p.p("(" + getName(type) + ") " + streamName + ".read_value(" + getName(type) + ".class);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1310
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1311
        case TYPE_IMPLEMENTATION:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1312
            p.p("(" + getName(type) + ") " + streamName + ".read_value(" + getName(type) + ".class);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1313
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1314
        case TYPE_NC_CLASS:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1315
            p.p("(" + getName(type) + ") " + streamName + ".read_value(" + getName(type) + ".class);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1316
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1317
        case TYPE_ARRAY:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1318
            p.p("(" + getName(type) + ") " + streamName + ".read_value(" + getName(type) + ".class);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1319
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1320
        case TYPE_JAVA_RMI_REMOTE:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1321
            p.p("(" + getName(type) + ") " +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1322
                "PortableRemoteObject.narrow(" + streamName + ".read_Object(), " + getName(type) + ".class);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1323
            //      p.p("(" + getName(type) + ") " + streamName + ".read_Object(" + getStubName(type) + ".class);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1324
            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1325
        default:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1326
            throw new Error("unexpected type code: " + typeCode);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1327
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1328
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1329
02bb8761fcce Initial load
duke
parents:
diff changeset
  1330
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1331
     * Get a list of all the RepositoryIDs for interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
  1332
     * implemented directly or indirectly by theType. In the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1333
     * case of an  ImplementationType which implements 2 or
02bb8761fcce Initial load
duke
parents:
diff changeset
  1334
     * more remote interfaces, this list will begin with the
02bb8761fcce Initial load
duke
parents:
diff changeset
  1335
     * Identifier for the implementation (see section 5.9 in
02bb8761fcce Initial load
duke
parents:
diff changeset
  1336
     * the Java -> IDL mapping). Ensures that the most derived
02bb8761fcce Initial load
duke
parents:
diff changeset
  1337
     * type is first in the list because the IOR is generated
02bb8761fcce Initial load
duke
parents:
diff changeset
  1338
     * using that entry in the _ids array.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1339
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1340
    String[] getAllRemoteRepIDs (CompoundType theType) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1341
02bb8761fcce Initial load
duke
parents:
diff changeset
  1342
        String[] result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1343
02bb8761fcce Initial load
duke
parents:
diff changeset
  1344
        // Collect up all the (inherited) remote interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
  1345
        // (ignores all the 'special' interfaces: Remote,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1346
        // Serializable, Externalizable)...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1347
02bb8761fcce Initial load
duke
parents:
diff changeset
  1348
        Type[] types = collectAllRemoteInterfaces(theType);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1349
02bb8761fcce Initial load
duke
parents:
diff changeset
  1350
        int length = types.length;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1351
        boolean haveImpl = theType instanceof ImplementationType;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1352
        InterfaceType[] interfaces = theType.getInterfaces();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1353
        int remoteCount = countRemote(interfaces,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1354
        int offset = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1355
02bb8761fcce Initial load
duke
parents:
diff changeset
  1356
        // Do we have an implementation type that implements
02bb8761fcce Initial load
duke
parents:
diff changeset
  1357
        // more than one remote interface?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1358
02bb8761fcce Initial load
duke
parents:
diff changeset
  1359
        if (haveImpl && remoteCount > 1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1360
02bb8761fcce Initial load
duke
parents:
diff changeset
  1361
            // Yes, so we need to insert it at the beginning...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1362
02bb8761fcce Initial load
duke
parents:
diff changeset
  1363
            result = new String[length + 1];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1364
            result[0] = getRepositoryID(theType);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1365
            offset = 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1366
02bb8761fcce Initial load
duke
parents:
diff changeset
  1367
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1368
02bb8761fcce Initial load
duke
parents:
diff changeset
  1369
            // No.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1370
02bb8761fcce Initial load
duke
parents:
diff changeset
  1371
            result = new String[length];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1372
02bb8761fcce Initial load
duke
parents:
diff changeset
  1373
            // Here we need to ensure that the most derived
02bb8761fcce Initial load
duke
parents:
diff changeset
  1374
            // interface ends up being first in the list. If
02bb8761fcce Initial load
duke
parents:
diff changeset
  1375
            // there is only one, we're done.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1376
02bb8761fcce Initial load
duke
parents:
diff changeset
  1377
            if (length > 1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1378
02bb8761fcce Initial load
duke
parents:
diff changeset
  1379
                // First, decide what the most derived type is...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1380
02bb8761fcce Initial load
duke
parents:
diff changeset
  1381
                String mostDerived = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1382
02bb8761fcce Initial load
duke
parents:
diff changeset
  1383
                if (haveImpl) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1384
02bb8761fcce Initial load
duke
parents:
diff changeset
  1385
                    // If we get here, we know that there is only one
02bb8761fcce Initial load
duke
parents:
diff changeset
  1386
                    // direct remote interface, so just find it...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1387
02bb8761fcce Initial load
duke
parents:
diff changeset
  1388
                    for (int i = 0; i < interfaces.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1389
                        if (interfaces[i].isType(TYPE_REMOTE)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1390
                            mostDerived = interfaces[i].getRepositoryID();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1391
                            break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1392
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1393
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1394
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1395
02bb8761fcce Initial load
duke
parents:
diff changeset
  1396
                    // If we get here we know that theType is a RemoteType
02bb8761fcce Initial load
duke
parents:
diff changeset
  1397
                    // so just use its id...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1398
02bb8761fcce Initial load
duke
parents:
diff changeset
  1399
                    mostDerived = theType.getRepositoryID();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1400
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1401
02bb8761fcce Initial load
duke
parents:
diff changeset
  1402
                // Now search types list and make sure mostDerived is
02bb8761fcce Initial load
duke
parents:
diff changeset
  1403
                // at index zero...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1404
02bb8761fcce Initial load
duke
parents:
diff changeset
  1405
                for (int i = 0; i < length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1406
                    if (types[i].getRepositoryID() == mostDerived) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1407
02bb8761fcce Initial load
duke
parents:
diff changeset
  1408
                        // Found it. Swap it if we need to...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1409
02bb8761fcce Initial load
duke
parents:
diff changeset
  1410
                        if (i > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1411
                            Type temp = types[0];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1412
                            types[0] = types[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1413
                            types[i] = temp;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1414
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1415
02bb8761fcce Initial load
duke
parents:
diff changeset
  1416
                        break;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1417
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1418
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1419
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1420
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1421
02bb8761fcce Initial load
duke
parents:
diff changeset
  1422
        // Now copy contents of the types array...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1423
02bb8761fcce Initial load
duke
parents:
diff changeset
  1424
        for (int i = 0; i < types.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1425
            result[offset++] = getRepositoryID(types[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1426
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1427
02bb8761fcce Initial load
duke
parents:
diff changeset
  1428
        // If we're supposed to, reverse the array. This
02bb8761fcce Initial load
duke
parents:
diff changeset
  1429
        // is only done when the -testReverseIDs flag is
02bb8761fcce Initial load
duke
parents:
diff changeset
  1430
        // passed, and that should ONLY be done for test
02bb8761fcce Initial load
duke
parents:
diff changeset
  1431
        // cases. This is an undocumented feature.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1432
02bb8761fcce Initial load
duke
parents:
diff changeset
  1433
        if (reverseIDs) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1434
            int start = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1435
            int end = result.length -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1436
            while (start < end) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1437
                String temp = result[start];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1438
                result[start++] = result[end];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1439
                result[end--] = temp;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1440
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1441
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1442
02bb8761fcce Initial load
duke
parents:
diff changeset
  1443
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1444
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1445
02bb8761fcce Initial load
duke
parents:
diff changeset
  1446
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1447
     * Collect all the inherited remote interfaces.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1448
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1449
    Type[] collectAllRemoteInterfaces (CompoundType theType) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1450
        Vector list = new Vector();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1451
02bb8761fcce Initial load
duke
parents:
diff changeset
  1452
        // Collect up all the Remote interfaces, and get an instance
02bb8761fcce Initial load
duke
parents:
diff changeset
  1453
        // for java.rmi.Remote...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1454
02bb8761fcce Initial load
duke
parents:
diff changeset
  1455
        addRemoteInterfaces(list,theType);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1456
02bb8761fcce Initial load
duke
parents:
diff changeset
  1457
        // Create and return our results...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1458
02bb8761fcce Initial load
duke
parents:
diff changeset
  1459
        Type[] result = new Type[list.size()];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1460
        list.copyInto(result);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1461
02bb8761fcce Initial load
duke
parents:
diff changeset
  1462
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1463
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1464
02bb8761fcce Initial load
duke
parents:
diff changeset
  1465
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1466
     * Add all the inherited remote interfaces to list.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1467
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1468
    void addRemoteInterfaces(Vector list, CompoundType theType) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1469
02bb8761fcce Initial load
duke
parents:
diff changeset
  1470
        if (theType != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1471
            if (theType.isInterface() && !list.contains(theType)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1472
                list.addElement(theType);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1473
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1474
02bb8761fcce Initial load
duke
parents:
diff changeset
  1475
            InterfaceType[] interfaces = theType.getInterfaces();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1476
            for (int i = 0; i < interfaces.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1477
02bb8761fcce Initial load
duke
parents:
diff changeset
  1478
                if (interfaces[i].isType(TYPE_REMOTE)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1479
                    addRemoteInterfaces(list,interfaces[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1480
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1481
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1482
02bb8761fcce Initial load
duke
parents:
diff changeset
  1483
            addRemoteInterfaces(list,theType.getSuperclass());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1484
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1485
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1486
02bb8761fcce Initial load
duke
parents:
diff changeset
  1487
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1488
     * Get a list of all the remote interfaces which this stub
02bb8761fcce Initial load
duke
parents:
diff changeset
  1489
     * should declare.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1490
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1491
    RemoteType[] getDirectRemoteInterfaces (CompoundType theType) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1492
02bb8761fcce Initial load
duke
parents:
diff changeset
  1493
        RemoteType[] result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1494
        InterfaceType[] interfaces = theType.getInterfaces();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1495
02bb8761fcce Initial load
duke
parents:
diff changeset
  1496
        // First, get a list of all the interfaces...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1497
02bb8761fcce Initial load
duke
parents:
diff changeset
  1498
        InterfaceType[] list;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1499
02bb8761fcce Initial load
duke
parents:
diff changeset
  1500
        // Because we can be passed either an ImplementationType
02bb8761fcce Initial load
duke
parents:
diff changeset
  1501
        // (which has interfaces) or a RemoteType (which is an
02bb8761fcce Initial load
duke
parents:
diff changeset
  1502
        // interface and may have interfaces) we must handle each
02bb8761fcce Initial load
duke
parents:
diff changeset
  1503
        // separately...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1504
02bb8761fcce Initial load
duke
parents:
diff changeset
  1505
        // Do we have an implementation type?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1506
02bb8761fcce Initial load
duke
parents:
diff changeset
  1507
        if (theType instanceof ImplementationType) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1508
02bb8761fcce Initial load
duke
parents:
diff changeset
  1509
            // Yes, so list is exactly what this type
02bb8761fcce Initial load
duke
parents:
diff changeset
  1510
            // implements and is correct already.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1511
02bb8761fcce Initial load
duke
parents:
diff changeset
  1512
            list = interfaces;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1513
02bb8761fcce Initial load
duke
parents:
diff changeset
  1514
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1515
02bb8761fcce Initial load
duke
parents:
diff changeset
  1516
            // No, so list is just theType...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1517
02bb8761fcce Initial load
duke
parents:
diff changeset
  1518
            list = new InterfaceType[1];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1519
            list[0] = (InterfaceType) theType;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1520
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1521
02bb8761fcce Initial load
duke
parents:
diff changeset
  1522
        // Ok, now count up the remote interfaces, allocate
02bb8761fcce Initial load
duke
parents:
diff changeset
  1523
        // our result and fill it in...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1524
02bb8761fcce Initial load
duke
parents:
diff changeset
  1525
        int remoteCount = countRemote(list,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1526
02bb8761fcce Initial load
duke
parents:
diff changeset
  1527
        if (remoteCount == 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1528
            throw new CompilerError("iiop.StubGenerator: No remote interfaces!");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1529
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1530
02bb8761fcce Initial load
duke
parents:
diff changeset
  1531
        result = new RemoteType[remoteCount];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1532
        int offset = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1533
        for (int i = 0; i < list.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1534
            if (list[i].isType(TYPE_REMOTE)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1535
                result[offset++] = (RemoteType)list[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1536
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1537
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1538
02bb8761fcce Initial load
duke
parents:
diff changeset
  1539
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1540
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1541
02bb8761fcce Initial load
duke
parents:
diff changeset
  1542
    int countRemote (Type[] list, boolean includeAbstract) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1543
        int remoteCount = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1544
        for (int i = 0; i < list.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1545
            if (list[i].isType(TYPE_REMOTE) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  1546
                (includeAbstract || !list[i].isType(TYPE_ABSTRACT))) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1547
                remoteCount++;
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 remoteCount;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1552
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1553
02bb8761fcce Initial load
duke
parents:
diff changeset
  1554
    void writeCastArray(IndentingWriter p) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1555
        if (castArray) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1556
            p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1557
            p.pln("// This method is required as a work-around for");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1558
            p.pln("// a bug in the JDK 1.1.6 verifier.");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1559
            p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1560
            p.plnI("private "+getName(idJavaIoSerializable)+" cast_array(Object obj) {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1561
            p.pln("return ("+getName(idJavaIoSerializable)+")obj;");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1562
            p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1563
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1564
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1565
    void writeIds(IndentingWriter p, CompoundType theType, boolean isTie
02bb8761fcce Initial load
duke
parents:
diff changeset
  1566
                  ) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1567
        p.plnI("private static final String[] _type_ids = {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1568
02bb8761fcce Initial load
duke
parents:
diff changeset
  1569
        String[] ids = getAllRemoteRepIDs(theType);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1570
02bb8761fcce Initial load
duke
parents:
diff changeset
  1571
        if (ids.length >0 ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1572
            for(int i = 0; i < ids.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1573
                if (i > 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1574
                    p.pln(", ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1575
                p.p("\"" + ids[i] + "\"");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1576
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1577
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1578
           // Must be an implementation which only implements Remote...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1579
           p.pln("\"\"");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1580
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1581
        String qname = theType.getQualifiedName() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1582
        boolean isTransactional = isTie && transactionalObjects.containsKey( qname ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1583
        // Add TransactionalObject if needed.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1584
        if (isTransactional) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1585
            // Have already written an id.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1586
            p.pln( ", " ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1587
            p.pln( "\"IDL:omg.org/CosTransactions/TransactionalObject:1.0\"" ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1588
        } else if (ids.length > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1589
            p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1590
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1591
        p.pOln("};");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1592
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1593
02bb8761fcce Initial load
duke
parents:
diff changeset
  1594
02bb8761fcce Initial load
duke
parents:
diff changeset
  1595
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  1596
     * Write the Tie for the remote class to a stream.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1597
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1598
    protected void writeTie(OutputType outputType,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1599
                            IndentingWriter p) throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1600
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1601
        CompoundType theType = (CompoundType) outputType.getType();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1602
        RemoteType[] remoteInterfaces = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1603
02bb8761fcce Initial load
duke
parents:
diff changeset
  1604
        // Write comment...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1605
        p.pln("// Tie class generated by rmic, do not edit.");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1606
        p.pln("// Contents subject to change without notice.");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1607
        p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1608
02bb8761fcce Initial load
duke
parents:
diff changeset
  1609
        // Set our standard classes...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1610
        setStandardClassesInUse(theType,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1611
02bb8761fcce Initial load
duke
parents:
diff changeset
  1612
        // Add classes for this type...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1613
        addClassesInUse(theType,remoteInterfaces);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1614
02bb8761fcce Initial load
duke
parents:
diff changeset
  1615
        // Write package and import statements...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1616
        writePackageAndImports(p);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1617
02bb8761fcce Initial load
duke
parents:
diff changeset
  1618
        // Declare the tie class.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1619
        p.p("public class " + currentClass + " extends " +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1620
            getName(tieBaseClass) + " implements Tie");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1621
02bb8761fcce Initial load
duke
parents:
diff changeset
  1622
        // Add java.rmi.Remote if this type does not implement it.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1623
        // This allows stubs for Abstract interfaces to be treated
02bb8761fcce Initial load
duke
parents:
diff changeset
  1624
        // uniformly...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1625
        if (!implementsRemote(theType)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1626
            p.pln(",");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1627
            p.p(getName("java.rmi.Remote"));
02bb8761fcce Initial load
duke
parents:
diff changeset
  1628
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1629
02bb8761fcce Initial load
duke
parents:
diff changeset
  1630
        p.plnI(" {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1631
02bb8761fcce Initial load
duke
parents:
diff changeset
  1632
        // Write data members...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1633
        p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1634
        p.pln("private " + getName(theType) + " target = null;");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1635
        p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1636
02bb8761fcce Initial load
duke
parents:
diff changeset
  1637
        // Write the ids...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1638
        writeIds( p, theType, true ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1639
02bb8761fcce Initial load
duke
parents:
diff changeset
  1640
        // Write setTarget method...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1641
        p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1642
        p.plnI("public void setTarget(Remote target) {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1643
        p.pln("this.target = (" + getName(theType) + ") target;");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1644
        p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1645
02bb8761fcce Initial load
duke
parents:
diff changeset
  1646
        // Write getTarget method...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1647
        p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1648
        p.plnI("public Remote getTarget() {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1649
        p.pln("return target;");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1650
        p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1651
02bb8761fcce Initial load
duke
parents:
diff changeset
  1652
        // Write thisObject method...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1653
        p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1654
        write_tie_thisObject_method(p,idCorbaObject);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1655
02bb8761fcce Initial load
duke
parents:
diff changeset
  1656
        // Write deactivate method...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1657
        p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1658
        write_tie_deactivate_method(p);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1659
02bb8761fcce Initial load
duke
parents:
diff changeset
  1660
        // Write get orb method...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1661
        p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1662
        p.plnI("public ORB orb() {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1663
        p.pln("return _orb();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1664
        p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1665
02bb8761fcce Initial load
duke
parents:
diff changeset
  1666
        // Write set orb method...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1667
        p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1668
        write_tie_orb_method(p);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1669
02bb8761fcce Initial load
duke
parents:
diff changeset
  1670
        // Write the _ids() method...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1671
        p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1672
        write_tie__ids_method(p);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1673
02bb8761fcce Initial load
duke
parents:
diff changeset
  1674
        // Get all the methods...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1675
        CompoundType.Method[] remoteMethods = theType.getMethods();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1676
02bb8761fcce Initial load
duke
parents:
diff changeset
  1677
        // Register all the argument names used, plus our
02bb8761fcce Initial load
duke
parents:
diff changeset
  1678
        // data member names...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1679
02bb8761fcce Initial load
duke
parents:
diff changeset
  1680
        addNamesInUse(remoteMethods);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1681
        addNameInUse("target");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1682
        addNameInUse("_type_ids");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1683
02bb8761fcce Initial load
duke
parents:
diff changeset
  1684
        // Write the _invoke method...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1685
        p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1686
02bb8761fcce Initial load
duke
parents:
diff changeset
  1687
        String in = getVariableName("in");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1688
        String _in = getVariableName("_in");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1689
        String ex = getVariableName("ex");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1690
        String method = getVariableName("method");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1691
        String reply = getVariableName("reply");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1692
02bb8761fcce Initial load
duke
parents:
diff changeset
  1693
        p.plnI("public OutputStream  _invoke(String "+method+", InputStream "+_in+", " +
02bb8761fcce Initial load
duke
parents:
diff changeset
  1694
               "ResponseHandler "+reply+") throws SystemException {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1695
02bb8761fcce Initial load
duke
parents:
diff changeset
  1696
        if (remoteMethods.length > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1697
            p.plnI("try {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1698
            p.plnI(idExtInputStream + " "+in+" = ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1699
            p.pln("(" + idExtInputStream + ") "+_in+";");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1700
            p.pO();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1701
02bb8761fcce Initial load
duke
parents:
diff changeset
  1702
            // See if we should use a hash table style
02bb8761fcce Initial load
duke
parents:
diff changeset
  1703
            // comparison...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1704
02bb8761fcce Initial load
duke
parents:
diff changeset
  1705
            StaticStringsHash hash = getStringsHash(remoteMethods);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1706
02bb8761fcce Initial load
duke
parents:
diff changeset
  1707
            if (hash != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1708
                p.plnI("switch ("+method+"."+hash.method+") {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1709
                for (int i = 0; i < hash.buckets.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1710
                    p.plnI("case "+hash.keys[i]+": ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1711
                    for (int j = 0; j < hash.buckets[i].length; j++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1712
                        CompoundType.Method current = remoteMethods[hash.buckets[i][j]];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1713
                        if (j > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1714
                            p.pO("} else ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1715
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1716
                        p.plnI("if ("+method+".equals(\""+ current.getIDLName() +"\")) {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1717
                        writeTieMethod(p, theType,current);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1718
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1719
                    p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1720
                    p.pO();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1721
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1722
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1723
                for(int i = 0; i < remoteMethods.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1724
                CompoundType.Method current = remoteMethods[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1725
                if (i > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1726
                    p.pO("} else ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1727
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1728
02bb8761fcce Initial load
duke
parents:
diff changeset
  1729
                p.plnI("if ("+method+".equals(\""+ current.getIDLName() +"\")) {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1730
                writeTieMethod(p, theType, current);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1731
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1732
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1733
02bb8761fcce Initial load
duke
parents:
diff changeset
  1734
            if (hash != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1735
                p.pI();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1736
                //        p.plnI("default:");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1737
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1738
                //   p.pOlnI("} else {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1739
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1740
            //              p.pln("throw new "+getName(idBadMethodException)+"();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1741
02bb8761fcce Initial load
duke
parents:
diff changeset
  1742
            if (hash != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1743
                p.pO();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1744
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1745
            p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1746
            p.pln("throw new "+getName(idBadMethodException)+"();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1747
02bb8761fcce Initial load
duke
parents:
diff changeset
  1748
            p.pOlnI("} catch ("+getName(idSystemException)+" "+ex+") {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1749
            p.pln("throw "+ex+";");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1750
02bb8761fcce Initial load
duke
parents:
diff changeset
  1751
            p.pOlnI("} catch ("+getName(idJavaLangThrowable)+" "+ex+") {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1752
            p.pln("throw new " + getName(idPortableUnknownException) + "("+ex+");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1753
            p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1754
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1755
            // No methods...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1756
02bb8761fcce Initial load
duke
parents:
diff changeset
  1757
            p.pln("throw new " + getName(idBadMethodException) + "();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1758
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1759
02bb8761fcce Initial load
duke
parents:
diff changeset
  1760
        p.pOln("}");            // end invoke
02bb8761fcce Initial load
duke
parents:
diff changeset
  1761
02bb8761fcce Initial load
duke
parents:
diff changeset
  1762
        // Write the cast array hack...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1763
02bb8761fcce Initial load
duke
parents:
diff changeset
  1764
        writeCastArray(p);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1765
02bb8761fcce Initial load
duke
parents:
diff changeset
  1766
        // End tie class...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1767
        p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1768
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1769
    public void catchWrongPolicy(IndentingWriter p) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1770
        p.pln("");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1771
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1772
    public void catchServantNotActive(IndentingWriter p) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1773
        p.pln("");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1774
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1775
    public void catchObjectNotActive(IndentingWriter p) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1776
        p.pln("");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1777
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1778
02bb8761fcce Initial load
duke
parents:
diff changeset
  1779
    public void write_tie_thisObject_method(IndentingWriter p,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1780
                                            Identifier idCorbaObject)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1781
        throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1782
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1783
        if(POATie){
02bb8761fcce Initial load
duke
parents:
diff changeset
  1784
            p.plnI("public " + idCorbaObject + " thisObject() {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1785
            /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1786
            p.pln("org.omg.CORBA.Object objref = null;");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1787
            p.pln("try{");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1788
            p.pln("objref = _poa().servant_to_reference(this);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1789
            p.pln("}catch (org.omg.PortableServer.POAPackage.WrongPolicy exception){");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1790
            catchWrongPolicy(p);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1791
            p.pln("}catch (org.omg.PortableServer.POAPackage.ServantNotActive exception){");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1792
            catchServantNotActive(p);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1793
            p.pln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1794
            p.pln("return objref;");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1795
            */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1796
            p.pln("return _this_object();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1797
            p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1798
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1799
            p.plnI("public " + idCorbaObject + " thisObject() {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1800
            p.pln("return this;");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1801
            p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1802
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1803
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1804
02bb8761fcce Initial load
duke
parents:
diff changeset
  1805
    public void write_tie_deactivate_method(IndentingWriter p)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1806
        throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1807
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1808
        if(POATie){
02bb8761fcce Initial load
duke
parents:
diff changeset
  1809
            p.plnI("public void deactivate() {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1810
            p.pln("try{");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1811
            p.pln("_poa().deactivate_object(_poa().servant_to_id(this));");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1812
            p.pln("}catch (org.omg.PortableServer.POAPackage.WrongPolicy exception){");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1813
            catchWrongPolicy(p);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1814
            p.pln("}catch (org.omg.PortableServer.POAPackage.ObjectNotActive exception){");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1815
            catchObjectNotActive(p);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1816
            p.pln("}catch (org.omg.PortableServer.POAPackage.ServantNotActive exception){");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1817
            catchServantNotActive(p);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1818
            p.pln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1819
            p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1820
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1821
            p.plnI("public void deactivate() {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1822
            p.pln("_orb().disconnect(this);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1823
            p.pln("_set_delegate(null);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1824
            p.pln("target = null;");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1825
            p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1826
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1827
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1828
02bb8761fcce Initial load
duke
parents:
diff changeset
  1829
    public void write_tie_orb_method(IndentingWriter p)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1830
        throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1831
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1832
        if(POATie){
02bb8761fcce Initial load
duke
parents:
diff changeset
  1833
        p.plnI("public void orb(ORB orb) {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1834
        /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1835
        p.pln("try{");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1836
        p.pln("orb.connect(_poa().servant_to_reference(this));");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1837
        p.pln("}catch (org.omg.PortableServer.POAPackage.WrongPolicy exception){");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1838
        catchWrongPolicy(p);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1839
        p.pln("}catch (org.omg.PortableServer.POAPackage.ServantNotActive exception){");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1840
        catchServantNotActive(p);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1841
        p.pln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1842
        */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1843
        p.pln("try {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1844
        p.pln("    ((org.omg.CORBA_2_3.ORB)orb).set_delegate(this);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1845
        p.pln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1846
        p.pln("catch(ClassCastException e) {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1847
        p.pln("    throw new org.omg.CORBA.BAD_PARAM");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1848
        p.pln("        (\"POA Servant requires an instance of org.omg.CORBA_2_3.ORB\");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1849
        p.pln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1850
        p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1851
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1852
        p.plnI("public void orb(ORB orb) {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1853
        p.pln("orb.connect(this);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1854
        p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1855
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1856
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1857
02bb8761fcce Initial load
duke
parents:
diff changeset
  1858
    public void write_tie__ids_method(IndentingWriter p)
02bb8761fcce Initial load
duke
parents:
diff changeset
  1859
        throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
  1860
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1861
        if(POATie){
02bb8761fcce Initial load
duke
parents:
diff changeset
  1862
        p.plnI("public String[] _all_interfaces(org.omg.PortableServer.POA poa, byte[] objectId){");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1863
        p.pln("return _type_ids;");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1864
        p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1865
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1866
        p.plnI("public String[] _ids() { ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1867
        p.pln("return _type_ids;");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1868
        p.pOln("}");
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
    StaticStringsHash getStringsHash (CompoundType.Method[] methods) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1874
        if (useHash && methods.length > 1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1875
            String[] methodNames = new String[methods.length];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1876
            for (int i = 0; i < methodNames.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1877
                methodNames[i] = methods[i].getIDLName();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1878
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1879
            return new StaticStringsHash(methodNames);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1880
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1881
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1882
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1883
02bb8761fcce Initial load
duke
parents:
diff changeset
  1884
    static boolean needNewReadStreamClass(Type type) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1885
        if (type.isType(TYPE_ABSTRACT)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1886
            return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1887
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1888
        // Handle late-breaking special case for
02bb8761fcce Initial load
duke
parents:
diff changeset
  1889
        // abstract IDL entities...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1890
        if ((type instanceof CompoundType) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  1891
            ((CompoundType)type).isAbstractBase()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1892
            return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1893
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1894
        return needNewWriteStreamClass(type);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1895
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1896
02bb8761fcce Initial load
duke
parents:
diff changeset
  1897
    static boolean needNewWriteStreamClass(Type type) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1898
        switch (type.getTypeCode()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1899
        case TYPE_VOID:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1900
        case TYPE_BOOLEAN:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1901
        case TYPE_BYTE:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1902
        case TYPE_CHAR:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1903
        case TYPE_SHORT:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1904
        case TYPE_INT:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1905
        case TYPE_LONG:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1906
        case TYPE_FLOAT:
02bb8761fcce Initial load
duke
parents:
diff changeset
  1907
        case TYPE_DOUBLE:           return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1908
02bb8761fcce Initial load
duke
parents:
diff changeset
  1909
        case TYPE_STRING:           return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1910
        case TYPE_ANY:              return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1911
        case TYPE_CORBA_OBJECT:     return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1912
        case TYPE_REMOTE:           return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1913
        case TYPE_ABSTRACT:         return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1914
        case TYPE_NC_INTERFACE:     return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1915
        case TYPE_VALUE:            return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1916
        case TYPE_IMPLEMENTATION:   return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1917
        case TYPE_NC_CLASS:         return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1918
        case TYPE_ARRAY:            return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1919
        case TYPE_JAVA_RMI_REMOTE:  return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1920
02bb8761fcce Initial load
duke
parents:
diff changeset
  1921
        default: throw new Error("unexpected type code: " + type.getTypeCode());
02bb8761fcce Initial load
duke
parents:
diff changeset
  1922
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1923
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1924
02bb8761fcce Initial load
duke
parents:
diff changeset
  1925
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
  1926
     * Decide which arguments need to be copied and write
02bb8761fcce Initial load
duke
parents:
diff changeset
  1927
     * the copy code. Returns an array of argument names to
02bb8761fcce Initial load
duke
parents:
diff changeset
  1928
     * use to refer to either the copy or the original.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1929
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  1930
    String[] writeCopyArguments(CompoundType.Method method,
02bb8761fcce Initial load
duke
parents:
diff changeset
  1931
                                IndentingWriter p) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1932
02bb8761fcce Initial load
duke
parents:
diff changeset
  1933
        Type[] args = method.getArguments();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1934
        String[] origNames = method.getArgumentNames();
02bb8761fcce Initial load
duke
parents:
diff changeset
  1935
02bb8761fcce Initial load
duke
parents:
diff changeset
  1936
        // Copy the current parameter names to a result array...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1937
02bb8761fcce Initial load
duke
parents:
diff changeset
  1938
        String[] result = new String[origNames.length];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1939
        for (int i = 0; i < result.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1940
            result[i] = origNames[i];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1941
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1942
02bb8761fcce Initial load
duke
parents:
diff changeset
  1943
        // Decide which arguments must be copied, if any. If
02bb8761fcce Initial load
duke
parents:
diff changeset
  1944
        // any of the arguments are types for which a 'real' copy
02bb8761fcce Initial load
duke
parents:
diff changeset
  1945
        // will be done, rather than just an autoConnect, set
02bb8761fcce Initial load
duke
parents:
diff changeset
  1946
        // realCopy = true. Note that abstract types may only
02bb8761fcce Initial load
duke
parents:
diff changeset
  1947
        // need autoConnect, but we cannot know that at compile
02bb8761fcce Initial load
duke
parents:
diff changeset
  1948
        // time...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1949
02bb8761fcce Initial load
duke
parents:
diff changeset
  1950
        boolean realCopy = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1951
        boolean[] copyArg = new boolean[args.length];
02bb8761fcce Initial load
duke
parents:
diff changeset
  1952
        int copyCount = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1953
        int firstCopiedArg = 0; // Only used in single copy case.  It is only the first arg that
02bb8761fcce Initial load
duke
parents:
diff changeset
  1954
                                // needs copying IF copyCount == 1.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1955
02bb8761fcce Initial load
duke
parents:
diff changeset
  1956
        for (int i = 0; i < args.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1957
            if (mustCopy(args[i])) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1958
                copyArg[i] = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1959
                copyCount++;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1960
                firstCopiedArg = i;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1961
                if (args[i].getTypeCode() != TYPE_REMOTE &&
02bb8761fcce Initial load
duke
parents:
diff changeset
  1962
                    args[i].getTypeCode() != TYPE_IMPLEMENTATION) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1963
                    realCopy = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1964
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1965
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1966
                copyArg[i] = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1967
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1968
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1969
02bb8761fcce Initial load
duke
parents:
diff changeset
  1970
        // Do we have any types which must be copied?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1971
        if (copyCount > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1972
            // Yes. Are we only doing the copy to ensure
02bb8761fcce Initial load
duke
parents:
diff changeset
  1973
            // that autoConnect occurs?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1974
            if (realCopy) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1975
                // Nope. We need to go back thru the list and
02bb8761fcce Initial load
duke
parents:
diff changeset
  1976
                // mark any strings so that they will be copied
02bb8761fcce Initial load
duke
parents:
diff changeset
  1977
                // to preserve any shared references...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1978
                for (int i = 0; i < args.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1979
                    if (args[i].getTypeCode() == TYPE_STRING) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1980
                        copyArg[i] = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1981
                        copyCount++;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1982
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1983
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1984
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1985
02bb8761fcce Initial load
duke
parents:
diff changeset
  1986
            // We're ready to generate code. Do we have more than
02bb8761fcce Initial load
duke
parents:
diff changeset
  1987
            // one to copy?
02bb8761fcce Initial load
duke
parents:
diff changeset
  1988
            if (copyCount > 1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1989
                // Generate a call to copyObjects...
02bb8761fcce Initial load
duke
parents:
diff changeset
  1990
                String arrayName = getVariableName("copies");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1991
                p.p("Object[] " + arrayName + " = Util.copyObjects(new Object[]{");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1992
                boolean first = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1993
                for (int i = 0; i < args.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1994
                    if (copyArg[i]) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1995
                        if (!first) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  1996
                            p.p(",");
02bb8761fcce Initial load
duke
parents:
diff changeset
  1997
                        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1998
                        first = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1999
                        p.p(origNames[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2000
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2001
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2002
                p.pln("},_orb());");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2003
02bb8761fcce Initial load
duke
parents:
diff changeset
  2004
                // For each of the types which was copied, create
02bb8761fcce Initial load
duke
parents:
diff changeset
  2005
                // a local temporary for it, updating the result
02bb8761fcce Initial load
duke
parents:
diff changeset
  2006
                // array with the new local parameter name...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2007
                int copyIndex = 0 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2008
                for (int i = 0; i < args.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2009
                    if (copyArg[i]) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2010
                        result[i] = getVariableName(result[i]+"Copy");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2011
                        p.pln( getName(args[i]) + " " + result[i] + " = (" + getName(args[i]) + ") " +
02bb8761fcce Initial load
duke
parents:
diff changeset
  2012
                               arrayName + "[" + copyIndex++ +"];");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2013
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2014
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2015
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2016
                // Generate a call to copyObject, updating the result
02bb8761fcce Initial load
duke
parents:
diff changeset
  2017
                // with the new local parameter name...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2018
                result[firstCopiedArg] = getVariableName(result[firstCopiedArg]+"Copy");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2019
                p.pln( getName(args[firstCopiedArg]) + " " + result[firstCopiedArg] + " = (" +
02bb8761fcce Initial load
duke
parents:
diff changeset
  2020
                       getName(args[firstCopiedArg]) + ") Util.copyObject(" +
02bb8761fcce Initial load
duke
parents:
diff changeset
  2021
                       origNames[firstCopiedArg] + ",_orb());");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2022
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2023
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2024
02bb8761fcce Initial load
duke
parents:
diff changeset
  2025
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2026
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2027
02bb8761fcce Initial load
duke
parents:
diff changeset
  2028
    static final String SINGLE_SLASH = "\\";
02bb8761fcce Initial load
duke
parents:
diff changeset
  2029
    static final String DOUBLE_SLASH = SINGLE_SLASH + SINGLE_SLASH;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2030
02bb8761fcce Initial load
duke
parents:
diff changeset
  2031
    String getRepositoryID(Type type) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2032
        return IDLNames.replace(type.getRepositoryID(), SINGLE_SLASH, DOUBLE_SLASH);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2033
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2034
02bb8761fcce Initial load
duke
parents:
diff changeset
  2035
    String getExceptionRepositoryID(Type type) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2036
        ClassType theType = (ClassType) type;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2037
        return IDLNames.getIDLRepositoryID(theType.getQualifiedIDLExceptionName(false));
02bb8761fcce Initial load
duke
parents:
diff changeset
  2038
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2039
02bb8761fcce Initial load
duke
parents:
diff changeset
  2040
    String getVariableName(String proposed) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2041
        while (namesInUse.contains(proposed)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2042
            proposed = "$" + proposed;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2043
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2044
02bb8761fcce Initial load
duke
parents:
diff changeset
  2045
        return proposed;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2046
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2047
02bb8761fcce Initial load
duke
parents:
diff changeset
  2048
    void addNamesInUse(CompoundType.Method[] methods) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2049
        for (int i = 0; i < methods.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2050
            addNamesInUse(methods[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2051
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2052
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2053
02bb8761fcce Initial load
duke
parents:
diff changeset
  2054
    void addNamesInUse(CompoundType.Method method) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2055
        String paramNames[] = method.getArgumentNames();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2056
        for (int i = 0; i < paramNames.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2057
            addNameInUse(paramNames[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2058
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2059
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2060
02bb8761fcce Initial load
duke
parents:
diff changeset
  2061
    void addNameInUse(String name) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2062
        namesInUse.add(name);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2063
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2064
02bb8761fcce Initial load
duke
parents:
diff changeset
  2065
    static boolean mustCopy(Type type) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2066
        switch (type.getTypeCode()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2067
        case TYPE_VOID:
02bb8761fcce Initial load
duke
parents:
diff changeset
  2068
        case TYPE_BOOLEAN:
02bb8761fcce Initial load
duke
parents:
diff changeset
  2069
        case TYPE_BYTE:
02bb8761fcce Initial load
duke
parents:
diff changeset
  2070
        case TYPE_CHAR:
02bb8761fcce Initial load
duke
parents:
diff changeset
  2071
        case TYPE_SHORT:
02bb8761fcce Initial load
duke
parents:
diff changeset
  2072
        case TYPE_INT:
02bb8761fcce Initial load
duke
parents:
diff changeset
  2073
        case TYPE_LONG:
02bb8761fcce Initial load
duke
parents:
diff changeset
  2074
        case TYPE_FLOAT:
02bb8761fcce Initial load
duke
parents:
diff changeset
  2075
        case TYPE_DOUBLE:
02bb8761fcce Initial load
duke
parents:
diff changeset
  2076
        case TYPE_STRING:           return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2077
02bb8761fcce Initial load
duke
parents:
diff changeset
  2078
        case TYPE_ANY:              return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2079
02bb8761fcce Initial load
duke
parents:
diff changeset
  2080
        case TYPE_CORBA_OBJECT:     return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2081
02bb8761fcce Initial load
duke
parents:
diff changeset
  2082
        case TYPE_REMOTE:
02bb8761fcce Initial load
duke
parents:
diff changeset
  2083
        case TYPE_ABSTRACT:
02bb8761fcce Initial load
duke
parents:
diff changeset
  2084
        case TYPE_NC_INTERFACE:
02bb8761fcce Initial load
duke
parents:
diff changeset
  2085
        case TYPE_VALUE:
02bb8761fcce Initial load
duke
parents:
diff changeset
  2086
        case TYPE_IMPLEMENTATION:
02bb8761fcce Initial load
duke
parents:
diff changeset
  2087
        case TYPE_NC_CLASS:
02bb8761fcce Initial load
duke
parents:
diff changeset
  2088
        case TYPE_ARRAY:
02bb8761fcce Initial load
duke
parents:
diff changeset
  2089
        case TYPE_JAVA_RMI_REMOTE:  return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2090
02bb8761fcce Initial load
duke
parents:
diff changeset
  2091
        default: throw new Error("unexpected type code: " + type.getTypeCode());
02bb8761fcce Initial load
duke
parents:
diff changeset
  2092
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2093
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2094
02bb8761fcce Initial load
duke
parents:
diff changeset
  2095
    ValueType[] getStubExceptions (CompoundType.Method method, boolean sort) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2096
02bb8761fcce Initial load
duke
parents:
diff changeset
  2097
        ValueType[] list = method.getFilteredStubExceptions(method.getExceptions());
02bb8761fcce Initial load
duke
parents:
diff changeset
  2098
02bb8761fcce Initial load
duke
parents:
diff changeset
  2099
        // Sort the list so that all org.omg.CORBA.UserException
02bb8761fcce Initial load
duke
parents:
diff changeset
  2100
        // subtypes are at the beginning of the list.  This ensures
02bb8761fcce Initial load
duke
parents:
diff changeset
  2101
        // that the stub will not call read_string() before calling
02bb8761fcce Initial load
duke
parents:
diff changeset
  2102
        // XXHelper.read().
02bb8761fcce Initial load
duke
parents:
diff changeset
  2103
02bb8761fcce Initial load
duke
parents:
diff changeset
  2104
        if (sort) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2105
            Arrays.sort(list,new UserExceptionComparator());
02bb8761fcce Initial load
duke
parents:
diff changeset
  2106
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2107
02bb8761fcce Initial load
duke
parents:
diff changeset
  2108
        return list;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2109
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2110
02bb8761fcce Initial load
duke
parents:
diff changeset
  2111
    ValueType[] getTieExceptions (CompoundType.Method method) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2112
        return method.getUniqueCatchList(method.getImplExceptions());
02bb8761fcce Initial load
duke
parents:
diff changeset
  2113
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2114
02bb8761fcce Initial load
duke
parents:
diff changeset
  2115
    void writeTieMethod(IndentingWriter p, CompoundType type,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2116
                        CompoundType.Method method) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2117
        String methodName = method.getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2118
        Type paramTypes[] = method.getArguments();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2119
        String paramNames[] = method.getArgumentNames();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2120
        Type returnType = method.getReturnType();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2121
        ValueType[] exceptions = getTieExceptions(method);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2122
        String in = getVariableName("in");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2123
        String ex = getVariableName("ex");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2124
        String out = getVariableName("out");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2125
        String reply = getVariableName("reply");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2126
02bb8761fcce Initial load
duke
parents:
diff changeset
  2127
        for (int i = 0; i < paramTypes.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2128
            p.p(getName(paramTypes[i])+" "+paramNames[i]+" = ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2129
            writeUnmarshalArgument(p, in, paramTypes[i], null);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2130
            p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2131
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2132
02bb8761fcce Initial load
duke
parents:
diff changeset
  2133
        boolean handleExceptions = exceptions != null;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2134
        boolean doReturn = !returnType.isType(TYPE_VOID);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2135
02bb8761fcce Initial load
duke
parents:
diff changeset
  2136
        if (handleExceptions && doReturn) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2137
            String objName = testUtil(getName(returnType), returnType);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2138
            p.pln(objName+" result;");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2139
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2140
02bb8761fcce Initial load
duke
parents:
diff changeset
  2141
        if (handleExceptions)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2142
            p.plnI("try {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2143
02bb8761fcce Initial load
duke
parents:
diff changeset
  2144
        if (doReturn) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2145
            if (handleExceptions) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2146
                p.p("result = ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2147
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2148
                p.p(getName(returnType)+" result = ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2149
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2150
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2151
02bb8761fcce Initial load
duke
parents:
diff changeset
  2152
        p.p("target."+methodName+"(");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2153
        for(int i = 0; i < paramNames.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2154
            if (i > 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2155
                p.p(", ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2156
            p.p(paramNames[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2157
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2158
        p.pln(");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2159
02bb8761fcce Initial load
duke
parents:
diff changeset
  2160
        if (handleExceptions) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2161
            for(int i = 0; i < exceptions.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2162
                p.pOlnI("} catch ("+getName(exceptions[i])+" "+ex+") {");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2163
02bb8761fcce Initial load
duke
parents:
diff changeset
  2164
                // Is this our IDLEntity Exception special case?
02bb8761fcce Initial load
duke
parents:
diff changeset
  2165
02bb8761fcce Initial load
duke
parents:
diff changeset
  2166
                if (exceptions[i].isIDLEntityException() && !exceptions[i].isCORBAUserException()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2167
02bb8761fcce Initial load
duke
parents:
diff changeset
  2168
                                // Yes...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2169
02bb8761fcce Initial load
duke
parents:
diff changeset
  2170
                    String helperName = IDLNames.replace(exceptions[i].getQualifiedIDLName(false),"::",".");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2171
                    helperName += "Helper";
02bb8761fcce Initial load
duke
parents:
diff changeset
  2172
                    p.pln(idOutputStream+" "+out +" = "+reply+".createExceptionReply();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2173
                    p.pln(helperName+".write("+out+","+ex+");");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2174
02bb8761fcce Initial load
duke
parents:
diff changeset
  2175
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2176
02bb8761fcce Initial load
duke
parents:
diff changeset
  2177
                                // No...
02bb8761fcce Initial load
duke
parents:
diff changeset
  2178
02bb8761fcce Initial load
duke
parents:
diff changeset
  2179
                    p.pln("String id = \"" + getExceptionRepositoryID(exceptions[i]) + "\";");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2180
                p.plnI(idExtOutputStream + " "+out+" = ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2181
                p.pln("(" + idExtOutputStream + ") "+reply+".createExceptionReply();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2182
                p.pOln(out+".write_string(id);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2183
                    p.pln(out+".write_value("+ex+"," + getName(exceptions[i]) + ".class);");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2184
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2185
02bb8761fcce Initial load
duke
parents:
diff changeset
  2186
                p.pln("return "+out+";");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2187
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2188
            p.pOln("}");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2189
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2190
02bb8761fcce Initial load
duke
parents:
diff changeset
  2191
        if (needNewWriteStreamClass(returnType)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2192
            p.plnI(idExtOutputStream + " "+out+" = ");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2193
            p.pln("(" + idExtOutputStream + ") "+reply+".createReply();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2194
            p.pO();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2195
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2196
            p.pln("OutputStream "+out+" = "+reply+".createReply();");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2197
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2198
02bb8761fcce Initial load
duke
parents:
diff changeset
  2199
        if (doReturn) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2200
            writeMarshalArgument(p, out, returnType, "result");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2201
            p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2202
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2203
02bb8761fcce Initial load
duke
parents:
diff changeset
  2204
        p.pln("return "+out+";");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2205
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2206
02bb8761fcce Initial load
duke
parents:
diff changeset
  2207
02bb8761fcce Initial load
duke
parents:
diff changeset
  2208
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2209
     * Write Java statements to marshal a series of values in order as
02bb8761fcce Initial load
duke
parents:
diff changeset
  2210
     * named in the "names" array, with types as specified in the "types"
02bb8761fcce Initial load
duke
parents:
diff changeset
  2211
     * array", to the java.io.ObjectOutput stream named "stream".
02bb8761fcce Initial load
duke
parents:
diff changeset
  2212
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2213
    void writeMarshalArguments(IndentingWriter p,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2214
                               String streamName,
02bb8761fcce Initial load
duke
parents:
diff changeset
  2215
                               Type[] types, String[] names)
02bb8761fcce Initial load
duke
parents:
diff changeset
  2216
        throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
  2217
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2218
        if (types.length != names.length) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2219
            throw new Error("paramter type and name arrays different sizes");
02bb8761fcce Initial load
duke
parents:
diff changeset
  2220
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2221
02bb8761fcce Initial load
duke
parents:
diff changeset
  2222
        for (int i = 0; i < types.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2223
            writeMarshalArgument(p, streamName, types[i], names[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2224
            if (i != types.length -1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2225
                p.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2226
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2227
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2228
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2229
02bb8761fcce Initial load
duke
parents:
diff changeset
  2230
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
  2231
     * Added for IASRI 4987274. Remote classes named "Util" were
02bb8761fcce Initial load
duke
parents:
diff changeset
  2232
     * getting confused with javax.rmi.CORBA.Util and the
02bb8761fcce Initial load
duke
parents:
diff changeset
  2233
     * unqualifiedName "Util".
02bb8761fcce Initial load
duke
parents:
diff changeset
  2234
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
  2235
    String testUtil(String objectName, Type ttype) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2236
        if (objectName.equals("Util")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2237
                String correctedName = (String)ttype.getPackageName() + "." + objectName;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2238
                return correctedName;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2239
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2240
                return objectName;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2241
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2242
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2243
}
02bb8761fcce Initial load
duke
parents:
diff changeset
  2244
02bb8761fcce Initial load
duke
parents:
diff changeset
  2245
class StringComparator implements java.util.Comparator {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2246
    public int compare(Object o1, Object o2) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2247
        String s1 = (String)o1;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2248
        String s2 = (String)o2;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2249
        return s1.compareTo(s2);
02bb8761fcce Initial load
duke
parents:
diff changeset
  2250
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2251
}
02bb8761fcce Initial load
duke
parents:
diff changeset
  2252
02bb8761fcce Initial load
duke
parents:
diff changeset
  2253
02bb8761fcce Initial load
duke
parents:
diff changeset
  2254
class UserExceptionComparator implements java.util.Comparator {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2255
    public int compare(Object o1, Object o2) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2256
        ValueType v1 = (ValueType)o1;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2257
        ValueType v2 = (ValueType)o2;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2258
        int result = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2259
        if (isUserException(v1)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2260
            if (!isUserException(v2)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2261
                result = -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2262
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2263
        } else if (isUserException(v2)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2264
            if (!isUserException(v1)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2265
                result = 1;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2266
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2267
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2268
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
  2269
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2270
02bb8761fcce Initial load
duke
parents:
diff changeset
  2271
    final boolean isUserException(ValueType it) {
02bb8761fcce Initial load
duke
parents:
diff changeset
  2272
        return it.isIDLEntityException() && !it.isCORBAUserException();
02bb8761fcce Initial load
duke
parents:
diff changeset
  2273
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  2274
}