duke@1: /* ohair@158: * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@158: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@158: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@158: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@158: * or visit www.oracle.com if you need additional information or have any ohair@158: * questions. duke@1: */ duke@1: duke@1: /* duke@1: * Licensed Materials - Property of IBM duke@1: * RMI-IIOP v1.0 duke@1: * Copyright IBM Corp. 1998 1999 All Rights Reserved duke@1: * duke@1: */ duke@1: duke@1: package sun.rmi.rmic.iiop; duke@1: duke@1: import sun.tools.java.ClassNotFound; duke@1: import sun.tools.java.CompilerError; duke@1: import sun.tools.java.Identifier; duke@1: import sun.tools.java.ClassDeclaration; duke@1: import sun.tools.java.ClassDefinition; duke@1: duke@1: /** duke@1: * SpecialInterfaceType represents any one of the following types: duke@1: *
duke@1:  *    java.rmi.Remote
duke@1:  *    java.io.Serializable
duke@1:  *    java.io.Externalizable
duke@1:  *    org.omg.CORBA.Object
duke@1:  *    org.omg.CORBA.portable.IDLEntity
duke@1:  * 
duke@1: * all of which are treated as special cases. For all but CORBA.Object, duke@1: * the type must match exactly. For CORBA.Object, the type must either be duke@1: * CORBA.Object or inherit from it. duke@1: *

duke@1: * The static forSpecial(...) method must be used to obtain an instance, and duke@1: * will return null if the type is non-conforming. duke@1: * duke@1: * @author Bryan Atsatt duke@1: */ duke@1: public class SpecialInterfaceType extends InterfaceType { duke@1: duke@1: //_____________________________________________________________________ duke@1: // Public Interfaces duke@1: //_____________________________________________________________________ duke@1: duke@1: /** duke@1: * Create a SpecialInterfaceType object for the given class. duke@1: * duke@1: * If the class is not a properly formed or if some other error occurs, the duke@1: * return value will be null, and errors will have been reported to the duke@1: * supplied BatchEnvironment. duke@1: */ duke@1: public static SpecialInterfaceType forSpecial ( ClassDefinition theClass, duke@1: ContextStack stack) { duke@1: duke@1: if (stack.anyErrors()) return null; duke@1: duke@1: // Do we already have it? duke@1: duke@1: sun.tools.java.Type type = theClass.getType(); duke@1: Type existing = getType(type,stack); duke@1: duke@1: if (existing != null) { duke@1: duke@1: if (!(existing instanceof SpecialInterfaceType)) return null; // False hit. duke@1: duke@1: // Yep, so return it... duke@1: duke@1: return (SpecialInterfaceType) existing; duke@1: } duke@1: duke@1: // Is it special? duke@1: duke@1: if (isSpecial(type,theClass,stack)) { duke@1: duke@1: // Yes... duke@1: duke@1: SpecialInterfaceType result = new SpecialInterfaceType(stack,0,theClass); duke@1: putType(type,result,stack); duke@1: stack.push(result); duke@1: duke@1: if (result.initialize(type,stack)) { duke@1: stack.pop(true); duke@1: return result; duke@1: } else { duke@1: removeType(type,stack); duke@1: stack.pop(false); duke@1: return null; duke@1: } duke@1: } duke@1: return null; duke@1: } duke@1: duke@1: /** duke@1: * Return a string describing this type. duke@1: */ duke@1: public String getTypeDescription () { duke@1: return "Special interface"; duke@1: } duke@1: duke@1: //_____________________________________________________________________ duke@1: // Subclass/Internal Interfaces duke@1: //_____________________________________________________________________ duke@1: duke@1: /** duke@1: * Create an SpecialInterfaceType instance for the given class. duke@1: */ duke@1: private SpecialInterfaceType(ContextStack stack, int typeCode, duke@1: ClassDefinition theClass) { duke@1: super(stack,typeCode | TM_SPECIAL_INTERFACE | TM_INTERFACE | TM_COMPOUND, theClass); duke@1: setNames(theClass.getName(),null,null); // Fixed in initialize. duke@1: } duke@1: duke@1: private static boolean isSpecial(sun.tools.java.Type type, duke@1: ClassDefinition theClass, duke@1: ContextStack stack) { duke@1: if (type.isType(TC_CLASS)) { duke@1: Identifier id = type.getClassName(); duke@1: duke@1: if (id.equals(idRemote)) return true; duke@1: if (id == idJavaIoSerializable) return true; duke@1: if (id == idJavaIoExternalizable) return true; duke@1: if (id == idCorbaObject) return true; duke@1: if (id == idIDLEntity) return true; duke@1: BatchEnvironment env = stack.getEnv(); duke@1: try { duke@1: if (env.defCorbaObject.implementedBy(env,theClass.getClassDeclaration())) return true; duke@1: } catch (ClassNotFound e) { duke@1: classNotFound(stack,e); duke@1: } duke@1: } duke@1: return false; duke@1: } duke@1: duke@1: private boolean initialize(sun.tools.java.Type type, ContextStack stack) { duke@1: duke@1: int typeCode = TYPE_NONE; duke@1: Identifier id = null; duke@1: String idlName = null; duke@1: String[] idlModuleName = null; duke@1: boolean constant = stack.size() > 0 && stack.getContext().isConstant(); duke@1: duke@1: if (type.isType(TC_CLASS)) { duke@1: id = type.getClassName(); duke@1: duke@1: if (id.equals(idRemote)) { duke@1: typeCode = TYPE_JAVA_RMI_REMOTE; duke@1: idlName = IDL_JAVA_RMI_REMOTE; duke@1: idlModuleName = IDL_JAVA_RMI_MODULE; duke@1: } else if (id == idJavaIoSerializable) { duke@1: typeCode = TYPE_ANY; duke@1: idlName = IDL_SERIALIZABLE; duke@1: idlModuleName = IDL_JAVA_IO_MODULE; duke@1: } else if (id == idJavaIoExternalizable) { duke@1: typeCode = TYPE_ANY; duke@1: idlName = IDL_EXTERNALIZABLE; duke@1: idlModuleName = IDL_JAVA_IO_MODULE; duke@1: } else if (id == idIDLEntity) { duke@1: typeCode = TYPE_ANY; duke@1: idlName = IDL_IDLENTITY; duke@1: idlModuleName = IDL_ORG_OMG_CORBA_PORTABLE_MODULE; duke@1: } else { duke@1: duke@1: typeCode = TYPE_CORBA_OBJECT; duke@1: duke@1: // Is it exactly org.omg.CORBA.Object? duke@1: duke@1: if (id == idCorbaObject) { duke@1: duke@1: // Yes, so special case... duke@1: duke@1: idlName = IDLNames.getTypeName(typeCode,constant); duke@1: idlModuleName = null; duke@1: duke@1: } else { duke@1: duke@1: // No, so get the correct names... duke@1: duke@1: try { duke@1: duke@1: // These can fail if we get case-sensitive name matches... duke@1: duke@1: idlName = IDLNames.getClassOrInterfaceName(id,env); duke@1: idlModuleName = IDLNames.getModuleNames(id,isBoxed(),env); duke@1: duke@1: } catch (Exception e) { duke@1: failedConstraint(7,false,stack,id.toString(),e.getMessage()); duke@1: throw new CompilerError(""); duke@1: } duke@1: } duke@1: } duke@1: } duke@1: duke@1: if (typeCode == TYPE_NONE) { duke@1: return false; duke@1: } duke@1: duke@1: // Reset type code... duke@1: duke@1: setTypeCode(typeCode | TM_SPECIAL_INTERFACE | TM_INTERFACE | TM_COMPOUND); duke@1: duke@1: // Set names duke@1: duke@1: if (idlName == null) { duke@1: throw new CompilerError("Not a special type"); duke@1: } duke@1: duke@1: setNames(id,idlModuleName,idlName); duke@1: duke@1: // Initialize CompoundType... duke@1: duke@1: return initialize(null,null,null,stack,false); duke@1: } duke@1: }