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