Build 1.0_r1(from source)

java.net
Class URLClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by java.net.URLClassLoader
Direct Known Subclasses:
URLClassLoader.SubURLClassLoader

public class URLClassLoader
extends SecureClassLoader

This class loader is responsible for loading classes and resources from a list of URLs which can refer to either directories or JAR files. Classes loaded by this URLClassLoader are granted permission to access the URLs contained in the URL search list.


Nested Class Summary
(package private) static class URLClassLoader.SubURLClassLoader
           
 
Field Summary
(package private)  HashMap<URL,URL[]> extensions
           
(package private)  Hashtable<String,URL[]>[] indexes
           
(package private)  Set<URL> invalidUrls
           
(package private)  URL[] orgUrls
           
(package private)  URL[] urls
           
 
Constructor Summary
URLClassLoader(URL[] urls)
          Constructs a new instance of this class.
URLClassLoader(URL[] urls, ClassLoader parent)
          Constructs a new instance of this class.
URLClassLoader(URL[] searchUrls, ClassLoader parent, URLStreamHandlerFactory factory)
          Constructs a new instance of this class.
 
Method Summary
protected  void addURL(URL url)
          Adds the specified URL to the search list.
(package private)  URL[] addURL(URL[] urlArray, URL url)
          Returns an array with the given URL added to the given array.
protected  Package definePackage(String packageName, Manifest manifest, URL url)
          Define a new Package using information extracted from the specified Manifest.
(package private)  URL[] explore(URL url, int indexNumber)
           
protected  Class<?> findClass(String clsName)
          Locates and loads the specified class, searching this URLClassLoader's list of URLS.
(package private)  Class<?> findClassImpl(URL[] searchURLs, String clsName)
           
(package private)  Object findInExtensions(URL[] newExtensions, String name, int i, Vector<URL> resources, boolean url)
          Returns an Object[] containing a Class, a URL, and a Vector of URLs, 2 of which are null, according to the caller, which is identified by the int type.
(package private)  Object findInIndex(int i, String name, Vector<URL> resources, boolean url)
          Returns an Object[] containing a Class, a URL, and a Vector of URLs, 2 of which are null, according to the caller, which is identified by the int type.
 URL findResource(String name)
          Returns a URL referencing the specified resource or null if no resource could be found.
(package private)  URL findResourceImpl(URL[] searchList, String resName)
          Returns a URL among the given ones referencing the specified resource or null if no resource could be found.
 Enumeration<URL> findResources(String name)
          Returns an enumeration of URLs that contain the specified resource.
(package private)  Vector<URL> findResources(URL[] searchURLs, String name, Vector<URL> result)
          Returns a Vector of URLs among the given ones that contain the specified resource.
protected  PermissionCollection getPermissions(CodeSource codesource)
          Returns the permissions for the given code source.
 URL[] getURLs()
          Returns the search list of this URLClassLoader
static URLClassLoader newInstance(URL[] urls)
          Returns an instance of URLClassLoader.
static URLClassLoader newInstance(URL[] urls, ClassLoader parentCl)
          Returns an instance of URLClassLoader.
 
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

urls

URL[] urls

orgUrls

URL[] orgUrls

invalidUrls

Set<URL> invalidUrls

extensions

HashMap<URL,URL[]> extensions

indexes

Hashtable<String,URL[]>[] indexes
Constructor Detail

URLClassLoader

public URLClassLoader(URL[] urls)
Constructs a new instance of this class. The newly created instance will have the system ClassLoader as its parent. URLs that end with "/" are assumed to be directories, otherwise they are assumed to be Jar files.

Parameters:
urls - the URLs to search
Throws:
SecurityException - if a security manager exists and its checkCreateClassLoader method doesn't allow creation of new ClassLoaders

URLClassLoader

public URLClassLoader(URL[] urls,
                      ClassLoader parent)
Constructs a new instance of this class. The newly created instance will have the specified ClassLoader as its parent. URLs that end with "/" are assumed to be directories, otherwise they are assumed to be Jar files.

Parameters:
urls - the URLs to search
parent - the ClassLoader to assign as this loader's parent.
Throws:
SecurityException - if a security manager exists and its checkCreateClassLoader method doesn't allow creation of new ClassLoaders

URLClassLoader

public URLClassLoader(URL[] searchUrls,
                      ClassLoader parent,
                      URLStreamHandlerFactory factory)
Constructs a new instance of this class. The newly created instance will have the specified ClassLoader as its parent and use the specified factory to create stream handlers. URLs that end with "/" are assumed to be directories, otherwise they are assumed to be Jar files.

Parameters:
searchUrls - java.net.URL[] the URLs that will be searched in the order they were specified for resource
parent - ClassLoader the ClassLoader name of the resource to find.
factory - java.net.URLStreamHandlerFactory the factory that will used to create stream (protocol) handlers
Throws:
SecurityException - if a security manager exists and its checkCreateClassLoader method doesn't allow creation of new ClassLoaders
Method Detail

addURL

protected void addURL(URL url)
Adds the specified URL to the search list.

Parameters:
url - java.net.URL the new URL

addURL

URL[] addURL(URL[] urlArray,
             URL url)
Returns an array with the given URL added to the given array.

Parameters:
urlArray - java.net.URL[] the source array
url - java.net.URL the URL to be added
Returns:
java.net.URL[] an array made of the given array and the new URL

findResources

public Enumeration<URL> findResources(String name)
                               throws IOException
Returns an enumeration of URLs that contain the specified resource.

Overrides:
findResources in class ClassLoader
Parameters:
name - java.lang.String the name of the requested resource
Returns:
Enumeration the enumeration of URLs that contain the specified resource.
Throws:
IOException - thrown if an IO Exception occurs while attempting to connect

findResources

Vector<URL> findResources(URL[] searchURLs,
                          String name,
                          Vector<URL> result)
Returns a Vector of URLs among the given ones that contain the specified resource.

Parameters:
searchURLs - java.net.URL[] the array to be searched
name - java.lang.String the name of the requested resource
Returns:
Vector the enumeration of URLs that contain the specified resource.

findInIndex

Object findInIndex(int i,
                   String name,
                   Vector<URL> resources,
                   boolean url)
Returns an Object[] containing a Class, a URL, and a Vector of URLs, 2 of which are null, according to the caller, which is identified by the int type.

Parameters:
i - int the index of 'indexes' array to use.
name - String the resource to look for : either a resource or a class.
resources - boolean indicates that a Vector of URL should be returned as the non-null element in Object[].
url - boolean if true a URL should be returned as the non null element, if false a Class should be returned.
Returns:
Object[] a 3-element array : {Class, URL, Vector}. The non-null element contains the resource(s) found, which are searched in in indexes[i].

findInExtensions

Object findInExtensions(URL[] newExtensions,
                        String name,
                        int i,
                        Vector<URL> resources,
                        boolean url)
Returns an Object[] containing a Class, a URL, and a Vector of URLs, 2 of which are null, according to the caller, which is identified by the int type.

Parameters:
newExtensions - URL[] the URLs to look in for.
name - String the resource to look for : either a resource or a class.
i - int the index of 'indexes' array to use.
resources - boolean indicates that a Vector of URL should be returned as the non-null element in Object[].
url - boolean if true a URL should be returned as the non null element, if false a Class should be returned.
Returns:
Object[] a 3-element array : {Class, URL, Vector}. The non-null element contains the resource(s) found, which are searched in newExtensions.

getPermissions

protected PermissionCollection getPermissions(CodeSource codesource)
Returns the permissions for the given code source. First this method retrieves the permissions from the system policy. If the protocol is "file:/" then a new permission, FilePermission, granting the read permission to the file is added to the permission collection. Otherwise, connecting to and accepting connections from the URL is granted.

Overrides:
getPermissions in class SecureClassLoader
Parameters:
codesource - CodeSource
Returns:
PermissionCollection

getURLs

public URL[] getURLs()
Returns the search list of this URLClassLoader

Returns:
java.net.URL[]

newInstance

public static URLClassLoader newInstance(URL[] urls)
Returns an instance of URLClassLoader. loadClass() of the new instance will call the SecurityManager's checkPackageAccess() before loading a class.

Parameters:
urls - java.net.URL[] a list of URLs that is passed to the new URLClassloader
Returns:
java.net.URLClassLoader the new instance of URLClassLoader

newInstance

public static URLClassLoader newInstance(URL[] urls,
                                         ClassLoader parentCl)
Returns an instance of URLClassLoader. loadClass() of the new instance will call security manager's checkPackageAccess() before loading a class.

Parameters:
urls - URL[] the list of URLs that is passed to the new URLClassloader
parentCl - ClassLoader the parent class loader that is passed to the new URLClassloader
Returns:
URLClassLoader the new instance of URLClassLoader

findClass

protected Class<?> findClass(String clsName)
                      throws ClassNotFoundException
Locates and loads the specified class, searching this URLClassLoader's list of URLS.

Overrides:
findClass in class ClassLoader
Parameters:
clsName - String the name of the class.
Returns:
Class the class that has been loaded.
Throws:
ClassNotFoundException - if the class cannot be loaded

findResource

public URL findResource(String name)
Returns a URL referencing the specified resource or null if no resource could be found.

Overrides:
findResource in class ClassLoader
Parameters:
name - java.lang.String the name of the requested resource
Returns:
URL URL for the resource.

findResourceImpl

URL findResourceImpl(URL[] searchList,
                     String resName)
Returns a URL among the given ones referencing the specified resource or null if no resource could be found.

Parameters:
searchList - java.net.URL[] the array to be searched
resName - java.lang.String the name of the requested resource
Returns:
URL URL for the resource.

definePackage

protected Package definePackage(String packageName,
                                Manifest manifest,
                                URL url)
                         throws IllegalArgumentException
Define a new Package using information extracted from the specified Manifest.

Parameters:
packageName - The name of the package
manifest - The Manifest for the Package
url - The code source for the Package
Returns:
The Package created
Throws:
IllegalArgumentException - if the Package already exists

findClassImpl

Class<?> findClassImpl(URL[] searchURLs,
                       String clsName)
Parameters:
searchURLs - java.net.URL[] the URLs to search in
clsName - java.lang.String the class name to be found
Returns:
Class the class found or null if not found

explore

URL[] explore(URL url,
              int indexNumber)
Parameters:
url - URL the URL to explore
indexNumber - int the index in extensions to consider
Returns:
URL[] the URLs of bundled extensions that have been found (i.e. the URL of jar files in the class-path attribute), or null if none. if an INDEX.LIST has been found, an empty array is returned

Build 1.0_r1(from source)

Please submit a feedback, bug or feature