org.brains2b.loader
Class DynamicClassLoader

java.lang.Object
  extended byorg.brains2b.loader.DynamicClassLoader

public class DynamicClassLoader
extends java.lang.Object

Loads classes dynamically from a directory or jar/zip file being passed in.

Note:If you load individual classes the classes referring to that class are also automatically loaded as long as they are available in the classpath supplied or in the bootstrap of the JVM.

Version:
1.00 [12-02-2006]
Author:
dennis@brains2b.nl

Field Summary
static char FILESEP
           
 
Constructor Summary
DynamicClassLoader()
           
 
Method Summary
static java.lang.Class[] findImplementation(java.lang.Class superOrInterface, java.net.URL[] url)
          find an implementation of an interface or class in the classpath supplied by the URLs
static java.lang.Class loadClass(java.lang.String name, java.net.URL[] url)
          load a specific class identified by it's fully qualified name from the passed URLs
static java.lang.Class[] loadClasses(java.net.URL[] url)
          load all the classes from the classpath supplied by the URLs
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILESEP

public static final char FILESEP
Constructor Detail

DynamicClassLoader

public DynamicClassLoader()
Method Detail

loadClass

public static final java.lang.Class loadClass(java.lang.String name,
                                              java.net.URL[] url)
                                       throws java.lang.ClassNotFoundException
load a specific class identified by it's fully qualified name from the passed URLs

Parameters:
name - String, the fully qualified class name
url - URL[], an array of URLs in which to find the class
Returns:
Class, the loaded Class. If url is null an attempt is made to load the class from the current ClassLoader
Throws:
ClassNotFoundException, - thrown if the class being loaded cannot be found in the supplied classpath or current ClassLoader if url was null.
java.lang.ClassNotFoundException

loadClasses

public static final java.lang.Class[] loadClasses(java.net.URL[] url)
                                           throws java.lang.ClassNotFoundException
load all the classes from the classpath supplied by the URLs

Parameters:
url - URL[], the paths to the classes or the jar file
Returns:
Class[] all the classes that have been loaded from the given URLs
Throws:
ClassNotFoundException, - thrown if a class cannot be loaded from one of the locations supplied by the URLs.
java.lang.ClassNotFoundException

findImplementation

public static final java.lang.Class[] findImplementation(java.lang.Class superOrInterface,
                                                         java.net.URL[] url)
                                                  throws java.lang.ClassNotFoundException
find an implementation of an interface or class in the classpath supplied by the URLs

Parameters:
superOrInterface - Class, the super class or interface to find in the classpath
url - URL[], the paths to the classes or the jar file
Returns:
Class[] the classes that implement the class or interface or null if it cannot be found.
Throws:
ClassNotFoundException, - thrown if a class cannot be loaded from one of the locations supplied by the URLs.
java.lang.ClassNotFoundException