public class RFC3986URLClassLoader extends URLClassLoader
URLClassLoader
are granted permission to access the
URLs contained in the URL search list.
Unlike java.net.URLClassLoader, CodeSource.equals(java.lang.Object)
and CodeSource.hashCode()
is based on Certificate
and RFC3986 Uri.equals(java.lang.Object)
and Uri.hashCode()
,
not URL.equals(java.lang.Object)
. SecureClassLoader
uses the overridden CodeSource equality as a key to cache ProtectionDomain's.
The following property
-Dnet.jini.loader.codebaseAnnotation=URL
may be set from the command line to revert to URL.equals(java.lang.Object)
and URL.hashCode()
.
This allows implementors of Remote
to do two things:
The locking strategy of this ClassLoader is by default, the standard ClassLoader strategy. This ClassLoader is also thread safe, so can use a Parallel loading / synchronization strategy if the platform supports it.
Constructor and Description |
---|
RFC3986URLClassLoader(URL[] urls)
Constructs a new
URLClassLoader instance. |
RFC3986URLClassLoader(URL[] urls,
ClassLoader parent)
Constructs a new URLClassLoader instance.
|
RFC3986URLClassLoader(URL[] searchUrls,
ClassLoader parent,
URLStreamHandlerFactory factory)
Constructs a new
URLClassLoader instance. |
Modifier and Type | Method and Description |
---|---|
protected void |
addURL(URL url)
Adds the specified URL to the search list.
|
void |
close()
Java 6 compatible implementation that overrides Java 7 URLClassLoader.close()
URLClassLoader implements Closeable in Java 7 to allow resources such
as open jar files to be released.
|
protected Package |
definePackage(String packageName,
Manifest manifest,
URL url)
Defines a new package using the information extracted from the specified
manifest.
|
protected Class<?> |
findClass(String clsName)
Tries to locate and load the specified class using the known URLs.
|
URL |
findResource(String name)
Returns an URL referencing the specified resource or
null if the
resource could not be found. |
Enumeration<URL> |
findResources(String name)
Returns all known URLs which point to the specified resource.
|
URL[] |
getURLs()
Returns the search list of this
URLClassLoader . |
static URLClassLoader |
newInstance(URL[] urls)
Returns a new
URLClassLoader instance for the given URLs and the
system ClassLoader as its parent. |
static URLClassLoader |
newInstance(URL[] urls,
ClassLoader parentCl)
Returns a new
URLClassLoader instance for the given URLs and the
specified ClassLoader as its parent. |
getPermissions, getResourceAsStream
defineClass, defineClass
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
public RFC3986URLClassLoader(URL[] urls)
URLClassLoader
instance. The newly created
instance will have the system ClassLoader as its parent. URLs that end
with "/" are assumed to be directories, otherwise they are assumed to be
JAR files.urls
- the list of URLs where a specific class or file could be
found.SecurityException
- if a security manager exists and its checkCreateClassLoader()
method doesn't allow creation of
new ClassLoaders.public RFC3986URLClassLoader(URL[] urls, ClassLoader parent)
urls
- the list of URLs where a specific class or file could be
found.parent
- the class loader to assign as this loader's parent.SecurityException
- if a security manager exists and its checkCreateClassLoader()
method doesn't allow creation of
new class loaders.public RFC3986URLClassLoader(URL[] searchUrls, ClassLoader parent, URLStreamHandlerFactory factory)
URLClassLoader
instance. The newly created
instance will have the specified ClassLoader
as its parent and
use the specified factory to create stream handlers. URLs that end with
"/" are assumed to be directories, otherwise they are assumed to be JAR
files.searchUrls
- the list of URLs where a specific class or file could be
found.parent
- the ClassLoader
to assign as this loader's parent.factory
- the factory that will be used to create protocol-specific
stream handlers.SecurityException
- if a security manager exists and its checkCreateClassLoader()
method doesn't allow creation of
new ClassLoader
s.protected void addURL(URL url)
addURL
in class URLClassLoader
url
- the URL which is to add.public Enumeration<URL> findResources(String name) throws IOException
findResources
in class URLClassLoader
name
- the name of the requested resource.IOException
- if an I/O error occurs while attempting to connect.public URL[] getURLs()
URLClassLoader
.getURLs
in class URLClassLoader
public static URLClassLoader newInstance(URL[] urls)
URLClassLoader
instance for the given URLs and the
system ClassLoader
as its parent. The method loadClass()
of the new instance will call SecurityManager.checkPackageAccess()
before loading a class.urls
- the list of URLs that is passed to the new URLClassloader
.URLClassLoader
instance.public static URLClassLoader newInstance(URL[] urls, ClassLoader parentCl)
URLClassLoader
instance for the given URLs and the
specified ClassLoader
as its parent. The method loadClass()
of the new instance will call the SecurityManager's checkPackageAccess()
before loading a class.urls
- the list of URLs that is passed to the new URLClassloader.parentCl
- the parent class loader that is passed to the new
URLClassloader.URLClassLoader
instance.protected Class<?> findClass(String clsName) throws ClassNotFoundException
findClass
in class URLClassLoader
clsName
- the name of the class which has to be found.ClassNotFoundException
- if the specified class cannot be loaded.public URL findResource(String name)
null
if the
resource could not be found.findResource
in class URLClassLoader
name
- the name of the requested resource.protected Package definePackage(String packageName, Manifest manifest, URL url) throws IllegalArgumentException
definePackage
in class URLClassLoader
packageName
- the name of the new package.manifest
- the manifest containing additional information for the new
package.url
- the URL to the code source for the new package.IllegalArgumentException
- if a package with the given name already exists.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class URLClassLoader
IOException
- if closing any file opened by this ClassLoader
causes an IOException, only the first instance is thrown.Copyright © 2016–2018 The Apache Software Foundation. All rights reserved.