src/share/classes/sun/rmi/rmic/iiop/BatchEnvironment.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 sun.rmi.rmic.Main;
duke@1 36 import sun.tools.java.ClassPath;
duke@1 37 import java.io.OutputStream;
duke@1 38 import sun.tools.java.ClassDefinition;
duke@1 39 import sun.tools.java.ClassDeclaration;
duke@1 40 import sun.tools.java.Identifier;
duke@1 41 import sun.tools.java.ClassNotFound;
duke@1 42 import java.util.HashSet;
duke@1 43 import java.util.Hashtable;
duke@1 44 import java.util.Enumeration;
duke@1 45 import java.util.Iterator;
duke@1 46
duke@1 47 /**
duke@1 48 * BatchEnvironment for iiop extends rmic's version to add
duke@1 49 * parse state.
duke@1 50 */
duke@1 51 public class BatchEnvironment extends sun.rmi.rmic.BatchEnvironment implements Constants {
duke@1 52
duke@1 53 /*
duke@1 54 * If the following flag is true, then the IDL generator can map
duke@1 55 * the methods and constants of non-conforming types. However,
duke@1 56 * this is very expensive, so the default should be false.
duke@1 57 */
duke@1 58 private boolean parseNonConforming = false;
duke@1 59
duke@1 60 /**
duke@1 61 * This flag indicates that the stubs and ties need to be generated without
duke@1 62 * the package prefix (org.omg.stub).
duke@1 63 */
duke@1 64 private boolean standardPackage;
duke@1 65
duke@1 66 /* Common objects used within package */
duke@1 67
duke@1 68 HashSet alreadyChecked = new HashSet();
duke@1 69 Hashtable allTypes = new Hashtable(3001, 0.5f);
duke@1 70 Hashtable invalidTypes = new Hashtable(256, 0.5f);
duke@1 71 DirectoryLoader loader = null;
duke@1 72 ClassPathLoader classPathLoader = null;
duke@1 73 Hashtable nameContexts = null;
duke@1 74 Hashtable namesCache = new Hashtable();
duke@1 75 NameContext modulesContext = new NameContext(false);
duke@1 76
duke@1 77 ClassDefinition defRemote = null;
duke@1 78 ClassDefinition defError = null;
duke@1 79 ClassDefinition defException = null;
duke@1 80 ClassDefinition defRemoteException = null;
duke@1 81 ClassDefinition defCorbaObject = null;
duke@1 82 ClassDefinition defSerializable = null;
duke@1 83 ClassDefinition defExternalizable = null;
duke@1 84 ClassDefinition defThrowable = null;
duke@1 85 ClassDefinition defRuntimeException = null;
duke@1 86 ClassDefinition defIDLEntity = null;
duke@1 87 ClassDefinition defValueBase = null;
duke@1 88
duke@1 89 sun.tools.java.Type typeRemoteException = null;
duke@1 90 sun.tools.java.Type typeIOException = null;
duke@1 91 sun.tools.java.Type typeException = null;
duke@1 92 sun.tools.java.Type typeThrowable = null;
duke@1 93
duke@1 94 ContextStack contextStack = null;
duke@1 95
duke@1 96 /**
duke@1 97 * Create a BatchEnvironment for rmic with the given class path,
duke@1 98 * stream for messages and Main.
duke@1 99 */
duke@1 100 public BatchEnvironment(OutputStream out, ClassPath path, Main main) {
duke@1 101
duke@1 102 super(out,path,main);
duke@1 103
duke@1 104 // Make sure we have our definitions...
duke@1 105
duke@1 106 try {
duke@1 107 defRemote =
duke@1 108 getClassDeclaration(idRemote).getClassDefinition(this);
duke@1 109 defError =
duke@1 110 getClassDeclaration(idJavaLangError).getClassDefinition(this);
duke@1 111 defException =
duke@1 112 getClassDeclaration(idJavaLangException).getClassDefinition(this);
duke@1 113 defRemoteException =
duke@1 114 getClassDeclaration(idRemoteException).getClassDefinition(this);
duke@1 115 defCorbaObject =
duke@1 116 getClassDeclaration(idCorbaObject).getClassDefinition(this);
duke@1 117 defSerializable =
duke@1 118 getClassDeclaration(idJavaIoSerializable).getClassDefinition(this);
duke@1 119 defRuntimeException =
duke@1 120 getClassDeclaration(idJavaLangRuntimeException).getClassDefinition(this);
duke@1 121 defExternalizable =
duke@1 122 getClassDeclaration(idJavaIoExternalizable).getClassDefinition(this);
duke@1 123 defThrowable=
duke@1 124 getClassDeclaration(idJavaLangThrowable).getClassDefinition(this);
duke@1 125 defIDLEntity=
duke@1 126 getClassDeclaration(idIDLEntity).getClassDefinition(this);
duke@1 127 defValueBase=
duke@1 128 getClassDeclaration(idValueBase).getClassDefinition(this);
duke@1 129 typeRemoteException = defRemoteException.getClassDeclaration().getType();
duke@1 130 typeException = defException.getClassDeclaration().getType();
duke@1 131 typeIOException = getClassDeclaration(idJavaIoIOException).getType();
duke@1 132 typeThrowable = getClassDeclaration(idJavaLangThrowable).getType();
duke@1 133
duke@1 134 classPathLoader = new ClassPathLoader(path);
duke@1 135
duke@1 136 } catch (ClassNotFound e) {
duke@1 137 error(0, "rmic.class.not.found", e.name);
duke@1 138 throw new Error();
duke@1 139 }
duke@1 140 }
duke@1 141
duke@1 142 /**
duke@1 143 * Return whether or not to parse non-conforming types.
duke@1 144 */
duke@1 145 public boolean getParseNonConforming () {
duke@1 146 return parseNonConforming;
duke@1 147 }
duke@1 148
duke@1 149 /**
duke@1 150 * Set whether or not to parse non-conforming types.
duke@1 151 */
duke@1 152 public void setParseNonConforming (boolean parseEm) {
duke@1 153
duke@1 154 // If we are transitioning from not parsing to
duke@1 155 // parsing, we need to throw out any previously
duke@1 156 // parsed types...
duke@1 157
duke@1 158 if (parseEm && !parseNonConforming) {
duke@1 159 reset();
duke@1 160 }
duke@1 161
duke@1 162 parseNonConforming = parseEm;
duke@1 163 }
duke@1 164
duke@1 165 void setStandardPackage(boolean standardPackage) {
duke@1 166 this.standardPackage = standardPackage;
duke@1 167 }
duke@1 168
duke@1 169 boolean getStandardPackage() {
duke@1 170 return standardPackage;
duke@1 171 }
duke@1 172
duke@1 173 /**
duke@1 174 * Clear out any data from previous executions.
duke@1 175 */
duke@1 176 public void reset () {
duke@1 177
duke@1 178 // First, find all Type instances and call destroy()
duke@1 179 // on them...
duke@1 180
duke@1 181 for (Enumeration e = allTypes.elements() ; e.hasMoreElements() ;) {
duke@1 182 Type type = (Type) e.nextElement();
duke@1 183 type.destroy();
duke@1 184 }
duke@1 185
duke@1 186 for (Enumeration e = invalidTypes.keys() ; e.hasMoreElements() ;) {
duke@1 187 Type type = (Type) e.nextElement();
duke@1 188 type.destroy();
duke@1 189 }
duke@1 190
duke@1 191 for (Iterator e = alreadyChecked.iterator() ; e.hasNext() ;) {
duke@1 192 Type type = (Type) e.next();
duke@1 193 type.destroy();
duke@1 194 }
duke@1 195
duke@1 196 if (contextStack != null) contextStack.clear();
duke@1 197
duke@1 198 // Remove and clear all NameContexts in the
duke@1 199 // nameContexts cache...
duke@1 200
duke@1 201 if (nameContexts != null) {
duke@1 202 for (Enumeration e = nameContexts.elements() ; e.hasMoreElements() ;) {
duke@1 203 NameContext context = (NameContext) e.nextElement();
duke@1 204 context.clear();
duke@1 205 }
duke@1 206 nameContexts.clear();
duke@1 207 }
duke@1 208
duke@1 209 // Now remove all table entries...
duke@1 210
duke@1 211 allTypes.clear();
duke@1 212 invalidTypes.clear();
duke@1 213 alreadyChecked.clear();
duke@1 214 namesCache.clear();
duke@1 215 modulesContext.clear();
duke@1 216
duke@1 217 // Clean up remaining...
duke@1 218 loader = null;
duke@1 219 parseNonConforming = false;
duke@1 220
duke@1 221 // REVISIT - can't clean up classPathLoader here
duke@1 222 }
duke@1 223
duke@1 224 /**
duke@1 225 * Release resources, if any.
duke@1 226 */
duke@1 227 public void shutdown() {
duke@1 228 if (alreadyChecked != null) {
duke@1 229 //System.out.println();
duke@1 230 //System.out.println("allTypes.size() = "+ allTypes.size());
duke@1 231 //System.out.println(" InstanceCount before reset = "+Type.instanceCount);
duke@1 232 reset();
duke@1 233 //System.out.println(" InstanceCount AFTER reset = "+Type.instanceCount);
duke@1 234
duke@1 235 alreadyChecked = null;
duke@1 236 allTypes = null;
duke@1 237 invalidTypes = null;
duke@1 238 nameContexts = null;
duke@1 239 namesCache = null;
duke@1 240 modulesContext = null;
duke@1 241 defRemote = null;
duke@1 242 defError = null;
duke@1 243 defException = null;
duke@1 244 defRemoteException = null;
duke@1 245 defCorbaObject = null;
duke@1 246 defSerializable = null;
duke@1 247 defExternalizable = null;
duke@1 248 defThrowable = null;
duke@1 249 defRuntimeException = null;
duke@1 250 defIDLEntity = null;
duke@1 251 defValueBase = null;
duke@1 252 typeRemoteException = null;
duke@1 253 typeIOException = null;
duke@1 254 typeException = null;
duke@1 255 typeThrowable = null;
duke@1 256
duke@1 257 super.shutdown();
duke@1 258 }
duke@1 259 }
duke@1 260 }

mercurial