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

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