URLClassPath.java revision 28
3909N/A * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Sun designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Sun in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 2362N/A * CA 95054 USA or visit www.sun.com if you need additional information or 787N/A * This class is used to maintain a search path of URLs for loading classes 787N/A * and resources from both JAR files and directories. 0N/A * @author David Connelly 0N/A /* The original search path of URLs. */ 0N/A /* The stack of unopened URLs */ 0N/A /* The resulting search path of Loaders */ 0N/A /* Map of each URL opened to its corresponding Loader */ 0N/A /* The jar protocol handler to use when creating new URLs */ 0N/A * Creates a new URLClassPath for the given URLs. The URLs will be 0N/A * searched in the order specified for classes and resources. A URL 0N/A * ending with a '/' is assumed to refer to a directory. Otherwise, 0N/A * the URL is assumed to refer to a JAR file. 0N/A * @param urls the directory and JAR file URLs to search for classes 3499N/A * @param factory the URLStreamHandlerFactory to use when creating new URLs 0N/A * Appends the specified URL to the search path of directory and JAR 0N/A * file URLs from which to load classes and resources. 792N/A * If the URL specified is null or is already in the list of 792N/A * URLs, then invoking this method has no effect. 0N/A * Returns the original search path of URLs. 0N/A * Finds the resource with the specified name on the URL search path 792N/A * or null if not found or security check fails. 792N/A * @param name the name of the resource 0N/A * @param check whether to perform a security check 0N/A * @return a <code>URL</code> for the resource, or <code>null</code> 0N/A * if the resource could not be found. 792N/A * Finds the first Resource on the URL search path which has the specified 792N/A * name. Returns null if no Resource could be found. 0N/A * @param name the name of the Resource 0N/A * @param check whether to perform a security check 0N/A * @return the Resource, or null if not found 0N/A * Finds all resources on the URL search path with the given name. 0N/A * Returns an enumeration of the URL objects. 0N/A * @param name the resource name 792N/A * @return an Enumeration of all the urls having the specified name * Finds all resources on the URL search path with the given name. * Returns an enumeration of the Resource objects. * @param name the resource name * @return an Enumeration of all the resources having the specified name * Returns the Loader at the specified position in the URL search * path. The URLs are opened and expanded as needed. Returns null * if the specified index is out of range. // Expand URL search path until the request can be satisfied // or the URL stack is empty. // Pop the next URL from the URL stack // Skip this URL if it already has a Loader. (Loader // may be null in the case where URL has not been opened // but is referenced by a JAR index.) // Otherwise, create a new Loader for the URL. // If the loader defines a local class path then add the // URLs to the list of URLs to be opened. // Silently ignore for now... // Finally, add the Loader to the search path. * Returns the Loader for the specified base URL. * Pushes the specified URLs onto the list of unopened URLs. for (
int i =
us.
length -
1; i >=
0; --i) {
* Convert class path specification into an array of file URLs. * The path of the file is encoded before conversion into URL * form so that reserved characters can safely appear in the path. // use the non-canonicalized filename * Check whether the resource URL should be returned. * Return null on security check failure. * Called by java.net.URLClassLoader. * Check whether the resource URL should be returned. * Throw exception on failure. * Called internally within this file. }
else if ((
perm instanceof * Inner class used to represent a loader of resources and classes * Creates a new Loader for the specified URL. * Returns the base URL for this Loader. * For a HTTP connection we use the HEAD method to * check if the resource exists. // our best guess for the other cases * Returns the Resource for the specified name, or null if not * found or the caller does not have the permission to get the * Returns the local class path for this loader, or null if none. * Inner class used to represent a Loader of resources from a JAR URL. * Creates a new JarLoader for the specified URL referring to // If the meta index is found but the file is not // installed, set metaIndex to null. A typical // senario is charsets.jar which won't be installed // when the user is running in certain locale environment. // The side effect of null metaIndex will cause // ensureOpen get called so that IOException is thrown. // metaIndex is null when either there is no such jar file // entry recorded in meta-index file or such jar file is // missing in JRE. See bug 6340399. // Add all the dependent URLs to the lmap so that loaders // will not be created for them by URLClassPath.getLoader(int) // if the same URL occurs later on the main class path. We set // Loader to null here to avoid creating a Loader for each // URL until we actually need to try to load something from them. // If a non-null loader already exists, leave it alone. // Optimize case where url refers to a local jar file * Returns the index of this JarLoader if it exists. * Creates the resource and if the check flag is set to true, checks if * is its okay to return the resource. // throw new IllegalArgumentException("name"); * Returns true iff atleast one resource in the jar file has the same * package name as that of the specified resource name. * Returns the URL for a resource with the specified name * Returns the JAR Resource for the specified name. * Version of getResource() that tracks the jar files that have been * visited by linking through the index files. This helper method uses * a HashSet to store the URLs of jar files that have been searched and * uses it to avoid going into an infinite loop, looking for a /* If there no jar files in the index that can potential contain * this resource then return immediately. /* loop through the mapped jar file list */ /* no loader has been set up for this jar file /* this newly opened jar file has its own index, * merge it into the parent's index, taking into * account the relative path. /* put it in the global hashtable */ /* Note that the addition of the url to the list of visited * jars incorporates a check for presence in the hashmap /* Verify that at least one other resource with the * same package name as the lookedup resource is /* the mapping is wrong */ /* If newLoader is the current loader or if it is a * loader that has already been searched or if the new * loader does not have an index then skip it * and move on to the next loader. /* Process the index of the new loader // Get the list of jar files again as the list could have grown // due to merging of index files. // If the count is unchanged, we are done. * Returns the JAR file local class path, or null if none. * parse the standard extension dependencies * Parses value of the Class-Path manifest attribute and returns * an array of URLs relative to the specified base URL. * Inner class used to represent a loader of classes and resources * from a file URL that refers to a directory. * Returns the URL for a resource with the specified name // requested resource had ../..'s in path