org.argouml.moduleloader
Class ModuleLoader2

java.lang.Object
  extended byorg.argouml.moduleloader.ModuleLoader2

public class ModuleLoader2
extends Object

This is the module loader that loads modules implementing the ModuleInterface.

This is a singleton. There are convenience functions that are static to access the module.

Since:
0.15.4

Nested Class Summary
(package private)  class ModuleLoader2.JarFileFilter
           
 
Field Summary
static String CLASS_SUFFIX
          Class file suffix
private static ModuleLoader2 INSTANCE
          The module loader object.
private static Logger LOG
          Logger.
private  Map moduleStatus
          This map contains the module loader information about the module.
 
Constructor Summary
private ModuleLoader2()
          Constructor for this object.
 
Method Summary
private  void addClass(ClassLoader classLoader, String classname)
          Try to load a module from the given ClassLoader.
static void addClass(String classname)
          Add a class from the current class loader.
private  void addModule(ModuleInterface mf)
          Add a newly found module to moduleStatus.
static Collection allModules()
          Get a Collection with all the names.
private  Collection availableModules()
          Return a collection of all available modules.
private  void doInternal(boolean failingAllowed)
          Enables all selected modules.
static void doLoad(boolean failingAllowed)
          Enables all selected modules and disabling all modules not selected.
private  Map.Entry findModule(String name)
          Return the ModuleInterface, ModuleStatus pair for the module with the given name or null if there isn't any.
static String getDescription(String name)
          Create a description of the module based on the information provided by the module itself.
private  String getDescriptionInternal(String name)
           
static ModuleLoader2 getInstance()
          Get hold of the instance of this object.
private  void huntForModules()
          Tries to find as many available modules as possible.
private  void huntForModulesFromExtensionDir()
          Find and enable modules from our "ext" directory and from the directory specified in "argo.ext.dir".
private  void huntModulesFromNamedDirectory(String dirname)
          Find and enable a module from a given directory.
static boolean isEnabled(String name)
          Gets the loaded status for some other module.
private  boolean isEnabledInternal(String name)
          Gets the loaded status for some other module.
static boolean isSelected(String name)
          Get the selected.
private  boolean isSelectedInternal(String name)
           
static SortedMap notYetLoadedModules()
          Get a list of not yet loaded modules.
private  void processJarFile(ClassLoader classloader, File file)
          Check the manifest of a jar file for an extension.
static void setSelected(String name, boolean value)
          Set the selected value.
 void setSelectedInternal(String name, boolean value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

private static final Logger LOG
Logger.


moduleStatus

private Map moduleStatus
This map contains the module loader information about the module.

The keys is the list of available modules.

The keys are ModuleInterface. The values are ModuleStatus.


INSTANCE

private static final ModuleLoader2 INSTANCE
The module loader object.


CLASS_SUFFIX

public static final String CLASS_SUFFIX
Class file suffix

See Also:
Constant Field Values
Constructor Detail

ModuleLoader2

private ModuleLoader2()
Constructor for this object.

Method Detail

getInstance

public static ModuleLoader2 getInstance()
Get hold of the instance of this object.

Returns:
the instance

availableModules

private Collection availableModules()
Return a collection of all available modules.


doLoad

public static void doLoad(boolean failingAllowed)
Enables all selected modules and disabling all modules not selected.

In short this attempts to make the modules obey their selection.

Parameters:
failingAllowed - is true if enabling or disabling of some of the modules is allowed to fail.

isEnabled

public static boolean isEnabled(String name)
Gets the loaded status for some other module.

Parameters:
name - is the module name of the queried module
Returns:
true if the module exists and is enabled.

allModules

public static Collection allModules()
Get a Collection with all the names.

Returns:
all the names.

isSelected

public static boolean isSelected(String name)
Get the selected.

Parameters:
name - The name of the module.
Returns:
true if the module is selected.

isSelectedInternal

private boolean isSelectedInternal(String name)
See Also:
isSelected(String)

setSelected

public static void setSelected(String name,
                               boolean value)
Set the selected value.

Parameters:
name - The name of the module.
value - Selected or not.

setSelectedInternal

public void setSelectedInternal(String name,
                                boolean value)
See Also:
setSelected(String, boolean)

getDescription

public static String getDescription(String name)
Create a description of the module based on the information provided by the module itself.

Parameters:
name - The name of the module.
Returns:
The description.

getDescriptionInternal

private String getDescriptionInternal(String name)
See Also:
getDescription(String)

notYetLoadedModules

public static SortedMap notYetLoadedModules()
Get a list of not yet loaded modules.

TODO: For the moment these modules are hardcoded into this file. Eventually they will be available in some config file.

Returns:
a SortedMap from name (String) to classname String.

doInternal

private void doInternal(boolean failingAllowed)
Enables all selected modules.

Parameters:
failingAllowed - is true if this is not the last attempt at turning on.

isEnabledInternal

private boolean isEnabledInternal(String name)
Gets the loaded status for some other module.

Parameters:
name - is the module name of the queried module
Returns:
true if the module exists and is enabled.

findModule

private Map.Entry findModule(String name)
Return the ModuleInterface, ModuleStatus pair for the module with the given name or null if there isn't any.

Parameters:
name - The given name.
Returns:
A pair (Map.Entry).

huntForModules

private void huntForModules()
Tries to find as many available modules as possible.

As the modules are found they are appended to moduleStatus.


huntForModulesFromExtensionDir

private void huntForModulesFromExtensionDir()
Find and enable modules from our "ext" directory and from the directory specified in "argo.ext.dir".

TODO: This does a calculation of where our "ext" directory is. We should eventually make sure that this calculation is only present in one place in the code and not several.


huntModulesFromNamedDirectory

private void huntModulesFromNamedDirectory(String dirname)
Find and enable a module from a given directory.

Parameters:
dirname - The name of the directory.

processJarFile

private void processJarFile(ClassLoader classloader,
                            File file)
Check the manifest of a jar file for an extension.

If there isn't a manifest or it isn't readable, we fail silently.

Parameters:
classloader - The classloader to use.
file - The file to process.

addClass

public static void addClass(String classname)
Add a class from the current class loader.

Parameters:
classname - The name of the class (including package).

addClass

private void addClass(ClassLoader classLoader,
                      String classname)
Try to load a module from the given ClassLoader.

Only add it as a module if it is a module (i.e. it implements the ModuleInterface interface.

Parameters:
classLoader - The ClassLoader to load from.
classname - The name.

addModule

private void addModule(ModuleInterface mf)
Add a newly found module to moduleStatus. If we already know about it, don't add it.



ArgoUML © 1996-2004 (20050222)ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook