src/share/classes/sun/rmi/rmic/iiop/RemoteType.java

Mon, 26 Mar 2012 14:01:40 +0100

author
coffeys
date
Mon, 26 Mar 2012 14:01:40 +0100
changeset 370
5222b7d658d4
parent 158
91006f157c46
child 748
6845b95cba6b
permissions
-rw-r--r--

7143851: Improve IIOP stub and tie generation in RMIC
7149048: Changes to corba rmic stubGenerator class are not used during jdk build process
Reviewed-by: mschoene, robm

duke@1 1 /*
ohair@158 2 * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@158 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@158 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@158 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@158 22 * or visit www.oracle.com if you need additional information or have any
ohair@158 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 /*
duke@1 27 * Licensed Materials - Property of IBM
duke@1 28 * RMI-IIOP v1.0
duke@1 29 * Copyright IBM Corp. 1998 1999 All Rights Reserved
duke@1 30 *
duke@1 31 */
duke@1 32
duke@1 33 package sun.rmi.rmic.iiop;
duke@1 34
duke@1 35 import java.util.Vector;
duke@1 36 import sun.tools.java.CompilerError;
duke@1 37 import sun.tools.java.ClassDefinition;
duke@1 38 import sun.tools.java.ClassNotFound;
duke@1 39
duke@1 40 /**
duke@1 41 * RemoteType represents any non-special interface which inherits
duke@1 42 * from java.rmi.Remote.
duke@1 43 * <p>
duke@1 44 * The static forRemote(...) method must be used to obtain an instance, and will
duke@1 45 * return null if the ClassDefinition is non-conforming.
duke@1 46 * @author Bryan Atsatt
duke@1 47 */
duke@1 48 public class RemoteType extends InterfaceType {
duke@1 49
duke@1 50 //_____________________________________________________________________
duke@1 51 // Public Interfaces
duke@1 52 //_____________________________________________________________________
duke@1 53
duke@1 54 /**
duke@1 55 * Create an RemoteType for the given class.
duke@1 56 *
duke@1 57 * If the class is not a properly formed or if some other error occurs, the
duke@1 58 * return value will be null, and errors will have been reported to the
duke@1 59 * supplied BatchEnvironment.
duke@1 60 */
duke@1 61 public static RemoteType forRemote(ClassDefinition classDef,
duke@1 62 ContextStack stack,
duke@1 63 boolean quiet) {
duke@1 64
duke@1 65 if (stack.anyErrors()) return null;
duke@1 66
duke@1 67 boolean doPop = false;
duke@1 68 RemoteType result = null;
duke@1 69
duke@1 70 try {
duke@1 71 // Do we already have it?
duke@1 72
duke@1 73 sun.tools.java.Type theType = classDef.getType();
duke@1 74 Type existing = getType(theType,stack);
duke@1 75
duke@1 76 if (existing != null) {
duke@1 77
duke@1 78 if (!(existing instanceof RemoteType)) return null; // False hit.
duke@1 79
duke@1 80 // Yep, so return it...
duke@1 81
duke@1 82 return (RemoteType) existing;
duke@1 83 }
duke@1 84
duke@1 85 // Could this be a remote type?
duke@1 86
duke@1 87 if (couldBeRemote(quiet,stack,classDef)) {
duke@1 88
duke@1 89 // Yes, so check it...
duke@1 90
duke@1 91 RemoteType it = new RemoteType(stack,classDef);
duke@1 92 putType(theType,it,stack);
duke@1 93 stack.push(it);
duke@1 94 doPop = true;
duke@1 95
duke@1 96 if (it.initialize(quiet,stack)) {
duke@1 97 stack.pop(true);
duke@1 98 result = it;
duke@1 99 } else {
duke@1 100 removeType(theType,stack);
duke@1 101 stack.pop(false);
duke@1 102 }
duke@1 103 }
duke@1 104 } catch (CompilerError e) {
duke@1 105 if (doPop) stack.pop(false);
duke@1 106 }
duke@1 107
duke@1 108 return result;
duke@1 109 }
duke@1 110
duke@1 111 /**
duke@1 112 * Return a string describing this type.
duke@1 113 */
duke@1 114 public String getTypeDescription () {
duke@1 115 return "Remote interface";
duke@1 116 }
duke@1 117
duke@1 118 //_____________________________________________________________________
duke@1 119 // Internal/Subclass Interfaces
duke@1 120 //_____________________________________________________________________
duke@1 121
duke@1 122 /**
duke@1 123 * Create a RemoteType instance for the given class. The resulting
duke@1 124 * object is not yet completely initialized.
duke@1 125 */
duke@1 126 protected RemoteType(ContextStack stack, ClassDefinition classDef) {
duke@1 127 super(stack,classDef,TYPE_REMOTE | TM_INTERFACE | TM_COMPOUND);
duke@1 128 }
duke@1 129
duke@1 130 /**
duke@1 131 * Create a RemoteType instance for the given class. The resulting
duke@1 132 * object is not yet completely initialized.
duke@1 133 */
duke@1 134 protected RemoteType(ContextStack stack, ClassDefinition classDef, int typeCode) {
duke@1 135 super(stack,classDef,typeCode);
duke@1 136 }
duke@1 137
duke@1 138 //_____________________________________________________________________
duke@1 139 // Internal Interfaces
duke@1 140 //_____________________________________________________________________
duke@1 141
duke@1 142
duke@1 143 private static boolean couldBeRemote (boolean quiet, ContextStack stack,
duke@1 144 ClassDefinition classDef) {
duke@1 145
duke@1 146 boolean result = false;
duke@1 147 BatchEnvironment env = stack.getEnv();
duke@1 148
duke@1 149 try {
duke@1 150 if (!classDef.isInterface()) {
duke@1 151 failedConstraint(16,quiet,stack,classDef.getName());
duke@1 152 } else {
duke@1 153 result = env.defRemote.implementedBy(env,classDef.getClassDeclaration());
duke@1 154 if (!result) failedConstraint(1,quiet,stack,classDef.getName());
duke@1 155 }
duke@1 156 } catch (ClassNotFound e) {
duke@1 157 classNotFound(stack,e);
duke@1 158 }
duke@1 159
duke@1 160 return result;
duke@1 161 }
duke@1 162
duke@1 163
duke@1 164 /**
duke@1 165 * Initialize this instance.
duke@1 166 */
duke@1 167 private boolean initialize (boolean quiet,ContextStack stack) {
duke@1 168
duke@1 169 boolean result = false;
duke@1 170
duke@1 171 // Go check it out and gather up the info we need...
duke@1 172
duke@1 173 Vector directInterfaces = new Vector();
duke@1 174 Vector directMethods = new Vector();
duke@1 175 Vector directConstants = new Vector();
duke@1 176
duke@1 177 if (isConformingRemoteInterface(directInterfaces,
duke@1 178 directMethods,
duke@1 179 directConstants,
duke@1 180 quiet,
duke@1 181 stack)){
duke@1 182
duke@1 183 // We're ok, so pass 'em up...
duke@1 184
duke@1 185 result = initialize(directInterfaces,directMethods,directConstants,stack,quiet);
duke@1 186 }
duke@1 187
duke@1 188 return result;
duke@1 189 }
duke@1 190
duke@1 191 /**
duke@1 192 * Check to ensure that the interface and all it's methods and arguments
duke@1 193 * conforms to the RMI/IDL java subset for remote interfaces as defined
duke@1 194 * by the "Java to IDL Mapping" specification, section 4.
duke@1 195 * @param directInterfaces All directly implmented interfaces will be
duke@1 196 * added to this list.
duke@1 197 * @param directMethods All directly implemented methods (other than
duke@1 198 * constructors and initializers) will be added to this list.
duke@1 199 * @param directConstants All constants defined by theInterface will be
duke@1 200 * added to this list.
duke@1 201 * @param quiet True if should not report constraint failures.
duke@1 202 * @return true if constraints satisfied, false otherwise.
duke@1 203 */
duke@1 204 private boolean isConformingRemoteInterface ( Vector directInterfaces,
duke@1 205 Vector directMethods,
duke@1 206 Vector directConstants,
duke@1 207 boolean quiet,
duke@1 208 ContextStack stack) {
duke@1 209
duke@1 210 ClassDefinition theInterface = getClassDefinition();
duke@1 211
duke@1 212 try {
duke@1 213
duke@1 214 // Get all remote interfaces...
duke@1 215
duke@1 216 if (addRemoteInterfaces(directInterfaces,false,stack) == null ) {
duke@1 217 return false;
duke@1 218 }
duke@1 219
duke@1 220 // Make sure all constants are conforming...
duke@1 221
duke@1 222 if (!addAllMembers(directConstants,true,quiet,stack)) {
duke@1 223 return false;
duke@1 224 }
duke@1 225
duke@1 226 // Now, collect up all methods...
duke@1 227
duke@1 228 if (addAllMethods(theInterface,directMethods,true,quiet,stack) == null) {
duke@1 229 // Failed a constraint check...
duke@1 230 return false;
duke@1 231 }
duke@1 232
duke@1 233 // Now walk 'em, ensuring each is a valid remote method...
duke@1 234
duke@1 235 boolean methodsConform = true;
duke@1 236 for (int i = 0; i < directMethods.size(); i++) {
duke@1 237 if (! isConformingRemoteMethod((Method) directMethods.elementAt(i),quiet)) {
duke@1 238 methodsConform = false;
duke@1 239 }
duke@1 240 }
duke@1 241 if (!methodsConform) {
duke@1 242 return false;
duke@1 243 }
duke@1 244 } catch (ClassNotFound e) {
duke@1 245 classNotFound(stack,e);
duke@1 246 return false;
duke@1 247 }
duke@1 248
duke@1 249 return true;
duke@1 250 }
duke@1 251 }

mercurial