org.brains2b.loader
Class DynamicClassLoader
java.lang.Object
org.brains2b.loader.DynamicClassLoader
- public class DynamicClassLoader
- extends java.lang.Object
Loads classes dynamically from a directory or jar/zip file being
passed in.
It is not a class loader itself, but uses URLClassLoader to do
the actual loading. It does supply the following options:
- find an Implementation of a Class or Interface in the classpath
supplied and load them, f.e. java.sql.Driver in a specific vendors driver jar
- Load a specific class from a jar
- Load all classes from a jar
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
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 |
FILESEP
public static final char FILESEP
DynamicClassLoader
public DynamicClassLoader()
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 nameurl
- 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 classpathurl
- 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