org.arakhne.vmutil
Class DynamicURLClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by org.arakhne.vmutil.DynamicURLClassLoader
Direct Known Subclasses:
DynamicURLClassLoader.FactoryDynamicURLClassLoader

public class DynamicURLClassLoader
extends SecureClassLoader

This class loader permits to load classes from a set of classpaths.

Version:
6.3 (rev:285) 2011-10-14 12:02:41
Author:
Stéphane GALLAND
Maven Group Id:
org.arakhne.afc
Maven Artifact Id:
arakhneVmutils

Nested Class Summary
protected static class DynamicURLClassLoader.FactoryDynamicURLClassLoader
           
 
Field Summary
protected  AccessControlContext _acc
          The context to be used when loading classes and resources
protected  sun.misc.URLClassPath _ucp
          The search path for classes and resources.
 
Constructor Summary
protected DynamicURLClassLoader(ClassLoader parent, AccessControlContext acc, URL... urls)
          Constructs a new ClassPathClassLoader for the given URLs.
 
Method Summary
 void addURL(URL url)
          Appends the specified URL to the list of URLs to search for classes and resources.
 void addURLs(URL... urls)
          Appends the specified URL to the list of URLs to search for classes and resources.
protected  Class<?> defineClass(String name, sun.misc.Resource res)
          Defines a Class using the class bytes obtained from the specified Resource.
protected  Package definePackage(String name, Manifest man, URL url)
          Defines a new package by name in this ClassLoader.
protected  Class<?> findClass(String name)
          Finds and loads the class with the specified name from the URL search path.
 URL findResource(String name)
          Finds the resource with the specified name on the URL search path.
 Enumeration<URL> findResources(String name)
          Returns an Enumeration of URLs representing all of the resources on the URL search path having the specified name.
protected  PermissionCollection getPermissions(CodeSource codesource)
          Returns the permissions for the given codesource object.
 URL[] getURLs()
          Returns the search path of URLs for loading classes and resources.
static DynamicURLClassLoader newInstance(ClassLoader parent, URL... urls)
          Creates a new instance of DynamicURLClassLoader for the specified URLs and parent class loader.
 void removeURL(URL url)
          Appends the specified URL to the list of URLs to search for classes and resources.
 void removeURLs(URL... urls)
          Appends the specified URL to the list of URLs to search for classes and resources.
 
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

_ucp

protected sun.misc.URLClassPath _ucp
The search path for classes and resources.


_acc

protected AccessControlContext _acc
The context to be used when loading classes and resources

Constructor Detail

DynamicURLClassLoader

protected DynamicURLClassLoader(ClassLoader parent,
                                AccessControlContext acc,
                                URL... urls)
Constructs a new ClassPathClassLoader for the given URLs. The URLs will be searched in the order specified for classes and resources after first searching in the specified parent class loader. Any URL that ends with a '/' is assumed to refer to a directory. Otherwise, the URL is assumed to refer to a JAR file which will be downloaded and opened as needed.

If there is a security manager, this method first calls the security manager's checkCreateClassLoader method to ensure creation of a class loader is allowed.

Parameters:
parent - the parent class loader for delegation
acc - is the current access context
urls - the URLs from which to load classes and resources
Throws:
SecurityException - if a security manager exists and its checkCreateClassLoader method doesn't allow creation of a class loader.
See Also:
SecurityManager.checkCreateClassLoader()
Method Detail

addURL

public void addURL(URL url)
Appends the specified URL to the list of URLs to search for classes and resources.

Parameters:
url - the URL to be added to the search path of URLs

addURLs

public void addURLs(URL... urls)
Appends the specified URL to the list of URLs to search for classes and resources.

Parameters:
urls - the URLs to be added to the search path of URLs

removeURLs

public void removeURLs(URL... urls)
Appends the specified URL to the list of URLs to search for classes and resources.

Parameters:
urls - the URL to be added to the search path of URLs

removeURL

public void removeURL(URL url)
Appends the specified URL to the list of URLs to search for classes and resources.

Parameters:
url - the URL to be added to the search path of URLs

getURLs

public URL[] getURLs()
Returns the search path of URLs for loading classes and resources. This includes the original list of URLs specified to the constructor, along with any URLs subsequently appended by the addURL() method.

Returns:
the search path of URLs for loading classes and resources.

findClass

protected Class<?> findClass(String name)
                      throws ClassNotFoundException
Finds and loads the class with the specified name from the URL search path. Any URLs referring to JAR files are loaded and opened as needed until the class is found.

Overrides:
findClass in class ClassLoader
Parameters:
name - the name of the class
Returns:
the resulting class
Throws:
ClassNotFoundException - if the class could not be found

defineClass

protected Class<?> defineClass(String name,
                               sun.misc.Resource res)
                        throws IOException
Defines a Class using the class bytes obtained from the specified Resource. The resulting Class must be resolved before it can be used.

Parameters:
name - is the name of the class to define
res - is the resource from which the class byte-code could be obtained
Returns:
the loaded class.
Throws:
IOException - in case the byte-code was unavailable.

definePackage

protected Package definePackage(String name,
                                Manifest man,
                                URL url)
                         throws IllegalArgumentException
Defines a new package by name in this ClassLoader. The attributes contained in the specified Manifest will be used to obtain package version and sealing information. For sealed packages, the additional URL specifies the code source URL from which the package was loaded.

Parameters:
name - the package name
man - the Manifest containing package version and sealing information
url - the code source url for the package, or null if none
Returns:
the newly defined Package object
Throws:
IllegalArgumentException - if the package name duplicates an existing package either in this class loader or one of its ancestors

findResource

public URL findResource(String name)
Finds the resource with the specified name on the URL search path.

Overrides:
findResource in class ClassLoader
Parameters:
name - the name of the resource
Returns:
a URL for the resource, or null if the resource could not be found.

findResources

public Enumeration<URL> findResources(String name)
                               throws IOException
Returns an Enumeration of URLs representing all of the resources on the URL search path having the specified name.

Overrides:
findResources in class ClassLoader
Parameters:
name - the resource name
Returns:
an Enumeration of URLs
Throws:
IOException - if an I/O exception occurs

getPermissions

protected PermissionCollection getPermissions(CodeSource codesource)
Returns the permissions for the given codesource object. The implementation of this method first calls super.getPermissions and then adds permissions based on the URL of the codesource.

If the protocol is "file" and the path specifies a file, then permission to read that file is granted. If protocol is "file" and the path is a directory, permission is granted to read all files and (recursively) all files and subdirectories contained in that directory.

If the protocol is not "file", then to connect to and accept connections from the URL's host is granted.

Overrides:
getPermissions in class SecureClassLoader
Parameters:
codesource - the codesource
Returns:
the permissions granted to the codesource

newInstance

public static DynamicURLClassLoader newInstance(ClassLoader parent,
                                                URL... urls)
Creates a new instance of DynamicURLClassLoader for the specified URLs and parent class loader. If a security manager is installed, the loadClass method of the URLClassLoader returned by this method will invoke the SecurityManager.checkPackageAccess method before loading the class.

Parameters:
parent - the parent class loader for delegation
urls - the URLs to search for classes and resources
Returns:
the resulting class loader


Copyright © 2006-2011 Arakhnê.org Consortium. All rights reserved under LGPL license terms.