Save This Page
Home » apache-tomcat-6.0.16-src » org.apache » tomcat » util » loader » [javadoc | source]
org.apache.tomcat.util.loader
public class: ModuleClassLoader [javadoc | source]
java.lang.Object
   java.lang.ClassLoader
      java.security.SecureClassLoader
         java.net.URLClassLoader
            org.apache.tomcat.util.loader.ModuleClassLoader
Simple module class loader. Will search the repository if the class is not found locally. TODO: findResources() - merge all responses from the repo and parent. Based on StandardClassLoader and WebappClassLoader.
Field Summary
protected  Repository repository     
protected  boolean delegate    Should this class loader delegate to the parent class loader before searching its own repositories (i.e. the usual Java2 delegation model)? If set to false, this class loader will search its own repositories first, and delegate to the parent only if the class or resource is not found locally. 
protected  long lastJarAccessed    Last time a JAR was accessed. TODO: change to last time the loader was accessed 
protected  long lastModified     
protected  boolean started    Has this component been started? 
protected  Module module     
 Object debugObj     
Constructor:
 public ModuleClassLoader(URL[] repositories) 
 public ModuleClassLoader(URL[] repositories,
    ClassLoader parent) 
Method from org.apache.tomcat.util.loader.ModuleClassLoader Summary:
addRepository,   findClass,   findClass2,   findLocalClass,   findResource,   findResource2,   findResources,   findResources2,   getModule,   getResource,   getResource2,   isStarted,   loadClass,   loadClass2,   modified,   setDelegate,   setModule,   setRepository,   setWorkDir,   start,   stop,   toString,   updateStamp,   validate
Methods from java.net.URLClassLoader:
findResource,   findResources,   getURLs,   newInstance,   newInstance
Methods from java.lang.ClassLoader:
clearAssertionStatus,   getParent,   getResource,   getResourceAsStream,   getResources,   getSystemClassLoader,   getSystemResource,   getSystemResourceAsStream,   getSystemResources,   loadClass,   setClassAssertionStatus,   setDefaultAssertionStatus,   setPackageAssertionStatus
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.tomcat.util.loader.ModuleClassLoader Detail:
  void addRepository(String repository) 
    Add a new repository to the set of places this ClassLoader can look for classes to be loaded.
 public Class findClass(String name) throws ClassNotFoundException 
    Find the specified class in our local repositories, if possible. If not found, throw ClassNotFoundException.
 public Class findClass2(String name,
    boolean del2repo) throws ClassNotFoundException 
 public Class findLocalClass(String name) throws ClassNotFoundException 
    Same as findClass, but also checks if the class has been previously loaded. In most implementations, findClass() doesn't check with findLoadedClass(). In order to implement repository, we need to ask each loader in the group to load only from it's local resources - however this will lead to errors ( duplicated definition ) if findClass() is used.
 public URL findResource(String name) 
    Find the specified resource in our local repository, and return a URL refering to it, or null if this resource cannot be found.
 public URL findResource2(String name,
    boolean del2repo) 
 public Enumeration findResources(String name) throws IOException 
    Return an enumeration of URLs representing all of the resources with the given name. If no resources with this name are found, return an empty enumeration.
 Enumeration findResources2(String name,
    boolean del2repo) throws IOException 
 Module getModule() 
    Not public - his can only be called from package. To get the module from a ClassLoader you need access to the Loader instance.
 public URL getResource(String name) 
    getResource() - modified to implement the search alghoritm
 URL getResource2(String name,
    ClassLoader originator,
    boolean delegate2repo) 
    getResource() - same thing, but don't delegate to repo if called from repo
 boolean isStarted() 
    Support for "disabled" state.
 public Class loadClass(String name,
    boolean resolve) throws ClassNotFoundException 
    Load the class with the specified name, searching using the following algorithm until it finds and returns the class. If the class cannot be found, returns ClassNotFoundException.
    • Call findLoadedClass(String) to check if the class has already been loaded. If it has, the same Class object is returned.
    • If the delegate property is set to true, call the loadClass() method of the parent class loader, if any.
    • Call findClass() to find this class in our locally defined repositories.
    • Call the loadClass() method of our parent class loader, if any.
    If the class was found using the above steps, and the resolve flag is true, this method will then call resolveClass(Class) on the resulting Class object.
 public Class loadClass2(String name,
    boolean resolve,
    boolean del2repo) throws ClassNotFoundException 
 boolean modified() 
    Have one or more classes or resources been modified so that a reload is appropriate? Not public - call it via Module
  void setDelegate(boolean delegate) 
    Set the "delegate first" flag for this class loader.
  void setModule(Module webappLoader) 
  void setRepository(Repository lg) 
  void setWorkDir(File s) 
  void start() 
    Start the class loader.
  void stop() 
    Stop the class loader.
 public String toString() 
    Render a String representation of this object.
  void updateStamp() 
 protected boolean validate(String name) 
    Validate a classname. As per SRV.9.7.2, we must restict loading of classes from J2SE (java.*) and classes of the servlet API (javax.servlet.*). That should enhance robustness and prevent a number of user error (where an older version of servlet.jar would be present in /WEB-INF/lib).