Top Description Fields Constructors Methods
net.sf.ehcache.management

public Class ResourceClassLoader

extends ClassLoader
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .File, .IOException, .InputStream, java.lang.reflect.InvocationTargetException, .Method, java.net.URL, .URLConnection, java.util.ArrayList, .Collections, .Enumeration, .List, java.util.jar.Attributes, .Manifest, .Attributes.Name, net.sf.ehcache.util.MergedEnumeration, org.slf4j.Logger, .LoggerFactory

ResourceClassLoader can load classes nested in a subdirectory of a jar Example : ehcache.jar!/net/sf/ehcache/CacheManager is in the "normal" classpath and will be loaded by any typical classloader ehcache.jar!/subdirectory/net/sf/ehcache/CacheManager can only be loaded by the ResourceClassLoader, with prefix "subdirectory" Assumes classes under prefix directory to have ending .clazz
Author
Anthony Dahanne

Field Summary

Modifier and TypeField and Description
private static final int
private final String
private static final Logger
private final String
private static final String

Constructor Summary

AccessConstructor and Description
public
ResourceClassLoader(String prefix, ClassLoader parent)

Given a parent classloader and the prefix to apply to the lookup path Creates a ResourceClassLoader able to load classes from resources prefixed with "prefix"

Method Summary

Modifier and TypeMethod and Description
protected Class<?>
findClass(String
The binary name of the class
className
)

Overrides java.lang.ClassLoader.findClass.

Finds the class with the specified binary name.
protected URL
findResource(String
The resource name
name
)

Overrides java.lang.ClassLoader.findResource.

Finds the resource with the given name.
protected Enumeration<URL>
findResources(String
The resource name
name
)

Overrides java.lang.ClassLoader.findResources.

Returns an enumeration of URL objects representing all the resources with the given name.
public URL
getResource(String
The resource name
name
)

Overrides java.lang.ClassLoader.getResource.

Finds the resource with the given name.
public Enumeration<URL>
getResources(String
The resource name
resourceName
)

Overrides java.lang.ClassLoader.getResources.

Finds all the resources with the given name.
public synchronized Class<?>
loadClass(String
The binary name of the class
name
,
boolean
If true then resolve the class
resolve
)

Overrides java.lang.ClassLoader.loadClass.

Loads the class with the specified binary name.
private String
private URL
translateFromVFSToPhysicalURL(URL vfsUrl)

DEV-8100 add support for Jboss AS jersey does not understand Jboss VFS URLs , so we use Jboss VFS classes to translate those URLs to file: URLs

private void
unpackVfsResourceToPhysicalURLLocation(URL physicalUrl, Object vfsVirtualFile, Method recursiveCopy)

Inherited from java.lang.ClassLoader:
clearAssertionStatusdefineClassdefineClassdefineClassdefineClassdefinePackagefindClassfindLibraryfindLoadedClassfindResourcefindSystemClassgetClassLoadingLockgetDefinedPackagegetDefinedPackagesgetNamegetPackagegetPackagesgetParentgetPlatformClassLoadergetResourceAsStreamgetSystemClassLoadergetSystemResourcegetSystemResourceAsStreamgetSystemResourcesgetUnnamedModuleisRegisteredAsParallelCapableloadClassregisterAsParallelCapableresolveClassresourcessetClassAssertionStatussetDefaultAssertionStatussetPackageAssertionStatussetSigners

Field Detail

BUFFER_SIZEback to summary
private static final int BUFFER_SIZE
implementationVersionback to summary
private final String implementationVersion
LOGback to summary
private static final Logger LOG
prefixback to summary
private final String prefix
PRIVATE_CLASS_SUFFIXback to summary
private static final String PRIVATE_CLASS_SUFFIX

Constructor Detail

ResourceClassLoaderback to summary
public ResourceClassLoader(String prefix, ClassLoader parent)

Given a parent classloader and the prefix to apply to the lookup path Creates a ResourceClassLoader able to load classes from resources prefixed with "prefix"

Method Detail

findClassback to summary
protected Class<?> findClass(String className) throws ClassNotFoundException

Overrides java.lang.ClassLoader.findClass.

Doc from java.lang.ClassLoader.findClass.

Finds the class with the specified binary name. This method should be overridden by class loader implementations that follow the delegation model for loading classes, and will be invoked by the loadClass method after checking the parent class loader for the requested class.

Parameters
className:String

The binary name of the class

Returns:Class<?>

The resulting Class object

Annotations
@Override
Exceptions
ClassNotFoundException:
If the class could not be found
findResourceback to summary
protected URL findResource(String name)

Overrides java.lang.ClassLoader.findResource.

Doc from java.lang.ClassLoader.findResource.

Finds the resource with the given name. Class loader implementations should override this method.

For resources in named modules then the method must implement the rules for encapsulation specified in the Module getResourceAsStream method. Additionally, it must not find non-".class" resources in packages of named modules unless the package is opened unconditionally.

Parameters
name:String

The resource name

Returns:URL

URL object for reading the resource; null if the resource could not be found, a URL could not be constructed to locate the resource, the resource is in a package that is not opened unconditionally, or access to the resource is denied by the security manager.

Annotations
@Override
findResourcesback to summary
protected Enumeration<URL> findResources(String name) throws IOException

Overrides java.lang.ClassLoader.findResources.

Doc from java.lang.ClassLoader.findResources.

Returns an enumeration of URL objects representing all the resources with the given name. Class loader implementations should override this method.

For resources in named modules then the method must implement the rules for encapsulation specified in the Module getResourceAsStream method. Additionally, it must not find non-".class" resources in packages of named modules unless the package is opened unconditionally.

Parameters
name:String

The resource name

Returns:Enumeration<URL>

An enumeration of URL objects for the resource. If no resources could be found, the enumeration will be empty. Resources for which a URL cannot be constructed, are in a package that is not opened unconditionally, or access to the resource is denied by the security manager, are not returned in the enumeration.

Annotations
@Override
Exceptions
IOException:
If I/O errors occur
getResourceback to summary
public URL getResource(String name)

Overrides java.lang.ClassLoader.getResource.

Doc from java.lang.ClassLoader.getResource.

Finds 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.

Resources in named modules are subject to the encapsulation rules specified by Module.getResourceAsStream. Additionally, and except for the special case where the resource has a name ending with ".class", this method will only find resources in packages of named modules when the package is opened unconditionally (even if the caller of this method is in the same module as the resource).

Parameters
name:String

The resource name

Returns:URL

URL object for reading the resource; null if the resource could not be found, a URL could not be constructed to locate the resource, the resource is in a package that is not opened unconditionally, or access to the resource is denied by the security manager.

Annotations
@Override
getResourcesback to summary
public Enumeration<URL> getResources(String resourceName) throws IOException

Overrides java.lang.ClassLoader.getResources.

Doc from java.lang.ClassLoader.getResources.

Finds all the resources 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.

Resources in named modules are subject to the encapsulation rules specified by Module.getResourceAsStream. Additionally, and except for the special case where the resource has a name ending with ".class", this method will only find resources in packages of named modules when the package is opened unconditionally (even if the caller of this method is in the same module as the resource).

Parameters
resourceName:String

The resource name

Returns:Enumeration<URL>

An enumeration of URL objects for the resource. If no resources could be found, the enumeration will be empty. Resources for which a URL cannot be constructed, are in a package that is not opened unconditionally, or access to the resource is denied by the security manager, are not returned in the enumeration.

Annotations
@Override
Exceptions
IOException:
If I/O errors occur
loadClassback to summary
public synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException

Overrides java.lang.ClassLoader.loadClass.

Doc from java.lang.ClassLoader.loadClass.

Loads the class with the specified binary name. The default implementation of this method searches for classes in the following order:

  1. Invoke findLoadedClass(String) to check if the class has already been loaded.

  2. Invoke the loadClass method on the parent class loader. If the parent is null the class loader built into the virtual machine is used, instead.

  3. Invoke the findClass(String) method to find the class.

If the class was found using the above steps, and the resolve flag is true, this method will then invoke the resolveClass(Class) method on the resulting Class object.

Subclasses of ClassLoader are encouraged to override findClass(String), rather than this method.

Unless overridden, this method synchronizes on the result of getClassLoadingLock method during the entire class loading process.

Parameters
name:String

The binary name of the class

resolve:boolean

If true then resolve the class

Returns:Class<?>

The resulting Class object

Annotations
@Override
Exceptions
ClassNotFoundException:
If the class could not be found
replaceWithPrivateSuffixback to summary
private String replaceWithPrivateSuffix(String name)
translateFromVFSToPhysicalURLback to summary
private URL translateFromVFSToPhysicalURL(URL vfsUrl) throws IOException

DEV-8100 add support for Jboss AS jersey does not understand Jboss VFS URLs , so we use Jboss VFS classes to translate those URLs to file: URLs

unpackVfsResourceToPhysicalURLLocationback to summary
private void unpackVfsResourceToPhysicalURLLocation(URL physicalUrl, Object vfsVirtualFile, Method recursiveCopy) throws IllegalAccessException, InvocationTargetException