org.ungoverned.moduleloader.search
Class ExhaustiveSearchPolicy

java.lang.Object
  extended byorg.ungoverned.moduleloader.search.ExhaustiveSearchPolicy
All Implemented Interfaces:
SearchPolicy

public class ExhaustiveSearchPolicy
extends java.lang.Object
implements SearchPolicy

This class implements a ModuleLoader search policy that exhaustively and linearly searches all modules when trying to load a particular class or resource. As a result of this algorithm, every class loader for every module is essentially identical, meaning that each will load a given class or resource from the same class loader. This search policy provides behavior similar to the standard CLASSPATH environment variable approach. The main difference is that modules can be added to the module manager at run time; thus, the class path is dynamically extended. This search policy is not fully dynamic, since it does not support the removal of modules at run time; if a module is removed from the module manager at run time, there is no attempt to clean up its loaded classes.

See Also:
SearchPolicy, Module, ModuleClassLoader, ModuleManager

Constructor Summary
ExhaustiveSearchPolicy()
           
 
Method Summary
 java.lang.Class findClass(Module module, java.lang.String name)
          This method finds the specified class for the specified module.
 java.net.URL findResource(Module module, java.lang.String name)
          This method finds the specified resource for the specified module.
 void setModuleManager(ModuleManager mgr)
          This method is part of the SearchPolicy interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExhaustiveSearchPolicy

public ExhaustiveSearchPolicy()
Method Detail

setModuleManager

public void setModuleManager(ModuleManager mgr)
                      throws java.lang.IllegalStateException
This method is part of the SearchPolicy interface. This method is called by the ModuleManager once to give the search policy instance a reference to its associated module manager. This method should be implemented such that it cannot be called twice; calling this method a second time should produce an illegal state exception.

Specified by:
setModuleManager in interface SearchPolicy
Parameters:
mgr - the module manager associated with this search policy.
Throws:
java.lang.IllegalStateException - if the method is called more than once.

findClass

public java.lang.Class findClass(Module module,
                                 java.lang.String name)
This method finds the specified class for the specified module. It finds the class by linearly asking each module in the module manager for the specific class. As soon as the class is found, it is returned.

Specified by:
findClass in interface SearchPolicy
Parameters:
module - the target module that is loading the class.
name - the name of the class being loaded.
Returns:
the class if found, null otherwise.

findResource

public java.net.URL findResource(Module module,
                                 java.lang.String name)
This method finds the specified resource for the specified module. It finds the resource by linearly asking each module in the module manager for specific resource. As soon as the resource is found, a URL to it is returned.

Specified by:
findResource in interface SearchPolicy
Parameters:
module - the target module that is loading the resource.
name - the name of the resource being loaded.
Returns:
a URL to the resource if found, null otherwise.