org.jboss.mx.loading
Class RepositoryClassLoader

java.lang.Object
  extended byjava.lang.ClassLoader
      extended byjava.security.SecureClassLoader
          extended byjava.net.URLClassLoader
              extended byorg.jboss.mx.loading.RepositoryClassLoader
Direct Known Subclasses:
UnifiedClassLoader (src)

public abstract class RepositoryClassLoader
extends java.net.URLClassLoader

A RepositoryClassLoader.


Field Summary
protected  ReentrantLock loadLock
          Lock
protected  java.lang.ClassLoader parent
          The parent classloader
protected  LoaderRepository (src) repository
          Reference to the repository.
protected  java.lang.Exception unregisterTrace
          The location where unregister is called from
 
Constructor Summary
protected RepositoryClassLoader(java.net.URL[] urls, java.lang.ClassLoader parent)
          Create a new LoaderRepositoryClassLoader
 
Method Summary
protected  void acquire()
          Acquire the class loading lock.
 void addToClassBlackList(java.lang.String name)
          Black list a class
 void addToResourceBlackList(java.lang.String name)
          Black list a resource
 void addURL(java.net.URL url)
          Append the given url to the URLs used for class and resource loading
protected  boolean attempt(long waitMS)
          Attempt to acquire the class loading lock.
 void clearBlackLists()
          Clear all blacklists
 void clearClassBlackList()
          Clear any class black list.
 void clearResourceBlackList()
          Clear any resource blacklist.
protected  void definePackage(java.lang.String className)
          Define the package for the class if not already done
 boolean equals(java.lang.Object other)
          This is here to document that this must delegate to the super implementation to perform identity based equality.
protected  java.lang.Class findClass(java.lang.String name)
          Called by loadClassLocally to find the requested class within this class loaders class path.
protected  java.lang.Class findClassLocally(java.lang.String name)
          Find the class
 java.util.Enumeration findResources(java.lang.String name)
          Find all resource URLs for the given name.
 java.util.Enumeration findResourcesLocally(java.lang.String name)
          Provides the same functionality as URLClassLoader.findResources(java.lang.String).
 int getAddedOrder()
          Get the order this classloader was added to the repository
 java.net.URL[] getAllURLs()
          Return all library URLs associated with this RepositoryClassLoader
 java.net.URL[] getClasspath()
          This method simply invokes the super.getURLs() method to access the list of URLs that make up the RepositoryClassLoader classpath.
 LoaderRepository (src) getLoaderRepository()
          Get the loader repository for this classloader
abstract  ObjectName (src) getObjectName()
          Get the ObjectName
 java.lang.Package getPackage(java.lang.String name)
           
 java.lang.Package[] getPackages()
           
protected  java.security.ProtectionDomain getProtectionDomain(java.net.URL codesourceUrl)
          Determine the protection domain.
 java.net.URL getResource(java.lang.String name)
          Attempts to load the resource from its URL and if not found forwards to the request to LoaderRepository (src) .
 java.net.URL getResourceLocally(java.lang.String name)
          Provides the same functionality as ClassLoader.getResource(java.lang.String).
 java.net.URL getURL()
          Get the URL associated with the UCL.
 java.net.URL[] getURLs()
          Return an empty URL array to force the RMI marshalling subsystem to use the java.server.codebase property as the annotated codebase.
 int hashCode()
          This is here to document that this must delegate to the super implementation to perform identity based hashing.
 boolean isClassBlackListed(java.lang.String name)
          Is the class black listed?
 boolean isResourceBlackListed(java.lang.String name)
          Is the resource black listed?
protected  byte[] loadByteCode(java.lang.String classname)
          Obtain the bytecode for the indicated class from this class loaders classpath.
protected  byte[] loadByteCode(java.net.URL classURL)
          Obtain the bytecode for the indicated class from this class loaders classpath.
 java.lang.Class loadClass(java.lang.String name, boolean resolve)
          The only caller of this method should be the VM initiated loadClassInternal() method.
 java.lang.Class loadClassBefore(java.lang.String name)
          The only caller of this method should be the VM initiated loadClassInternal() method.
 java.lang.Class loadClassImpl(java.lang.String name, boolean resolve, int stopAt)
           
 java.lang.Class loadClassLocally(java.lang.String name, boolean resolve)
          Called to attempt to load a class from the set of URLs associated with this classloader.
protected  void release()
          Release the class loading lock previous acquired through the acquire method.
 void removeFromClassBlackList(java.lang.String name)
          Remove class from black list
 void removeFromResourceBlackList(java.lang.String name)
          Remove resource from black list
 void setAddedOrder(int addedOrder)
          Set the order this classloader was added to the repository
 void setRepository(LoaderRepository (src)  repository)
          Set the loader repository
 java.lang.String toString()
          Returns a string representation.
 void unregister()
           
 
Methods inherited from class java.net.URLClassLoader
definePackage, findResource, getPermissions, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getParent, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

repository

protected LoaderRepository (src)  repository
Reference to the repository.


unregisterTrace

protected java.lang.Exception unregisterTrace
The location where unregister is called from


parent

protected java.lang.ClassLoader parent
The parent classloader


loadLock

protected ReentrantLock loadLock
Lock

Constructor Detail

RepositoryClassLoader

protected RepositoryClassLoader(java.net.URL[] urls,
                                java.lang.ClassLoader parent)
Create a new LoaderRepositoryClassLoader

Parameters:
urls - the urls
parent - the parent classloader
Method Detail

getObjectName

public abstract ObjectName (src)  getObjectName()
                                  throws MalformedObjectNameException (src) 
Get the ObjectName

Returns:
the object name
Throws:
MalformedObjectNameException (src)

getLoaderRepository

public LoaderRepository (src)  getLoaderRepository()
Get the loader repository for this classloader


setRepository

public void setRepository(LoaderRepository (src)  repository)
Set the loader repository

Parameters:
repository - the repository

getAddedOrder

public int getAddedOrder()
Get the order this classloader was added to the repository

Returns:
the order

setAddedOrder

public void setAddedOrder(int addedOrder)
Set the order this classloader was added to the repository

Parameters:
addedOrder - the added order

loadClassLocally

public java.lang.Class loadClassLocally(java.lang.String name,
                                        boolean resolve)
                                 throws java.lang.ClassNotFoundException
Called to attempt to load a class from the set of URLs associated with this classloader.

Throws:
java.lang.ClassNotFoundException

getResourceLocally

public java.net.URL getResourceLocally(java.lang.String name)
Provides the same functionality as ClassLoader.getResource(java.lang.String).


getURL

public java.net.URL getURL()
Get the URL associated with the UCL.

Returns:
the url

unregister

public void unregister()

getClasspath

public java.net.URL[] getClasspath()
This method simply invokes the super.getURLs() method to access the list of URLs that make up the RepositoryClassLoader classpath.

Returns:
the urls that make up the classpath

getAllURLs

public java.net.URL[] getAllURLs()
Return all library URLs associated with this RepositoryClassLoader

Do not remove this method without running the WebIntegrationTestSuite


addToClassBlackList

public void addToClassBlackList(java.lang.String name)
Black list a class

Parameters:
name - the name of the class

removeFromClassBlackList

public void removeFromClassBlackList(java.lang.String name)
Remove class from black list

Parameters:
name - the name of the class

isClassBlackListed

public boolean isClassBlackListed(java.lang.String name)
Is the class black listed?

Parameters:
name - the name of the class
Returns:
true when the class is black listed, false otherwise

clearClassBlackList

public void clearClassBlackList()
Clear any class black list.


addToResourceBlackList

public void addToResourceBlackList(java.lang.String name)
Black list a resource

Parameters:
name - the name of the resource

removeFromResourceBlackList

public void removeFromResourceBlackList(java.lang.String name)
Remove resource from black list

Parameters:
name - the name of the resource

isResourceBlackListed

public boolean isResourceBlackListed(java.lang.String name)
Is the resource black listed?

Parameters:
name - the name of the resource
Returns:
true when the resource is black listed, false otherwise

clearResourceBlackList

public void clearResourceBlackList()
Clear any resource blacklist.


clearBlackLists

public void clearBlackLists()
Clear all blacklists


loadClass

public java.lang.Class loadClass(java.lang.String name,
                                 boolean resolve)
                          throws java.lang.ClassNotFoundException
The only caller of this method should be the VM initiated loadClassInternal() method. This method attempts to acquire the UnifiedLoaderRepository2 lock and then asks the repository to load the class.

Forwards request to LoaderRepository (src) .

Throws:
java.lang.ClassNotFoundException

loadClassBefore

public java.lang.Class loadClassBefore(java.lang.String name)
                                throws java.lang.ClassNotFoundException
The only caller of this method should be the VM initiated loadClassInternal() method. This method attempts to acquire the UnifiedLoaderRepository2 lock and then asks the repository to load the class.

Forwards request to LoaderRepository (src) .

Throws:
java.lang.ClassNotFoundException

loadClassImpl

public java.lang.Class loadClassImpl(java.lang.String name,
                                     boolean resolve,
                                     int stopAt)
                              throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

getResource

public java.net.URL getResource(java.lang.String name)
Attempts to load the resource from its URL and if not found forwards to the request to LoaderRepository (src) .


findResources

public java.util.Enumeration findResources(java.lang.String name)
                                    throws java.io.IOException
Find all resource URLs for the given name. This overrides the URLClassLoader version to look for resources in the repository.

Parameters:
name - the name of the resource
Returns:
Enumeration
Throws:
java.io.IOException

findResourcesLocally

public java.util.Enumeration findResourcesLocally(java.lang.String name)
                                           throws java.io.IOException
Provides the same functionality as URLClassLoader.findResources(java.lang.String).

Throws:
java.io.IOException

findClass

protected java.lang.Class findClass(java.lang.String name)
                             throws java.lang.ClassNotFoundException
Called by loadClassLocally to find the requested class within this class loaders class path.

Parameters:
name - the name of the class
Returns:
the resulting class
Throws:
java.lang.ClassNotFoundException - if the class could not be found

findClassLocally

protected java.lang.Class findClassLocally(java.lang.String name)
                                    throws java.lang.ClassNotFoundException
Find the class

Parameters:
name - the name of the class
Returns:
the class
Throws:
java.lang.ClassNotFoundException

definePackage

protected void definePackage(java.lang.String className)
Define the package for the class if not already done

Parameters:
className - the class name

addURL

public void addURL(java.net.URL url)
Append the given url to the URLs used for class and resource loading

Parameters:
url - the URL to load from

getURLs

public java.net.URL[] getURLs()
Return an empty URL array to force the RMI marshalling subsystem to use the java.server.codebase property as the annotated codebase.

Do not remove this method without discussing it on the dev list.

Returns:
Empty URL[]

getPackage

public java.lang.Package getPackage(java.lang.String name)

getPackages

public java.lang.Package[] getPackages()

equals

public final boolean equals(java.lang.Object other)
This is here to document that this must delegate to the super implementation to perform identity based equality. Using URL based equality caused conflicts with the Class.forName(String, boolean, ClassLoader).


hashCode

public final int hashCode()
This is here to document that this must delegate to the super implementation to perform identity based hashing. Using URL based hashing caused conflicts with the Class.forName(String, boolean, ClassLoader).


toString

public java.lang.String toString()
Returns a string representation.


attempt

protected boolean attempt(long waitMS)
Attempt to acquire the class loading lock. This lock must be acquired before a thread enters the class loading task loop in loadClass. This method maintains any interrupted state of the calling thread.

See Also:
loadClass(String, boolean)

acquire

protected void acquire()
Acquire the class loading lock. This lock must be acquired before a thread enters the class loading task loop in loadClass.

See Also:
loadClass(String, boolean)

release

protected void release()
Release the class loading lock previous acquired through the acquire method.


loadByteCode

protected byte[] loadByteCode(java.lang.String classname)
                       throws java.lang.ClassNotFoundException,
                              java.io.IOException
Obtain the bytecode for the indicated class from this class loaders classpath.

Parameters:
classname -
Returns:
the bytecode array if found
Throws:
java.lang.ClassNotFoundException - - if the class resource could not be found
java.io.IOException

loadByteCode

protected byte[] loadByteCode(java.net.URL classURL)
                       throws java.lang.ClassNotFoundException,
                              java.io.IOException
Obtain the bytecode for the indicated class from this class loaders classpath.

Parameters:
classURL -
Returns:
the bytecode array if found
Throws:
java.lang.ClassNotFoundException - - if the class resource could not be found
java.io.IOException

getProtectionDomain

protected java.security.ProtectionDomain getProtectionDomain(java.net.URL codesourceUrl)
Determine the protection domain. If we are a copy of the original deployment, use the original url as the codebase.

Returns:
the protection domain