src/share/classes/sun/rmi/rmic/iiop/SpecialInterfaceType.java

Thu, 31 Aug 2017 18:10:36 +0800

author
aoqi
date
Thu, 31 Aug 2017 18:10:36 +0800
changeset 748
6845b95cba6b
parent 158
91006f157c46
parent 0
7ef37b2cdcad
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 /*
aoqi@0 27 * Licensed Materials - Property of IBM
aoqi@0 28 * RMI-IIOP v1.0
aoqi@0 29 * Copyright IBM Corp. 1998 1999 All Rights Reserved
aoqi@0 30 *
aoqi@0 31 */
aoqi@0 32
aoqi@0 33 package sun.rmi.rmic.iiop;
aoqi@0 34
aoqi@0 35 import sun.tools.java.ClassNotFound;
aoqi@0 36 import sun.tools.java.CompilerError;
aoqi@0 37 import sun.tools.java.Identifier;
aoqi@0 38 import sun.tools.java.ClassDeclaration;
aoqi@0 39 import sun.tools.java.ClassDefinition;
aoqi@0 40
aoqi@0 41 /**
aoqi@0 42 * SpecialInterfaceType represents any one of the following types:
aoqi@0 43 * <pre>
aoqi@0 44 * java.rmi.Remote
aoqi@0 45 * java.io.Serializable
aoqi@0 46 * java.io.Externalizable
aoqi@0 47 * org.omg.CORBA.Object
aoqi@0 48 * org.omg.CORBA.portable.IDLEntity
aoqi@0 49 * </pre>
aoqi@0 50 * all of which are treated as special cases. For all but CORBA.Object,
aoqi@0 51 * the type must match exactly. For CORBA.Object, the type must either be
aoqi@0 52 * CORBA.Object or inherit from it.
aoqi@0 53 * <p>
aoqi@0 54 * The static forSpecial(...) method must be used to obtain an instance, and
aoqi@0 55 * will return null if the type is non-conforming.
aoqi@0 56 *
aoqi@0 57 * @author Bryan Atsatt
aoqi@0 58 */
aoqi@0 59 public class SpecialInterfaceType extends InterfaceType {
aoqi@0 60
aoqi@0 61 //_____________________________________________________________________
aoqi@0 62 // Public Interfaces
aoqi@0 63 //_____________________________________________________________________
aoqi@0 64
aoqi@0 65 /**
aoqi@0 66 * Create a SpecialInterfaceType object for the given class.
aoqi@0 67 *
aoqi@0 68 * If the class is not a properly formed or if some other error occurs, the
aoqi@0 69 * return value will be null, and errors will have been reported to the
aoqi@0 70 * supplied BatchEnvironment.
aoqi@0 71 */
aoqi@0 72 public static SpecialInterfaceType forSpecial ( ClassDefinition theClass,
aoqi@0 73 ContextStack stack) {
aoqi@0 74
aoqi@0 75 if (stack.anyErrors()) return null;
aoqi@0 76
aoqi@0 77 // Do we already have it?
aoqi@0 78
aoqi@0 79 sun.tools.java.Type type = theClass.getType();
aoqi@0 80 Type existing = getType(type,stack);
aoqi@0 81
aoqi@0 82 if (existing != null) {
aoqi@0 83
aoqi@0 84 if (!(existing instanceof SpecialInterfaceType)) return null; // False hit.
aoqi@0 85
aoqi@0 86 // Yep, so return it...
aoqi@0 87
aoqi@0 88 return (SpecialInterfaceType) existing;
aoqi@0 89 }
aoqi@0 90
aoqi@0 91 // Is it special?
aoqi@0 92
aoqi@0 93 if (isSpecial(type,theClass,stack)) {
aoqi@0 94
aoqi@0 95 // Yes...
aoqi@0 96
aoqi@0 97 SpecialInterfaceType result = new SpecialInterfaceType(stack,0,theClass);
aoqi@0 98 putType(type,result,stack);
aoqi@0 99 stack.push(result);
aoqi@0 100
aoqi@0 101 if (result.initialize(type,stack)) {
aoqi@0 102 stack.pop(true);
aoqi@0 103 return result;
aoqi@0 104 } else {
aoqi@0 105 removeType(type,stack);
aoqi@0 106 stack.pop(false);
aoqi@0 107 return null;
aoqi@0 108 }
aoqi@0 109 }
aoqi@0 110 return null;
aoqi@0 111 }
aoqi@0 112
aoqi@0 113 /**
aoqi@0 114 * Return a string describing this type.
aoqi@0 115 */
aoqi@0 116 public String getTypeDescription () {
aoqi@0 117 return "Special interface";
aoqi@0 118 }
aoqi@0 119
aoqi@0 120 //_____________________________________________________________________
aoqi@0 121 // Subclass/Internal Interfaces
aoqi@0 122 //_____________________________________________________________________
aoqi@0 123
aoqi@0 124 /**
aoqi@0 125 * Create an SpecialInterfaceType instance for the given class.
aoqi@0 126 */
aoqi@0 127 private SpecialInterfaceType(ContextStack stack, int typeCode,
aoqi@0 128 ClassDefinition theClass) {
aoqi@0 129 super(stack,typeCode | TM_SPECIAL_INTERFACE | TM_INTERFACE | TM_COMPOUND, theClass);
aoqi@0 130 setNames(theClass.getName(),null,null); // Fixed in initialize.
aoqi@0 131 }
aoqi@0 132
aoqi@0 133 private static boolean isSpecial(sun.tools.java.Type type,
aoqi@0 134 ClassDefinition theClass,
aoqi@0 135 ContextStack stack) {
aoqi@0 136 if (type.isType(TC_CLASS)) {
aoqi@0 137 Identifier id = type.getClassName();
aoqi@0 138
aoqi@0 139 if (id.equals(idRemote)) return true;
aoqi@0 140 if (id == idJavaIoSerializable) return true;
aoqi@0 141 if (id == idJavaIoExternalizable) return true;
aoqi@0 142 if (id == idCorbaObject) return true;
aoqi@0 143 if (id == idIDLEntity) return true;
aoqi@0 144 BatchEnvironment env = stack.getEnv();
aoqi@0 145 try {
aoqi@0 146 if (env.defCorbaObject.implementedBy(env,theClass.getClassDeclaration())) return true;
aoqi@0 147 } catch (ClassNotFound e) {
aoqi@0 148 classNotFound(stack,e);
aoqi@0 149 }
aoqi@0 150 }
aoqi@0 151 return false;
aoqi@0 152 }
aoqi@0 153
aoqi@0 154 private boolean initialize(sun.tools.java.Type type, ContextStack stack) {
aoqi@0 155
aoqi@0 156 int typeCode = TYPE_NONE;
aoqi@0 157 Identifier id = null;
aoqi@0 158 String idlName = null;
aoqi@0 159 String[] idlModuleName = null;
aoqi@0 160 boolean constant = stack.size() > 0 && stack.getContext().isConstant();
aoqi@0 161
aoqi@0 162 if (type.isType(TC_CLASS)) {
aoqi@0 163 id = type.getClassName();
aoqi@0 164
aoqi@0 165 if (id.equals(idRemote)) {
aoqi@0 166 typeCode = TYPE_JAVA_RMI_REMOTE;
aoqi@0 167 idlName = IDL_JAVA_RMI_REMOTE;
aoqi@0 168 idlModuleName = IDL_JAVA_RMI_MODULE;
aoqi@0 169 } else if (id == idJavaIoSerializable) {
aoqi@0 170 typeCode = TYPE_ANY;
aoqi@0 171 idlName = IDL_SERIALIZABLE;
aoqi@0 172 idlModuleName = IDL_JAVA_IO_MODULE;
aoqi@0 173 } else if (id == idJavaIoExternalizable) {
aoqi@0 174 typeCode = TYPE_ANY;
aoqi@0 175 idlName = IDL_EXTERNALIZABLE;
aoqi@0 176 idlModuleName = IDL_JAVA_IO_MODULE;
aoqi@0 177 } else if (id == idIDLEntity) {
aoqi@0 178 typeCode = TYPE_ANY;
aoqi@0 179 idlName = IDL_IDLENTITY;
aoqi@0 180 idlModuleName = IDL_ORG_OMG_CORBA_PORTABLE_MODULE;
aoqi@0 181 } else {
aoqi@0 182
aoqi@0 183 typeCode = TYPE_CORBA_OBJECT;
aoqi@0 184
aoqi@0 185 // Is it exactly org.omg.CORBA.Object?
aoqi@0 186
aoqi@0 187 if (id == idCorbaObject) {
aoqi@0 188
aoqi@0 189 // Yes, so special case...
aoqi@0 190
aoqi@0 191 idlName = IDLNames.getTypeName(typeCode,constant);
aoqi@0 192 idlModuleName = null;
aoqi@0 193
aoqi@0 194 } else {
aoqi@0 195
aoqi@0 196 // No, so get the correct names...
aoqi@0 197
aoqi@0 198 try {
aoqi@0 199
aoqi@0 200 // These can fail if we get case-sensitive name matches...
aoqi@0 201
aoqi@0 202 idlName = IDLNames.getClassOrInterfaceName(id,env);
aoqi@0 203 idlModuleName = IDLNames.getModuleNames(id,isBoxed(),env);
aoqi@0 204
aoqi@0 205 } catch (Exception e) {
aoqi@0 206 failedConstraint(7,false,stack,id.toString(),e.getMessage());
aoqi@0 207 throw new CompilerError("");
aoqi@0 208 }
aoqi@0 209 }
aoqi@0 210 }
aoqi@0 211 }
aoqi@0 212
aoqi@0 213 if (typeCode == TYPE_NONE) {
aoqi@0 214 return false;
aoqi@0 215 }
aoqi@0 216
aoqi@0 217 // Reset type code...
aoqi@0 218
aoqi@0 219 setTypeCode(typeCode | TM_SPECIAL_INTERFACE | TM_INTERFACE | TM_COMPOUND);
aoqi@0 220
aoqi@0 221 // Set names
aoqi@0 222
aoqi@0 223 if (idlName == null) {
aoqi@0 224 throw new CompilerError("Not a special type");
aoqi@0 225 }
aoqi@0 226
aoqi@0 227 setNames(id,idlModuleName,idlName);
aoqi@0 228
aoqi@0 229 // Initialize CompoundType...
aoqi@0 230
aoqi@0 231 return initialize(null,null,null,stack,false);
aoqi@0 232 }
aoqi@0 233 }

mercurial