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.ClassNotFound; duke@1: import sun.tools.java.ClassDefinition; duke@1: duke@1: /** duke@1: * AbstractType represents any non-special interface which does not duke@1: * inherit from java.rmi.Remote, for which all methods throw RemoteException. duke@1: *

duke@1: * The static forAbstract(...) 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 AbstractType extends RemoteType { duke@1: duke@1: //_____________________________________________________________________ duke@1: // Public Interfaces duke@1: //_____________________________________________________________________ duke@1: duke@1: /** duke@1: * Create an AbstractType 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 AbstractType forAbstract(ClassDefinition classDef, duke@1: ContextStack stack, duke@1: boolean quiet) duke@1: { duke@1: boolean doPop = false; duke@1: AbstractType result = null; duke@1: duke@1: try { duke@1: 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 AbstractType)) return null; // False hit. duke@1: duke@1: // Yep, so return it... duke@1: duke@1: return (AbstractType) existing; duke@1: duke@1: } duke@1: duke@1: // Could this be an abstract? duke@1: duke@1: if (couldBeAbstract(stack,classDef,quiet)) { duke@1: duke@1: // Yes, so try it... duke@1: duke@1: AbstractType it = new AbstractType(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 "Abstract interface"; duke@1: } duke@1: duke@1: //_____________________________________________________________________ duke@1: // Internal/Subclass Interfaces duke@1: //_____________________________________________________________________ duke@1: duke@1: /** duke@1: * Create a AbstractType instance for the given class. The resulting duke@1: * object is not yet completely initialized. duke@1: */ duke@1: private AbstractType(ContextStack stack, ClassDefinition classDef) { duke@1: super(stack,classDef,TYPE_ABSTRACT | TM_INTERFACE | TM_COMPOUND); duke@1: } duke@1: duke@1: //_____________________________________________________________________ duke@1: // Internal Interfaces duke@1: //_____________________________________________________________________ duke@1: duke@1: duke@1: private static boolean couldBeAbstract(ContextStack stack, ClassDefinition classDef, duke@1: boolean quiet) { duke@1: duke@1: // Return true if interface and not remote... duke@1: duke@1: boolean result = false; duke@1: duke@1: if (classDef.isInterface()) { duke@1: BatchEnvironment env = stack.getEnv(); duke@1: duke@1: try { duke@1: result = ! env.defRemote.implementedBy(env, classDef.getClassDeclaration()); duke@1: if (!result) failedConstraint(15,quiet,stack,classDef.getName()); duke@1: } catch (ClassNotFound e) { duke@1: classNotFound(stack,e); duke@1: } duke@1: } else { duke@1: failedConstraint(14,quiet,stack,classDef.getName()); duke@1: } 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: ClassDefinition self = getClassDefinition(); duke@1: duke@1: try { duke@1: duke@1: // Get methods... duke@1: duke@1: Vector directMethods = new Vector(); duke@1: duke@1: if (addAllMethods(self,directMethods,true,quiet,stack) != null) { duke@1: duke@1: // Do we have any methods? duke@1: duke@1: boolean validMethods = true; duke@1: duke@1: if (directMethods.size() > 0) { duke@1: duke@1: // Yes. Walk 'em, ensuring each is a valid remote method... duke@1: duke@1: for (int i = 0; i < directMethods.size(); i++) { duke@1: duke@1: if (! isConformingRemoteMethod((Method) directMethods.elementAt(i),true)) { duke@1: validMethods = false; duke@1: } duke@1: } duke@1: } duke@1: duke@1: if (validMethods) { duke@1: duke@1: // We're ok, so pass 'em up... duke@1: duke@1: result = initialize(null,directMethods,null,stack,quiet); duke@1: } duke@1: } duke@1: } catch (ClassNotFound e) { duke@1: classNotFound(stack,e); duke@1: } duke@1: duke@1: return result; duke@1: } duke@1: }