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

Mon, 26 Mar 2012 14:01:40 +0100

author
coffeys
date
Mon, 26 Mar 2012 14:01:40 +0100
changeset 370
5222b7d658d4
parent 158
91006f157c46
child 748
6845b95cba6b
permissions
-rw-r--r--

7143851: Improve IIOP stub and tie generation in RMIC
7149048: Changes to corba rmic stubGenerator class are not used during jdk build process
Reviewed-by: mschoene, robm

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

mercurial