public class ModuleClassLoader extends ClassLoader
This is a ClassLoader that knows how to load the code for a Module. It first looks for code in its own JAR, and then delegates to the ModuleClassLoaders of the Modules that this Module depends on.
This used to inherit from URLClassLoader, but the URLClassLoader did mysterious things (it suddenly added additional JARs to itself and I have no idea where they came from), so I did it myself.
Modifier and Type | Class and Description |
---|---|
static class |
ModuleClassLoader.CompoundIterator<T>
Compound iterator helper class.
|
Modifier and Type | Field and Description |
---|---|
protected static Object |
CANNOT_FIND_OBJECT
Marker object to be inserted into the cannotFindTable.
|
protected HashMap<String,Object> |
cannotFindTable
This map maps names of resources that we know for sure we can't load to a
marker object, so we stop attempting to load here and not delegate.
|
protected ModuleClassLoader[] |
theDependencyClassLoaders
The set of ModuleClassLoaders from the dependent Modules.
|
protected String[] |
theDoNotLoadClassPrefixes
Always load classes with these prefixes through the default ClassLoader.
|
protected Module |
theModule
The Module whose classes this ClassLoader is responsible for loading.
|
protected URLStreamHandler |
theStreamHandler
Our StreamHandler, allocated as needed.
|
Constructor and Description |
---|
ModuleClassLoader(Module mod,
ClassLoader parent,
ModuleClassLoader[] dependencyClassLoaders,
String[] doNotLoadClassPrefixes)
Construct one with the Module whose classes this ModuleClassLoader is
supposed to load, the parent/system ClassLoader, and the ClassLoaders of dependent Modules.
|
Modifier and Type | Method and Description |
---|---|
void |
addModuleJarUrls(Set<URL> set)
Add, to the provided set, all URLs to Module JARs, of this ModuleClassLoader
and all dependent ClassLoaders.
|
protected Package |
definePackage(String name,
Manifest man,
URL url)
Verbatim copy from JDK's URLClassLoader.
|
URL |
findResource(String name)
Find a URL.
|
protected Package |
getAndVerifyPackage(String pkgname,
Manifest man,
URL url)
Verbatim copy from JDK's URLClassLoader.
|
ModuleClassLoader[] |
getDependencyClassLoaders()
Obtain the ClassLoaders from dependent Modules.
|
Module |
getModule()
Obtain the Module whose classes this ModuleClassLoader loads.
|
ModuleRegistry |
getModuleRegistry()
Convenience method to obtain the ModuleRegistry in use.
|
URL |
getResource(String name)
Find a resource through this ClassLoader.
|
Enumeration<URL> |
getResources(String name)
Obtain an Enumeration of Resources.
|
Class |
loadClass(String name,
boolean resolve)
Override loadClass() per comment above.
|
protected static byte[] |
slurpJarEntry(JarFile file,
JarEntry entry)
Helper method to read a byte array from a JarEntry.
|
String |
toString()
Convert to a string representation for debugging.
|
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResources, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResourceAsStream, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
protected Module theModule
protected ModuleClassLoader[] theDependencyClassLoaders
protected URLStreamHandler theStreamHandler
protected String[] theDoNotLoadClassPrefixes
protected HashMap<String,Object> cannotFindTable
protected static final Object CANNOT_FIND_OBJECT
public ModuleClassLoader(Module mod, ClassLoader parent, ModuleClassLoader[] dependencyClassLoaders, String[] doNotLoadClassPrefixes)
mod
- the Module whose classes this ClassLoader will loadparent
- the parent ClassLoader of this ClassLoaderdependencyClassLoaders
- the ModuleClassLoaders of the Module's dependent ModulesdoNotLoadClassPrefixes
- prefixes of classes always to be loaded through the system class loader, not this onepublic Module getModule()
public ModuleRegistry getModuleRegistry()
public void addModuleJarUrls(Set<URL> set) throws MalformedURLException
set
- the set to addMalformedURLException
- thrown if a URL was invalidpublic URL getResource(String name)
getResource
in class ClassLoader
name
- name of the resource to findpublic Enumeration<URL> getResources(String name) throws IOException
getResources
in class ClassLoader
name
- the name of the ResourceIOException
- thrown if an I/O error occurredpublic Class loadClass(String name, boolean resolve) throws ClassNotFoundException
loadClass
in class ClassLoader
name
- name of the to-be-loaded classresolve
- do we also resolve the classClassNotFoundException
- loading the class failed, it could not be foundpublic URL findResource(String name)
findResource
in class ClassLoader
name
- the name of the resourceprotected static byte[] slurpJarEntry(JarFile file, JarEntry entry) throws IOException
file
- the JarFile from which to read the JarEntryentry
- the JarEntry to read. If null, return nullIOException
- thrown if an I/O error occurredpublic ModuleClassLoader[] getDependencyClassLoaders()
public String toString()
protected Package getAndVerifyPackage(String pkgname, Manifest man, URL url)
pkgname
- the name of the packageman
- the applicable Manifesturl
- the URLprotected Package definePackage(String name, Manifest man, URL url) throws IllegalArgumentException
name
- the package nameman
- the Manifest containing package version and sealing
informationurl
- the code source url for the package, or null if noneIllegalArgumentException
- if the package name duplicates
an existing package either in this class loader or one
of its ancestorsCopyright © 2018. All rights reserved.