Return to www.inductionframework.org

com.acciente.commons.loader
Class ReloadingClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by com.acciente.commons.loader.ReloadingClassLoader

public class ReloadingClassLoader
extends java.security.SecureClassLoader

This classloader loads classes retrieved via a class definition loader (aka ClassDefLoader). This class loader uses the methods provided by a ClassDef (a ClassDef is returned by the ClassDefLoader) to determine if the class has been modified and transparently reloads the class into the JVM if the ClassDef reports that the class has been modified.

This class loader also reads dependency information from the ClassDef. When the load of a class, say A, is requested it recursively checks for modificiations to dependent classes. If any of the the dependent classes are modified it first reloads the dependent classes and then proceeds to reload the class A.

Author:
Adinath Raveendra Raj
See Also:
ClassDefLoader, ClassDef

Constructor Summary
ReloadingClassLoader()
          Creates a class loader with no parent class loader, this is expected to cause the system class loader to be used as the parent class loader
ReloadingClassLoader(java.lang.ClassLoader oParentClassLoader)
          Creates a class loader that delegates to the specified parent class loader
 
Method Summary
 void addClassDefLoader(ClassDefLoader oClassDefLoader)
          Adds a class definition loader to the list of class definition loaders to search
 void addIgnoredClassName(java.lang.String sIgnoredClassName)
          This method is used to add to the list classnames that should be "ignored" as regards the dependency checking.
 void addIgnoredClassNamePrefix(java.lang.String sIgnoredClassNamePrefix)
          This method is used to add to list of classname prefixes that should be "ignored" as regards the dependency checking.
protected  java.lang.Class findClass(java.lang.String sClassName)
           
 java.util.List getClassDefLoaders()
          A list of ClassDefLoaders searched by this class loader.
 java.util.Collection getIgnoredClassNamePrefixes()
          Returns the set of classname prefixes that are being "ignored" as regards the dependency checking
 java.util.Collection getIgnoredClassNames()
          Returns the set of classnames that are being "ignored" as regards the dependency checking
 java.io.InputStream getResourceAsStream(java.lang.String sResourceName)
          Used to load a resource via this classloader
 java.lang.Class loadClass(java.lang.String sClassName, boolean bResolve)
           
 
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass, getPermissions
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, 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()
Creates a class loader with no parent class loader, this is expected to cause the system class loader to be used as the parent class loader


ReloadingClassLoader

public ReloadingClassLoader(java.lang.ClassLoader oParentClassLoader)
Creates a class loader that delegates to the specified parent class loader

Parameters:
oParentClassLoader - the parent class loader
Method Detail

addClassDefLoader

public void addClassDefLoader(ClassDefLoader oClassDefLoader)
Adds a class definition loader to the list of class definition loaders to search

Parameters:
oClassDefLoader - an object that implements the class ClassDefLoader interface

getClassDefLoaders

public java.util.List getClassDefLoaders()
A list of ClassDefLoaders searched by this class loader.

Returns:
a list containing (in order of search) the classdefloader in use

addIgnoredClassName

public void addIgnoredClassName(java.lang.String sIgnoredClassName)
This method is used to add to the list classnames that should be "ignored" as regards the dependency checking. By "ignored" is meant the following: If class A depends on class B, and if class B changes, then if class B is on the list of classes to be "ignored" then the behavior is identical to that if class A had no dependency on class B.

Parameters:
sIgnoredClassName - a string representing a fully qualified classname

addIgnoredClassNamePrefix

public void addIgnoredClassNamePrefix(java.lang.String sIgnoredClassNamePrefix)
This method is used to add to list of classname prefixes that should be "ignored" as regards the dependency checking. For example specifying "com.foo.bar." will cause all classesname starting with com.foo.bar. package to be ignored. By "ignored" is meant the following: If class A depends on class B, and if class B changes, then if class B is on the list of classes to be "ignored" then the behavior is identical to if class A had no dependency on class B

Parameters:
sIgnoredClassNamePrefix - a string representing the prefix of one or more fully qualified classnames

getIgnoredClassNames

public java.util.Collection getIgnoredClassNames()
Returns the set of classnames that are being "ignored" as regards the dependency checking

Returns:
a set of strings representing classnames that should be ignored by the dependency checker.

getIgnoredClassNamePrefixes

public java.util.Collection getIgnoredClassNamePrefixes()
Returns the set of classname prefixes that are being "ignored" as regards the dependency checking

Returns:
a set of strings representing classname prefixes that should be ignored by the dependency checker.

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String sResourceName)
Used to load a resource via this classloader

Overrides:
getResourceAsStream in class java.lang.ClassLoader
Returns:
an input stream, or null if the resource could not be loaded

loadClass

public java.lang.Class loadClass(java.lang.String sClassName,
                                 boolean bResolve)
                          throws java.lang.ClassNotFoundException
Overrides:
loadClass in class java.lang.ClassLoader
Throws:
java.lang.ClassNotFoundException

findClass

protected java.lang.Class findClass(java.lang.String sClassName)
                             throws java.lang.ClassNotFoundException
Overrides:
findClass in class java.lang.ClassLoader
Throws:
java.lang.ClassNotFoundException

Return to www.inductionframework.org

Copyright © 2008-2011 Acciente, LLC. All Rights Reserved.