org.clapper.util.classutil
Class ClassLoaderBuilder

java.lang.Object
  extended by org.clapper.util.classutil.ClassLoaderBuilder

public class ClassLoaderBuilder
extends java.lang.Object

A ClassLoaderBuilder is used to build an alternate class loader that includes additional jar files, zip files and/or directories in its load path. It's basically a convenient wrapper around java.net.URLClassLoader.

Version:
$Revision: 6735 $
Author:
Copyright © 2006 Brian M. Clapper

Constructor Summary
ClassLoaderBuilder()
          Create a new ClassLoaderBuilder.
 
Method Summary
 int add(java.util.Collection<java.io.File> files)
          Add a Collection of jar files, zip files or directories to the list of places the not-yet-constructed class loader will search.
 boolean add(java.io.File file)
          Add a jar file, zip file or directory to the list of places the not-yet-constructed class loader will search.
 int add(java.io.File[] files)
          Add an array of jar files, zip files or directories to the list of places the not-yet-constructed class loader will search.
 void addClassPath()
          Add the contents of the classpath.
 void clear()
          Clear the stored files in this object.
 java.lang.ClassLoader createClassLoader()
          Create and return a class loader that will search the additional places defined in this builder.
 java.lang.ClassLoader createClassLoader(java.lang.ClassLoader parentLoader)
          Create and return a class loader that will search the additional places defined in this builder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassLoaderBuilder

public ClassLoaderBuilder()
Create a new ClassLoaderBuilder.

Method Detail

add

public boolean add(java.io.File file)
Add a jar file, zip file or directory to the list of places the not-yet-constructed class loader will search. If the directory or file does not exist, or isn't a jar file, zip file, or directory, this method just ignores it and returns false.

Parameters:
file - the jar file, zip file or directory
Returns:
true if the file was suitable for adding; false if it was not a jar file, zip file, or directory.

add

public int add(java.io.File[] files)
Add an array of jar files, zip files or directories to the list of places the not-yet-constructed class loader will search. If the directory or file does not exist, or isn't a jar file, zip file, or directory, this method just ignores it and returns false.

Parameters:
files - the array
Returns:
the number of entries from the array that were actually added

add

public int add(java.util.Collection<java.io.File> files)
Add a Collection of jar files, zip files or directories to the list of places the not-yet-constructed class loader will search. If the directory or file does not exist, or isn't a jar file, zip file, or directory, this method just ignores it and returns false.

Parameters:
files - the collection
Returns:
the number of entries from the collection that were actually added

addClassPath

public void addClassPath()
Add the contents of the classpath.


clear

public void clear()
Clear the stored files in this object.


createClassLoader

public java.lang.ClassLoader createClassLoader()
                                        throws java.lang.SecurityException
Create and return a class loader that will search the additional places defined in this builder. The resulting class loader uses the default delegation parent ClassLoader.

Throws:
java.lang.SecurityException - if a security manager exists and its checkCreateClassLoader() method does not allow creation of a class loader

createClassLoader

public java.lang.ClassLoader createClassLoader(java.lang.ClassLoader parentLoader)
                                        throws java.lang.SecurityException
Create and return a class loader that will search the additional places defined in this builder. The resulting class loader uses the specified parent ClassLoader.

Parameters:
parentLoader - the desired parent class loader
Throws:
java.lang.SecurityException - if a security manager exists and its checkCreateClassLoader() method does not allow creation of a class loader


Copyright © 2004-2007 Brian M. Clapper. All Rights Reserved.