Save This Page
Home » apache-tomcat-6.0.26-src » org.apache » catalina » loader » [javadoc | source]
org.apache.catalina.loader
public class: WebappClassLoader [javadoc | source]
java.lang.Object
   java.lang.ClassLoader
      java.security.SecureClassLoader
         java.net.URLClassLoader
            org.apache.catalina.loader.WebappClassLoader

All Implemented Interfaces:
    Reloader, Lifecycle

Specialized web application class loader.

This class loader is a full reimplementation of the URLClassLoader from the JDK. It is designed to be fully compatible with a normal URLClassLoader, although its internal behavior may be completely different.

IMPLEMENTATION NOTE - This class loader faithfully follows the delegation model recommended in the specification. The system class loader will be queried first, then the local repositories, and only then delegation to the parent class loader will occur. This allows the web application to override any shared class except the classes from J2SE. Special handling is provided from the JAXP XML parser interfaces, the JNDI interfaces, and the classes from the servlet API, which are never loaded from the webapp repository.

IMPLEMENTATION NOTE - Due to limitations in Jasper compilation technology, any repository which contains classes from the servlet API will be ignored by the class loader.

IMPLEMENTATION NOTE - The class loader generates source URLs which include the full JAR URL when a class is loaded from a JAR file, which allows setting security permission at the class level, even when a class is contained inside a JAR.

IMPLEMENTATION NOTE - Local repositories are searched in the order they are added via the initial constructor and/or any subsequent calls to addRepository() or addJar().

IMPLEMENTATION NOTE - No check for sealing violations or security is made unless a security manager is present.

Nested Class Summary:
protected class  WebappClassLoader.PrivilegedFindResource   
protected class  WebappClassLoader.PrivilegedFindResourceByName   
protected final class  WebappClassLoader.PrivilegedGetClassLoader   
Field Summary
protected static  Log log     
public static final  boolean ENABLE_CLEAR_REFERENCES     
protected static final  String[] triggers    The set of trigger classes that will cause a proposed repository not to be added if this class is visible to the class loader that loaded this factory class. Typically, trigger classes will be listed for components that have been integrated into the JDK for later versions, but where the corresponding JAR files are required to run on earlier versions. 
protected static final  String[] packageTriggers    Set of package names which are not allowed to be loaded from a webapp class loader without delegating first. 
protected static final  StringManager sm    The string manager for this package. 
 boolean antiJARLocking    Use anti JAR locking code, which does URL rerouting when accessing resources. 
protected  DirContext resources    Associated directory context giving access to the resources in this webapp. 
protected  HashMap resourceEntries    The cache of ResourceEntry for classes and resources we have loaded, keyed by resource name. 
protected  HashMap<String, String> notFoundResources    The list of not found resources. 
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. 
protected  String[] repositories    The list of local repositories, in the order they should be searched for locally loaded classes or resources. 
protected  URL[] repositoryURLs    Repositories URLs, used to cache the result of getURLs. 
protected  File[] files    Repositories translated as path in the work directory (for Jasper originally), but which is used to generate fake URLs should getURLs be called. 
protected  JarFile[] jarFiles    The list of JARs, in the order they should be searched for locally loaded classes or resources. 
protected  File[] jarRealFiles    The list of JARs, in the order they should be searched for locally loaded classes or resources. 
protected  String jarPath    The path which will be monitored for added Jar files. 
protected  String[] jarNames    The list of JARs, in the order they should be searched for locally loaded classes or resources. 
protected  long[] lastModifiedDates    The list of JARs last modified dates, in the order they should be searched for locally loaded classes or resources. 
protected  String[] paths    The list of resources which should be checked when checking for modifications. 
protected  ArrayList permissionList    A list of read File and Jndi Permission's required if this loader is for a web application context. 
protected  File loaderDir    Path where resources loaded from JARs will be extracted. 
protected  String canonicalLoaderDir     
protected  HashMap loaderPC    The PermissionCollection for each CodeSource for a web application context. 
protected  SecurityManager securityManager    Instance of the SecurityManager installed. 
protected  ClassLoader parent    The parent class loader. 
protected  ClassLoader system    The system class loader. 
protected  boolean started    Has this component been started? 
protected  boolean hasExternalRepositories    Has external repositories. 
protected  boolean needConvert    need conversion for properties files 
protected  Permission allPermission    All permission. 
Fields inherited from java.net.URLClassLoader:
ucp
Fields inherited from java.lang.ClassLoader:
nocerts,  classAssertionStatus
Constructor:
 public WebappClassLoader() 
 public WebappClassLoader(ClassLoader parent) 
    Construct a new ClassLoader with no defined repositories and no parent ClassLoader.
Method from org.apache.catalina.loader.WebappClassLoader Summary:
addJar,   addLifecycleListener,   addPermission,   addPermission,   addPermission,   addRepository,   addRepository,   addURL,   clearReferences,   closeJARs,   deleteDir,   filter,   findClass,   findClassInternal,   findLifecycleListeners,   findLoadedClass0,   findLoadedResource,   findRepositories,   findResource,   findResourceInternal,   findResourceInternal,   findResources,   getAntiJARLocking,   getClearReferencesLogFactoryRelease,   getClearReferencesStopThreads,   getDelegate,   getJarPath,   getPermissions,   getResource,   getResourceAsStream,   getResources,   getURI,   getURL,   getURLs,   isPackageSealed,   isStarted,   loadClass,   loadClass,   loadedByThisOrChild,   modified,   openJARs,   refreshPolicy,   removeLifecycleListener,   setAntiJARLocking,   setClearReferencesLogFactoryRelease,   setClearReferencesStopThreads,   setDelegate,   setJarPath,   setParentClassLoader,   setResources,   setWorkDir,   start,   stop,   toString,   validate,   validateJarFile
Methods from java.net.URLClassLoader:
access$000,   access$100,   addURL,   definePackage,   findClass,   findResource,   findResources,   getPermissions,   getURLs,   newInstance,   newInstance
Methods from java.security.SecureClassLoader:
defineClass,   defineClass,   getPermissions
Methods from java.lang.ClassLoader:
access$000,   access$100,   addClass,   clearAssertionStatus,   defineClass,   defineClass,   defineClass,   defineClass,   definePackage,   desiredAssertionStatus,   findClass,   findLibrary,   findLoadedClass,   findNative,   findResource,   findResources,   findSystemClass,   getBootstrapClassPath,   getCallerClassLoader,   getPackage,   getPackages,   getParent,   getResource,   getResourceAsStream,   getResources,   getSystemClassLoader,   getSystemResource,   getSystemResourceAsStream,   getSystemResources,   isAncestor,   loadClass,   loadClass,   loadLibrary,   resolveClass,   setClassAssertionStatus,   setDefaultAssertionStatus,   setPackageAssertionStatus,   setSigners
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.catalina.loader.WebappClassLoader Detail:
 synchronized  void addJar(String jar,
    JarFile jarFile,
    File file) throws IOException 
 public  void addLifecycleListener(LifecycleListener listener) 
    Add a lifecycle event listener to this component.
 public  void addPermission(String path) 
    If there is a Java SecurityManager create a read FilePermission or JndiPermission for the file directory path.
 public  void addPermission(URL url) 
    If there is a Java SecurityManager create a read FilePermission or JndiPermission for URL.
 public  void addPermission(Permission permission) 
    If there is a Java SecurityManager create a Permission.
 public  void addRepository(String repository) 
    Add a new repository to the set of places this ClassLoader can look for classes to be loaded.
 synchronized  void addRepository(String repository,
    File file) 
    Add a new repository to the set of places this ClassLoader can look for classes to be loaded.
 protected  void addURL(URL url) 
    Add the specified URL to the classloader.
 protected  void clearReferences() 
    Clear references.
 public  void closeJARs(boolean force) 
    Used to periodically signal to the classloader to release JAR resources.
 protected static  void deleteDir(File dir) 
    Delete the specified directory, including all of its contents and subdirectories recursively.
 protected boolean filter(String name) 
    Filter classes.
 public Class findClass(String name) throws ClassNotFoundException 
    Find the specified class in our local repositories, if possible. If not found, throw ClassNotFoundException.
 protected Class findClassInternal(String name) throws ClassNotFoundException 
    Find specified class in local repositories.
 public LifecycleListener[] findLifecycleListeners() 
    Get the lifecycle listeners associated with this lifecycle. If this Lifecycle has no listeners registered, a zero-length array is returned.
 protected Class findLoadedClass0(String name) 
    Finds the class with the given name if it has previously been loaded and cached by this class loader, and return the Class object. If this class has not been cached, return null.
 protected InputStream findLoadedResource(String name) 
    Finds the resource with the given name if it has previously been loaded and cached by this class loader, and return an input stream to the resource data. If this resource has not been cached, return null.
 public String[] findRepositories() 
    Return a String array of the current repositories for this class loader. If there are no repositories, a zero-length array is returned.For security reason, returns a clone of the Array (since String are immutable).
 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.
 protected ResourceEntry findResourceInternal(File file,
    String path) 
    Find specified resource in local repositories.
 protected ResourceEntry findResourceInternal(String name,
    String path) 
    Find specified resource in local repositories.
 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.
 public boolean getAntiJARLocking() 
 public boolean getClearReferencesLogFactoryRelease() 
    Return the clearReferencesLogFactoryRelease flag for this Context.
 public boolean getClearReferencesStopThreads() 
    Return the clearReferencesStopThreads flag for this Context.
 public boolean getDelegate() 
    Return the "delegate first" flag for this class loader.
 public String getJarPath() 
    Return the JAR path.
 protected PermissionCollection getPermissions(CodeSource codeSource) 
    Get the Permissions for a CodeSource. If this instance of WebappClassLoader is for a web application context, add read FilePermission or JndiPermissions for the base directory (if unpacked), the context URL, and jar file resources.
 public URL getResource(String name) 
    Find the resource with the given name. A resource is some data (images, audio, text, etc.) that can be accessed by class code in a way that is independent of the location of the code. The name of a resource is a "/"-separated path name that identifies the resource. If the resource cannot be found, return null.

    This method searches according to the following algorithm, returning as soon as it finds the appropriate URL. If the resource cannot be found, returns null.

    • If the delegate property is set to true, call the getResource() method of the parent class loader, if any.
    • Call findResource() to find this resource in our locally defined repositories.
    • Call the getResource() method of the parent class loader, if any.
 public InputStream getResourceAsStream(String name) 
    Find the resource with the given name, and return an input stream that can be used for reading it. The search order is as described for getResource(), after checking to see if the resource data has been previously cached. If the resource cannot be found, return null.
 public DirContext getResources() 
    Get associated resources.
 protected URL getURI(File file) throws MalformedURLException 
    Get URL.
 protected URL getURL(File file,
    boolean encoded) throws MalformedURLException 
    Get URL.
 public URL[] getURLs() 
    Returns the search path of URLs for loading classes and resources. This includes the original list of URLs specified to the constructor, along with any URLs subsequently appended by the addURL() method.
 protected boolean isPackageSealed(String name,
    Manifest man) 
    Returns true if the specified package name is sealed according to the given manifest.
 public boolean isStarted() 
 public Class loadClass(String name) throws ClassNotFoundException 
    Load the class with the specified name. This method searches for classes in the same manner as loadClass(String, boolean) with false as the second argument.
 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.
 protected boolean loadedByThisOrChild(Class clazz) 
    Determine whether a class was loaded by this class loader or one of its child class loaders.
 public boolean modified() 
    Have one or more classes or resources been modified so that a reload is appropriate?
 protected boolean openJARs() 
    Used to periodically signal to the classloader to release JAR resources.
 protected  void refreshPolicy() 
    Refresh the system policy file, to pick up eventual changes.
 public  void removeLifecycleListener(LifecycleListener listener) 
    Remove a lifecycle event listener from this component.
 public  void setAntiJARLocking(boolean antiJARLocking) 
 public  void setClearReferencesLogFactoryRelease(boolean clearReferencesLogFactoryRelease) 
    Set the clearReferencesLogFactoryRelease feature for this Context.
 public  void setClearReferencesStopThreads(boolean clearReferencesStopThreads) 
    Set the clearReferencesStopThreads feature for this Context.
 public  void setDelegate(boolean delegate) 
    Set the "delegate first" flag for this class loader.
 public  void setJarPath(String jarPath) 
    Change the Jar path.
 protected  void setParentClassLoader(ClassLoader pcl) 
    Utility method for use in subclasses. Must be called before Lifecycle methods to have any effect.
 public  void setResources(DirContext resources) 
    Set associated resources.
 public  void setWorkDir(File workDir) 
    Change the work directory.
 public  void start() throws LifecycleException 
    Start the class loader.
 public  void stop() throws LifecycleException 
    Stop the class loader.
 public String toString() 
    Render a String representation of this object.
 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).
 protected boolean validateJarFile(File jarfile) throws IOException 
    Check the specified JAR file, and return true if it does not contain any of the trigger classes.