org.abstracthorizon.extend.server.deployment.support
Class ModuleClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by org.abstracthorizon.extend.server.deployment.support.ModuleClassLoader
All Implemented Interfaces:
LocalClassLoader

public class ModuleClassLoader
extends ClassLoader
implements LocalClassLoader

Class loader for Module. It searches for class in current class loader and then in class loaders of all modules Module depends on.

Author:
Daniel Sendula

Nested Class Summary
protected  class ModuleClassLoader.Enumerations<T>
          Class that implements enumeration interface and enumerates through all enumeration passed to it
 
Field Summary
protected  Module context
          Context this class loader depends on
protected  ClassLoader serverClassLoader
          Top level - server's class loader
protected  boolean useThreadContextLoader
          Should module class loader use thread's context class loader in searching for the resource
 
Constructor Summary
ModuleClassLoader(ClassLoader parent, Module context)
          Constructor
 
Method Summary
protected  Set<Module> collectAllModules()
           
protected  void collectAllModules(Module module, Set<Module> modules)
           
 Class<?> findClass(String name)
          Searches for the class in dependent modules and server's class loader at the end.
 URL findResource(String name)
          Searches for resource in dependent modules and server's class loader at the end.
 Enumeration<URL> findResources(String name)
          Searches for resources in dependent modules and server's class loader at the end.
 URL getLocalResource(String name)
           
 Enumeration<URL> getLocalResources(String name)
           
 Module getModule()
          Returns module this class loader belongs to
 ClassLoader getServerClassLoader()
          Returns server's class loader
 boolean getUseThreadClassLoader()
          Returns should this class loader use context class loader or not
 Class<?> loadLocalClass(String name)
           
 void setServerClassLoader(ClassLoader serverClassLoader)
          Sets server's class loader
 void setUserThreadClassLoader(boolean useThreadContextLoader)
          Sets should this class loader use context class loader or not
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

protected Module context
Context this class loader depends on


serverClassLoader

protected ClassLoader serverClassLoader
Top level - server's class loader


useThreadContextLoader

protected boolean useThreadContextLoader
Should module class loader use thread's context class loader in searching for the resource

Constructor Detail

ModuleClassLoader

public ModuleClassLoader(ClassLoader parent,
                         Module context)
Constructor

Parameters:
parent - parent class loader
context - module this class loader belongs to.
Method Detail

getUseThreadClassLoader

public boolean getUseThreadClassLoader()
Returns should this class loader use context class loader or not

Returns:
true if this class loader should use context class loader or not

setUserThreadClassLoader

public void setUserThreadClassLoader(boolean useThreadContextLoader)
Sets should this class loader use context class loader or not

Parameters:
useThreadContextLoader - flag

findClass

public Class<?> findClass(String name)
                   throws ClassNotFoundException
Searches for the class in dependent modules and server's class loader at the end.

Overrides:
findClass in class ClassLoader
Parameters:
name - class name
Throws:
ClassNotFoundException

findResource

public URL findResource(String name)
Searches for resource in dependent modules and server's class loader at the end.

Overrides:
findResource in class ClassLoader
Parameters:
name - resource name

findResources

public Enumeration<URL> findResources(String name)
                               throws IOException
Searches for resources in dependent modules and server's class loader at the end.

Overrides:
findResources in class ClassLoader
Parameters:
name - resource name
Returns:
enumeration containing all URLs for given resource name
Throws:
IOException

collectAllModules

protected Set<Module> collectAllModules()

collectAllModules

protected void collectAllModules(Module module,
                                 Set<Module> modules)

getModule

public Module getModule()
Returns module this class loader belongs to

Returns:
module this class loader belongs to

getServerClassLoader

public ClassLoader getServerClassLoader()
Returns server's class loader

Returns:
server's class loader

setServerClassLoader

public void setServerClassLoader(ClassLoader serverClassLoader)
Sets server's class loader

Parameters:
serverClassLoader - server's class loader

getLocalResource

public URL getLocalResource(String name)
Specified by:
getLocalResource in interface LocalClassLoader

getLocalResources

public Enumeration<URL> getLocalResources(String name)
                                   throws IOException
Specified by:
getLocalResources in interface LocalClassLoader
Throws:
IOException

loadLocalClass

public Class<?> loadLocalClass(String name)
                        throws ClassNotFoundException
Specified by:
loadLocalClass in interface LocalClassLoader
Throws:
ClassNotFoundException


Copyright © 2005-2009 Abstract Horizon. All Rights Reserved.