jdk/src/share/classes/sun/applet/AppletClassLoader.java
author herrick
Fri, 12 Jun 2009 14:56:32 -0400
changeset 3111 fefdeafb7ab9
parent 2 90ce3da70b43
child 4188 f67abce80f05
permissions -rw-r--r--
6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7 6845973: Update JDK7 with deployment changes in 6u13, 6u14 4802695: Support 64-bit Java Plug-in and Java webstart on Windows/Linux on AMD64 6825019: DownloadManager should not be loaded and referenced for full JRE 6738770: REGRESSION:JSException throws when use LiveConnect javascript facility 6772884: plugin2 : java.lang.OutOfMemoryError or crash 6707535: Crossing domain hole affecting multiple sites/domains using plug-in 6728071: Non-verification of Update files may allow unintended updates 6704154: Code loaded from local filesystem should not get access to localhost 6727081: Web Start security restrictions bypass using special extension jnlp 6727079: Java Web Start Socket() restriction bypass 6727071: Cache location/user name information disclosure in SingleInstanceImpl. 6716217: AppletClassLoader adds permissions based on codebase regardless of CS 6694892: Java Webstart inclusion via system properties override [CVE-2008-2086] 6704074: localhost socket access due to cache location exposed 6703909: Java webstart arbitrary file creation using nativelib 6665315: browser crashes when deployment.properties has more slashes ( / ) 6660121: Encoding values in JNLP files can cause buffer overflow 6606110: URLConnection.setProxiedHost for resources that are loaded via proxy 6581221: SSV(VISTA): Redirection FAILS to work if user does a downgrade install 6609756: Buffer Overflow in Java ActiveX component 6608712: Bypassing the same origin policy in Java with crafted names 6534630: "gnumake clobber" doesn't 6849953: JDK7 - replacement of bufferoverflowU.lib on amd64 breaks build 6849029: Need some JDK7 merge clean-up after comments on the webrev 6847582: Build problem on JDK7 with isSecureProperty in merge 6827935: JDK 7 deployment merging - problem in Compiler-msvm.gmk 6823215: latest merge fixes from 6u12 -> JDK7 6816153: further mergers for JDK7 deployment integration 6807074: Fix Java Kernel and JQS in initial JDK7 builds Summary: Initial changeset for implementing 6uX Deployment Features into JDK7 Reviewed-by: dgu, billyh
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1995-2005 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.lang.NullPointerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.net.URLClassLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.net.SocketPermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.net.URLConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.net.InetAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.net.UnknownHostException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.FilePermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.BufferedInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.util.NoSuchElementException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.security.AccessControlContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.security.PrivilegedExceptionAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.security.PrivilegedActionException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.security.CodeSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.security.Permission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.security.PermissionCollection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import sun.awt.AppContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import sun.net.www.ParseUtil;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import sun.security.util.SecurityConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * This class defines the class loader for loading applet classes and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * resources. It extends URLClassLoader to search the applet code base
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * for the class or resource after checking any loaded JAR files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
public class AppletClassLoader extends URLClassLoader {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private URL base;   /* applet code base URL */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private CodeSource codesource; /* codesource for the base URL */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private AccessControlContext acc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private boolean exceptionStatus = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private final Object threadGroupSynchronizer = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private final Object grabReleaseSynchronizer = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private boolean codebaseLookup = true;
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
    72
    private volatile boolean allowRecursiveDirectoryRead = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * Creates a new AppletClassLoader for the specified base URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    protected AppletClassLoader(URL base) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        super(new URL[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        this.base = base;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        this.codesource =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            new CodeSource(base, (java.security.cert.Certificate[]) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        acc = AccessController.getContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
    85
    public void disableRecursiveDirectoryRead() {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
    86
        allowRecursiveDirectoryRead = false;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
    87
    }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
    88
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
    89
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Set the codebase lookup flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    void setCodebaseLookup(boolean codebaseLookup)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        this.codebaseLookup = codebaseLookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Returns the applet code base URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    URL getBaseURL() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return base;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Returns the URLs used for loading classes and resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public URL[] getURLs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        URL[] jars = super.getURLs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        URL[] urls = new URL[jars.length + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        System.arraycopy(jars, 0, urls, 0, jars.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        urls[urls.length - 1] = base;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        return urls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Adds the specified JAR file to the search path of loaded JAR files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Changed modifier to protected in order to be able to overwrite addJar()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * in PluginClassLoader.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    protected void addJar(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        URL url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            url = new URL(base, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        } catch (MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            throw new IllegalArgumentException("name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        addURL(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        // DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        //URL[] urls = getURLs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        //for (int i = 0; i < urls.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        //    System.out.println("url[" + i + "] = " + urls[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        //}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Override loadClass so that class loading errors can be caught in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * order to print better error messages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public synchronized Class loadClass(String name, boolean resolve)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        throws ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        // First check if we have permission to access the package. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        // should go away once we've added support for exported packages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        int i = name.lastIndexOf('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (i != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            if (sm != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                sm.checkPackageAccess(name.substring(0, i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            return super.loadClass(name, resolve);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            //printError(name, e.getException());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        } catch (RuntimeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            //printError(name, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        } catch (Error e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            //printError(name, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Finds the applet class with the specified name. First searches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * loaded JAR files then the applet code base for the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    protected Class findClass(String name) throws ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        int index = name.indexOf(";");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        String cookie = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        if(index != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                cookie = name.substring(index, name.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                name = name.substring(0, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        // check loaded JAR files
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            return super.findClass(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        // Otherwise, try loading the class from the code base URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        // 4668479: Option to turn off codebase lookup in AppletClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        // during resource requests. [stanley.ho]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        if (codebaseLookup == false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            throw new ClassNotFoundException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
//      final String path = name.replace('.', '/').concat(".class").concat(cookie);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        String encodedName = ParseUtil.encodePath(name.replace('.', '/'), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        final String path = (new StringBuffer(encodedName)).append(".class").append(cookie).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            byte[] b = (byte[]) AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                               new PrivilegedExceptionAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                public Object run() throws IOException {
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   197
                   try {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   198
                        URL finalURL = new URL(base, path);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   199
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   200
                        // Make sure the codebase won't be modified
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   201
                        if (base.getProtocol().equals(finalURL.getProtocol()) &&
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   202
                            base.getHost().equals(finalURL.getHost()) &&
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   203
                            base.getPort() == finalURL.getPort()) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   204
                            return getBytes(finalURL);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   205
                        }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   206
                        else {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   207
                            return null;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   208
                        }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   209
                    } catch (Exception e) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   210
                        return null;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   211
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            }, acc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            if (b != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                return defineClass(name, b, 0, b.length, codesource);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                throw new ClassNotFoundException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        } catch (PrivilegedActionException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            throw new ClassNotFoundException(name, e.getException());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * Returns the permissions for the given codesource object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * The implementation of this method first calls super.getPermissions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * to get the permissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * granted by the super class, and then adds additional permissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * based on the URL of the codesource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * If the protocol is "file"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * and the path specifies a file, permission is granted to read all files
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * and (recursively) all files and subdirectories contained in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * that directory. This is so applets with a codebase of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * file:/blah/some.jar can read in file:/blah/, which is needed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * be backward compatible. We also add permission to connect back to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * the "localhost".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @param codesource the codesource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @return the permissions granted to the codesource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    protected PermissionCollection getPermissions(CodeSource codesource)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        final PermissionCollection perms = super.getPermissions(codesource);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        URL url = codesource.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        String path = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        Permission p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            p = url.openConnection().getPermission();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        } catch (java.io.IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            p = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if (p instanceof FilePermission) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            path = p.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        } else if ((p == null) && (url.getProtocol().equals("file"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            path = url.getFile().replace('/', File.separatorChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            path = ParseUtil.decode(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        if (path != null) {
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   266
            final String rawPath = path;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            if (!path.endsWith(File.separator)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                int endIndex = path.lastIndexOf(File.separatorChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                if (endIndex != -1) {
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   270
                        path = path.substring(0, endIndex + 1) + "-";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                        perms.add(new FilePermission(path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                            SecurityConstants.FILE_READ_ACTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            }
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   275
            final File f = new File(rawPath);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   276
            final boolean isDirectory = f.isDirectory();
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   277
            // grant codebase recursive read permission
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   278
            // this should only be granted to non-UNC file URL codebase and
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   279
            // the codesource path must either be a directory, or a file
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   280
            // that ends with .jar or .zip
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   281
            if (allowRecursiveDirectoryRead && (isDirectory ||
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   282
                    rawPath.toLowerCase().endsWith(".jar") ||
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   283
                    rawPath.toLowerCase().endsWith(".zip"))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            Permission bperm;
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   286
                try {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   287
                    bperm = base.openConnection().getPermission();
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   288
                } catch (java.io.IOException ioe) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   289
                    bperm = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                }
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   291
                if (bperm instanceof FilePermission) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   292
                    String bpath = bperm.getName();
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   293
                    if (bpath.endsWith(File.separator)) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   294
                        bpath += "-";
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   295
                    }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   296
                    perms.add(new FilePermission(bpath,
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   297
                        SecurityConstants.FILE_READ_ACTION));
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   298
                } else if ((bperm == null) && (base.getProtocol().equals("file"))) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   299
                    String bpath = base.getFile().replace('/', File.separatorChar);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   300
                    bpath = ParseUtil.decode(bpath);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   301
                    if (bpath.endsWith(File.separator)) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   302
                        bpath += "-";
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   303
                    }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   304
                    perms.add(new FilePermission(bpath, SecurityConstants.FILE_READ_ACTION));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                }
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   306
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        return perms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * Returns the contents of the specified URL as an array of bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    private static byte[] getBytes(URL url) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        URLConnection uc = url.openConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        if (uc instanceof java.net.HttpURLConnection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            java.net.HttpURLConnection huc = (java.net.HttpURLConnection) uc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            int code = huc.getResponseCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            if (code >= java.net.HttpURLConnection.HTTP_BAD_REQUEST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                throw new IOException("open HTTP connection failed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        int len = uc.getContentLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        // Fixed #4507227: Slow performance to load
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        // class and resources. [stanleyh]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        // Use buffered input stream [stanleyh]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        InputStream in = new BufferedInputStream(uc.getInputStream());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        byte[] b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            if (len != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                // Read exactly len bytes from the input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                b = new byte[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                while (len > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                    int n = in.read(b, b.length - len, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                    if (n == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                        throw new IOException("unexpected EOF");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                    len -= n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                // Read until end of stream is reached - use 8K buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                // to speed up performance [stanleyh]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                b = new byte[8192];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                int total = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                while ((len = in.read(b, total, b.length - total)) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                    total += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    if (total >= b.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                        byte[] tmp = new byte[total * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                        System.arraycopy(b, 0, tmp, 0, total);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                        b = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                // Trim array to correct size, if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                if (total != b.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                    byte[] tmp = new byte[total];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    System.arraycopy(b, 0, tmp, 0, total);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                    b = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    // Object for synchronization around getResourceAsStream()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    private Object syncResourceAsStream = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    private Object syncResourceAsStreamFromJar = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    // Flag to indicate getResourceAsStream() is in call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    private boolean resourceAsStreamInCall = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    private boolean resourceAsStreamFromJarInCall = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * Returns an input stream for reading the specified resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * The search order is described in the documentation for {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * #getResource(String)}.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @param  name the resource name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @return an input stream for reading the resource, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *         if the resource could not be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @since  JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    public InputStream getResourceAsStream(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            throw new NullPointerException("name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            InputStream is = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            // Fixed #4507227: Slow performance to load
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            // class and resources. [stanleyh]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            // The following is used to avoid calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            // AppletClassLoader.findResource() in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            // super.getResourceAsStream(). Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            // unnecessary connection will be made.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            synchronized(syncResourceAsStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                resourceAsStreamInCall = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                // Call super class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                is = super.getResourceAsStream(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                resourceAsStreamInCall = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            // 4668479: Option to turn off codebase lookup in AppletClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            // during resource requests. [stanley.ho]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            if (codebaseLookup == true && is == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                // If resource cannot be obtained,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                // try to download it from codebase
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                URL url = new URL(base, ParseUtil.encodePath(name, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                is = url.openStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            return is;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        catch (Exception e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * Returns an input stream for reading the specified resource from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * the loaded jar files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * The search order is described in the documentation for {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * #getResource(String)}.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @param  name the resource name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @return an input stream for reading the resource, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *         if the resource could not be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @since  JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    public InputStream getResourceAsStreamFromJar(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            throw new NullPointerException("name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            InputStream is = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            synchronized(syncResourceAsStreamFromJar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                resourceAsStreamFromJarInCall = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                // Call super class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                is = super.getResourceAsStream(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                resourceAsStreamFromJarInCall = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            return is;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * Finds the applet resource with the specified name. First checks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * loaded JAR files then the applet code base for the resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    public URL findResource(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        // check loaded JAR files
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        URL url = super.findResource(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        // 6215746:  Disable META-INF/* lookup from codebase in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        // applet/plugin classloader. [stanley.ho]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        if (name.startsWith("META-INF/"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            return url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        // 4668479: Option to turn off codebase lookup in AppletClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        // during resource requests. [stanley.ho]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        if (codebaseLookup == false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            return url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        if (url == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            //#4805170, if it is a call from Applet.getImage()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            //we should check for the image only in the archives
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            boolean insideGetResourceAsStreamFromJar = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                synchronized(syncResourceAsStreamFromJar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                insideGetResourceAsStreamFromJar = resourceAsStreamFromJarInCall;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            if (insideGetResourceAsStreamFromJar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            // Fixed #4507227: Slow performance to load
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            // class and resources. [stanleyh]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            // Check if getResourceAsStream is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            boolean insideGetResourceAsStream = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            synchronized(syncResourceAsStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                insideGetResourceAsStream = resourceAsStreamInCall;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            // If getResourceAsStream is called, don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            // trigger the following code. Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            // unnecessary connection will be made.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            if (insideGetResourceAsStream == false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                // otherwise, try the code base
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                    url = new URL(base, ParseUtil.encodePath(name, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                    // check if resource exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                    if(!resourceExists(url))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                        url = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                    // all exceptions, including security exceptions, are caught
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                    url = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        return url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    private boolean resourceExists(URL url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        // Check if the resource exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        // It almost works to just try to do an openConnection() but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        // HttpURLConnection will return true on HTTP_BAD_REQUEST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        // when the requested name ends in ".html", ".htm", and ".txt"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        // and we want to be able to handle these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        // Also, cannot just open a connection for things like FileURLConnection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        // because they succeed when connecting to a nonexistent file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        // So, in those cases we open and close an input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        boolean ok = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            URLConnection conn = url.openConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            if (conn instanceof java.net.HttpURLConnection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                java.net.HttpURLConnection hconn =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                    (java.net.HttpURLConnection) conn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                // To reduce overhead, using http HEAD method instead of GET method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                hconn.setRequestMethod("HEAD");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                int code = hconn.getResponseCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                if (code == java.net.HttpURLConnection.HTTP_OK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                if (code >= java.net.HttpURLConnection.HTTP_BAD_REQUEST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                 * Fix for #4182052 - stanleyh
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                 * The same connection should be reused to avoid multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                 * HTTP connections
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                // our best guess for the other cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                InputStream is = conn.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                is.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        return ok;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * Returns an enumeration of all the applet resources with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * name. First checks loaded JAR files then the applet code base for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * available resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    public Enumeration findResources(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        final Enumeration e = super.findResources(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        // 6215746:  Disable META-INF/* lookup from codebase in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        // applet/plugin classloader. [stanley.ho]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        if (name.startsWith("META-INF/"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        // 4668479: Option to turn off codebase lookup in AppletClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        // during resource requests. [stanley.ho]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        if (codebaseLookup == false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        URL u = new URL(base, ParseUtil.encodePath(name, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        if (!resourceExists(u)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            u = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        final URL url = u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        return new Enumeration() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            private boolean done;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            public Object nextElement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                if (!done) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                    if (e.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                        return e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                    done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                    if (url != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                        return url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                throw new NoSuchElementException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            public boolean hasMoreElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                return !done && (e.hasMoreElements() || url != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * Load and resolve the file specified by the applet tag CODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * attribute. The argument can either be the relative path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * of the class file itself or just the name of the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    Class loadCode(String name) throws ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        // first convert any '/' or native file separator to .
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        name = name.replace('/', '.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        name = name.replace(File.separatorChar, '.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        // deal with URL rewriting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        String cookie = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        int index = name.indexOf(";");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        if(index != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                cookie = name.substring(index, name.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                name = name.substring(0, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        // save that name for later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        String fullName = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        // then strip off any suffixes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        if (name.endsWith(".class") || name.endsWith(".java")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            name = name.substring(0, name.lastIndexOf('.'));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                if(cookie != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                        name = (new StringBuffer(name)).append(cookie).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            return loadClass(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        // then if it didn't end with .java or .class, or in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        // really pathological case of a class named class or java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        if(cookie != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                fullName = (new StringBuffer(fullName)).append(cookie).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        return loadClass(fullName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * The threadgroup that the applets loaded by this classloader live
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * in. In the sun.* implementation of applets, the security manager's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * (AppletSecurity) getThreadGroup returns the thread group of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * first applet on the stack, which is the applet's thread group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    private AppletThreadGroup threadGroup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    private AppContext appContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    public ThreadGroup getThreadGroup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
      synchronized (threadGroupSynchronizer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        if (threadGroup == null || threadGroup.isDestroyed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            AccessController.doPrivileged(new PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                    threadGroup = new AppletThreadGroup(base + "-threadGroup");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                    // threadGroup.setDaemon(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                    // threadGroup is now destroyed by AppContext.dispose()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                    // Create the new AppContext from within a Thread belonging
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                    // to the newly created ThreadGroup, and wait for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                    // creation to complete before returning from this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                    AppContextCreator creatorThread = new AppContextCreator(threadGroup);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                    // Since this thread will later be used to launch the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                    // applet's AWT-event dispatch thread and we want the applet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                    // code executing the AWT callbacks to use their own class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                    // loader rather than the system class loader, explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                    // set the context class loader to the AppletClassLoader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                    creatorThread.setContextClassLoader(AppletClassLoader.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                    synchronized(creatorThread.syncObject)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                        creatorThread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                            creatorThread.syncObject.wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                        } catch (InterruptedException e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                        appContext = creatorThread.appContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        return threadGroup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * Get the AppContext, if any, corresponding to this AppletClassLoader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    public AppContext getAppContext()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        return appContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    int usageCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * Grab this AppletClassLoader and its ThreadGroup/AppContext, so they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * won't be destroyed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     */
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   722
public     void grab() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        synchronized(grabReleaseSynchronizer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            usageCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        getThreadGroup(); // Make sure ThreadGroup/AppContext exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    protected void setExceptionStatus()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        exceptionStatus = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    public boolean getExceptionStatus()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        return exceptionStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * Release this AppletClassLoader and its ThreadGroup/AppContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * If nothing else has grabbed this AppletClassLoader, its ThreadGroup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * and AppContext will be destroyed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * Because this method may destroy the AppletClassLoader's ThreadGroup,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * this method should NOT be called from within the AppletClassLoader's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * ThreadGroup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * Changed modifier to protected in order to be able to overwrite this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * function in PluginClassLoader.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    protected void release() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        AppContext tempAppContext = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        synchronized(grabReleaseSynchronizer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            if (usageCount > 1)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                --usageCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                synchronized(threadGroupSynchronizer) {
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   760
                    tempAppContext = resetAppContext();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        // Dispose appContext outside any sync block to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        // prevent potential deadlock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        if (tempAppContext != null)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                tempAppContext.dispose(); // nuke the world!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            } catch (IllegalThreadStateException e) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   774
    /*
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   775
     * reset classloader's AppContext and ThreadGroup
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   776
     * This method is for subclass PluginClassLoader to
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   777
     * reset superclass's AppContext and ThreadGroup but do
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   778
     * not dispose the AppContext. PluginClassLoader does not
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   779
     * use UsageCount to decide whether to dispose AppContext
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   780
     *
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   781
     * @return previous AppContext
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   782
     */
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   783
    protected AppContext resetAppContext() {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   784
        AppContext tempAppContext = null;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   785
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   786
        synchronized(threadGroupSynchronizer) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   787
            // Store app context in temp variable
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   788
            tempAppContext = appContext;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   789
            usageCount = 0;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   790
            appContext = null;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   791
            threadGroup = null;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   792
        }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   793
        return tempAppContext;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   794
    }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   795
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2
diff changeset
   796
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    // Hash map to store applet compatibility info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    private HashMap jdk11AppletInfo = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    private HashMap jdk12AppletInfo = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * Set applet target level as JDK 1.1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * @param clazz Applet class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * @param bool true if JDK is targeted for JDK 1.1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     *             false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    void setJDK11Target(Class clazz, boolean bool)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
         jdk11AppletInfo.put(clazz.toString(), Boolean.valueOf(bool));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * Set applet target level as JDK 1.2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * @param clazz Applet class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * @param bool true if JDK is targeted for JDK 1.2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     *             false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    void setJDK12Target(Class clazz, boolean bool)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        jdk12AppletInfo.put(clazz.toString(), Boolean.valueOf(bool));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * Determine if applet is targeted for JDK 1.1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * @param applet Applet class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * @return TRUE if applet is targeted for JDK 1.1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     *         FALSE if applet is not;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     *         null if applet is unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    Boolean isJDK11Target(Class clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        return (Boolean) jdk11AppletInfo.get(clazz.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * Determine if applet is targeted for JDK 1.2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * @param applet Applet class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * @return TRUE if applet is targeted for JDK 1.2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     *         FALSE if applet is not;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     *         null if applet is unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    Boolean isJDK12Target(Class clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        return (Boolean) jdk12AppletInfo.get(clazz.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    private static AppletMessageHandler mh =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        new AppletMessageHandler("appletclassloader");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * Prints a class loading error message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    private static void printError(String name, Throwable e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        String s = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        if (e == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            s = mh.getMessage("filenotfound", name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        } else if (e instanceof IOException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            s = mh.getMessage("fileioexception", name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        } else if (e instanceof ClassFormatError) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            s = mh.getMessage("fileformat", name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        } else if (e instanceof ThreadDeath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            s = mh.getMessage("filedeath", name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        } else if (e instanceof Error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            s = mh.getMessage("fileerror", e.toString(), name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            System.err.println(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
 * The AppContextCreator class is used to create an AppContext from within
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
 * a Thread belonging to the new AppContext's ThreadGroup.  To wait for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
 * this operation to complete before continuing, wait for the notifyAll()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
 * operation on the syncObject to occur.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
class AppContextCreator extends Thread  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    Object syncObject = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    AppContext appContext = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    AppContextCreator(ThreadGroup group)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        super(group, "AppContextCreator");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    public void run()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        synchronized(syncObject)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            appContext = SunToolkit.createNewAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            syncObject.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    } // run()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
} // class AppContextCreator