java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
org.apache.wicket.application.ReloadingClassLoader
- All Implemented Interfaces:
Closeable
,AutoCloseable
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
ConstructorDescriptionReloadingClassLoader
(ClassLoader parent) Create a new reloading ClassLoader from a list of URLs, and initialize the ModificationWatcher to detect class file modifications -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addLocation
(URL url) Add the location of a directory containing class filesvoid
destroy()
Remove the ModificationWatcher from the current reloading class loaderstatic void
excludePattern
(String pattern) Exclude a patternReturns the list of all configured locations of directories containing class filesReturns the list of all configured inclusion or exclusion patternsfinal URL
getResource
(String name) Gets a resource from thisClassLoader.
static void
includePattern
(String pattern) Include a patternfinal Class<?>
Loads the class from thisClassLoader.
void
setListener
(IChangeListener<Class<?>> listener) Sets the listener that will be notified when a class changesprotected boolean
tryClassHere
(String name) Methods inherited from class java.net.URLClassLoader
addURL, close, definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, 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, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Constructor Details
-
ReloadingClassLoader
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 Details
-
tryClassHere
- Parameters:
name
-- Returns:
- true if class if found, false otherwise
-
includePattern
Include a pattern- Parameters:
pattern
- the pattern to include
-
excludePattern
Exclude a pattern- Parameters:
pattern
- the pattern to exclude
-
getPatterns
Returns the list of all configured inclusion or exclusion patterns- Returns:
- list of patterns as String
-
addLocation
Add the location of a directory containing class files- Parameters:
url
- the URL for the directory
-
getLocations
Returns the list of all configured locations of directories containing class files- Returns:
- list of locations as URL
-
getResource
Gets a resource from thisClassLoader. 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 classClassLoader
- Parameters:
name
- of resource
-
loadClass
Loads the class from thisClassLoader. 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 classClassLoader
- Parameters:
name
- the name of the classresolve
- iftrue
then resolve the class- Returns:
- the resulting
Class
object - Throws:
ClassNotFoundException
- if the class could not be found
-
setListener
Sets the listener that will be notified when a class changes- Parameters:
listener
- the listener to notify upon class change
-
destroy
Remove the ModificationWatcher from the current reloading class loader
-