org.jboss.classloader.spi.base
Class BaseClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by org.jboss.classloader.spi.base.BaseClassLoader
All Implemented Interfaces:
BaseClassLoaderMBean, org.jboss.classloading.spi.RealClassLoader, org.jboss.util.loading.Translatable

public class BaseClassLoader
extends SecureClassLoader
implements BaseClassLoaderMBean, org.jboss.classloading.spi.RealClassLoader

BaseClassLoader.

Version:
$Revision: 1.1 $
Author:
Adrian Brock

Constructor Summary
BaseClassLoader(ClassLoaderPolicy policy)
          Create a new ClassLoader with no parent.
 
Method Summary
protected  Class<?> checkCacheAndBlackList(String name, boolean failIfBlackListed, boolean trace)
          Check the cache and blacklist
 void clearBlackList()
          Clear the black list
 void clearBlackList(String name)
          Clear an entry from the black list
protected  void definePackage(String className, URL codeSourceURL)
          Define the package for the class if not already done
 ClassLoader findClassLoader(String className)
          Find the classloader for a class but don't load the class
 ObjectName findClassLoaderForClass(String name)
          Find the classloader for a class
protected  Enumeration<URL> findResources(String name)
           
 Class<?> getCachedClass(String name)
           
 URL getCachedResource(String name)
           
 ObjectName getClassLoaderDomain()
          Get the classloader domain
 String getName()
          Get the name of the classloader
 ObjectName getObjectName()
           
protected  Package getPackage(String name)
           
protected  Package[] getPackages()
           
 URL getResource(String name)
           
 int getResourceBlackListSize()
          Get the number of resources black listed
 int getResourceCacheSize()
          Get the number of resource cached
 URL getResourceLocally(String name)
          Try to find the resource locally
 boolean isBlackListable()
          Whether to cache misses
 boolean isCacheable()
          Whether to cache<
 boolean isImportAll()
          Whether to import all exports from other classloaders in the domain
protected  Class<?> isLoadedClass(String name, boolean trace)
          Check to see if the class is already loaded
 boolean isValid()
          Whether the classloader is still valid
 Set<String> listExportedPackages()
          Get the exported packages
 List<ObjectName> listImports()
          Get the imports of this classloader
 Set<String> listLoadedClasses()
          Get the loaded classes
 Set<String> listLoadedResourceNames()
          Get the loaded resource names
 Set<URL> listLoadedResources()
          Get the loaded resources
 String listPolicyDetails()
          Get the policy as a string
 Set<String> listResourceBlackList()
          Show the resource blacklist
 Map<String,URL> listResourceCache()
          Show the resource cache
protected  Class<?> loadClass(String name, boolean resolve)
           
protected  Class<?> loadClassFromDomain(String name, boolean trace)
          Try to load the class from the domain
 Set<URL> loadResources(String name)
          Get resources
protected  void shutdownClassLoader()
          Shutdown the classloader
 String toLongString()
          A long version of the classloader
protected  void toLongString(StringBuilder builder)
          For subclasses to add things to the long string
 String toString()
           
 
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass, getPermissions
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getParent, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jboss.classloader.spi.base.BaseClassLoaderMBean
loadClass
 

Constructor Detail

BaseClassLoader

public BaseClassLoader(ClassLoaderPolicy policy)
Create a new ClassLoader with no parent.

Parameters:
policy - the policy
Throws:
IllegalArgumentException - for a null policy
IllegalStateException - if the policy is already associated with a classloader
Method Detail

getObjectName

public ObjectName getObjectName()
Specified by:
getObjectName in interface org.jboss.classloading.spi.RealClassLoader

getClassLoaderDomain

public ObjectName getClassLoaderDomain()
Description copied from interface: BaseClassLoaderMBean
Get the classloader domain

Specified by:
getClassLoaderDomain in interface BaseClassLoaderMBean
Returns:
the domain

getName

public String getName()
Description copied from interface: BaseClassLoaderMBean
Get the name of the classloader

Specified by:
getName in interface BaseClassLoaderMBean
Returns:
the name

isBlackListable

public boolean isBlackListable()
Description copied from interface: BaseClassLoaderMBean
Whether to cache misses

Specified by:
isBlackListable in interface BaseClassLoaderMBean
Returns:
true to cache misses

isCacheable

public boolean isCacheable()
Description copied from interface: BaseClassLoaderMBean
Whether to cache<

Specified by:
isCacheable in interface BaseClassLoaderMBean
Returns:
true to cache

isImportAll

public boolean isImportAll()
Description copied from interface: BaseClassLoaderMBean
Whether to import all exports from other classloaders in the domain

Specified by:
isImportAll in interface BaseClassLoaderMBean
Returns:
true to import all

listExportedPackages

public Set<String> listExportedPackages()
Description copied from interface: BaseClassLoaderMBean
Get the exported packages

Specified by:
listExportedPackages in interface BaseClassLoaderMBean
Returns:
the exported packages

listImports

public List<ObjectName> listImports()
Description copied from interface: BaseClassLoaderMBean
Get the imports of this classloader

Specified by:
listImports in interface BaseClassLoaderMBean
Returns:
the imports

listPolicyDetails

public String listPolicyDetails()
Description copied from interface: BaseClassLoaderMBean
Get the policy as a string

Specified by:
listPolicyDetails in interface BaseClassLoaderMBean
Returns:
the policy string

findClassLoaderForClass

public ObjectName findClassLoaderForClass(String name)
                                   throws ClassNotFoundException
Description copied from interface: BaseClassLoaderMBean
Find the classloader for a class

Specified by:
findClassLoaderForClass in interface BaseClassLoaderMBean
Parameters:
name - the class name
Returns:
the classloader or null if it is not loaded by a managed classloader
Throws:
ClassNotFoundException - when the class is not found

listLoadedClasses

public Set<String> listLoadedClasses()
Description copied from interface: BaseClassLoaderMBean
Get the loaded classes

Specified by:
listLoadedClasses in interface BaseClassLoaderMBean
Returns:
the loaded classes

listLoadedResourceNames

public Set<String> listLoadedResourceNames()
Description copied from interface: BaseClassLoaderMBean
Get the loaded resource names

Specified by:
listLoadedResourceNames in interface BaseClassLoaderMBean
Returns:
the loaded resources names

listLoadedResources

public Set<URL> listLoadedResources()
Description copied from interface: BaseClassLoaderMBean
Get the loaded resources

Specified by:
listLoadedResources in interface BaseClassLoaderMBean
Returns:
the loaded resources

getPackage

protected Package getPackage(String name)
Overrides:
getPackage in class ClassLoader

getPackages

protected Package[] getPackages()
Overrides:
getPackages in class ClassLoader

isLoadedClass

protected Class<?> isLoadedClass(String name,
                                 boolean trace)
Check to see if the class is already loaded

Parameters:
name - the name of the class
trace - whether trace is enabled
Returns:
the class is if it is already loaded, null otherwise

checkCacheAndBlackList

protected Class<?> checkCacheAndBlackList(String name,
                                          boolean failIfBlackListed,
                                          boolean trace)
                                   throws ClassNotFoundException
Check the cache and blacklist

Parameters:
name - the name of the class
failIfBlackListed - true if a blacklisted class should result in ClassNotFoundException; false if a null return value is acceptable
trace - whether trace is enabled
Returns:
the class is if it is already loaded, null otherwise
Throws:
ClassNotFoundException - when the class is blacklisted and failIfBlackListed is true

findClassLoader

public ClassLoader findClassLoader(String className)
                            throws ClassNotFoundException
Find the classloader for a class but don't load the class

Parameters:
className - the class name
Returns:
the classloader
Throws:
ClassNotFoundException - if the class is not found
IllegalStateException - if the classloader is not installed
SecurityException - if the called doesn't have the getClassLoader runtime permission

loadClass

protected Class<?> loadClass(String name,
                             boolean resolve)
                      throws ClassNotFoundException
Overrides:
loadClass in class ClassLoader
Throws:
ClassNotFoundException

getResource

public URL getResource(String name)
Overrides:
getResource in class ClassLoader

findResources

protected Enumeration<URL> findResources(String name)
                                  throws IOException
Overrides:
findResources in class ClassLoader
Throws:
IOException

loadResources

public Set<URL> loadResources(String name)
                       throws IOException
Description copied from interface: BaseClassLoaderMBean
Get resources

Specified by:
loadResources in interface BaseClassLoaderMBean
Parameters:
name - the name of the resource
Returns:
the resource urls
Throws:
IOException - for any error

getResourceLocally

public URL getResourceLocally(String name)
Try to find the resource locally

Specified by:
getResourceLocally in interface org.jboss.util.loading.Translatable
Parameters:
name - the resource name
Returns:
the url if found

definePackage

protected void definePackage(String className,
                             URL codeSourceURL)
Define the package for the class if not already done

Parameters:
className - the class name
codeSourceURL - the code source url

loadClassFromDomain

protected Class<?> loadClassFromDomain(String name,
                                       boolean trace)
                                throws ClassNotFoundException
Try to load the class from the domain

Parameters:
name - the class name
trace - whether trace is enabled
Returns:
the class if found in the parent
Throws:
ClassNotFoundException - for any error

isValid

public boolean isValid()
Description copied from interface: BaseClassLoaderMBean
Whether the classloader is still valid

Specified by:
isValid in interface BaseClassLoaderMBean
Specified by:
isValid in interface org.jboss.classloading.spi.RealClassLoader
Returns:
true when still valid

getCachedClass

public Class<?> getCachedClass(String name)
Specified by:
getCachedClass in interface org.jboss.classloading.spi.RealClassLoader

getCachedResource

public URL getCachedResource(String name)
Specified by:
getCachedResource in interface org.jboss.classloading.spi.RealClassLoader

getResourceBlackListSize

public int getResourceBlackListSize()
Description copied from interface: BaseClassLoaderMBean
Get the number of resources black listed

Specified by:
getResourceBlackListSize in interface BaseClassLoaderMBean
Returns:
the size

getResourceCacheSize

public int getResourceCacheSize()
Description copied from interface: BaseClassLoaderMBean
Get the number of resource cached

Specified by:
getResourceCacheSize in interface BaseClassLoaderMBean
Returns:
the size

listResourceBlackList

public Set<String> listResourceBlackList()
Description copied from interface: BaseClassLoaderMBean
Show the resource blacklist

Specified by:
listResourceBlackList in interface BaseClassLoaderMBean
Returns:
a set of resource names

listResourceCache

public Map<String,URL> listResourceCache()
Description copied from interface: BaseClassLoaderMBean
Show the resource cache

Specified by:
listResourceCache in interface BaseClassLoaderMBean
Returns:
a map of resource name to urls

clearBlackList

public void clearBlackList()
Description copied from interface: BaseClassLoaderMBean
Clear the black list

Specified by:
clearBlackList in interface BaseClassLoaderMBean

clearBlackList

public void clearBlackList(String name)
Description copied from interface: BaseClassLoaderMBean
Clear an entry from the black list

Specified by:
clearBlackList in interface BaseClassLoaderMBean
Specified by:
clearBlackList in interface org.jboss.classloading.spi.RealClassLoader
Parameters:
name - the name of the entry to remove

toLongString

public String toLongString()
A long version of the classloader

Returns:
the long string

shutdownClassLoader

protected void shutdownClassLoader()
Shutdown the classloader


toLongString

protected void toLongString(StringBuilder builder)
For subclasses to add things to the long string

Parameters:
builder - the builder

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2011 JBoss, a division of Red Hat, Inc.. All Rights Reserved.