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

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