corba/src/jdk.rmic/share/classes/sun/rmi/rmic/iiop/SpecialInterfaceType.java
author lana
Fri, 04 Aug 2017 23:29:08 +0000
changeset 46099 da187c3e130c
parent 25862 a5e25d68f971
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 sun.tools.java.ClassNotFound;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import sun.tools.java.CompilerError;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import sun.tools.java.Identifier;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import sun.tools.java.ClassDeclaration;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import sun.tools.java.ClassDefinition;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
 * SpecialInterfaceType represents any one of the following types:
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
 * <pre>
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
 *    java.rmi.Remote
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
 *    java.io.Serializable
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
 *    java.io.Externalizable
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
 *    org.omg.CORBA.Object
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
 *    org.omg.CORBA.portable.IDLEntity
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
 * </pre>
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
 * all of which are treated as special cases. For all but CORBA.Object,
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
 * the type must match exactly. For CORBA.Object, the type must either be
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
 * CORBA.Object or inherit from it.
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
 * <p>
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
 * The static forSpecial(...) method must be used to obtain an instance, and
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
 * will return null if the type is non-conforming.
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
 * @author  Bryan Atsatt
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
public class SpecialInterfaceType extends InterfaceType {
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
    // Public Interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
     * Create a SpecialInterfaceType object for the given class.
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
     * If the class is not a properly formed or if some other error occurs, the
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
     * return value will be null, and errors will have been reported to the
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
     * supplied BatchEnvironment.
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
    public static SpecialInterfaceType forSpecial ( ClassDefinition theClass,
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
                                                    ContextStack stack) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
        if (stack.anyErrors()) return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
        // Do we already have it?
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
        sun.tools.java.Type type = theClass.getType();
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
        Type existing = getType(type,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
        if (existing != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
            if (!(existing instanceof SpecialInterfaceType)) return null; // False hit.
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
            // Yep, so return it...
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
            return (SpecialInterfaceType) existing;
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
        // Is it special?
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
        if (isSpecial(type,theClass,stack)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
            // Yes...
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
            SpecialInterfaceType result = new SpecialInterfaceType(stack,0,theClass);
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
            putType(type,result,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
            stack.push(result);
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
            if (result.initialize(type,stack)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
                stack.pop(true);
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
                return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
                removeType(type,stack);
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
                stack.pop(false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
                return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
     * Return a string describing this type.
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
    public String getTypeDescription () {
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
        return "Special interface";
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
    // Subclass/Internal Interfaces
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
    //_____________________________________________________________________
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
     * Create an SpecialInterfaceType instance for the given class.
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
    private SpecialInterfaceType(ContextStack stack, int typeCode,
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
                                 ClassDefinition theClass) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
        super(stack,typeCode | TM_SPECIAL_INTERFACE | TM_INTERFACE | TM_COMPOUND, theClass);
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
        setNames(theClass.getName(),null,null); // Fixed in initialize.
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
    private static boolean isSpecial(sun.tools.java.Type type,
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
                                     ClassDefinition theClass,
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
                                     ContextStack stack) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
        if (type.isType(TC_CLASS)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
            Identifier id = type.getClassName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
            if (id.equals(idRemote)) return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
            if (id == idJavaIoSerializable) return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
            if (id == idJavaIoExternalizable) return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
            if (id == idCorbaObject) return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
            if (id == idIDLEntity) return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
            BatchEnvironment env = stack.getEnv();
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
                if (env.defCorbaObject.implementedBy(env,theClass.getClassDeclaration())) return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
            } catch (ClassNotFound e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
                classNotFound(stack,e);
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
        return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
    private boolean initialize(sun.tools.java.Type type, ContextStack stack) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
        int typeCode = TYPE_NONE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
        Identifier id = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
        String idlName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
        String[] idlModuleName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
        boolean constant = stack.size() > 0 && stack.getContext().isConstant();
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
        if (type.isType(TC_CLASS)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
            id = type.getClassName();
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
            if (id.equals(idRemote)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
                typeCode = TYPE_JAVA_RMI_REMOTE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
                idlName = IDL_JAVA_RMI_REMOTE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
                idlModuleName = IDL_JAVA_RMI_MODULE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
            } else if (id == idJavaIoSerializable) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
                typeCode = TYPE_ANY;
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
                idlName = IDL_SERIALIZABLE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
                idlModuleName = IDL_JAVA_IO_MODULE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
            } else if (id == idJavaIoExternalizable) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
                typeCode = TYPE_ANY;
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
                idlName = IDL_EXTERNALIZABLE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
                idlModuleName = IDL_JAVA_IO_MODULE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
            } else if (id == idIDLEntity) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
                typeCode = TYPE_ANY;
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
                idlName = IDL_IDLENTITY;
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
                idlModuleName = IDL_ORG_OMG_CORBA_PORTABLE_MODULE;
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
                typeCode = TYPE_CORBA_OBJECT;
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
                // Is it exactly org.omg.CORBA.Object?
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
                if (id == idCorbaObject) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
                    // Yes, so special case...
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
                    idlName = IDLNames.getTypeName(typeCode,constant);
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
                    idlModuleName = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
                    // No, so get the correct names...
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
                    try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
                        // These can fail if we get case-sensitive name matches...
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
                        idlName = IDLNames.getClassOrInterfaceName(id,env);
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
                        idlModuleName = IDLNames.getModuleNames(id,isBoxed(),env);
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
                    } catch (Exception e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
                        failedConstraint(7,false,stack,id.toString(),e.getMessage());
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
                        throw new CompilerError("");
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
                    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
        if (typeCode == TYPE_NONE) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
            return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
        // Reset type code...
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
        setTypeCode(typeCode | TM_SPECIAL_INTERFACE | TM_INTERFACE | TM_COMPOUND);
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
        // Set names
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
        if (idlName == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
            throw new CompilerError("Not a special type");
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
        setNames(id,idlModuleName,idlName);
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
        // Initialize CompoundType...
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
        return initialize(null,null,null,stack,false);
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
}