Thu, 24 May 2018 16:41:12 +0800
Merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | /* |
aoqi@0 | 27 | * Licensed Materials - Property of IBM |
aoqi@0 | 28 | * RMI-IIOP v1.0 |
aoqi@0 | 29 | * Copyright IBM Corp. 1998 1999 All Rights Reserved |
aoqi@0 | 30 | * |
aoqi@0 | 31 | */ |
aoqi@0 | 32 | |
aoqi@0 | 33 | package sun.rmi.rmic.iiop; |
aoqi@0 | 34 | |
aoqi@0 | 35 | import sun.rmi.rmic.Main; |
aoqi@0 | 36 | import sun.tools.java.ClassPath; |
aoqi@0 | 37 | import java.io.OutputStream; |
aoqi@0 | 38 | import sun.tools.java.ClassDefinition; |
aoqi@0 | 39 | import sun.tools.java.ClassDeclaration; |
aoqi@0 | 40 | import sun.tools.java.Identifier; |
aoqi@0 | 41 | import sun.tools.java.ClassNotFound; |
aoqi@0 | 42 | import java.util.HashSet; |
aoqi@0 | 43 | import java.util.Hashtable; |
aoqi@0 | 44 | import java.util.Enumeration; |
aoqi@0 | 45 | import java.util.Iterator; |
aoqi@0 | 46 | |
aoqi@0 | 47 | /** |
aoqi@0 | 48 | * BatchEnvironment for iiop extends rmic's version to add |
aoqi@0 | 49 | * parse state. |
aoqi@0 | 50 | */ |
aoqi@0 | 51 | public class BatchEnvironment extends sun.rmi.rmic.BatchEnvironment implements Constants { |
aoqi@0 | 52 | |
aoqi@0 | 53 | /* |
aoqi@0 | 54 | * If the following flag is true, then the IDL generator can map |
aoqi@0 | 55 | * the methods and constants of non-conforming types. However, |
aoqi@0 | 56 | * this is very expensive, so the default should be false. |
aoqi@0 | 57 | */ |
aoqi@0 | 58 | private boolean parseNonConforming = false; |
aoqi@0 | 59 | |
aoqi@0 | 60 | /** |
aoqi@0 | 61 | * This flag indicates that the stubs and ties need to be generated without |
aoqi@0 | 62 | * the package prefix (org.omg.stub). |
aoqi@0 | 63 | */ |
aoqi@0 | 64 | private boolean standardPackage; |
aoqi@0 | 65 | |
aoqi@0 | 66 | /* Common objects used within package */ |
aoqi@0 | 67 | |
aoqi@0 | 68 | HashSet alreadyChecked = new HashSet(); |
aoqi@0 | 69 | Hashtable allTypes = new Hashtable(3001, 0.5f); |
aoqi@0 | 70 | Hashtable invalidTypes = new Hashtable(256, 0.5f); |
aoqi@0 | 71 | DirectoryLoader loader = null; |
aoqi@0 | 72 | ClassPathLoader classPathLoader = null; |
aoqi@0 | 73 | Hashtable nameContexts = null; |
aoqi@0 | 74 | Hashtable namesCache = new Hashtable(); |
aoqi@0 | 75 | NameContext modulesContext = new NameContext(false); |
aoqi@0 | 76 | |
aoqi@0 | 77 | ClassDefinition defRemote = null; |
aoqi@0 | 78 | ClassDefinition defError = null; |
aoqi@0 | 79 | ClassDefinition defException = null; |
aoqi@0 | 80 | ClassDefinition defRemoteException = null; |
aoqi@0 | 81 | ClassDefinition defCorbaObject = null; |
aoqi@0 | 82 | ClassDefinition defSerializable = null; |
aoqi@0 | 83 | ClassDefinition defExternalizable = null; |
aoqi@0 | 84 | ClassDefinition defThrowable = null; |
aoqi@0 | 85 | ClassDefinition defRuntimeException = null; |
aoqi@0 | 86 | ClassDefinition defIDLEntity = null; |
aoqi@0 | 87 | ClassDefinition defValueBase = null; |
aoqi@0 | 88 | |
aoqi@0 | 89 | sun.tools.java.Type typeRemoteException = null; |
aoqi@0 | 90 | sun.tools.java.Type typeIOException = null; |
aoqi@0 | 91 | sun.tools.java.Type typeException = null; |
aoqi@0 | 92 | sun.tools.java.Type typeThrowable = null; |
aoqi@0 | 93 | |
aoqi@0 | 94 | ContextStack contextStack = null; |
aoqi@0 | 95 | |
aoqi@0 | 96 | /** |
aoqi@0 | 97 | * Create a BatchEnvironment for rmic with the given class path, |
aoqi@0 | 98 | * stream for messages and Main. |
aoqi@0 | 99 | */ |
aoqi@0 | 100 | public BatchEnvironment(OutputStream out, ClassPath path, Main main) { |
aoqi@0 | 101 | |
aoqi@0 | 102 | super(out,path,main); |
aoqi@0 | 103 | |
aoqi@0 | 104 | // Make sure we have our definitions... |
aoqi@0 | 105 | |
aoqi@0 | 106 | try { |
aoqi@0 | 107 | defRemote = |
aoqi@0 | 108 | getClassDeclaration(idRemote).getClassDefinition(this); |
aoqi@0 | 109 | defError = |
aoqi@0 | 110 | getClassDeclaration(idJavaLangError).getClassDefinition(this); |
aoqi@0 | 111 | defException = |
aoqi@0 | 112 | getClassDeclaration(idJavaLangException).getClassDefinition(this); |
aoqi@0 | 113 | defRemoteException = |
aoqi@0 | 114 | getClassDeclaration(idRemoteException).getClassDefinition(this); |
aoqi@0 | 115 | defCorbaObject = |
aoqi@0 | 116 | getClassDeclaration(idCorbaObject).getClassDefinition(this); |
aoqi@0 | 117 | defSerializable = |
aoqi@0 | 118 | getClassDeclaration(idJavaIoSerializable).getClassDefinition(this); |
aoqi@0 | 119 | defRuntimeException = |
aoqi@0 | 120 | getClassDeclaration(idJavaLangRuntimeException).getClassDefinition(this); |
aoqi@0 | 121 | defExternalizable = |
aoqi@0 | 122 | getClassDeclaration(idJavaIoExternalizable).getClassDefinition(this); |
aoqi@0 | 123 | defThrowable= |
aoqi@0 | 124 | getClassDeclaration(idJavaLangThrowable).getClassDefinition(this); |
aoqi@0 | 125 | defIDLEntity= |
aoqi@0 | 126 | getClassDeclaration(idIDLEntity).getClassDefinition(this); |
aoqi@0 | 127 | defValueBase= |
aoqi@0 | 128 | getClassDeclaration(idValueBase).getClassDefinition(this); |
aoqi@0 | 129 | typeRemoteException = defRemoteException.getClassDeclaration().getType(); |
aoqi@0 | 130 | typeException = defException.getClassDeclaration().getType(); |
aoqi@0 | 131 | typeIOException = getClassDeclaration(idJavaIoIOException).getType(); |
aoqi@0 | 132 | typeThrowable = getClassDeclaration(idJavaLangThrowable).getType(); |
aoqi@0 | 133 | |
aoqi@0 | 134 | classPathLoader = new ClassPathLoader(path); |
aoqi@0 | 135 | |
aoqi@0 | 136 | } catch (ClassNotFound e) { |
aoqi@0 | 137 | error(0, "rmic.class.not.found", e.name); |
aoqi@0 | 138 | throw new Error(); |
aoqi@0 | 139 | } |
aoqi@0 | 140 | } |
aoqi@0 | 141 | |
aoqi@0 | 142 | /** |
aoqi@0 | 143 | * Return whether or not to parse non-conforming types. |
aoqi@0 | 144 | */ |
aoqi@0 | 145 | public boolean getParseNonConforming () { |
aoqi@0 | 146 | return parseNonConforming; |
aoqi@0 | 147 | } |
aoqi@0 | 148 | |
aoqi@0 | 149 | /** |
aoqi@0 | 150 | * Set whether or not to parse non-conforming types. |
aoqi@0 | 151 | */ |
aoqi@0 | 152 | public void setParseNonConforming (boolean parseEm) { |
aoqi@0 | 153 | |
aoqi@0 | 154 | // If we are transitioning from not parsing to |
aoqi@0 | 155 | // parsing, we need to throw out any previously |
aoqi@0 | 156 | // parsed types... |
aoqi@0 | 157 | |
aoqi@0 | 158 | if (parseEm && !parseNonConforming) { |
aoqi@0 | 159 | reset(); |
aoqi@0 | 160 | } |
aoqi@0 | 161 | |
aoqi@0 | 162 | parseNonConforming = parseEm; |
aoqi@0 | 163 | } |
aoqi@0 | 164 | |
aoqi@0 | 165 | void setStandardPackage(boolean standardPackage) { |
aoqi@0 | 166 | this.standardPackage = standardPackage; |
aoqi@0 | 167 | } |
aoqi@0 | 168 | |
aoqi@0 | 169 | boolean getStandardPackage() { |
aoqi@0 | 170 | return standardPackage; |
aoqi@0 | 171 | } |
aoqi@0 | 172 | |
aoqi@0 | 173 | /** |
aoqi@0 | 174 | * Clear out any data from previous executions. |
aoqi@0 | 175 | */ |
aoqi@0 | 176 | public void reset () { |
aoqi@0 | 177 | |
aoqi@0 | 178 | // First, find all Type instances and call destroy() |
aoqi@0 | 179 | // on them... |
aoqi@0 | 180 | |
aoqi@0 | 181 | for (Enumeration e = allTypes.elements() ; e.hasMoreElements() ;) { |
aoqi@0 | 182 | Type type = (Type) e.nextElement(); |
aoqi@0 | 183 | type.destroy(); |
aoqi@0 | 184 | } |
aoqi@0 | 185 | |
aoqi@0 | 186 | for (Enumeration e = invalidTypes.keys() ; e.hasMoreElements() ;) { |
aoqi@0 | 187 | Type type = (Type) e.nextElement(); |
aoqi@0 | 188 | type.destroy(); |
aoqi@0 | 189 | } |
aoqi@0 | 190 | |
aoqi@0 | 191 | for (Iterator e = alreadyChecked.iterator() ; e.hasNext() ;) { |
aoqi@0 | 192 | Type type = (Type) e.next(); |
aoqi@0 | 193 | type.destroy(); |
aoqi@0 | 194 | } |
aoqi@0 | 195 | |
aoqi@0 | 196 | if (contextStack != null) contextStack.clear(); |
aoqi@0 | 197 | |
aoqi@0 | 198 | // Remove and clear all NameContexts in the |
aoqi@0 | 199 | // nameContexts cache... |
aoqi@0 | 200 | |
aoqi@0 | 201 | if (nameContexts != null) { |
aoqi@0 | 202 | for (Enumeration e = nameContexts.elements() ; e.hasMoreElements() ;) { |
aoqi@0 | 203 | NameContext context = (NameContext) e.nextElement(); |
aoqi@0 | 204 | context.clear(); |
aoqi@0 | 205 | } |
aoqi@0 | 206 | nameContexts.clear(); |
aoqi@0 | 207 | } |
aoqi@0 | 208 | |
aoqi@0 | 209 | // Now remove all table entries... |
aoqi@0 | 210 | |
aoqi@0 | 211 | allTypes.clear(); |
aoqi@0 | 212 | invalidTypes.clear(); |
aoqi@0 | 213 | alreadyChecked.clear(); |
aoqi@0 | 214 | namesCache.clear(); |
aoqi@0 | 215 | modulesContext.clear(); |
aoqi@0 | 216 | |
aoqi@0 | 217 | // Clean up remaining... |
aoqi@0 | 218 | loader = null; |
aoqi@0 | 219 | parseNonConforming = false; |
aoqi@0 | 220 | |
aoqi@0 | 221 | // REVISIT - can't clean up classPathLoader here |
aoqi@0 | 222 | } |
aoqi@0 | 223 | |
aoqi@0 | 224 | /** |
aoqi@0 | 225 | * Release resources, if any. |
aoqi@0 | 226 | */ |
aoqi@0 | 227 | public void shutdown() { |
aoqi@0 | 228 | if (alreadyChecked != null) { |
aoqi@0 | 229 | //System.out.println(); |
aoqi@0 | 230 | //System.out.println("allTypes.size() = "+ allTypes.size()); |
aoqi@0 | 231 | //System.out.println(" InstanceCount before reset = "+Type.instanceCount); |
aoqi@0 | 232 | reset(); |
aoqi@0 | 233 | //System.out.println(" InstanceCount AFTER reset = "+Type.instanceCount); |
aoqi@0 | 234 | |
aoqi@0 | 235 | alreadyChecked = null; |
aoqi@0 | 236 | allTypes = null; |
aoqi@0 | 237 | invalidTypes = null; |
aoqi@0 | 238 | nameContexts = null; |
aoqi@0 | 239 | namesCache = null; |
aoqi@0 | 240 | modulesContext = null; |
aoqi@0 | 241 | defRemote = null; |
aoqi@0 | 242 | defError = null; |
aoqi@0 | 243 | defException = null; |
aoqi@0 | 244 | defRemoteException = null; |
aoqi@0 | 245 | defCorbaObject = null; |
aoqi@0 | 246 | defSerializable = null; |
aoqi@0 | 247 | defExternalizable = null; |
aoqi@0 | 248 | defThrowable = null; |
aoqi@0 | 249 | defRuntimeException = null; |
aoqi@0 | 250 | defIDLEntity = null; |
aoqi@0 | 251 | defValueBase = null; |
aoqi@0 | 252 | typeRemoteException = null; |
aoqi@0 | 253 | typeIOException = null; |
aoqi@0 | 254 | typeException = null; |
aoqi@0 | 255 | typeThrowable = null; |
aoqi@0 | 256 | |
aoqi@0 | 257 | super.shutdown(); |
aoqi@0 | 258 | } |
aoqi@0 | 259 | } |
aoqi@0 | 260 | } |