1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/sun/rmi/rmic/iiop/RemoteType.java Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,251 @@ 1.4 +/* 1.5 + * Portions Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Sun designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Sun in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.26 + * have any questions. 1.27 + */ 1.28 + 1.29 +/* 1.30 + * Licensed Materials - Property of IBM 1.31 + * RMI-IIOP v1.0 1.32 + * Copyright IBM Corp. 1998 1999 All Rights Reserved 1.33 + * 1.34 + */ 1.35 + 1.36 +package sun.rmi.rmic.iiop; 1.37 + 1.38 +import java.util.Vector; 1.39 +import sun.tools.java.CompilerError; 1.40 +import sun.tools.java.ClassDefinition; 1.41 +import sun.tools.java.ClassNotFound; 1.42 + 1.43 +/** 1.44 + * RemoteType represents any non-special interface which inherits 1.45 + * from java.rmi.Remote. 1.46 + * <p> 1.47 + * The static forRemote(...) method must be used to obtain an instance, and will 1.48 + * return null if the ClassDefinition is non-conforming. 1.49 + * @author Bryan Atsatt 1.50 + */ 1.51 +public class RemoteType extends InterfaceType { 1.52 + 1.53 + //_____________________________________________________________________ 1.54 + // Public Interfaces 1.55 + //_____________________________________________________________________ 1.56 + 1.57 + /** 1.58 + * Create an RemoteType for the given class. 1.59 + * 1.60 + * If the class is not a properly formed or if some other error occurs, the 1.61 + * return value will be null, and errors will have been reported to the 1.62 + * supplied BatchEnvironment. 1.63 + */ 1.64 + public static RemoteType forRemote(ClassDefinition classDef, 1.65 + ContextStack stack, 1.66 + boolean quiet) { 1.67 + 1.68 + if (stack.anyErrors()) return null; 1.69 + 1.70 + boolean doPop = false; 1.71 + RemoteType result = null; 1.72 + 1.73 + try { 1.74 + // Do we already have it? 1.75 + 1.76 + sun.tools.java.Type theType = classDef.getType(); 1.77 + Type existing = getType(theType,stack); 1.78 + 1.79 + if (existing != null) { 1.80 + 1.81 + if (!(existing instanceof RemoteType)) return null; // False hit. 1.82 + 1.83 + // Yep, so return it... 1.84 + 1.85 + return (RemoteType) existing; 1.86 + } 1.87 + 1.88 + // Could this be a remote type? 1.89 + 1.90 + if (couldBeRemote(quiet,stack,classDef)) { 1.91 + 1.92 + // Yes, so check it... 1.93 + 1.94 + RemoteType it = new RemoteType(stack,classDef); 1.95 + putType(theType,it,stack); 1.96 + stack.push(it); 1.97 + doPop = true; 1.98 + 1.99 + if (it.initialize(quiet,stack)) { 1.100 + stack.pop(true); 1.101 + result = it; 1.102 + } else { 1.103 + removeType(theType,stack); 1.104 + stack.pop(false); 1.105 + } 1.106 + } 1.107 + } catch (CompilerError e) { 1.108 + if (doPop) stack.pop(false); 1.109 + } 1.110 + 1.111 + return result; 1.112 + } 1.113 + 1.114 + /** 1.115 + * Return a string describing this type. 1.116 + */ 1.117 + public String getTypeDescription () { 1.118 + return "Remote interface"; 1.119 + } 1.120 + 1.121 + //_____________________________________________________________________ 1.122 + // Internal/Subclass Interfaces 1.123 + //_____________________________________________________________________ 1.124 + 1.125 + /** 1.126 + * Create a RemoteType instance for the given class. The resulting 1.127 + * object is not yet completely initialized. 1.128 + */ 1.129 + protected RemoteType(ContextStack stack, ClassDefinition classDef) { 1.130 + super(stack,classDef,TYPE_REMOTE | TM_INTERFACE | TM_COMPOUND); 1.131 + } 1.132 + 1.133 + /** 1.134 + * Create a RemoteType instance for the given class. The resulting 1.135 + * object is not yet completely initialized. 1.136 + */ 1.137 + protected RemoteType(ContextStack stack, ClassDefinition classDef, int typeCode) { 1.138 + super(stack,classDef,typeCode); 1.139 + } 1.140 + 1.141 + //_____________________________________________________________________ 1.142 + // Internal Interfaces 1.143 + //_____________________________________________________________________ 1.144 + 1.145 + 1.146 + private static boolean couldBeRemote (boolean quiet, ContextStack stack, 1.147 + ClassDefinition classDef) { 1.148 + 1.149 + boolean result = false; 1.150 + BatchEnvironment env = stack.getEnv(); 1.151 + 1.152 + try { 1.153 + if (!classDef.isInterface()) { 1.154 + failedConstraint(16,quiet,stack,classDef.getName()); 1.155 + } else { 1.156 + result = env.defRemote.implementedBy(env,classDef.getClassDeclaration()); 1.157 + if (!result) failedConstraint(1,quiet,stack,classDef.getName()); 1.158 + } 1.159 + } catch (ClassNotFound e) { 1.160 + classNotFound(stack,e); 1.161 + } 1.162 + 1.163 + return result; 1.164 + } 1.165 + 1.166 + 1.167 + /** 1.168 + * Initialize this instance. 1.169 + */ 1.170 + private boolean initialize (boolean quiet,ContextStack stack) { 1.171 + 1.172 + boolean result = false; 1.173 + 1.174 + // Go check it out and gather up the info we need... 1.175 + 1.176 + Vector directInterfaces = new Vector(); 1.177 + Vector directMethods = new Vector(); 1.178 + Vector directConstants = new Vector(); 1.179 + 1.180 + if (isConformingRemoteInterface(directInterfaces, 1.181 + directMethods, 1.182 + directConstants, 1.183 + quiet, 1.184 + stack)){ 1.185 + 1.186 + // We're ok, so pass 'em up... 1.187 + 1.188 + result = initialize(directInterfaces,directMethods,directConstants,stack,quiet); 1.189 + } 1.190 + 1.191 + return result; 1.192 + } 1.193 + 1.194 + /** 1.195 + * Check to ensure that the interface and all it's methods and arguments 1.196 + * conforms to the RMI/IDL java subset for remote interfaces as defined 1.197 + * by the "Java to IDL Mapping" specification, section 4. 1.198 + * @param directInterfaces All directly implmented interfaces will be 1.199 + * added to this list. 1.200 + * @param directMethods All directly implemented methods (other than 1.201 + * constructors and initializers) will be added to this list. 1.202 + * @param directConstants All constants defined by theInterface will be 1.203 + * added to this list. 1.204 + * @param quiet True if should not report constraint failures. 1.205 + * @return true if constraints satisfied, false otherwise. 1.206 + */ 1.207 + private boolean isConformingRemoteInterface ( Vector directInterfaces, 1.208 + Vector directMethods, 1.209 + Vector directConstants, 1.210 + boolean quiet, 1.211 + ContextStack stack) { 1.212 + 1.213 + ClassDefinition theInterface = getClassDefinition(); 1.214 + 1.215 + try { 1.216 + 1.217 + // Get all remote interfaces... 1.218 + 1.219 + if (addRemoteInterfaces(directInterfaces,false,stack) == null ) { 1.220 + return false; 1.221 + } 1.222 + 1.223 + // Make sure all constants are conforming... 1.224 + 1.225 + if (!addAllMembers(directConstants,true,quiet,stack)) { 1.226 + return false; 1.227 + } 1.228 + 1.229 + // Now, collect up all methods... 1.230 + 1.231 + if (addAllMethods(theInterface,directMethods,true,quiet,stack) == null) { 1.232 + // Failed a constraint check... 1.233 + return false; 1.234 + } 1.235 + 1.236 + // Now walk 'em, ensuring each is a valid remote method... 1.237 + 1.238 + boolean methodsConform = true; 1.239 + for (int i = 0; i < directMethods.size(); i++) { 1.240 + if (! isConformingRemoteMethod((Method) directMethods.elementAt(i),quiet)) { 1.241 + methodsConform = false; 1.242 + } 1.243 + } 1.244 + if (!methodsConform) { 1.245 + return false; 1.246 + } 1.247 + } catch (ClassNotFound e) { 1.248 + classNotFound(stack,e); 1.249 + return false; 1.250 + } 1.251 + 1.252 + return true; 1.253 + } 1.254 +}