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

changeset 0
7ef37b2cdcad
child 748
6845b95cba6b
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/sun/rmi/rmic/iiop/BatchEnvironment.java	Wed Apr 27 01:21:28 2016 +0800
     1.3 @@ -0,0 +1,260 @@
     1.4 +/*
     1.5 + * Copyright (c) 1998, 2007, Oracle and/or its affiliates. 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.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * 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 sun.rmi.rmic.Main;
    1.39 +import sun.tools.java.ClassPath;
    1.40 +import java.io.OutputStream;
    1.41 +import sun.tools.java.ClassDefinition;
    1.42 +import sun.tools.java.ClassDeclaration;
    1.43 +import sun.tools.java.Identifier;
    1.44 +import sun.tools.java.ClassNotFound;
    1.45 +import java.util.HashSet;
    1.46 +import java.util.Hashtable;
    1.47 +import java.util.Enumeration;
    1.48 +import java.util.Iterator;
    1.49 +
    1.50 +/**
    1.51 + * BatchEnvironment for iiop extends rmic's version to add
    1.52 + * parse state.
    1.53 + */
    1.54 +public class BatchEnvironment extends sun.rmi.rmic.BatchEnvironment implements Constants {
    1.55 +
    1.56 +    /*
    1.57 +     * If the following flag is true, then the IDL generator can map
    1.58 +     * the methods and constants of non-conforming types. However,
    1.59 +     * this is very expensive, so the default should be false.
    1.60 +     */
    1.61 +    private boolean parseNonConforming = false;
    1.62 +
    1.63 +    /**
    1.64 +     * This flag indicates that the stubs and ties need to be generated without
    1.65 +     * the package prefix (org.omg.stub).
    1.66 +     */
    1.67 +    private boolean standardPackage;
    1.68 +
    1.69 +    /* Common objects used within package */
    1.70 +
    1.71 +    HashSet alreadyChecked = new HashSet();
    1.72 +    Hashtable allTypes = new Hashtable(3001, 0.5f);
    1.73 +    Hashtable invalidTypes = new Hashtable(256, 0.5f);
    1.74 +    DirectoryLoader loader = null;
    1.75 +    ClassPathLoader classPathLoader = null;
    1.76 +    Hashtable nameContexts = null;
    1.77 +    Hashtable namesCache = new Hashtable();
    1.78 +    NameContext modulesContext = new NameContext(false);
    1.79 +
    1.80 +    ClassDefinition defRemote = null;
    1.81 +    ClassDefinition defError = null;
    1.82 +    ClassDefinition defException = null;
    1.83 +    ClassDefinition defRemoteException = null;
    1.84 +    ClassDefinition defCorbaObject = null;
    1.85 +    ClassDefinition defSerializable = null;
    1.86 +    ClassDefinition defExternalizable = null;
    1.87 +    ClassDefinition defThrowable = null;
    1.88 +    ClassDefinition defRuntimeException = null;
    1.89 +    ClassDefinition defIDLEntity = null;
    1.90 +    ClassDefinition defValueBase = null;
    1.91 +
    1.92 +    sun.tools.java.Type typeRemoteException = null;
    1.93 +    sun.tools.java.Type typeIOException = null;
    1.94 +    sun.tools.java.Type typeException = null;
    1.95 +    sun.tools.java.Type typeThrowable = null;
    1.96 +
    1.97 +    ContextStack contextStack = null;
    1.98 +
    1.99 +    /**
   1.100 +     * Create a BatchEnvironment for rmic with the given class path,
   1.101 +     * stream for messages and Main.
   1.102 +     */
   1.103 +    public BatchEnvironment(OutputStream out, ClassPath path, Main main) {
   1.104 +
   1.105 +        super(out,path,main);
   1.106 +
   1.107 +        // Make sure we have our definitions...
   1.108 +
   1.109 +        try {
   1.110 +            defRemote =
   1.111 +                getClassDeclaration(idRemote).getClassDefinition(this);
   1.112 +            defError =
   1.113 +                getClassDeclaration(idJavaLangError).getClassDefinition(this);
   1.114 +            defException =
   1.115 +                getClassDeclaration(idJavaLangException).getClassDefinition(this);
   1.116 +            defRemoteException =
   1.117 +                getClassDeclaration(idRemoteException).getClassDefinition(this);
   1.118 +            defCorbaObject =
   1.119 +                getClassDeclaration(idCorbaObject).getClassDefinition(this);
   1.120 +            defSerializable =
   1.121 +                getClassDeclaration(idJavaIoSerializable).getClassDefinition(this);
   1.122 +            defRuntimeException =
   1.123 +                getClassDeclaration(idJavaLangRuntimeException).getClassDefinition(this);
   1.124 +            defExternalizable =
   1.125 +                getClassDeclaration(idJavaIoExternalizable).getClassDefinition(this);
   1.126 +            defThrowable=
   1.127 +                getClassDeclaration(idJavaLangThrowable).getClassDefinition(this);
   1.128 +            defIDLEntity=
   1.129 +                getClassDeclaration(idIDLEntity).getClassDefinition(this);
   1.130 +            defValueBase=
   1.131 +                getClassDeclaration(idValueBase).getClassDefinition(this);
   1.132 +            typeRemoteException = defRemoteException.getClassDeclaration().getType();
   1.133 +            typeException = defException.getClassDeclaration().getType();
   1.134 +            typeIOException = getClassDeclaration(idJavaIoIOException).getType();
   1.135 +            typeThrowable = getClassDeclaration(idJavaLangThrowable).getType();
   1.136 +
   1.137 +            classPathLoader = new ClassPathLoader(path);
   1.138 +
   1.139 +        } catch (ClassNotFound e) {
   1.140 +            error(0, "rmic.class.not.found", e.name);
   1.141 +            throw new Error();
   1.142 +        }
   1.143 +    }
   1.144 +
   1.145 +    /**
   1.146 +     * Return whether or not to parse non-conforming types.
   1.147 +     */
   1.148 +    public boolean getParseNonConforming () {
   1.149 +        return parseNonConforming;
   1.150 +    }
   1.151 +
   1.152 +    /**
   1.153 +     * Set whether or not to parse non-conforming types.
   1.154 +     */
   1.155 +    public void setParseNonConforming (boolean parseEm) {
   1.156 +
   1.157 +        // If we are transitioning from not parsing to
   1.158 +        // parsing, we need to throw out any previously
   1.159 +        // parsed types...
   1.160 +
   1.161 +        if (parseEm && !parseNonConforming) {
   1.162 +            reset();
   1.163 +        }
   1.164 +
   1.165 +        parseNonConforming = parseEm;
   1.166 +    }
   1.167 +
   1.168 +    void setStandardPackage(boolean standardPackage) {
   1.169 +        this.standardPackage = standardPackage;
   1.170 +    }
   1.171 +
   1.172 +    boolean getStandardPackage() {
   1.173 +        return standardPackage;
   1.174 +    }
   1.175 +
   1.176 +    /**
   1.177 +     * Clear out any data from previous executions.
   1.178 +     */
   1.179 +    public void reset () {
   1.180 +
   1.181 +        // First, find all Type instances and call destroy()
   1.182 +        // on them...
   1.183 +
   1.184 +        for (Enumeration e = allTypes.elements() ; e.hasMoreElements() ;) {
   1.185 +            Type type = (Type) e.nextElement();
   1.186 +            type.destroy();
   1.187 +        }
   1.188 +
   1.189 +        for (Enumeration e = invalidTypes.keys() ; e.hasMoreElements() ;) {
   1.190 +            Type type = (Type) e.nextElement();
   1.191 +            type.destroy();
   1.192 +        }
   1.193 +
   1.194 +        for (Iterator e = alreadyChecked.iterator() ; e.hasNext() ;) {
   1.195 +            Type type = (Type) e.next();
   1.196 +            type.destroy();
   1.197 +        }
   1.198 +
   1.199 +        if (contextStack != null) contextStack.clear();
   1.200 +
   1.201 +        // Remove and clear all NameContexts in the
   1.202 +        // nameContexts cache...
   1.203 +
   1.204 +        if (nameContexts != null) {
   1.205 +            for (Enumeration e = nameContexts.elements() ; e.hasMoreElements() ;) {
   1.206 +                NameContext context = (NameContext) e.nextElement();
   1.207 +                context.clear();
   1.208 +            }
   1.209 +            nameContexts.clear();
   1.210 +        }
   1.211 +
   1.212 +        // Now remove all table entries...
   1.213 +
   1.214 +        allTypes.clear();
   1.215 +        invalidTypes.clear();
   1.216 +        alreadyChecked.clear();
   1.217 +        namesCache.clear();
   1.218 +        modulesContext.clear();
   1.219 +
   1.220 +        // Clean up remaining...
   1.221 +        loader = null;
   1.222 +        parseNonConforming = false;
   1.223 +
   1.224 +        // REVISIT - can't clean up classPathLoader here
   1.225 +    }
   1.226 +
   1.227 +    /**
   1.228 +     * Release resources, if any.
   1.229 +     */
   1.230 +    public void shutdown() {
   1.231 +        if (alreadyChecked != null) {
   1.232 +            //System.out.println();
   1.233 +            //System.out.println("allTypes.size() = "+ allTypes.size());
   1.234 +            //System.out.println("    InstanceCount before reset = "+Type.instanceCount);
   1.235 +            reset();
   1.236 +            //System.out.println("    InstanceCount AFTER reset = "+Type.instanceCount);
   1.237 +
   1.238 +            alreadyChecked = null;
   1.239 +            allTypes = null;
   1.240 +            invalidTypes = null;
   1.241 +            nameContexts = null;
   1.242 +            namesCache = null;
   1.243 +            modulesContext = null;
   1.244 +            defRemote = null;
   1.245 +            defError = null;
   1.246 +            defException = null;
   1.247 +            defRemoteException = null;
   1.248 +            defCorbaObject = null;
   1.249 +            defSerializable = null;
   1.250 +            defExternalizable = null;
   1.251 +            defThrowable = null;
   1.252 +            defRuntimeException = null;
   1.253 +            defIDLEntity = null;
   1.254 +            defValueBase = null;
   1.255 +            typeRemoteException = null;
   1.256 +            typeIOException = null;
   1.257 +            typeException = null;
   1.258 +            typeThrowable = null;
   1.259 +
   1.260 +            super.shutdown();
   1.261 +        }
   1.262 +    }
   1.263 +}

mercurial