src/share/classes/sun/rmi/rmic/iiop/RemoteType.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

     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 java.util.Vector;
    36 import sun.tools.java.CompilerError;
    37 import sun.tools.java.ClassDefinition;
    38 import sun.tools.java.ClassNotFound;
    40 /**
    41  * RemoteType represents any non-special interface which inherits
    42  * from java.rmi.Remote.
    43  * <p>
    44  * The static forRemote(...) method must be used to obtain an instance, and will
    45  * return null if the ClassDefinition is non-conforming.
    46  * @author      Bryan Atsatt
    47  */
    48 public class RemoteType extends InterfaceType {
    50     //_____________________________________________________________________
    51     // Public Interfaces
    52     //_____________________________________________________________________
    54     /**
    55      * Create an RemoteType for the given class.
    56      *
    57      * If the class is not a properly formed or if some other error occurs, the
    58      * return value will be null, and errors will have been reported to the
    59      * supplied BatchEnvironment.
    60      */
    61     public static RemoteType forRemote(ClassDefinition classDef,
    62                                        ContextStack stack,
    63                                        boolean quiet) {
    65         if (stack.anyErrors()) return null;
    67         boolean doPop = false;
    68         RemoteType result = null;
    70         try {
    71             // Do we already have it?
    73             sun.tools.java.Type theType = classDef.getType();
    74             Type existing = getType(theType,stack);
    76             if (existing != null) {
    78                 if (!(existing instanceof RemoteType)) return null; // False hit.
    80                                 // Yep, so return it...
    82                 return (RemoteType) existing;
    83             }
    85             // Could this be a remote type?
    87             if (couldBeRemote(quiet,stack,classDef)) {
    89                 // Yes, so check it...
    91                 RemoteType it = new RemoteType(stack,classDef);
    92                 putType(theType,it,stack);
    93                 stack.push(it);
    94                 doPop = true;
    96                 if (it.initialize(quiet,stack)) {
    97                     stack.pop(true);
    98                     result = it;
    99                 } else {
   100                     removeType(theType,stack);
   101                     stack.pop(false);
   102                 }
   103             }
   104         } catch (CompilerError e) {
   105             if (doPop) stack.pop(false);
   106         }
   108         return result;
   109     }
   111     /**
   112      * Return a string describing this type.
   113      */
   114     public String getTypeDescription () {
   115         return "Remote interface";
   116     }
   118     //_____________________________________________________________________
   119     // Internal/Subclass Interfaces
   120     //_____________________________________________________________________
   122     /**
   123      * Create a RemoteType instance for the given class.  The resulting
   124      * object is not yet completely initialized.
   125      */
   126     protected RemoteType(ContextStack stack, ClassDefinition classDef) {
   127         super(stack,classDef,TYPE_REMOTE | TM_INTERFACE | TM_COMPOUND);
   128     }
   130     /**
   131      * Create a RemoteType instance for the given class.  The resulting
   132      * object is not yet completely initialized.
   133      */
   134     protected RemoteType(ContextStack stack, ClassDefinition classDef, int typeCode) {
   135         super(stack,classDef,typeCode);
   136     }
   138     //_____________________________________________________________________
   139     // Internal Interfaces
   140     //_____________________________________________________________________
   143     private static boolean couldBeRemote (boolean quiet, ContextStack stack,
   144                                           ClassDefinition classDef) {
   146         boolean result = false;
   147         BatchEnvironment env = stack.getEnv();
   149         try {
   150             if (!classDef.isInterface()) {
   151                 failedConstraint(16,quiet,stack,classDef.getName());
   152             } else {
   153                 result = env.defRemote.implementedBy(env,classDef.getClassDeclaration());
   154                 if (!result) failedConstraint(1,quiet,stack,classDef.getName());
   155             }
   156         } catch (ClassNotFound e) {
   157             classNotFound(stack,e);
   158         }
   160         return result;
   161     }
   164     /**
   165      * Initialize this instance.
   166      */
   167     private boolean initialize (boolean quiet,ContextStack stack) {
   169         boolean result = false;
   171         // Go check it out and gather up the info we need...
   173         Vector directInterfaces = new Vector();
   174         Vector directMethods = new Vector();
   175         Vector directConstants = new Vector();
   177         if (isConformingRemoteInterface(directInterfaces,
   178                                         directMethods,
   179                                         directConstants,
   180                                         quiet,
   181                                         stack)){
   183             // We're ok, so pass 'em up...
   185             result = initialize(directInterfaces,directMethods,directConstants,stack,quiet);
   186         }
   188         return result;
   189     }
   191     /**
   192      * Check to ensure that the interface and all it's methods and arguments
   193      * conforms to the RMI/IDL java subset for remote interfaces as defined
   194      * by the "Java to IDL Mapping" specification, section 4.
   195      * @param directInterfaces All directly implmented interfaces will be
   196      *   added to this list.
   197      * @param directMethods All directly implemented methods (other than
   198      *  constructors and initializers) will be added to this list.
   199      * @param directConstants All constants defined by theInterface will be
   200      *  added to this list.
   201      * @param quiet True if should not report constraint failures.
   202      * @return true if constraints satisfied, false otherwise.
   203      */
   204     private boolean isConformingRemoteInterface (       Vector directInterfaces,
   205                                                         Vector directMethods,
   206                                                         Vector directConstants,
   207                                                         boolean quiet,
   208                                                         ContextStack stack) {
   210         ClassDefinition theInterface = getClassDefinition();
   212         try {
   214             // Get all remote interfaces...
   216             if (addRemoteInterfaces(directInterfaces,false,stack) == null ) {
   217                 return false;
   218             }
   220             // Make sure all constants are conforming...
   222             if (!addAllMembers(directConstants,true,quiet,stack)) {
   223                 return false;
   224             }
   226             // Now, collect up all methods...
   228             if (addAllMethods(theInterface,directMethods,true,quiet,stack) == null) {
   229                 // Failed a constraint check...
   230                 return false;
   231             }
   233             // Now walk 'em, ensuring each is a valid remote method...
   235             boolean methodsConform = true;
   236             for (int i = 0; i < directMethods.size(); i++) {
   237                 if (! isConformingRemoteMethod((Method) directMethods.elementAt(i),quiet)) {
   238                     methodsConform = false;
   239                 }
   240             }
   241             if (!methodsConform) {
   242                 return false;
   243             }
   244         } catch (ClassNotFound e) {
   245             classNotFound(stack,e);
   246             return false;
   247         }
   249         return true;
   250     }
   251 }

mercurial