|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
org.xwiki.classloader.ExtendedURLClassLoader
org.xwiki.classloader.URIClassLoader
public class URIClassLoader
Equivalent of java.net.URLClassloader but without bugs related to ill-formed URLs and with customizable JAR caching policy. The standard URLClassLoader accepts URLs containing spaces and other characters which are forbidden in the URI syntax, according to the RFC 2396. As a workaround to this problem, Java escapes and un-escapes URLs in various arbitrary places; however, this is inconsistent and leads to numerous problems with URLs referring to local files with spaces in the path. SUN acknowledges the problem, but refuses to modify the behavior for compatibility reasons; see Java Bug Parade 4273532, 4466485.
Additionally, the JAR caching policy used by URLClassLoader is system-wide and inflexible: once downloaded JAR files are never re-downloaded, even if one creates a fresh instance of the class loader that happens to have the same URL in its search path. In fact, that policy is a security vulnerability: it is possible to crash any URL class loader, thus affecting potentially separate part of the system, by creating URL connection to one of the URLs of that class loader search path and closing the associated JAR file. See Java Bug Parade 4405789, 4388666, 4639900.
This class avoids these problems by 1) using URIs instead of URLs for the search path (thus enforcing strict syntax conformance and defining precise escaping semantics), and 2) using custom URLStreamHandler which ensures per-classloader JAR caching policy.
Originally written by Dawid Kurzyniec and released to the public domain, as explained at http://creativecommons.org/licenses/publicdomain
Source: http://dcl.mathcs.emory.edu/php/loadPage.php?content=util/features.html#classloading
File.toURL(),
File.toURI()| Constructor Summary | |
|---|---|
URIClassLoader(URI[] uris)
Creates URIClassLoader with the specified search path. |
|
URIClassLoader(URI[] uris,
ClassLoader parent)
Creates URIClassLoader with the specified search path and parent class loader. |
|
URIClassLoader(URI[] uris,
ClassLoader parent,
URLStreamHandlerFactory handlerFactory)
Creates URIClassLoader with the specified search path and parent class loader. |
|
URIClassLoader(URI[] uris,
URLStreamHandlerFactory handlerFactory)
Creates URIClassLoader with the specified search path. |
|
| Method Summary | |
|---|---|
protected void |
addURI(URI uri)
Add specified URI at the end of the search path. |
void |
addURL(URL url)
Add specified URL at the end of the search path. |
void |
addURLs(List<URL> urls)
Add specified URLs at the end of the search path. |
protected Class<?> |
defineClass(String name,
edu.emory.mathcs.util.classloader.ResourceHandle h)
|
protected Class<?> |
findClass(String name)
Finds and loads the class with the specified name. |
protected String |
findLibrary(String libname)
Returns the absolute path name of a native library. |
URL |
findResource(String name)
Finds the resource with the specified name. |
Enumeration<URL> |
findResources(String name)
Returns an Enumeration of URLs representing all of the resources having the specified name. |
protected edu.emory.mathcs.util.classloader.ResourceHandle |
getClassHandle(String name)
Finds the ResourceHandle object for the class with the specified name. |
protected edu.emory.mathcs.util.classloader.ResourceHandle |
getLibraryHandle(String name)
Finds the ResourceHandle object for the native library with the specified name. |
protected edu.emory.mathcs.util.classloader.ResourceHandle |
getResourceHandle(String name)
Finds the ResourceHandle object for the resource with the specified name. |
protected Enumeration<edu.emory.mathcs.util.classloader.ResourceHandle> |
getResourceHandles(String name)
Returns an Enumeration of ResourceHandle objects representing all of the resources having the specified name. |
URL[] |
getURLs()
|
| Methods inherited from class java.net.URLClassLoader |
|---|
definePackage, getPermissions, newInstance, newInstance |
| Methods inherited from class java.security.SecureClassLoader |
|---|
defineClass, defineClass |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public URIClassLoader(URI[] uris)
uris - the search path
public URIClassLoader(URI[] uris,
URLStreamHandlerFactory handlerFactory)
uris - the search pathhandlerFactory - the URLStreamHandlerFactory to use when creating URLs
public URIClassLoader(URI[] uris,
ClassLoader parent)
uris - the search pathparent - the parent class loader
public URIClassLoader(URI[] uris,
ClassLoader parent,
URLStreamHandlerFactory handlerFactory)
uris - the search pathparent - the parent class loader.handlerFactory - the URLStreamHandlerFactory to use when creating URLs| Method Detail |
|---|
protected void addURI(URI uri)
uri - the URI to addpublic void addURL(URL url)
addURL in class ExtendedURLClassLoaderurl - the URL to addpublic void addURLs(List<URL> urls)
addURLs in class ExtendedURLClassLoaderurls - the URLs to addpublic URL[] getURLs()
getURLs in class URLClassLoader
protected Class<?> findClass(String name)
throws ClassNotFoundException
findClass in class URLClassLoadername - the name of the class
ClassNotFoundException - if the class could not be found
protected Class<?> defineClass(String name,
edu.emory.mathcs.util.classloader.ResourceHandle h)
throws IOException
IOExceptionpublic URL findResource(String name)
findResource in class URLClassLoadername - the name of the resource
URL for the resource, or null if the resource could not be found.
public Enumeration<URL> findResources(String name)
throws IOException
findResources in class URLClassLoadername - the resource name
Enumeration of URLs
IOException - if an I/O exception occursprotected String findLibrary(String libname)
null, the VM searches
the library along the path specified as the java.library.path property. This method invoke
getLibraryHandle(java.lang.String) method to find handle of this library. If the handle is found and its URL protocol is
"file", the system-dependent absolute library file path is returned. Otherwise this method returns null.
Subclasses can override this method to provide specific approaches in library searching.
findLibrary in class ClassLoaderlibname - the library name
System.loadLibrary(java.lang.String),
System.mapLibraryName(java.lang.String)protected edu.emory.mathcs.util.classloader.ResourceHandle getClassHandle(String name)
findClass(), this
method does not load the class.
name - the name of the class
protected edu.emory.mathcs.util.classloader.ResourceHandle getResourceHandle(String name)
name - the name of the resource
protected edu.emory.mathcs.util.classloader.ResourceHandle getLibraryHandle(String name)
System.mapLibraryName(String) method). Next, the ResourceFinder is used to look for the
library as it was ordinary resource.
Subclasses can override this method to provide specific approaches in library searching.
name - the name of the library
protected Enumeration<edu.emory.mathcs.util.classloader.ResourceHandle> getResourceHandles(String name)
name - the name of the resource
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||