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 java.util.Vector; aoqi@0: import sun.tools.java.CompilerError; aoqi@0: import sun.tools.java.ClassDefinition; aoqi@0: import sun.tools.java.ClassNotFound; aoqi@0: aoqi@0: /** aoqi@0: * RemoteType represents any non-special interface which inherits aoqi@0: * from java.rmi.Remote. aoqi@0: *

aoqi@0: * The static forRemote(...) method must be used to obtain an instance, and will aoqi@0: * return null if the ClassDefinition is non-conforming. aoqi@0: * @author Bryan Atsatt aoqi@0: */ aoqi@0: public class RemoteType extends InterfaceType { aoqi@0: aoqi@0: //_____________________________________________________________________ aoqi@0: // Public Interfaces aoqi@0: //_____________________________________________________________________ aoqi@0: aoqi@0: /** aoqi@0: * Create an RemoteType 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 RemoteType forRemote(ClassDefinition classDef, aoqi@0: ContextStack stack, aoqi@0: boolean quiet) { aoqi@0: aoqi@0: if (stack.anyErrors()) return null; aoqi@0: aoqi@0: boolean doPop = false; aoqi@0: RemoteType result = null; aoqi@0: aoqi@0: try { aoqi@0: // Do we already have it? aoqi@0: aoqi@0: sun.tools.java.Type theType = classDef.getType(); aoqi@0: Type existing = getType(theType,stack); aoqi@0: aoqi@0: if (existing != null) { aoqi@0: aoqi@0: if (!(existing instanceof RemoteType)) return null; // False hit. aoqi@0: aoqi@0: // Yep, so return it... aoqi@0: aoqi@0: return (RemoteType) existing; aoqi@0: } aoqi@0: aoqi@0: // Could this be a remote type? aoqi@0: aoqi@0: if (couldBeRemote(quiet,stack,classDef)) { aoqi@0: aoqi@0: // Yes, so check it... aoqi@0: aoqi@0: RemoteType it = new RemoteType(stack,classDef); aoqi@0: putType(theType,it,stack); aoqi@0: stack.push(it); aoqi@0: doPop = true; aoqi@0: aoqi@0: if (it.initialize(quiet,stack)) { aoqi@0: stack.pop(true); aoqi@0: result = it; aoqi@0: } else { aoqi@0: removeType(theType,stack); aoqi@0: stack.pop(false); aoqi@0: } aoqi@0: } aoqi@0: } catch (CompilerError e) { aoqi@0: if (doPop) stack.pop(false); aoqi@0: } aoqi@0: aoqi@0: return result; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return a string describing this type. aoqi@0: */ aoqi@0: public String getTypeDescription () { aoqi@0: return "Remote interface"; aoqi@0: } aoqi@0: aoqi@0: //_____________________________________________________________________ aoqi@0: // Internal/Subclass Interfaces aoqi@0: //_____________________________________________________________________ aoqi@0: aoqi@0: /** aoqi@0: * Create a RemoteType instance for the given class. The resulting aoqi@0: * object is not yet completely initialized. aoqi@0: */ aoqi@0: protected RemoteType(ContextStack stack, ClassDefinition classDef) { aoqi@0: super(stack,classDef,TYPE_REMOTE | TM_INTERFACE | TM_COMPOUND); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Create a RemoteType instance for the given class. The resulting aoqi@0: * object is not yet completely initialized. aoqi@0: */ aoqi@0: protected RemoteType(ContextStack stack, ClassDefinition classDef, int typeCode) { aoqi@0: super(stack,classDef,typeCode); aoqi@0: } aoqi@0: aoqi@0: //_____________________________________________________________________ aoqi@0: // Internal Interfaces aoqi@0: //_____________________________________________________________________ aoqi@0: aoqi@0: aoqi@0: private static boolean couldBeRemote (boolean quiet, ContextStack stack, aoqi@0: ClassDefinition classDef) { aoqi@0: aoqi@0: boolean result = false; aoqi@0: BatchEnvironment env = stack.getEnv(); aoqi@0: aoqi@0: try { aoqi@0: if (!classDef.isInterface()) { aoqi@0: failedConstraint(16,quiet,stack,classDef.getName()); aoqi@0: } else { aoqi@0: result = env.defRemote.implementedBy(env,classDef.getClassDeclaration()); aoqi@0: if (!result) failedConstraint(1,quiet,stack,classDef.getName()); aoqi@0: } aoqi@0: } catch (ClassNotFound e) { aoqi@0: classNotFound(stack,e); aoqi@0: } aoqi@0: aoqi@0: return result; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: /** aoqi@0: * Initialize this instance. aoqi@0: */ aoqi@0: private boolean initialize (boolean quiet,ContextStack stack) { aoqi@0: aoqi@0: boolean result = false; aoqi@0: aoqi@0: // Go check it out and gather up the info we need... aoqi@0: aoqi@0: Vector directInterfaces = new Vector(); aoqi@0: Vector directMethods = new Vector(); aoqi@0: Vector directConstants = new Vector(); aoqi@0: aoqi@0: if (isConformingRemoteInterface(directInterfaces, aoqi@0: directMethods, aoqi@0: directConstants, aoqi@0: quiet, aoqi@0: stack)){ aoqi@0: aoqi@0: // We're ok, so pass 'em up... aoqi@0: aoqi@0: result = initialize(directInterfaces,directMethods,directConstants,stack,quiet); aoqi@0: } aoqi@0: aoqi@0: return result; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Check to ensure that the interface and all it's methods and arguments aoqi@0: * conforms to the RMI/IDL java subset for remote interfaces as defined aoqi@0: * by the "Java to IDL Mapping" specification, section 4. aoqi@0: * @param directInterfaces All directly implmented interfaces will be aoqi@0: * added to this list. aoqi@0: * @param directMethods All directly implemented methods (other than aoqi@0: * constructors and initializers) will be added to this list. aoqi@0: * @param directConstants All constants defined by theInterface will be aoqi@0: * added to this list. aoqi@0: * @param quiet True if should not report constraint failures. aoqi@0: * @return true if constraints satisfied, false otherwise. aoqi@0: */ aoqi@0: private boolean isConformingRemoteInterface ( Vector directInterfaces, aoqi@0: Vector directMethods, aoqi@0: Vector directConstants, aoqi@0: boolean quiet, aoqi@0: ContextStack stack) { aoqi@0: aoqi@0: ClassDefinition theInterface = getClassDefinition(); aoqi@0: aoqi@0: try { aoqi@0: aoqi@0: // Get all remote interfaces... aoqi@0: aoqi@0: if (addRemoteInterfaces(directInterfaces,false,stack) == null ) { aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: // Make sure all constants are conforming... aoqi@0: aoqi@0: if (!addAllMembers(directConstants,true,quiet,stack)) { aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: // Now, collect up all methods... aoqi@0: aoqi@0: if (addAllMethods(theInterface,directMethods,true,quiet,stack) == null) { aoqi@0: // Failed a constraint check... aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: // Now walk 'em, ensuring each is a valid remote method... aoqi@0: aoqi@0: boolean methodsConform = true; aoqi@0: for (int i = 0; i < directMethods.size(); i++) { aoqi@0: if (! isConformingRemoteMethod((Method) directMethods.elementAt(i),quiet)) { aoqi@0: methodsConform = false; aoqi@0: } aoqi@0: } aoqi@0: if (!methodsConform) { aoqi@0: return false; aoqi@0: } aoqi@0: } catch (ClassNotFound e) { aoqi@0: classNotFound(stack,e); aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: return true; aoqi@0: } aoqi@0: }