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

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

mercurial