Top Description Fields Constructors Methods
org.springframework.instrument.classloading

public Class ResourceOverridingShadowingClassLoader

extends ShadowingClassLoader
Class Inheritance
Imports
java.io.IOException, .InputStream, java.net.URL, java.util.Enumeration, .HashMap, .Map, org.springframework.lang.Nullable, org.springframework.util.Assert

Subclass of ShadowingClassLoader that overrides attempts to locate certain files.
Authors
Rod Johnson, Adrian Colyer
Since
2.0

Field Summary

Modifier and TypeField and Description
private static final Enumeration<URL>
private final Map<String, String>
overrides

Key is asked for value: value is actual value.

Inherited from org.springframework.instrument.classloading.ShadowingClassLoader:
DEFAULT_EXCLUDED_PACKAGES

Constructor Summary

AccessConstructor and Description
public
ResourceOverridingShadowingClassLoader(ClassLoader
the ClassLoader to decorate
enclosingClassLoader
)

Create a new ResourceOverridingShadowingClassLoader, decorating the given ClassLoader.

Method Summary

Modifier and TypeMethod and Description
public void
copyOverrides(ResourceOverridingShadowingClassLoader
the other ClassLoader to copy from
other
)

Copy all overrides from the given ClassLoader.

public URL
getResource(String
The resource name
requestedPath
)

Overrides org.springframework.instrument.classloading.ShadowingClassLoader.getResource.

Finds the resource with the given name.

public InputStream
getResourceAsStream(String
The resource name
requestedPath
)

Overrides org.springframework.instrument.classloading.ShadowingClassLoader.getResourceAsStream.

Returns an input stream for reading the specified resource.

public Enumeration<URL>
getResources(String
The resource name
requestedPath
)

Overrides org.springframework.instrument.classloading.ShadowingClassLoader.getResources.

Finds all the resources with the given name.

public void
override(String
the path requested
oldPath
,
String
the actual path to be looked up
newPath
)

Return the resource (if any) at the new path on an attempt to locate a resource at the old path.

public void
suppress(String
the path of the resource to hide even if it exists in the parent ClassLoader
oldPath
)

Ensure that a resource with the given path is not found.

Inherited from org.springframework.instrument.classloading.ShadowingClassLoader:
addTransformercopyTransformersisEligibleForShadowingloadClass

Field Detail

EMPTY_URL_ENUMERATIONback to summary
private static final Enumeration<URL> EMPTY_URL_ENUMERATION
overridesback to summary
private final Map<String, String> overrides

Key is asked for value: value is actual value.

Constructor Detail

ResourceOverridingShadowingClassLoaderback to summary
public ResourceOverridingShadowingClassLoader(ClassLoader enclosingClassLoader)

Create a new ResourceOverridingShadowingClassLoader, decorating the given ClassLoader.

Parameters
enclosingClassLoader:ClassLoader

the ClassLoader to decorate

Method Detail

copyOverridesback to summary
public void copyOverrides(ResourceOverridingShadowingClassLoader other)

Copy all overrides from the given ClassLoader.

Parameters
other:ResourceOverridingShadowingClassLoader

the other ClassLoader to copy from

getResourceback to summary
public URL getResource(String requestedPath)

Overrides org.springframework.instrument.classloading.ShadowingClassLoader.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
requestedPath: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
getResourceAsStreamback to summary
public InputStream getResourceAsStream(String requestedPath)

Overrides org.springframework.instrument.classloading.ShadowingClassLoader.getResourceAsStream.

Doc from java.lang.ClassLoader.getResourceAsStream.

Returns an input stream for reading the specified resource.

The search order is described in the documentation for getResource(String).

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.

Parameters
requestedPath:String

The resource name

Returns:InputStream

An input stream for reading the resource; null if the resource could not be found, the resource is in a package that is not opened unconditionally, or access to the resource is denied by the security manager.

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

Overrides org.springframework.instrument.classloading.ShadowingClassLoader.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
requestedPath: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
overrideback to summary
public void override(String oldPath, String newPath)

Return the resource (if any) at the new path on an attempt to locate a resource at the old path.

Parameters
oldPath:String

the path requested

newPath:String

the actual path to be looked up

suppressback to summary
public void suppress(String oldPath)

Ensure that a resource with the given path is not found.

Parameters
oldPath:String

the path of the resource to hide even if it exists in the parent ClassLoader