org.openmrs.module
Class ModuleClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by java.net.URLClassLoader
              extended by org.openmrs.module.ModuleClassLoader

public class ModuleClassLoader
extends java.net.URLClassLoader

Standard implementation of module class loader.
Code adapted from the Java Plug-in Framework (JPF) - LGPL - Copyright (C)
2004-2006 Dmitry Olshansky


Constructor Summary
  ModuleClassLoader(Module module, java.lang.ClassLoader parent)
          Creates class instance configured to load classes and resources for given module.
protected ModuleClassLoader(Module module, java.util.List<java.net.URL> urls)
           
protected ModuleClassLoader(Module module, java.util.List<java.net.URL> urls, java.lang.ClassLoader parent)
           
protected ModuleClassLoader(Module module, java.util.List<java.net.URL> urls, java.lang.ClassLoader parent, java.net.URLStreamHandlerFactory factory)
           
 
Method Summary
 void addAdditionalPackage(java.lang.String additionalPackage)
          Convenience method to add another package name to the list of packages provided by this module
 void addAllAdditionalPackages(java.util.Collection<java.lang.String> providedPackages)
          Convenience method to add a bunch of package names to the list of packages provided by this module
protected  java.io.File cacheLibrary(java.net.URL libUrl, java.lang.String libname)
          Saves the given library in the openmrs cache.
protected  void checkClassVisibility(java.lang.Class<?> cls, ModuleClassLoader requestor)
          Checking the given class's visibility in this module
protected  void collectFilters()
          Get and cache the filters for this module (not currently implemented)
protected  void collectRequiredModuleImports()
          Get and cache the imports for this module.
 void dispose()
           
protected  java.lang.String findLibrary(java.lang.String name)
           
 java.net.URL findResource(java.lang.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  java.net.URL findResource(java.lang.String name, ModuleClassLoader requestor, java.util.Set<java.lang.String> seenModules)
          Find a resource (image, file, etc) in the module structure
protected  void findResources(java.util.List<java.net.URL> result, java.lang.String name, ModuleClassLoader requestor, java.util.Set<java.lang.String> seenModules)
          Find all occurrences of a resource (image, file, etc) in the module structure
 java.util.Enumeration<java.net.URL> findResources(java.lang.String name)
           
 java.util.Set<java.lang.String> getAdditionalPackages()
          Package names that this module should try to load.
static java.io.File getLibCacheFolderForModule(Module module)
          Get the library cache folder for the given module.
 Module getModule()
           
protected  boolean isResourceVisible(java.lang.String name, java.net.URL url, ModuleClassLoader requestor)
          Check if the given resource (image, file, etc) is visible by this classloader
protected  java.lang.Class<?> loadClass(java.lang.String name, boolean resolve)
           
protected  java.lang.Class<?> loadClass(java.lang.String name, boolean resolve, ModuleClassLoader requestor, java.util.Set<java.lang.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 setAdditionalPackages(java.util.Set<java.lang.String> additionalPackages)
           
 void setProbeParentLoaderLast(boolean value)
          Allow the probe parent loader last variable to be set.
 java.lang.String toString()
           
 
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, findClass, getPermissions, getURLs, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ModuleClassLoader

protected ModuleClassLoader(Module module,
                            java.util.List<java.net.URL> urls,
                            java.lang.ClassLoader parent,
                            java.net.URLStreamHandlerFactory factory)
Parameters:
module - Module
urls - resources "managed" by this class loader
parent - parent class loader
factory - URL stream handler factory
See Also:
URLClassLoader.URLClassLoader(java.net.URL[], java.lang.ClassLoader, java.net.URLStreamHandlerFactory)

ModuleClassLoader

protected ModuleClassLoader(Module module,
                            java.util.List<java.net.URL> urls,
                            java.lang.ClassLoader parent)
Parameters:
module - the Module to load
urls - List of the resources "managed" by this class loader
parent - parent ClassLoader
See Also:
URLClassLoader.URLClassLoader(java.net.URL[], java.lang.ClassLoader)

ModuleClassLoader

protected ModuleClassLoader(Module module,
                            java.util.List<java.net.URL> urls)
Parameters:
module - the Module to load
urls - List of thee resources "managed" by this class loader
See Also:
URLClassLoader.URLClassLoader(java.net.URL[])

ModuleClassLoader

public ModuleClassLoader(Module module,
                         java.lang.ClassLoader parent)
Creates class instance configured to load classes and resources for given module.

Parameters:
module - the Module to load
parent - parent ClassLoader
Method Detail

getModule

public Module getModule()
Returns:
returns this classloader's module

getLibCacheFolderForModule

public static java.io.File getLibCacheFolderForModule(Module module)
Get the library cache folder for the given module. Each module has a different cache folder to ease cleanup when unloading a module while openmrs is running

Parameters:
module - Module which the cache will be used for
Returns:
File directory where the files will be placed

collectRequiredModuleImports

protected void collectRequiredModuleImports()
Get and cache the imports for this module. The imports should just be the modules that set as "required" by this module


collectFilters

protected void collectFilters()
Get and cache the filters for this module (not currently implemented)


modulesSetChanged

protected void modulesSetChanged()
See Also:
modulesSetChanged()

dispose

public void dispose()
See Also:
ModuleFactory.stopModule(Module,boolean)

setProbeParentLoaderLast

public void setProbeParentLoaderLast(boolean value)
Allow the probe parent loader last variable to be set. Usually this is set to true to allow modules to override and create their own classes

Parameters:
value - boolean true/false whether or not to look at the parent classloader last

loadClass

protected java.lang.Class<?> loadClass(java.lang.String name,
                                       boolean resolve)
                                throws java.lang.ClassNotFoundException
Overrides:
loadClass in class java.lang.ClassLoader
Throws:
java.lang.ClassNotFoundException
See Also:
ClassLoader.loadClass(java.lang.String, boolean)

loadClass

protected java.lang.Class<?> loadClass(java.lang.String name,
                                       boolean resolve,
                                       ModuleClassLoader requestor,
                                       java.util.Set<java.lang.String> seenModules)
                                throws java.lang.ClassNotFoundException
Custom loadClass implementation to allow for loading from a given ModuleClassLoader and skip the modules that have been tried already

Parameters:
name - String path and name of the class to load
resolve - boolean whether or not to resolve this class before returning
requestor - ModuleClassLoader with which to try loading
seenModules - Set moduleIds that have been tried already
Returns:
Class that has been loaded or null if none
Throws:
java.lang.ClassNotFoundException - if no class found

checkClassVisibility

protected void checkClassVisibility(java.lang.Class<?> cls,
                                    ModuleClassLoader requestor)
                             throws java.lang.ClassNotFoundException
Checking the given class's visibility in this module

Parameters:
cls - Class to check
requestor - ModuleClassLoader to check against
Throws:
java.lang.ClassNotFoundException

findLibrary

protected java.lang.String findLibrary(java.lang.String name)
Overrides:
findLibrary in class java.lang.ClassLoader
See Also:
ClassLoader.findLibrary(java.lang.String)

cacheLibrary

protected java.io.File cacheLibrary(java.net.URL libUrl,
                                    java.lang.String libname)
Saves the given library in the openmrs cache. This prevents locking of jars/files by servlet container

Parameters:
libUrl - URL to the library/jar file
libname - name of the jar that will be the name of the cached file
Returns:
file that is now copied and cached

findResource

public java.net.URL findResource(java.lang.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

Overrides:
findResource in class java.net.URLClassLoader
See Also:
ClassLoader.findResource(java.lang.String)

findResources

public java.util.Enumeration<java.net.URL> findResources(java.lang.String name)
                                                  throws java.io.IOException
Overrides:
findResources in class java.net.URLClassLoader
Throws:
java.io.IOException
See Also:
ClassLoader.findResources(java.lang.String)

findResource

protected java.net.URL findResource(java.lang.String name,
                                    ModuleClassLoader requestor,
                                    java.util.Set<java.lang.String> seenModules)
Find a resource (image, file, etc) in the module structure

Parameters:
name - String path and name of the file
requestor - ModuleClassLoader in which to look
seenModules - Set modules that have been checked already
Returns:
URL to resource
See Also:
findResource(String)

findResources

protected void findResources(java.util.List<java.net.URL> result,
                             java.lang.String name,
                             ModuleClassLoader requestor,
                             java.util.Set<java.lang.String> seenModules)
                      throws java.io.IOException
Find all occurrences of a resource (image, file, etc) in the module structure

Parameters:
result - URL of the file found
name - String path and name of the file to find
requestor - ModuleClassLoader in which to start
seenModules - Set moduleIds that have been checked already
Throws:
java.io.IOException
See Also:
findResources(String), findResource(String, ModuleClassLoader, Set)

isResourceVisible

protected boolean isResourceVisible(java.lang.String name,
                                    java.net.URL url,
                                    ModuleClassLoader requestor)
Check if the given resource (image, file, etc) is visible by this classloader

Parameters:
name - String path and name to check
url - URL of the library file
requestor - ModuleClassLoader in which to look
Returns:
true/false whether this resource is visibile by this classloader

getAdditionalPackages

public java.util.Set<java.lang.String> getAdditionalPackages()
Package names that this module should try to load. All classes/packages within the omod and the lib folder are already checked, this method/variable are used for extreme circumstances where an omod needs to know about another after being loaded

Returns:
the additionalPackages

setAdditionalPackages

public void setAdditionalPackages(java.util.Set<java.lang.String> additionalPackages)
Parameters:
additionalPackages - the package names to set that this module contains that are outside the normal omod and omod/lib folders

addAdditionalPackage

public void addAdditionalPackage(java.lang.String additionalPackage)
Convenience method to add another package name to the list of packages provided by this module

Parameters:
additionalPackage - string package name
See Also:
#setProvidedPackages(Set)

addAllAdditionalPackages

public void addAllAdditionalPackages(java.util.Collection<java.lang.String> providedPackages)
Convenience method to add a bunch of package names to the list of packages provided by this module

Parameters:
providedPackages - list/set of strings that are package names
See Also:
#setProvidedPackages(Set)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

OpenMRS-1.7.x

Generated Apr 27 2012 10:06 PM. NOTE - these libraries are in active development and subject to change