classpathhelper.tomcat.listener
Class VersionFourTomcatClassLoaderService

java.lang.Object
  extended byclasspathhelper.tomcat.listener.TomcatClassLoaderService
      extended byclasspathhelper.tomcat.listener.VersionFourTomcatClassLoaderService
All Implemented Interfaces:
ITomcatClassLoaderService

public class VersionFourTomcatClassLoaderService
extends TomcatClassLoaderService

Instance of the ITomcatClassLoaderService that mimics the version 4 classloading properties of Apache's Tomcat. The following is an excerp directly from the 4.0 documentation.

Like many server applications, Tomcat 4 installs a variety of class loaders (that is, classes that implement java.lang.ClassLoader) to allow different portions of the container, and the web applications running on the container, to have access to different repositories of available classes and resources. This mechanism is used to provide the functionality defined in the Servlet Specification, version 2.3 -- in particular, Sections 9.4 and 9.6.

In a Java 2 (that is, JDK 1.2 or later) environment, class loaders are arranged in a parent-child tree. Normally, when a class loader is asked to load a particular class or resource, it delegates the request to a parent class loader first, and then looks in its own repositories only if the parent class loader(s) cannot find the requested class or resource. The model for web application class loaders differs slightly from this, as discussed below, but the main principles are the same.

When Tomcat 4 is started, it creates a set of class loaders that are organized into the following parent-child relationships, where the parent class loader is above the child class loader:


       Bootstrap
          |
        System
          |
       Common
      /      \
  Catalina   Shared
             /   \
        Webapp1  Webapp2 ... 
The characteristics of each of these class loaders, including the source of classes and resources that they make visible, are discussed in detail in the following section.

As indicated in the diagram above, Tomcat 4 creates the following class loaders as it is initialized:

As mentioned above, the web application class loader diverges from the default Java 2 delegation model (in accordance with the recommendations in the Servlet Specification, version 2.3, section 9.6). When a request to load a class from the web application's WebappX class loader is processed, this class loader will look in the local repositories first, instead of delegating before looking. All other class loaders in Tomcat 4 follow the usual delegation pattern.

Therefore, from the perspective of a web application, class or resource loading looks in the following repositories, in this order:

Since:
1.0
Author:
bharris

Field Summary
 
Fields inherited from class classpathhelper.tomcat.listener.TomcatClassLoaderService
properties
 
Constructor Summary
protected VersionFourTomcatClassLoaderService(TomcatProperties theProperties)
          Basic constructor, not called directly, instances of this class are provided via TomcatClassLoaderService.getService(TomcatProperties).
 
Method Summary
protected static java.lang.String convertPathsToPath(java.util.List paths)
          Internal method that takes a list of File and File[] objects and appends them to a string in a classic classpath format.
 CGClassLoader createClassLoader(java.lang.String appName, CGClassLoaderFilter filter, FileChangeMonitor fileMonitor)
          Method that creates the appropriate class loader hierarchy consistent with the associated instance of Tomcat and the supplied application.
protected static java.io.File[] enumerateJars(java.io.File root)
          Internal method that enumerates the jar files at the path supplied.
 java.lang.String[] getAppNames()
          Returns an array of application names in the associated Tomcat instance.
 
Methods inherited from class classpathhelper.tomcat.listener.TomcatClassLoaderService
getService
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VersionFourTomcatClassLoaderService

protected VersionFourTomcatClassLoaderService(TomcatProperties theProperties)
Basic constructor, not called directly, instances of this class are provided via TomcatClassLoaderService.getService(TomcatProperties).

Parameters:
theProperties - The properties associate with this instance of Tomcat.
Since:
1.0
Method Detail

enumerateJars

protected static java.io.File[] enumerateJars(java.io.File root)
Internal method that enumerates the jar files at the path supplied. This method is used building up lib directories.

Parameters:
root - The root dir to look up files in.
Returns:
An array of files corresponding to files ending in .jar or .zip
Since:
1.0

convertPathsToPath

protected static java.lang.String convertPathsToPath(java.util.List paths)
Internal method that takes a list of File and File[] objects and appends them to a string in a classic classpath format.

Parameters:
paths - The list of files and file arrays.
Returns:
A typical classpath string.
Since:
1.0

getAppNames

public java.lang.String[] getAppNames()
Description copied from interface: ITomcatClassLoaderService
Returns an array of application names in the associated Tomcat instance.

Returns:
An array of application names, suitable for input to ITomcatClassLoaderService.createClassLoader(java.lang.String, classpathhelper.CGClassLoaderFilter, classpathhelper.filechangelistener.FileChangeMonitor).

createClassLoader

public CGClassLoader createClassLoader(java.lang.String appName,
                                       CGClassLoaderFilter filter,
                                       FileChangeMonitor fileMonitor)
Description copied from interface: ITomcatClassLoaderService
Method that creates the appropriate class loader hierarchy consistent with the associated instance of Tomcat and the supplied application.

Parameters:
appName - The application name, should be a value from ITomcatClassLoaderService.getAppNames().
filter - The filter for the class loader.
fileMonitor - An optional (may be null) file monitor that will be populated with the files to monitor related to this classloader.
Returns:
A class loader consistent with the classloading of the supplied application, or null if the application name is invalid.