saker.util Documentation TaskDoc JavaDoc Packages
public class MultiClassLoader extends ClassLoader
ClassLoader implementation that aggregates multiple parent classloaders.

This classloader forwards class loading and resource retrieval requests to the enclosed classloader references.

This classloader can be used when a parent classloader is required that provides access to multiple separate classloaders. This is often useful when multiple classpaths are loaded from different sources and a newly loaded classpath entity needs access to more already loaded classpaths.

This class is subclassable, but generally is not recommended. Users can use one of the static create(ClassLoader, Collection<extends ClassLoader>) methods to create a new instance.

Fields
protected final Collection<ClassLoader>
The collection of classloaders which are used by this classloader.
Constructors
protected
MultiClassLoader(ClassLoader parent, Collection<extends ClassLoader> classLoaders)
Creates a new instance that has the argument parent classloader, and the specified classloaders.
protected
MultiClassLoader(Collection<extends ClassLoader> classLoaders)
Methods
public static ClassLoader
create(ClassLoader parent, Collection<extends ClassLoader> classloaders)
Gets a classloader which loads classes using the argument classloaders.
public static ClassLoader
create(Collection<extends ClassLoader> classloaders)
Gets a classloader which loads classes using the argument classloaders.
protected Class<?>
Finds the class with the specified binary name.
protected URL
Finds the resource with the given name.
protected Enumeration<URL>
Returns an enumeration of URL objects representing all the resources with the given name.
public InputStream
Returns an input stream for reading the specified resource.
public static Set<ClassLoader>
reduceClassLoaders(Collection<extends ClassLoader> classloaders)
Reduces the argument classloaders to its smallest set that doesn't contain duplicate parent classloaders.
public String
Returns a string representation of the object.
The collection of classloaders which are used by this classloader.

Immutable collection.

protected MultiClassLoader(ClassLoader parent, Collection<extends ClassLoader> classLoaders)
Creates a new instance that has the argument parent classloader, and the specified classloaders.
parentThe parent classloader.
classLoadersThe classloaders to delegate to.
protected MultiClassLoader(Collection<extends ClassLoader> classLoaders)
public static ClassLoader create(ClassLoader parent, Collection<extends ClassLoader> classloaders) throws NullPointerException
Gets a classloader which loads classes using the argument classloaders.

The classloaders will be reduced according to the rules of reduceClassLoaders(Collection<extends ClassLoader>).

The returned classloader might not be an instance of MultiClassLoader. This can be the case when the argument collection is empty, or contains a single item and the parent is null.

parentThe parent classloader to use.
classloadersThe classloaders.
A classloader defined by the argument.
NullPointerExceptionIf the classloaders are null.
public static ClassLoader create(Collection<extends ClassLoader> classloaders) throws NullPointerException
Gets a classloader which loads classes using the argument classloaders.

The classloaders will be reduced according to the rules of reduceClassLoaders(Collection<extends ClassLoader>).

The null classloader will be used as a parent classloader for the newly created classloader. That is the bootstrap classloader, and not the system classloader.

Unlike the constructor ClassLoader.ClassLoader(), which has the system classloader as its parent, the returned classloader will have the bootstrap classloader instead.

classloadersThe classloaders.
A classloader defined by the argument.
NullPointerExceptionIf the argument is null.
protected Class<?> findClass(String name) throws ClassNotFoundException
Overridden from: ClassLoader
Finds the class with the specified binary name. This method should be overridden by class loader implementations that follow the delegation model for loading classes, and will be invoked by the loadClass method after checking the parent class loader for the requested class. The default implementation throws a ClassNotFoundException.
nameThe binary name of the class
The resulting Class object
ClassNotFoundExceptionIf the class could not be found
1.2
protected URL findResource(String name)
Overridden from: ClassLoader
Finds the resource with the given name. Class loader implementations should override this method to specify where to find resources.
nameThe resource name
A URL object for reading the resource, or null if the resource could not be found
1.2
Overridden from: ClassLoader
Returns an enumeration of URL objects representing all the resources with the given name. Class loader implementations should override this method to specify where to load resources from.
nameThe resource name
An enumeration of URL objects for the resources
IOExceptionIf I/O errors occur
1.2
Overridden from: ClassLoader
Returns an input stream for reading the specified resource.

The search order is described in the documentation for ClassLoader.getResource(String).

nameThe resource name
An input stream for reading the resource, or null if the resource could not be found
1.1
public static Set<ClassLoader> reduceClassLoaders(Collection<extends ClassLoader> classloaders)
Reduces the argument classloaders to its smallest set that doesn't contain duplicate parent classloaders.

All classloaders will be part of the result set, unless:

  • It is null. null classloader represents the bootstrap classloader, which is always accessible.
  • A classloader is already present as a parent of an other classloader. E.g. If P is the parent of C, then if the set of [P, C, X] is reduced, the result will only be [C, X], as P is already accessible via C.
classloadersThe classloaders to reduce.
A set of reduced classloaders, or null if the argument is null.
public String toString()
Overridden from: Object
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 
a string representation of the object.