org.apache.jackrabbit.classloader
Class RepositoryClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by java.net.URLClassLoader
              extended by org.apache.jackrabbit.classloader.RepositoryClassLoader
Direct Known Subclasses:
DynamicRepositoryClassLoader

public class RepositoryClassLoader
extends URLClassLoader

The RepositoryClassLoader class extends the URLClassLoader and provides the functionality to load classes and resources from JCR Repository.

This class loader supports loading classes from the Repository hierarchy, such as a classes 'folder', but also from Jar and Zip files stored in the Repository.

For enhanced performance, this class loader keeps a list of resources and classes which have already been loaded through this class loader. If later requests ask for already cached resources, these are returned without checking whether the underlying repository actually still exists.

This class is not intended to be extended by clients.

Author:
Felix Meschberger

Constructor Summary
RepositoryClassLoader(Session session, String[] classPath, ClassLoader parent)
          Creates a RepositoryClassLoader from a list of item path strings containing globbing pattens for the paths defining the class path.
 
Method Summary
protected  void addClassPathEntry(org.apache.jackrabbit.classloader.ClassPathEntry cpe)
          Adds the class path entry to the current class path list.
protected  org.apache.jackrabbit.classloader.ClassPathEntry[] addClassPathEntry(org.apache.jackrabbit.classloader.ClassPathEntry[] list, org.apache.jackrabbit.classloader.ClassPathEntry newEntry)
          Helper method for class path handling to a new entry to an existing list and return the new list.
 void addHandle(String path)
          Appends the specified path to the list of handles to search for classes and resources.
protected  void addURL(URL url)
          Appends the specified URL to the list of URLs to search for classes and resources.
protected  void buildRepository()
          Builds the repository list from the list of path patterns and appends the path entries from any added handles.
protected  void cleanCache()
          Removes all entries from the cache of loaded resources, which mark resources, which have not been found as of yet.
 void destroy()
          Destroys this class loader.
protected  Class findClass(String name)
          Finds and loads the class with the specified name from the class path.
 URL findResource(String name)
          Finds the resource with the specified name on the search path.
 Enumeration findResources(String name)
          Returns an Enumeration of URLs representing all of the resources on the search path having the specified name.
protected  org.apache.jackrabbit.classloader.ClassPathEntry[] getRepository()
          Returns the current active class path entries list or null if this class loader has already been destroyed.
protected  Session getSession()
          Returns the session used by this class loader to access the repository.
 URL[] getURLs()
          Returns the search path of URLs for loading classes and resources.
protected  boolean hasLoadedResources()
          Returns true, if the cache is not empty.
protected  boolean isDestroyed()
          Returns true if this class loader has already been destroyed by calling destroy().
protected  void setRepository(org.apache.jackrabbit.classloader.ClassPathEntry[] classPath)
          Sets the current active class path to the list of class path entries.
 String toString()
          Returns a string representation of this instance.
 
Methods inherited from class java.net.URLClassLoader
definePackage, getPermissions, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RepositoryClassLoader

public RepositoryClassLoader(Session session,
                             String[] classPath,
                             ClassLoader parent)
Creates a RepositoryClassLoader from a list of item path strings containing globbing pattens for the paths defining the class path.

Parameters:
session - The Session to use to access the class items.
classPath - The list of path strings making up the (initial) class path of this class loader. The strings may contain globbing characters which will be resolved to build the actual class path.
parent - The parent ClassLoader, which may be null.
Throws:
NullPointerException - if either the session or the handles list is null.
Method Detail

isDestroyed

protected boolean isDestroyed()
Returns true if this class loader has already been destroyed by calling destroy().


destroy

public void destroy()
Destroys this class loader. This process encompasses all steps needed to remove as much references to this class loader as possible.

NOTE: This method just clears all internal fields and especially the class path to render this class loader unusable.

This implementation does not throw any exceptions.


findClass

protected Class findClass(String name)
                   throws ClassNotFoundException
Finds and loads the class with the specified name from the class path.

Overrides:
findClass in class URLClassLoader
Parameters:
name - the name of the class
Returns:
the resulting class
Throws:
ClassNotFoundException - If the named class could not be found or if this class loader has already been destroyed.

findResource

public URL findResource(String name)
Finds the resource with the specified name on the search path.

Overrides:
findResource in class URLClassLoader
Parameters:
name - the name of the resource
Returns:
a URL for the resource, or null if the resource could not be found or if the class loader has already been destroyed.

findResources

public Enumeration findResources(String name)
Returns an Enumeration of URLs representing all of the resources on the search path having the specified name.

Overrides:
findResources in class URLClassLoader
Parameters:
name - the resource name
Returns:
an Enumeration of URLs. This is an empty enumeration if no resources are found by this class loader or if this class loader has already been destroyed.

getURLs

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(URL) and addHandle(String) methods.

Overrides:
getURLs in class URLClassLoader
Returns:
the search path of URLs for loading classes and resources. The list is empty, if this class loader has already been destroyed.

addURL

protected void addURL(URL url)
Appends the specified URL to the list of URLs to search for classes and resources. Only Repository URLs with the protocol set to JCR are considered for addition. The system will find out whether the URL points to a directory or a jar archive.

URLs added using this method will be preserved through reconfiguration and reinstantiation.

If this class loader has already been destroyed this method has no effect.

Overrides:
addURL in class URLClassLoader
Parameters:
url - the JCR URL to be added to the search path of URLs.

addHandle

public void addHandle(String path)
Appends the specified path to the list of handles to search for classes and resources. The system will find out whether the path points to a directory or a JAR or ZIP archive. The path is added as is, provided it is valid to be used in the class path and therefore must not contain any globbing characters.

If this class loader has already been destroyed, this method has no effect.

Parameters:
path - The path to be added to the search path.

cleanCache

protected void cleanCache()
Removes all entries from the cache of loaded resources, which mark resources, which have not been found as of yet.

Throws:
NullPointerException - If this class loader has already been destroyed.

hasLoadedResources

protected boolean hasLoadedResources()
Returns true, if the cache is not empty. If the cleanCache() method is not called before calling this method, a false positive result may be returned.

Throws:
NullPointerException - If this class loader has already been destroyed.

getSession

protected Session getSession()
Returns the session used by this class loader to access the repository. If this class loader has already been destroyed, this null is returned.


setRepository

protected void setRepository(org.apache.jackrabbit.classloader.ClassPathEntry[] classPath)
Sets the current active class path to the list of class path entries.


getRepository

protected org.apache.jackrabbit.classloader.ClassPathEntry[] getRepository()
Returns the current active class path entries list or null if this class loader has already been destroyed.


addClassPathEntry

protected void addClassPathEntry(org.apache.jackrabbit.classloader.ClassPathEntry cpe)
Adds the class path entry to the current class path list. If the class loader has already been destroyed, this method creates a single entry class path list with the new class path entry.


addClassPathEntry

protected org.apache.jackrabbit.classloader.ClassPathEntry[] addClassPathEntry(org.apache.jackrabbit.classloader.ClassPathEntry[] list,
                                                                               org.apache.jackrabbit.classloader.ClassPathEntry newEntry)
Helper method for class path handling to a new entry to an existing list and return the new list.

If list is null a new array is returned with a single element newEntry. Otherwise the array returned contains all elements of list and newEntry at the last position.

Parameters:
list - The array of class path entries, to which a new entry is to be appended. This may be null.
newEntry - The new entry to append to the class path list.
Returns:
The extended class path list.

toString

public String toString()
Returns a string representation of this instance.

Overrides:
toString in class Object

buildRepository

protected void buildRepository()
Builds the repository list from the list of path patterns and appends the path entries from any added handles. This method may be used multiple times, each time replacing the currently defined repository list.

Throws:
NullPointerException - If this class loader has already been destroyed.


Copyright © 2004-2008 The Apache Software Foundation. All Rights Reserved.