public class ModuleClassLoader extends URLClassLoader
Modifier | Constructor and Description |
---|---|
|
ModuleClassLoader(Module module,
ClassLoader parent)
Creates class instance configured to load classes and resources for given module.
|
protected |
ModuleClassLoader(Module module,
List<URL> urls) |
protected |
ModuleClassLoader(Module module,
List<URL> urls,
ClassLoader parent) |
protected |
ModuleClassLoader(Module module,
List<URL> urls,
ClassLoader parent,
URLStreamHandlerFactory factory) |
Modifier and Type | Method and Description |
---|---|
protected File |
cacheLibrary(URL libUrl,
String libname)
Saves the given library in the openmrs cache.
|
protected void |
checkClassVisibility(Class<?> cls,
ModuleClassLoader requestor)
Checking the given class's visibility in this module
|
protected static Module[] |
collectAwareOfModuleImports(Module module)
Get and cache the imports for this module.
|
protected static Module[] |
collectRequiredModuleImports(Module module)
Get and cache the imports for this module.
|
void |
dispose() |
protected String |
findLibrary(String name) |
URL |
findResource(String name)
If a resource is found within a jar, that jar URL is converted to a temporary file and a URL
to that is returned
|
protected URL |
findResource(String name,
ModuleClassLoader requestor,
Set<String> seenModules)
Find a resource (image, file, etc) in the module structure
|
protected void |
findResources(List<URL> result,
String name,
ModuleClassLoader requestor,
Set<String> seenModules)
Find all occurrences of a resource (image, file, etc) in the module structure
|
Enumeration<URL> |
findResources(String name) |
static File |
getLibCacheFolderForModule(Module module)
Get the library cache folder for the given module.
|
Module |
getModule() |
Set<String> |
getProvidedPackages()
Contains all class packages provided by the module, including those contained in jars.
|
boolean |
isDisposed() |
protected boolean |
isResourceVisible(String name,
URL url,
ModuleClassLoader requestor)
Check if the given resource (image, file, etc) is visible by this classloader
|
protected Class<?> |
loadClass(String name,
boolean resolve) |
protected Class<?> |
loadClass(String name,
boolean resolve,
ModuleClassLoader requestor,
Set<String> seenModules)
Custom loadClass implementation to allow for loading from a given ModuleClassLoader and skip
the modules that have been tried already
|
protected void |
modulesSetChanged() |
void |
setProbeParentLoaderLast(boolean value)
Allow the probe parent loader last variable to be set.
|
String |
toString() |
addURL, close, definePackage, findClass, getPermissions, getResourceAsStream, getURLs, newInstance, newInstance
defineClass, defineClass
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
protected ModuleClassLoader(Module module, List<URL> urls, ClassLoader parent, URLStreamHandlerFactory factory)
module
- Moduleurls
- resources "managed" by this class loaderparent
- parent class loaderfactory
- URL stream handler factoryURLClassLoader(java.net.URL[], java.lang.ClassLoader,
java.net.URLStreamHandlerFactory)
protected ModuleClassLoader(Module module, List<URL> urls, ClassLoader parent)
module
- the Module
to loadurls
- List<URL>
of the resources "managed" by this class loaderparent
- parent ClassLoader
URLClassLoader(java.net.URL[], java.lang.ClassLoader)
protected ModuleClassLoader(Module module, List<URL> urls)
module
- the Module
to loadurls
- List<URL>
of thee resources "managed" by this class loaderURLClassLoader(java.net.URL[])
public ModuleClassLoader(Module module, ClassLoader parent)
module
- the Module
to loadparent
- parent ClassLoader
public Module getModule()
public boolean isDisposed()
public static File getLibCacheFolderForModule(Module module)
module
- Module which the cache will be used forprotected static Module[] collectRequiredModuleImports(Module module)
protected static Module[] collectAwareOfModuleImports(Module module)
protected void modulesSetChanged()
modulesSetChanged()
public void dispose()
public void setProbeParentLoaderLast(boolean value)
value
- boolean true/false whether or not to look at the parent classloader lastprotected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
loadClass
in class ClassLoader
ClassNotFoundException
ClassLoader.loadClass(java.lang.String, boolean)
protected Class<?> loadClass(String name, boolean resolve, ModuleClassLoader requestor, Set<String> seenModules) throws ClassNotFoundException
name
- String path and name of the class to loadresolve
- boolean whether or not to resolve this class before returningrequestor
- ModuleClassLoader with which to try loadingseenModules
- Set<String> moduleIds that have been tried alreadyClassNotFoundException
- if no class foundprotected void checkClassVisibility(Class<?> cls, ModuleClassLoader requestor) throws ClassNotFoundException
cls
- Class to checkrequestor
- ModuleClassLoader to check againstClassNotFoundException
protected String findLibrary(String name)
findLibrary
in class ClassLoader
ClassLoader.findLibrary(java.lang.String)
protected File cacheLibrary(URL libUrl, String libname)
libUrl
- URL to the library/jar filelibname
- name of the jar that will be the name of the cached filepublic URL findResource(String name)
findResource
in class URLClassLoader
ClassLoader.findResource(java.lang.String)
public Enumeration<URL> findResources(String name) throws IOException
findResources
in class URLClassLoader
IOException
ClassLoader.findResources(java.lang.String)
protected URL findResource(String name, ModuleClassLoader requestor, Set<String> seenModules)
name
- String path and name of the filerequestor
- ModuleClassLoader in which to lookseenModules
- Set<String> modules that have been checked alreadyfindResource(String)
protected void findResources(List<URL> result, String name, ModuleClassLoader requestor, Set<String> seenModules) throws IOException
result
- URL of the file foundname
- String path and name of the file to findrequestor
- ModuleClassLoader in which to startseenModules
- Set<String> moduleIds that have been checked alreadyIOException
findResources(String)
,
findResource(String, ModuleClassLoader, Set)
protected boolean isResourceVisible(String name, URL url, ModuleClassLoader requestor)
name
- String path and name to checkurl
- URL of the library filerequestor
- ModuleClassLoader in which to lookpublic Set<String> getProvidedPackages()
It is used by OpenmrsClassLoader.loadClass(String, boolean)
and in particular
ModuleFactory.getModuleClassLoadersForPackage(String)
to quickly find possible
loaders for the given class. Although it takes some time to extract all provided packages
from a module, it pays off when loading classes. It is much faster to query a map of packages
than iterating over all class loaders to find which one to use.
public String toString()
toString
in class Object
Object.toString()
Copyright © 2024 OpenMRS Inc.. All rights reserved.