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

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