corba/src/jdk.rmic/share/classes/sun/rmi/rmic/iiop/Type.java
author lana
Fri, 04 Aug 2017 23:29:08 +0000
changeset 46099 da187c3e130c
parent 30383 45960fdbe465
permissions -rw-r--r--
Added tag jdk-10+18 for changeset 0bdcd03d587a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
/*
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.util.Vector;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import java.util.Hashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import java.util.Enumeration;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import java.io.IOException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import sun.tools.java.ClassDefinition;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import sun.tools.java.ClassDeclaration;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import sun.tools.java.Identifier;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import sun.tools.java.ClassNotFound;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import sun.tools.java.CompilerError;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import sun.rmi.rmic.IndentingWriter;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import java.util.HashSet;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import com.sun.corba.se.impl.util.RepositoryId;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import sun.rmi.rmic.Names;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
 * Type is an abstract base class for a family of types which provide
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
 * conformance checking and name mapping as defined in the "Java to IDL
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
 * Mapping" OMG specification.  The family is composed of the following
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
 * fixed set of types:
30383
45960fdbe465 8079075: some docs cleanup for CORBA - part 1
avstepan
parents: 25862
diff changeset
    54
 * <pre>{@literal
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
 *                                              +- RemoteType <-- AbstractType
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
 *                                              |
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
 *                           +- InterfaceType <-+- SpecialInterfaceType
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
 *         +- PrimitiveType  |                  |
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
 *         |                 |                  +- NCInterfaceType
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
 *  Type <-+- CompoundType <-|
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
 *         |                 |                  +- ValueType
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
 *         +- ArrayType      |                  |
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
 *                           +- ClassType <-----+- ImplementationType
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
 *                                              |
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
 *                                              +- SpecialClassType
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
 *                                              |
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
 *                                              +- NCClassType
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
 *
30383
45960fdbe465 8079075: some docs cleanup for CORBA - part 1
avstepan
parents: 25862
diff changeset
    70
 * }</pre>
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
 * PrimitiveType represents a primitive or a void type.
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
 * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
 * CompoundType is an abstract base representing any non-special class
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
 * or interface type.
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
 * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
 * InterfaceType is an abstract base representing any non-special
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
 * interface type.
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
 * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
 * RemoteType represents any non-special interface which inherits
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
 * from java.rmi.Remote.
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
 * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
 * AbstractType represents any non-special interface which does not
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
 * inherit from java.rmi.Remote, for which all methods throw RemoteException.
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
 * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
 * SpecialInterfaceType represents any one of the following types:
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
 * <pre>
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
 *    java.rmi.Remote
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
 *    java.io.Serializable
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
 *    java.io.Externalizable
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
 * </pre>
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
 * all of which are treated as special cases.
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
 * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
 * NCInterfaceType represents any non-special, non-conforming interface.
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
 * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
 * ClassType is an abstract base representing any non-special class
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
 * type.
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
 * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
 * ValueType represents any non-special class which does inherit from
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
 * java.io.Serializable and does not inherit from java.rmi.Remote.
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
 * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
 * ImplementationType represents any non-special class which implements
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
 * one or more interfaces which inherit from java.rmi.Remote.
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
 * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
 * SpecialClassType represents any one of the following types:
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
 * <pre>
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
 *    java.lang.Object
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
 *    java.lang.String
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
 *    org.omg.CORBA.Object
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
 * </pre>
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
 * all of which are treated as special cases. For all but CORBA.Object,
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
 * the type must match exactly. For CORBA.Object, the type must either be
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
 * CORBA.Object or inherit from it.
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
 * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
 * NCClassType represents any non-special, non-conforming class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
 * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
 * ArrayType is a wrapper for any of the other types. The getElementType()
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
 * method can be used to get the array element type.  The getArrayDimension()
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
 * method can be used to get the array dimension.
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
 * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
 * <i><strong>NOTE:</strong> None of these types is multi-thread-safe</i>
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
 * @author      Bryan Atsatt
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
public abstract class Type implements sun.rmi.rmic.iiop.Constants, ContextElement, Cloneable {
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
    private int typeCode;
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
    private int fullTypeCode;
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
    private Identifier id;
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
    private String name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
    private String packageName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
    private String qualifiedName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
    private String idlName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
    private String[] idlModuleNames;
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
    private String qualifiedIDLName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
    private String repositoryID;
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
    private Class ourClass;
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
    private int status = STATUS_PENDING;
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
    protected BatchEnvironment env;     // Easy access for subclasses.
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
    protected ContextStack stack;       // Easy access for subclasses.
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
    protected boolean destroyed = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
    // Public Interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
     * Return the unqualified name for this type (e.g. com.acme.Dynamite would
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
     * return "Dynamite").
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
    public String getName() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
        return name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
     * Return the package of this type (e.g. com.acme.Dynamite would
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
     * return "com.acme"). Will return null if default package or
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
     * if this type is a primitive.
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
    public String getPackageName() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
        return packageName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
     * Return the fully qualified name of this type  (e.g. com.acme.Dynamite
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
     * would return "com.acme.Dynamite")
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
    public String getQualifiedName() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
        return qualifiedName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
     * Return signature for this type  (e.g. com.acme.Dynamite
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
     * would return "com.acme.Dynamite", byte = "B")
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
    public abstract String getSignature();
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
     * IDL_Naming
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
     * Return the unqualified IDL name of this type (e.g. com.acme.Dynamite would
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
     * return "Dynamite").
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
    public String getIDLName() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
        return idlName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
     * IDL_Naming
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
     * Return the IDL module name for this type (e.g. com.acme.Dynamite would return
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
     * a three element array of {"com","acme"). May be a zero length array if
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
     * there is no module name.
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
    public String[] getIDLModuleNames() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
        return idlModuleNames;
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
     * IDL_Naming
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
     * Return the fully qualified IDL name for this type (e.g. com.acme.Dynamite would
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
     * return "com::acme::Dynamite").
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
     * @param global If true, prepends "::".
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
    public String getQualifiedIDLName(boolean global) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
        if (global && getIDLModuleNames().length > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
            return IDL_NAME_SEPARATOR + qualifiedIDLName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
            return qualifiedIDLName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
     * Return the identifier for this type. May be qualified.
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
    public Identifier getIdentifier() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
        return id;
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
     * Return the repository ID for this type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
    public String getRepositoryID() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
        return repositoryID;
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
     * Return the repository ID for this "boxed" type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
    public String getBoxedRepositoryID() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
        return RepositoryId.createForJavaType(ourClass);
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
     * Return the Class for this type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
    public Class getClassInstance() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
        if (ourClass == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
            initClass();
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
        return ourClass;
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
     * Return the status of this type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
    public int getStatus() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
        return status;
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
     * Set the status of this type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
    public void setStatus(int status) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
        this.status = status;
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
     * Return the compiler environment for this type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
    public BatchEnvironment getEnv() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
        return env;
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
     * Get type code, without modifiers. Type codes are defined in sun.rmi.rmic.iiop.Constants.
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
    public int getTypeCode() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
        return typeCode;
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
     * Get type code, with modifiers. Type codes are defined in sun.rmi.rmic.iiop.Constants.
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
    public int getFullTypeCode() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
        return fullTypeCode;
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
     * Get type code modifiers. Type codes are defined in sun.rmi.rmic.iiop.Constants.
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
    public int getTypeCodeModifiers() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
        return fullTypeCode & TM_MASK;
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
     * Check for a certain type. Type codes are defined in sun.rmi.rmic.iiop.Constants.
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
     * Returns true if all of the bits in typeCodeMask are present in the full type code
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
     * of this object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
    public boolean isType(int typeCodeMask) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
        return (fullTypeCode & typeCodeMask) == typeCodeMask;
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
     * Like isType(), but returns true if <em>any</em> of the bits in typeCodeMask are
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
     * present in the full type code of this object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
    public boolean typeMatches(int typeCodeMask) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
        return (fullTypeCode & typeCodeMask) > 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
     * Return the fullTypeCode. If an array, returns the
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
     * type code from the element type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
    public int getRootTypeCode() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
        if (isArray()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
            return getElementType().getFullTypeCode();
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
            return fullTypeCode;
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
     * Return true if this type is-a InterfaceType.
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
    public boolean isInterface() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
        return (fullTypeCode & TM_INTERFACE) == TM_INTERFACE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
     * Return true if this type is-a ClassType.
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
    public boolean isClass() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
        return (fullTypeCode & TM_CLASS) == TM_CLASS;
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
     * Return true if this type is-a inner class or interface.
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
    public boolean isInner() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
        return (fullTypeCode & TM_INNER) == TM_INNER;
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
     * Return true if this type is-a SpecialInterfaceType.
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
    public boolean isSpecialInterface() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
        return (fullTypeCode & TM_SPECIAL_INTERFACE) == TM_SPECIAL_INTERFACE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
     * Return true if this type is-a SpecialClassType.
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
    public boolean isSpecialClass() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
        return (fullTypeCode & TM_SPECIAL_CLASS) == TM_SPECIAL_CLASS;
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
     * Return true if this type is-a CompoundType.
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
    public boolean isCompound() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
        return (fullTypeCode & TM_COMPOUND) == TM_COMPOUND;
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
     * Return true if this type is-a PrimitiveType.
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
    public boolean isPrimitive() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
        return (fullTypeCode & TM_PRIMITIVE) == TM_PRIMITIVE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
     * Return true if this type is-a ArrayType.
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
    public boolean isArray() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
        return (fullTypeCode & TYPE_ARRAY) == TYPE_ARRAY;
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
     * Return true if this type is a conforming type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
    public boolean isConforming() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
        return (fullTypeCode & TM_NON_CONFORMING) == TM_NON_CONFORMING;
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
     * Return a string representation of this type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
    public String toString () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
        return getQualifiedName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
     * Get element type. Returns null if not an array.
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
    public Type getElementType () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
     * Get array dimension. Returns zero if not an array.
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
    public int getArrayDimension () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
        return 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
     * Get brackets string. Returns "" if not an array.
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
    public String getArrayBrackets () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
        return "";
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
     * Equality check based on the string representation.
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
    public boolean equals(Object obj) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
        String us = toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
        String them = ((Type)obj).toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
        return us.equals(them);
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
     * Collect all the matching types referenced directly or indirectly
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
     * by this type, including itself.
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
     * @param typeCodeFilter The typeCode to use as a filter.
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
    public Type[] collectMatching (int typeCodeFilter) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
        return collectMatching(typeCodeFilter,new HashSet(env.allTypes.size()));
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
     * Collect all the matching types referenced directly or indirectly
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
     * by this type, including itself.
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
     * @param typeCodeFilter The typeCode to use as a filter.
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
     * @param alreadyChecked Contains types which have previously been checked
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
     * and will be ignored. Updated during collection.
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
    public Type[] collectMatching (int typeCodeFilter, HashSet alreadyChecked) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
        Vector matching = new Vector();
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
        // Fill up the list...
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
        addTypes(typeCodeFilter,alreadyChecked,matching);
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
        // Copy vector contents to array and return it...
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
        Type[] result = new Type[matching.size()];
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
        matching.copyInto(result);
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
     * Return a string describing this type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
    public abstract String getTypeDescription ();
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
     * Return the name of this type. For arrays, will include "[]" if useIDLNames == false.
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
     * @param useQualifiedNames If true, print qualified names; otherwise, print unqualified names.
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
     * @param useIDLNames If true, print IDL names; otherwise, print java names.
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
     * @param globalIDLNames If true and useIDLNames true, prepends "::".
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
    public String getTypeName ( boolean useQualifiedNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
                                boolean useIDLNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
                                boolean globalIDLNames) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
        if (useIDLNames) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
            if (useQualifiedNames) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
                return getQualifiedIDLName(globalIDLNames);
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
                return getIDLName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
            if (useQualifiedNames) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
                return getQualifiedName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
                return getName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
     * Print all types referenced directly or indirectly by this type which
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
     * match the filter.
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
     * @param writer The stream to print to.
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
     * @param typeCodeFilter The type codes to print.
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
     * @param useQualifiedNames If true, print qualified names; otherwise, print unqualified names.
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
     * @param useIDLNames If true, print IDL names; otherwise, print java names.
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
     * @param globalIDLNames If true and useIDLNames true, prepends "::".
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
    public void print ( IndentingWriter writer,
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
                        int typeCodeFilter,
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
                        boolean useQualifiedNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
                        boolean useIDLNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
                        boolean globalIDLNames) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
        Type[] theTypes = collectMatching(typeCodeFilter);
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
        print(writer,theTypes,useQualifiedNames,useIDLNames,globalIDLNames);
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
     * Print an array of types.
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
     * @param writer The stream to print to.
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
     * @param theTypes The types to print.
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
     * @param useQualifiedNames If true, print qualified names; otherwise, print unqualified names.
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
     * @param useIDLNames If true, print IDL names; otherwise, print java names.
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
     * @param globalIDLNames If true and useIDLNames true, prepends "::".
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
    public static void print (  IndentingWriter writer,
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
                                Type[] theTypes,
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
                                boolean useQualifiedNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
                                boolean useIDLNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
                                boolean globalIDLNames) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
        for (int i = 0; i < theTypes.length; i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
            theTypes[i].println(writer,useQualifiedNames,useIDLNames,globalIDLNames);
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
     * Print this type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
     * @param writer The stream to print to.
02bb8761fcce Initial load
duke
parents:
diff changeset
   522
     * @param useQualifiedNames If true, print qualified names; otherwise, print unqualified names.
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
     * @param useIDLNames If true, print IDL names; otherwise, print java names.
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
     * @param globalIDLNames If true and useIDLNames true, prepends "::".
02bb8761fcce Initial load
duke
parents:
diff changeset
   525
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
    public void print ( IndentingWriter writer,
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
                        boolean useQualifiedNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
                        boolean useIDLNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
                        boolean globalIDLNames) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
        printTypeName(writer,useQualifiedNames,useIDLNames,globalIDLNames);
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
     * Print this type, followed by a newline.
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
     * @param writer The stream to print to.
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
     * @param useQualifiedNames If true, print qualified names; otherwise, print unqualified names.
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
     * @param useIDLNames If true, print IDL names; otherwise, print java names.
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
     * @param globalIDLNames If true and useIDLNames true, prepends "::".
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
    public void println (       IndentingWriter writer,
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
                                boolean useQualifiedNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
                                boolean useIDLNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
                                boolean globalIDLNames) throws IOException  {
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
        print(writer,useQualifiedNames,useIDLNames,globalIDLNames);
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
        writer.pln();
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
     * Print the name of this type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
     * @param writer The stream to print to.
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
     * @param useQualifiedNames If true, print qualified names; otherwise, print unqualified names.
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
     * @param useIDLNames If true, print IDL names; otherwise, print java names.
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
     * @param globalIDLNames If true and useIDLNames true, prepends "::".
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
    public void printTypeName ( IndentingWriter writer,
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
                                boolean useQualifiedNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
                                boolean useIDLNames,
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
                                boolean globalIDLNames) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
        writer.p(getTypeName(useQualifiedNames,useIDLNames,globalIDLNames));
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   565
02bb8761fcce Initial load
duke
parents:
diff changeset
   566
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   567
     * Return context element name.
02bb8761fcce Initial load
duke
parents:
diff changeset
   568
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   569
    public String getElementName() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   570
        return getQualifiedName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   571
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   572
02bb8761fcce Initial load
duke
parents:
diff changeset
   573
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
   574
    // Subclass Interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
   575
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
   576
02bb8761fcce Initial load
duke
parents:
diff changeset
   577
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   578
     * Print the "opening" of the package or module of this type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   579
     * @param writer The stream to print to.
02bb8761fcce Initial load
duke
parents:
diff changeset
   580
     * @param useIDLNames If true, print IDL names; otherwise, print java names.
02bb8761fcce Initial load
duke
parents:
diff changeset
   581
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   582
    protected void printPackageOpen (   IndentingWriter writer,
02bb8761fcce Initial load
duke
parents:
diff changeset
   583
                                        boolean useIDLNames) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   584
02bb8761fcce Initial load
duke
parents:
diff changeset
   585
        if (useIDLNames) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   586
            String[] moduleNames = getIDLModuleNames();
02bb8761fcce Initial load
duke
parents:
diff changeset
   587
            for (int i = 0; i < moduleNames.length; i++ ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   588
                writer.plnI("module " + moduleNames[i] + " {");
02bb8761fcce Initial load
duke
parents:
diff changeset
   589
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   590
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   591
            String packageName = getPackageName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   592
            if (packageName != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   593
                writer.pln("package " + packageName + ";");
02bb8761fcce Initial load
duke
parents:
diff changeset
   594
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   595
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   596
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   597
02bb8761fcce Initial load
duke
parents:
diff changeset
   598
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   599
     * Get a type out of the table.
02bb8761fcce Initial load
duke
parents:
diff changeset
   600
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   601
    protected static Type getType (sun.tools.java.Type key, ContextStack stack) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   602
        return getType(key.toString(),stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
   603
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   604
02bb8761fcce Initial load
duke
parents:
diff changeset
   605
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   606
     * Get a type out of the table.
02bb8761fcce Initial load
duke
parents:
diff changeset
   607
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   608
    protected static Type getType (String key, ContextStack stack) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   609
        Type result = (Type) stack.getEnv().allTypes.get(key);
02bb8761fcce Initial load
duke
parents:
diff changeset
   610
02bb8761fcce Initial load
duke
parents:
diff changeset
   611
        if (result != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   612
            stack.traceExistingType(result);
02bb8761fcce Initial load
duke
parents:
diff changeset
   613
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   614
02bb8761fcce Initial load
duke
parents:
diff changeset
   615
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   616
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   617
02bb8761fcce Initial load
duke
parents:
diff changeset
   618
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   619
     * Remove a type from the table.
02bb8761fcce Initial load
duke
parents:
diff changeset
   620
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   621
    protected static void removeType (String key, ContextStack stack) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   622
        Type value = (Type) stack.getEnv().allTypes.remove(key);
02bb8761fcce Initial load
duke
parents:
diff changeset
   623
        stack.getEnv().invalidTypes.put(value,key);
02bb8761fcce Initial load
duke
parents:
diff changeset
   624
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   625
02bb8761fcce Initial load
duke
parents:
diff changeset
   626
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   627
     * Remove a type from the table.
02bb8761fcce Initial load
duke
parents:
diff changeset
   628
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   629
    protected static void removeType (sun.tools.java.Type key, ContextStack stack) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   630
        String theKey = key.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   631
        Type old = (Type) stack.getEnv().allTypes.remove(theKey);
02bb8761fcce Initial load
duke
parents:
diff changeset
   632
        putInvalidType(old,theKey,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
   633
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   634
02bb8761fcce Initial load
duke
parents:
diff changeset
   635
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   636
     * Put a type into the table.
02bb8761fcce Initial load
duke
parents:
diff changeset
   637
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   638
    protected static void putType (sun.tools.java.Type key, Type value, ContextStack stack) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   639
        stack.getEnv().allTypes.put(key.toString(),value);
02bb8761fcce Initial load
duke
parents:
diff changeset
   640
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   641
02bb8761fcce Initial load
duke
parents:
diff changeset
   642
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   643
     * Put a type into the table.
02bb8761fcce Initial load
duke
parents:
diff changeset
   644
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   645
    protected static void putType (String key, Type value, ContextStack stack) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   646
        stack.getEnv().allTypes.put(key,value);
02bb8761fcce Initial load
duke
parents:
diff changeset
   647
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   648
02bb8761fcce Initial load
duke
parents:
diff changeset
   649
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   650
     * Put an invalid type into the.
02bb8761fcce Initial load
duke
parents:
diff changeset
   651
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   652
    protected static void putInvalidType (Type key, String value, ContextStack stack) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   653
        stack.getEnv().invalidTypes.put(key,value);
02bb8761fcce Initial load
duke
parents:
diff changeset
   654
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   655
02bb8761fcce Initial load
duke
parents:
diff changeset
   656
02bb8761fcce Initial load
duke
parents:
diff changeset
   657
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   658
     * Remove all invalid types...
02bb8761fcce Initial load
duke
parents:
diff changeset
   659
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   660
    public void removeInvalidTypes () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   661
        if (env.invalidTypes.size() > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   662
            env.invalidTypes.clear();
02bb8761fcce Initial load
duke
parents:
diff changeset
   663
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   664
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   665
02bb8761fcce Initial load
duke
parents:
diff changeset
   666
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   667
     * Walk all types and tell them to update invalid types...
02bb8761fcce Initial load
duke
parents:
diff changeset
   668
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   669
    protected static void updateAllInvalidTypes (ContextStack stack) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   670
        BatchEnvironment env = stack.getEnv();
02bb8761fcce Initial load
duke
parents:
diff changeset
   671
        if (env.invalidTypes.size() > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   672
02bb8761fcce Initial load
duke
parents:
diff changeset
   673
            // Walk all types and swap invalid...
02bb8761fcce Initial load
duke
parents:
diff changeset
   674
02bb8761fcce Initial load
duke
parents:
diff changeset
   675
            for (Enumeration e = env.allTypes.elements() ; e.hasMoreElements() ;) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   676
                Type it = (Type) e.nextElement();
02bb8761fcce Initial load
duke
parents:
diff changeset
   677
                it.swapInvalidTypes();
02bb8761fcce Initial load
duke
parents:
diff changeset
   678
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   679
02bb8761fcce Initial load
duke
parents:
diff changeset
   680
            // Delete all invalidTypes...
02bb8761fcce Initial load
duke
parents:
diff changeset
   681
02bb8761fcce Initial load
duke
parents:
diff changeset
   682
            env.invalidTypes.clear();
02bb8761fcce Initial load
duke
parents:
diff changeset
   683
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   684
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   685
02bb8761fcce Initial load
duke
parents:
diff changeset
   686
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   687
     * Return count of previously parsed types.
02bb8761fcce Initial load
duke
parents:
diff changeset
   688
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   689
    protected int countTypes () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   690
        return env.allTypes.size();
02bb8761fcce Initial load
duke
parents:
diff changeset
   691
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   692
02bb8761fcce Initial load
duke
parents:
diff changeset
   693
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   694
     * Reset types removes all previously parsed types.
02bb8761fcce Initial load
duke
parents:
diff changeset
   695
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   696
    void resetTypes () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   697
        env.reset();
02bb8761fcce Initial load
duke
parents:
diff changeset
   698
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   699
02bb8761fcce Initial load
duke
parents:
diff changeset
   700
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   701
     * Release all resources.
02bb8761fcce Initial load
duke
parents:
diff changeset
   702
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   703
    protected void destroy () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   704
        if (!destroyed) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   705
            id = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   706
            name = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   707
            packageName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   708
            qualifiedName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   709
            idlName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   710
            idlModuleNames = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   711
            qualifiedIDLName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   712
            repositoryID = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   713
            ourClass = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   714
            env = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   715
            stack = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   716
            destroyed = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   717
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   718
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   719
02bb8761fcce Initial load
duke
parents:
diff changeset
   720
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   721
     * Convert all invalid types to valid ones.
02bb8761fcce Initial load
duke
parents:
diff changeset
   722
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   723
    protected void swapInvalidTypes () {
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
     * Convert an invalid type to a valid one.
02bb8761fcce Initial load
duke
parents:
diff changeset
   728
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   729
    protected Type getValidType (Type invalidType) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   730
        if (invalidType.getStatus() == STATUS_VALID) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   731
            return invalidType;
02bb8761fcce Initial load
duke
parents:
diff changeset
   732
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   733
02bb8761fcce Initial load
duke
parents:
diff changeset
   734
        String key = (String)env.invalidTypes.get(invalidType);
02bb8761fcce Initial load
duke
parents:
diff changeset
   735
        Type result = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   736
        if (key != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   737
            result = (Type) env.allTypes.get(key);
02bb8761fcce Initial load
duke
parents:
diff changeset
   738
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   739
02bb8761fcce Initial load
duke
parents:
diff changeset
   740
        if (result == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   741
            throw new Error("Failed to find valid type to swap for " + invalidType + " mis-identified as " + invalidType.getTypeDescription());
02bb8761fcce Initial load
duke
parents:
diff changeset
   742
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   743
        //System.out.println("Swapped " + result + " from " + invalidType.getTypeDescription()
02bb8761fcce Initial load
duke
parents:
diff changeset
   744
        //    + " to " + result.getTypeDescription());
02bb8761fcce Initial load
duke
parents:
diff changeset
   745
        //ContextStack.dumpCallStack();
02bb8761fcce Initial load
duke
parents:
diff changeset
   746
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   747
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   748
02bb8761fcce Initial load
duke
parents:
diff changeset
   749
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   750
     * Print the "closing" of the package or module of this type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   751
     * @param writer The stream to print to.
02bb8761fcce Initial load
duke
parents:
diff changeset
   752
     * @param useIDLNames If true, print IDL names; otherwise, print java names.
02bb8761fcce Initial load
duke
parents:
diff changeset
   753
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   754
    protected void printPackageClose (  IndentingWriter writer,
02bb8761fcce Initial load
duke
parents:
diff changeset
   755
                                        boolean useIDLNames) throws IOException {
02bb8761fcce Initial load
duke
parents:
diff changeset
   756
        if (useIDLNames) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   757
            String[] moduleNames = getIDLModuleNames();
02bb8761fcce Initial load
duke
parents:
diff changeset
   758
            for (int i = 0; i < moduleNames.length; i++ ) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   759
                writer.pOln("};");
02bb8761fcce Initial load
duke
parents:
diff changeset
   760
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   761
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   762
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   763
02bb8761fcce Initial load
duke
parents:
diff changeset
   764
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   765
     * Create a Type instance for the given type. Requires that
02bb8761fcce Initial load
duke
parents:
diff changeset
   766
     * setName(Identifier) be called afterward.
02bb8761fcce Initial load
duke
parents:
diff changeset
   767
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   768
    protected Type(ContextStack stack, int fullTypeCode) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   769
        this.env = stack.getEnv();
02bb8761fcce Initial load
duke
parents:
diff changeset
   770
        this.stack = stack;
02bb8761fcce Initial load
duke
parents:
diff changeset
   771
        this.fullTypeCode = fullTypeCode;
02bb8761fcce Initial load
duke
parents:
diff changeset
   772
        typeCode = fullTypeCode & TYPE_MASK;
02bb8761fcce Initial load
duke
parents:
diff changeset
   773
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   774
02bb8761fcce Initial load
duke
parents:
diff changeset
   775
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   776
     * Set type codes. May only be called during initialization.
02bb8761fcce Initial load
duke
parents:
diff changeset
   777
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   778
    protected void setTypeCode(int fullTypeCode) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   779
        this.fullTypeCode = fullTypeCode;
02bb8761fcce Initial load
duke
parents:
diff changeset
   780
        typeCode = fullTypeCode & TYPE_MASK;
02bb8761fcce Initial load
duke
parents:
diff changeset
   781
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   782
02bb8761fcce Initial load
duke
parents:
diff changeset
   783
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   784
     * Set name and package. May only be called during initialization.
02bb8761fcce Initial load
duke
parents:
diff changeset
   785
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   786
    protected void setNames(Identifier id, String[] idlModuleNames, String idlName) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   787
02bb8761fcce Initial load
duke
parents:
diff changeset
   788
        this.id = id;
02bb8761fcce Initial load
duke
parents:
diff changeset
   789
        name = Names.mangleClass(id).getName().toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   790
        packageName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   791
02bb8761fcce Initial load
duke
parents:
diff changeset
   792
        if (id.isQualified()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   793
            packageName = id.getQualifier().toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   794
            qualifiedName = packageName + NAME_SEPARATOR + name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   795
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   796
            qualifiedName = name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   797
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   798
02bb8761fcce Initial load
duke
parents:
diff changeset
   799
        setIDLNames(idlModuleNames,idlName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   800
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   801
02bb8761fcce Initial load
duke
parents:
diff changeset
   802
02bb8761fcce Initial load
duke
parents:
diff changeset
   803
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   804
     * Set IDL name. May only be called during initialization.
02bb8761fcce Initial load
duke
parents:
diff changeset
   805
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   806
    protected void setIDLNames(String[] idlModuleNames, String idlName) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   807
        this.idlName = idlName;
02bb8761fcce Initial load
duke
parents:
diff changeset
   808
02bb8761fcce Initial load
duke
parents:
diff changeset
   809
        if (idlModuleNames != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   810
            this.idlModuleNames = idlModuleNames;
02bb8761fcce Initial load
duke
parents:
diff changeset
   811
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   812
            this.idlModuleNames = new String[0];
02bb8761fcce Initial load
duke
parents:
diff changeset
   813
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   814
        qualifiedIDLName = IDLNames.getQualifiedName(idlModuleNames,idlName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   815
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   816
02bb8761fcce Initial load
duke
parents:
diff changeset
   817
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   818
     * Report a ClassNotFoundException thru the compiler environment.
02bb8761fcce Initial load
duke
parents:
diff changeset
   819
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   820
    protected static void classNotFound(ContextStack stack,
02bb8761fcce Initial load
duke
parents:
diff changeset
   821
                                        ClassNotFound e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   822
        classNotFound(false,stack,e);
02bb8761fcce Initial load
duke
parents:
diff changeset
   823
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   824
02bb8761fcce Initial load
duke
parents:
diff changeset
   825
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   826
     * Report a ClassNotFoundException thru the compiler environment.
02bb8761fcce Initial load
duke
parents:
diff changeset
   827
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   828
    protected static void classNotFound(boolean quiet,
02bb8761fcce Initial load
duke
parents:
diff changeset
   829
                                        ContextStack stack,
02bb8761fcce Initial load
duke
parents:
diff changeset
   830
                                        ClassNotFound e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   831
        if (!quiet) stack.getEnv().error(0, "rmic.class.not.found", e.name);
02bb8761fcce Initial load
duke
parents:
diff changeset
   832
        stack.traceCallStack();
02bb8761fcce Initial load
duke
parents:
diff changeset
   833
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   834
02bb8761fcce Initial load
duke
parents:
diff changeset
   835
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   836
     * Report a constraint failure thru the compiler environment.
02bb8761fcce Initial load
duke
parents:
diff changeset
   837
     * @param constraintNum Used to generate a key of the form
02bb8761fcce Initial load
duke
parents:
diff changeset
   838
     "rmic.iiop.constraint.N", which must identify a message
02bb8761fcce Initial load
duke
parents:
diff changeset
   839
     in the "rmic.properties" file.
02bb8761fcce Initial load
duke
parents:
diff changeset
   840
     * @param quiet True if should not cause failure or message.
02bb8761fcce Initial load
duke
parents:
diff changeset
   841
     * @param stack The context stack.
02bb8761fcce Initial load
duke
parents:
diff changeset
   842
     * @param arg0 An object to substitute for {0} in the message.
02bb8761fcce Initial load
duke
parents:
diff changeset
   843
     * @param arg1 An object to substitute for {1} in the message.
02bb8761fcce Initial load
duke
parents:
diff changeset
   844
     * @param arg2 An object to substitute for {2} in the message.
02bb8761fcce Initial load
duke
parents:
diff changeset
   845
     * @return false.
02bb8761fcce Initial load
duke
parents:
diff changeset
   846
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   847
    protected static boolean failedConstraint(int constraintNum,
02bb8761fcce Initial load
duke
parents:
diff changeset
   848
                                              boolean quiet,
02bb8761fcce Initial load
duke
parents:
diff changeset
   849
                                              ContextStack stack,
02bb8761fcce Initial load
duke
parents:
diff changeset
   850
                                              Object arg0, Object arg1, Object arg2) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   851
        String message = "rmic.iiop.constraint." + constraintNum;
02bb8761fcce Initial load
duke
parents:
diff changeset
   852
02bb8761fcce Initial load
duke
parents:
diff changeset
   853
        if (!quiet) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   854
            stack.getEnv().error(0,message,
02bb8761fcce Initial load
duke
parents:
diff changeset
   855
                                 (arg0 != null ? arg0.toString() : null),
02bb8761fcce Initial load
duke
parents:
diff changeset
   856
                                 (arg1 != null ? arg1.toString() : null),
02bb8761fcce Initial load
duke
parents:
diff changeset
   857
                                 (arg2 != null ? arg2.toString() : null));
02bb8761fcce Initial load
duke
parents:
diff changeset
   858
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   859
            String error = stack.getEnv().errorString(message,arg0,arg1,arg2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   860
            stack.traceln(error);
02bb8761fcce Initial load
duke
parents:
diff changeset
   861
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   862
02bb8761fcce Initial load
duke
parents:
diff changeset
   863
        return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   864
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   865
02bb8761fcce Initial load
duke
parents:
diff changeset
   866
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   867
     * Report a constraint failure thru the compiler environment.
02bb8761fcce Initial load
duke
parents:
diff changeset
   868
     * @param constraintNum Used to generate a key of the form
02bb8761fcce Initial load
duke
parents:
diff changeset
   869
     "rmic.iiop.constraint.N", which must identify a message
02bb8761fcce Initial load
duke
parents:
diff changeset
   870
     in the "rmic.properties" file.
02bb8761fcce Initial load
duke
parents:
diff changeset
   871
     * @param quiet True if should not cause failure or message.
02bb8761fcce Initial load
duke
parents:
diff changeset
   872
     * @param stack The context stack.
02bb8761fcce Initial load
duke
parents:
diff changeset
   873
     * @param arg0 An object to substitute for {0} in the message.
02bb8761fcce Initial load
duke
parents:
diff changeset
   874
     * @param arg1 An object to substitute for {1} in the message.
02bb8761fcce Initial load
duke
parents:
diff changeset
   875
     * @return false.
02bb8761fcce Initial load
duke
parents:
diff changeset
   876
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   877
    protected static boolean failedConstraint(int constraintNum,
02bb8761fcce Initial load
duke
parents:
diff changeset
   878
                                              boolean quiet,
02bb8761fcce Initial load
duke
parents:
diff changeset
   879
                                              ContextStack stack,
02bb8761fcce Initial load
duke
parents:
diff changeset
   880
                                              Object arg0, Object arg1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   881
        return failedConstraint(constraintNum,quiet,stack,arg0,arg1,null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   882
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   883
02bb8761fcce Initial load
duke
parents:
diff changeset
   884
02bb8761fcce Initial load
duke
parents:
diff changeset
   885
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   886
     * Report a constraint failure thru the compiler environment.
02bb8761fcce Initial load
duke
parents:
diff changeset
   887
     * @param constraintNum Used to generate a key of the form
02bb8761fcce Initial load
duke
parents:
diff changeset
   888
     "rmic.iiop.constraint.N", which must identify a message
02bb8761fcce Initial load
duke
parents:
diff changeset
   889
     in the "rmic.properties" file.
02bb8761fcce Initial load
duke
parents:
diff changeset
   890
     * @param quiet True if should not cause failure or message.
02bb8761fcce Initial load
duke
parents:
diff changeset
   891
     * @param stack The context stack.
02bb8761fcce Initial load
duke
parents:
diff changeset
   892
     * @param arg0 An object to substitute for {0} in the message.
02bb8761fcce Initial load
duke
parents:
diff changeset
   893
     * @return false.
02bb8761fcce Initial load
duke
parents:
diff changeset
   894
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   895
    protected static boolean failedConstraint(int constraintNum,
02bb8761fcce Initial load
duke
parents:
diff changeset
   896
                                              boolean quiet,
02bb8761fcce Initial load
duke
parents:
diff changeset
   897
                                              ContextStack stack,
02bb8761fcce Initial load
duke
parents:
diff changeset
   898
                                              Object arg0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   899
        return failedConstraint(constraintNum,quiet,stack,arg0,null,null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   900
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   901
02bb8761fcce Initial load
duke
parents:
diff changeset
   902
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   903
     * Report a constraint failure thru the compiler environment.
02bb8761fcce Initial load
duke
parents:
diff changeset
   904
     * @param quiet True if should not cause failure or message.
02bb8761fcce Initial load
duke
parents:
diff changeset
   905
     * @param stack The context stack.
02bb8761fcce Initial load
duke
parents:
diff changeset
   906
     * @param constraintNum Used to generate a key of the form
02bb8761fcce Initial load
duke
parents:
diff changeset
   907
     "rmic.iiop.constraint.N", which must identify a message
02bb8761fcce Initial load
duke
parents:
diff changeset
   908
     in the "rmic.properties" file.
02bb8761fcce Initial load
duke
parents:
diff changeset
   909
     * @return false.
02bb8761fcce Initial load
duke
parents:
diff changeset
   910
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   911
    protected static boolean failedConstraint(int constraintNum,
02bb8761fcce Initial load
duke
parents:
diff changeset
   912
                                              boolean quiet,
02bb8761fcce Initial load
duke
parents:
diff changeset
   913
                                              ContextStack stack) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   914
        return failedConstraint(constraintNum,quiet,stack,null,null,null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   915
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   916
02bb8761fcce Initial load
duke
parents:
diff changeset
   917
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   918
     * Cloning is supported by returning a shallow copy of this object.
02bb8761fcce Initial load
duke
parents:
diff changeset
   919
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   920
    protected Object clone() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   921
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   922
            return super.clone();
02bb8761fcce Initial load
duke
parents:
diff changeset
   923
        } catch (CloneNotSupportedException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   924
            throw new Error("clone failed");
02bb8761fcce Initial load
duke
parents:
diff changeset
   925
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   926
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   927
02bb8761fcce Initial load
duke
parents:
diff changeset
   928
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   929
     * Add matching types to list. Return true if this type has not
02bb8761fcce Initial load
duke
parents:
diff changeset
   930
     * been previously checked, false otherwise.
02bb8761fcce Initial load
duke
parents:
diff changeset
   931
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   932
    protected boolean addTypes (int typeCodeFilter,
02bb8761fcce Initial load
duke
parents:
diff changeset
   933
                                HashSet checked,
02bb8761fcce Initial load
duke
parents:
diff changeset
   934
                                Vector matching) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   935
02bb8761fcce Initial load
duke
parents:
diff changeset
   936
        boolean result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   937
02bb8761fcce Initial load
duke
parents:
diff changeset
   938
        // Have we already checked this type?
02bb8761fcce Initial load
duke
parents:
diff changeset
   939
02bb8761fcce Initial load
duke
parents:
diff changeset
   940
        if (checked.contains(this)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   941
02bb8761fcce Initial load
duke
parents:
diff changeset
   942
            // Yes, so return false.
02bb8761fcce Initial load
duke
parents:
diff changeset
   943
02bb8761fcce Initial load
duke
parents:
diff changeset
   944
            result = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   945
02bb8761fcce Initial load
duke
parents:
diff changeset
   946
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   947
02bb8761fcce Initial load
duke
parents:
diff changeset
   948
            // Nope, so add it...
02bb8761fcce Initial load
duke
parents:
diff changeset
   949
02bb8761fcce Initial load
duke
parents:
diff changeset
   950
            checked.add(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   951
02bb8761fcce Initial load
duke
parents:
diff changeset
   952
            // Do we match the filter?
02bb8761fcce Initial load
duke
parents:
diff changeset
   953
02bb8761fcce Initial load
duke
parents:
diff changeset
   954
            if (typeMatches(typeCodeFilter)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   955
02bb8761fcce Initial load
duke
parents:
diff changeset
   956
                // Yep. so add it and set result to true...
02bb8761fcce Initial load
duke
parents:
diff changeset
   957
02bb8761fcce Initial load
duke
parents:
diff changeset
   958
                matching.addElement(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   959
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   960
02bb8761fcce Initial load
duke
parents:
diff changeset
   961
            // Return true.
02bb8761fcce Initial load
duke
parents:
diff changeset
   962
02bb8761fcce Initial load
duke
parents:
diff changeset
   963
            result = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   964
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   965
02bb8761fcce Initial load
duke
parents:
diff changeset
   966
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   967
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   968
02bb8761fcce Initial load
duke
parents:
diff changeset
   969
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   970
     * Load a Class instance. Return null if fail.
02bb8761fcce Initial load
duke
parents:
diff changeset
   971
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   972
    protected abstract Class loadClass();
02bb8761fcce Initial load
duke
parents:
diff changeset
   973
02bb8761fcce Initial load
duke
parents:
diff changeset
   974
    private boolean initClass() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   975
        if (ourClass == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   976
            ourClass = loadClass();
02bb8761fcce Initial load
duke
parents:
diff changeset
   977
            if (ourClass == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   978
                failedConstraint(27,false,stack,getQualifiedName());
02bb8761fcce Initial load
duke
parents:
diff changeset
   979
                return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   980
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   981
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   982
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   983
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   984
02bb8761fcce Initial load
duke
parents:
diff changeset
   985
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   986
     * Set the clz and repositoryID fields. Reports error
02bb8761fcce Initial load
duke
parents:
diff changeset
   987
     * and returns false if fails, returns true if succeeds.
02bb8761fcce Initial load
duke
parents:
diff changeset
   988
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   989
    protected boolean setRepositoryID() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   990
02bb8761fcce Initial load
duke
parents:
diff changeset
   991
        // First, load the class...
02bb8761fcce Initial load
duke
parents:
diff changeset
   992
02bb8761fcce Initial load
duke
parents:
diff changeset
   993
        if (!initClass()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   994
            return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   995
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   996
02bb8761fcce Initial load
duke
parents:
diff changeset
   997
        // Now make the repositoryID and return success...
02bb8761fcce Initial load
duke
parents:
diff changeset
   998
02bb8761fcce Initial load
duke
parents:
diff changeset
   999
        repositoryID = RepositoryId.createForAnyType(ourClass);
02bb8761fcce Initial load
duke
parents:
diff changeset
  1000
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
  1001
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
  1002
02bb8761fcce Initial load
duke
parents:
diff changeset
  1003
02bb8761fcce Initial load
duke
parents:
diff changeset
  1004
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
  1005
    // Internal Interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
  1006
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
  1007
02bb8761fcce Initial load
duke
parents:
diff changeset
  1008
    private Type () {} // Disallowed.
02bb8761fcce Initial load
duke
parents:
diff changeset
  1009
}