NCInterfaceType.java revision 608:7e06bf1dcb09
1130803Smarcel/* 2130803Smarcel * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. 3130803Smarcel * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4130803Smarcel * 5130803Smarcel * This code is free software; you can redistribute it and/or modify it 6130803Smarcel * under the terms of the GNU General Public License version 2 only, as 7130803Smarcel * published by the Free Software Foundation. Oracle designates this 8130803Smarcel * particular file as subject to the "Classpath" exception as provided 9130803Smarcel * by Oracle in the LICENSE file that accompanied this code. 10130803Smarcel * 11130803Smarcel * This code is distributed in the hope that it will be useful, but WITHOUT 12130803Smarcel * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13130803Smarcel * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14130803Smarcel * version 2 for more details (a copy is included in the LICENSE file that 15130803Smarcel * accompanied this code). 16130803Smarcel * 17130803Smarcel * You should have received a copy of the GNU General Public License version 18130803Smarcel * 2 along with this work; if not, write to the Free Software Foundation, 19130803Smarcel * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20130803Smarcel * 21130803Smarcel * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22130803Smarcel * or visit www.oracle.com if you need additional information or have any 23130803Smarcel * questions. 24130803Smarcel */ 25130803Smarcel 26130803Smarcel/* 27130803Smarcel * Licensed Materials - Property of IBM 28130803Smarcel * RMI-IIOP v1.0 29130803Smarcel * Copyright IBM Corp. 1998 1999 All Rights Reserved 30130803Smarcel * 31130803Smarcel */ 32130803Smarcel 33130803Smarcelpackage sun.rmi.rmic.iiop; 34130803Smarcel 35130803Smarcelimport java.util.Vector; 36130803Smarcelimport sun.tools.java.CompilerError; 37130803Smarcelimport sun.tools.java.ClassNotFound; 38130803Smarcelimport sun.tools.java.ClassDefinition; 39130803Smarcel 40130803Smarcel/** 41130803Smarcel * NCInterfaceType represents any non-special, non-conforming interface. 42130803Smarcel * <p> 43130803Smarcel * The static forNCInterface(...) method must be used to obtain an instance. 44130803Smarcel * @author Bryan Atsatt 45130803Smarcel */ 46130803Smarcelpublic class NCInterfaceType extends InterfaceType { 47130803Smarcel 48130803Smarcel //_____________________________________________________________________ 49130803Smarcel // Public Interfaces 50130803Smarcel //_____________________________________________________________________ 51130803Smarcel 52130803Smarcel /** 53130803Smarcel * Create an NCInterfaceType for the given class. 54130803Smarcel * 55130803Smarcel * If the class is not a properly formed or if some other error occurs, the 56130803Smarcel * return value will be null, and errors will have been reported to the 57130803Smarcel * supplied BatchEnvironment. 58130803Smarcel */ 59130803Smarcel public static NCInterfaceType forNCInterface( ClassDefinition classDef, 60130803Smarcel ContextStack stack) { 61130803Smarcel if (stack.anyErrors()) return null; 62130803Smarcel 63130803Smarcel boolean doPop = false; 64130803Smarcel try { 65130803Smarcel // Do we already have it? 66130803Smarcel 67130803Smarcel sun.tools.java.Type theType = classDef.getType(); 68130803Smarcel Type existing = getType(theType,stack); 69130803Smarcel 70130803Smarcel if (existing != null) { 71130803Smarcel 72130803Smarcel if (!(existing instanceof NCInterfaceType)) return null; // False hit. 73130803Smarcel 74130803Smarcel // Yep, so return it... 75130803Smarcel 76130803Smarcel return (NCInterfaceType) existing; 77130803Smarcel } 78130803Smarcel 79130803Smarcel NCInterfaceType it = new NCInterfaceType(stack, classDef); 80130803Smarcel putType(theType,it,stack); 81130803Smarcel stack.push(it); 82130803Smarcel doPop = true; 83130803Smarcel 84130803Smarcel if (it.initialize(stack)) { 85130803Smarcel stack.pop(true); 86130803Smarcel return it; 87130803Smarcel } else { 88130803Smarcel removeType(theType,stack); 89130803Smarcel stack.pop(false); 90130803Smarcel return null; 91130803Smarcel } 92130803Smarcel } catch (CompilerError e) { 93130803Smarcel if (doPop) stack.pop(false); 94130803Smarcel return null; 95130803Smarcel } 96130803Smarcel } 97130803Smarcel 98130803Smarcel /** 99130803Smarcel * Return a string describing this type. 100130803Smarcel */ 101130803Smarcel public String getTypeDescription () { 102130803Smarcel return "Non-conforming interface"; 103130803Smarcel } 104130803Smarcel 105130803Smarcel //_____________________________________________________________________ 106130803Smarcel // Internal/Subclass Interfaces 107130803Smarcel //_____________________________________________________________________ 108130803Smarcel 109130803Smarcel /** 110130803Smarcel * Create a NCInterfaceType instance for the given class. The resulting 111130803Smarcel * object is not yet completely initialized. 112130803Smarcel */ 113130803Smarcel private NCInterfaceType(ContextStack stack, ClassDefinition classDef) { 114130803Smarcel super(stack,classDef,TYPE_NC_INTERFACE | TM_INTERFACE | TM_COMPOUND); 115130803Smarcel } 116130803Smarcel 117130803Smarcel //_____________________________________________________________________ 118130803Smarcel // Internal Interfaces 119130803Smarcel //_____________________________________________________________________ 120130803Smarcel 121130803Smarcel /** 122130803Smarcel * Initialize this instance. 123130803Smarcel */ 124130803Smarcel private boolean initialize (ContextStack stack) { 125130803Smarcel 126130803Smarcel if (stack.getEnv().getParseNonConforming()) { 127130803Smarcel 128130803Smarcel Vector directInterfaces = new Vector(); 129130803Smarcel Vector directMethods = new Vector(); 130130803Smarcel Vector directMembers = new Vector(); 131130803Smarcel 132130803Smarcel try { 133130803Smarcel 134130803Smarcel // need to include parent interfaces in IDL generation... 135130803Smarcel addNonRemoteInterfaces( directInterfaces,stack ); 136130803Smarcel 137130803Smarcel // Get methods... 138130803Smarcel 139130803Smarcel if (addAllMethods(getClassDefinition(),directMethods,false,false,stack) != null) { 140130803Smarcel 141130803Smarcel // Get conforming constants... 142130803Smarcel 143130803Smarcel if (addConformingConstants(directMembers,false,stack)) { 144130803Smarcel 145130803Smarcel // We're ok, so pass 'em up... 146130803Smarcel 147130803Smarcel if (!initialize(directInterfaces,directMethods,directMembers,stack,false)) { 148130803Smarcel return false; 149130803Smarcel } 150130803Smarcel } 151130803Smarcel } 152130803Smarcel return true; 153130803Smarcel 154130803Smarcel } catch (ClassNotFound e) { 155130803Smarcel classNotFound(stack,e); 156130803Smarcel } 157130803Smarcel return false; 158130803Smarcel } else { 159130803Smarcel return initialize(null,null,null,stack,false); 160130803Smarcel } 161130803Smarcel } 162130803Smarcel} 163130803Smarcel