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.
Modifier and Type | Class and Description |
---|---|
private static class |
RFC3986URLClassLoader.IndexFile |
private static class |
RFC3986URLClassLoader.SubURLClassLoader |
private static class |
RFC3986URLClassLoader.UriCodeSource
To avoid CodeSource equals and hashCode methods in SecureClassLoader keys.
|
private static class |
RFC3986URLClassLoader.URLFileHandler |
private static class |
RFC3986URLClassLoader.URLHandler |
private static class |
RFC3986URLClassLoader.URLJarHandler |
Modifier and Type | Field and Description |
---|---|
private AccessControlContext |
creationContext |
private URLStreamHandlerFactory |
factory |
private List<RFC3986URLClassLoader.URLHandler> |
handlerList |
private Map<Uri,RFC3986URLClassLoader.URLHandler> |
handlerMap |
private static Logger |
logger |
private List<URL> |
originalUrls |
private List<URL> |
searchList |
private static boolean |
uri
value of "net.jini.loader.codebaseAnnotation" property, as cached at class
initialization time.
|
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. |
RFC3986URLClassLoader(URL[] searchUrls,
ClassLoader parent,
URLStreamHandlerFactory factory,
AccessControlContext context) |
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.
|
private URL |
createSearchURL(URL url)
Returns an URL that will be checked if it contains the class or resource.
|
private RFC3986URLClassLoader.URLHandler |
createURLFileHandler(URL url) |
private RFC3986URLClassLoader.URLHandler |
createURLHandler(URL url) |
private RFC3986URLClassLoader.URLHandler |
createURLJarHandler(URL url) |
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.
|
(package private) Class<?> |
findClassImpl(String className) |
URL |
findResource(String name)
Returns an URL referencing the specified resource or
null if the
resource could not be found. |
(package private) URL |
findResourceImpl(String resName)
Returns a URL among the given ones referencing the specified resource or
null if no resource could be found.
|
Enumeration<URL> |
findResources(String name)
Returns all known URLs which point to the specified resource.
|
(package private) void |
findResourcesImpl(String name,
List<URL> result) |
private static byte[] |
getBytes(InputStream is)
Converts an input stream into a byte array.
|
(package private) RFC3986URLClassLoader.URLHandler |
getHandler(int num) |
private ArrayList<URL> |
getInternalURLs(URL root,
String classpath)
returns URLs referenced in the string classpath.
|
URL[] |
getURLs()
Returns the search list of this
URLClassLoader . |
private static boolean |
isDirectory(URL url)
Determines if the URL is pointing to a directory.
|
private boolean |
isSealed(Manifest manifest,
String dirName) |
private void |
makeNewHandler() |
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
private static final boolean uri
private static final Logger logger
private final List<RFC3986URLClassLoader.URLHandler> handlerList
private final Map<Uri,RFC3986URLClassLoader.URLHandler> handlerMap
private final URLStreamHandlerFactory factory
private final AccessControlContext creationContext
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.RFC3986URLClassLoader(URL[] searchUrls, ClassLoader parent, URLStreamHandlerFactory factory, AccessControlContext context)
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.private static byte[] getBytes(InputStream is) throws IOException
is
- the input streamIOException
public URL[] getURLs()
URLClassLoader
.getURLs
in class URLClassLoader
private static boolean isDirectory(URL url)
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.private URL createSearchURL(URL url) throws MalformedURLException
MalformedURLException
public URL findResource(String name)
null
if the
resource could not be found.findResource
in class URLClassLoader
name
- the name of the requested resource.URL findResourceImpl(String resName)
resName
- java.lang.String the name of the requested resourceRFC3986URLClassLoader.URLHandler getHandler(int num)
private void makeNewHandler()
private RFC3986URLClassLoader.URLHandler createURLHandler(URL url)
private RFC3986URLClassLoader.URLHandler createURLFileHandler(URL url)
private RFC3986URLClassLoader.URLHandler createURLJarHandler(URL url)
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.private ArrayList<URL> getInternalURLs(URL root, String classpath)
root
- the jar URL that classpath is related toclasspath
- the relative URLs separated by spacespublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class URLClassLoader
IOException
Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.