org.apache.wicket.application
Class ReloadingClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by java.net.URLClassLoader
              extended by org.apache.wicket.application.ReloadingClassLoader

public class ReloadingClassLoader
extends URLClassLoader

Custom ClassLoader that reverses the classloader lookups, and that is able to notify a listener when a class file is changed.

Author:
Jean-Baptiste Quenot

Constructor Summary
ReloadingClassLoader(ClassLoader parent)
          Create a new reloading ClassLoader from a list of URLs, and initialize the ModificationWatcher to detect class file modifications
 
Method Summary
static void addLocation(URL url)
          Add the location of a directory containing class files
 void destroy()
          Remove the ModificationWatcher from the current reloading class loader
static void excludePattern(String pattern)
          Exclude a pattern
static Set<URL> getLocations()
          Returns the list of all configured locations of directories containing class files
static List<String> getPatterns()
          Returns the list of all configured inclusion or exclusion patterns
 URL getResource(String name)
          Gets a resource from this ClassLoader.
static void includePattern(String pattern)
          Include a pattern
 Class<?> loadClass(String name, boolean resolve)
          Loads the class from this ClassLoader.
 void setListener(IChangeListener listener)
          Sets the listener that will be notified when a class changes
protected  boolean tryClassHere(String name)
           
 
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, findClass, findResource, findResources, getPermissions, getURLs, newInstance, newInstance
 
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, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReloadingClassLoader

public ReloadingClassLoader(ClassLoader parent)
Create a new reloading ClassLoader from a list of URLs, and initialize the ModificationWatcher to detect class file modifications

Parameters:
parent - the parent classloader in case the class file cannot be loaded from the above locations
Method Detail

tryClassHere

protected boolean tryClassHere(String name)
Parameters:
name -
Returns:
true if class if found, false otherwise

includePattern

public static void includePattern(String pattern)
Include a pattern

Parameters:
pattern - the pattern to include

excludePattern

public static void excludePattern(String pattern)
Exclude a pattern

Parameters:
pattern - the pattern to exclude

getPatterns

public static List<String> getPatterns()
Returns the list of all configured inclusion or exclusion patterns

Returns:
list of patterns as String

addLocation

public static void addLocation(URL url)
Add the location of a directory containing class files

Parameters:
url - the URL for the directory

getLocations

public static Set<URL> getLocations()
Returns the list of all configured locations of directories containing class files

Returns:
list of locations as URL

getResource

public final URL getResource(String name)
Gets a resource from this ClassLoader. If the resource does not exist in this one, we check the parent. Please note that this is the exact opposite of the ClassLoader spec. We use it to work around inconsistent class loaders from third party vendors.

Overrides:
getResource in class ClassLoader
Parameters:
name - of resource

loadClass

public final Class<?> loadClass(String name,
                                boolean resolve)
                         throws ClassNotFoundException
Loads the class from this ClassLoader. If the class does not exist in this one, we check the parent. Please note that this is the exact opposite of the ClassLoader spec. We use it to load the class from the same classloader as WicketFilter or WicketServlet. When found, the class file is watched for modifications.

Overrides:
loadClass in class ClassLoader
Parameters:
name - the name of the class
resolve - if true then resolve the class
Returns:
the resulting Class object
Throws:
ClassNotFoundException - if the class could not be found

setListener

public void setListener(IChangeListener listener)
Sets the listener that will be notified when a class changes

Parameters:
listener - the listener to notify upon class change

destroy

public void destroy()
Remove the ModificationWatcher from the current reloading class loader



Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.