org.argouml.application.modules
Class ModuleLoader

java.lang.Object
  |
  +--org.argouml.application.modules.ModuleLoader

public class ModuleLoader
extends java.lang.Object

Handles loading of modules and plugins for ArgoUML.

Since:
0.9.4

Nested Class Summary
(package private)  class ModuleLoader.JarFileFilter
           
 
Field Summary
private  java.util.Vector _menuActionList
           
private  java.util.ArrayList _moduleClasses
           
private static java.util.Hashtable _singletons
           
private static java.lang.String argoHome
           
private static java.lang.String argoRoot
           
private static Logger cat
          logger
static java.lang.String CLASS_SUFFIX
          Class file suffix
private static ModuleLoader SINGLETON
           
 
Constructor Summary
private ModuleLoader()
          Make sure the module loader cannot be instantiated from outside.
 
Method Summary
 boolean activateModule(ArgoModule module)
          Activate a loaded module.
 void addModuleAction(java.util.Vector popUpActions, java.lang.Object context)
          Process all of the modules to add popup actions for the given context.
private  boolean classImplements(java.lang.Object implementor, java.lang.Class implemented)
           
private  void fireEvent(int eventType, ArgoModule module)
           
 java.lang.String getArgoHome()
          Returns argo home
 java.lang.String getArgoRoot()
          Returns argo root
static ArgoModule getCurrentSingleton(java.lang.Class moduleClass)
          Gets the current singleton of the module type requested.
static ModuleLoader getInstance()
          Get the singleton instance
 java.lang.Object getModule(java.lang.String key)
          Locates a module by key.
 java.util.ArrayList getModules()
          Get the list of modules
 Pluggable getPlugin(java.lang.Class pluginType, java.lang.Object[] context)
          Returns a plug-in of a given type.
 java.util.ArrayList getPlugins(java.lang.Class pluginType, java.lang.Object[] context)
          Returns all plug-in of a given type.
 boolean hasPlugin(java.lang.Class pluginType, java.lang.Object[] context)
          Indicates whether a requested plug-in is available.
 void initialize()
          Load the internal modules.
private  boolean keyAlreadyLoaded(java.lang.String key)
           
private  void loadClassFromLoader(java.lang.ClassLoader classloader, java.lang.String key, java.lang.String classname, boolean secure)
           
 boolean loadInternalModules(java.lang.Class loaderClass, java.lang.String rsrcName)
          Load modules listed in Argo resources.
 boolean loadModules(java.io.InputStream is, java.lang.String filename)
          Load modules from an input stream.
 void loadModulesFromClassPathJars()
          Load modules from jars in the class path
 void loadModulesFromExtensionDir()
          Search for and load modules from classpath, and from other places.
 boolean loadModulesFromFile(java.lang.String moduleFile)
          Load modules from a property file.
 void loadModulesFromJar(java.lang.String filename)
          Load modules from a jar file
private  void loadModulesFromNamedDirectory(java.lang.String dirname)
           
 void loadModulesFromPredefinedLists()
          Search for and load modules from predefined places.
private  void processJarFile(java.lang.ClassLoader classloader, java.io.File file)
          Check the manifest of a jar file for an argo extension.
static boolean requestNewSingleton(java.lang.Class modClass, ArgoSingletonModule moduleInstance)
          Requests the passed singleton to become the current singleton of the module type requested.
 void shutdown()
          Shut down all modules
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cat

private static Logger cat
logger


CLASS_SUFFIX

public static final java.lang.String CLASS_SUFFIX
Class file suffix

See Also:
Constant Field Values

SINGLETON

private static ModuleLoader SINGLETON

_moduleClasses

private java.util.ArrayList _moduleClasses

_menuActionList

private java.util.Vector _menuActionList

_singletons

private static java.util.Hashtable _singletons

argoRoot

private static java.lang.String argoRoot

argoHome

private static java.lang.String argoHome
Constructor Detail

ModuleLoader

private ModuleLoader()
Make sure the module loader cannot be instantiated from outside.

Method Detail

getInstance

public static ModuleLoader getInstance()
Get the singleton instance

Returns:
the module loader singleton

initialize

public void initialize()
Load the internal modules.


loadModulesFromPredefinedLists

public void loadModulesFromPredefinedLists()
Search for and load modules from predefined places. Look in the following locations in the following order, using System.getProperty() to retrieve the values. Property name ${user.dir} ${user.home} ${java.home}/lib


processJarFile

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


loadModulesFromExtensionDir

public void loadModulesFromExtensionDir()
Search for and load modules from classpath, and from other places.


loadModulesFromNamedDirectory

private void loadModulesFromNamedDirectory(java.lang.String dirname)

loadModulesFromJar

public void loadModulesFromJar(java.lang.String filename)
Load modules from a jar file

Parameters:
filename - jar file name to load from

loadModulesFromClassPathJars

public void loadModulesFromClassPathJars()
Load modules from jars in the class path


loadInternalModules

public boolean loadInternalModules(java.lang.Class loaderClass,
                                   java.lang.String rsrcName)
Load modules listed in Argo resources.

Parameters:
loaderClass - class to retrieve classloader from
rsrcName - resource name to load
Returns:
false if the resource is not found

loadModulesFromFile

public boolean loadModulesFromFile(java.lang.String moduleFile)
Load modules from a property file. The load may be successful even if no modules are loaded.

Parameters:
moduleFile - name of file
Returns:
false if the load succeeded

keyAlreadyLoaded

private boolean keyAlreadyLoaded(java.lang.String key)

loadClassFromLoader

private void loadClassFromLoader(java.lang.ClassLoader classloader,
                                 java.lang.String key,
                                 java.lang.String classname,
                                 boolean secure)

loadModules

public boolean loadModules(java.io.InputStream is,
                           java.lang.String filename)
Load modules from an input stream. The load may be successful even if no modules are loaded.

Parameters:
is - input stream in property file format
filename - the input stream is from (for reporting purposes)
Returns:
false if the load succeeded

shutdown

public void shutdown()
Shut down all modules


addModuleAction

public void addModuleAction(java.util.Vector popUpActions,
                            java.lang.Object context)
Process all of the modules to add popup actions for the given context.

Parameters:
popUpActions - vector of actions
context - to filter by

getModules

public java.util.ArrayList getModules()
Get the list of modules

Returns:
the list of modules.

getModule

public java.lang.Object getModule(java.lang.String key)
Locates a module by key.

Parameters:
key - module identifier to find
Returns:
a module object or null if not found.

activateModule

public boolean activateModule(ArgoModule module)
Activate a loaded module.

Parameters:
module - to activate
Returns:
true if the module was activated, false if not or if it was already active.

getCurrentSingleton

public static ArgoModule getCurrentSingleton(java.lang.Class moduleClass)
Gets the current singleton of the module type requested.

Parameters:
moduleClass - the class of the module singleton
Returns:
null if there is some problem.

requestNewSingleton

public static boolean requestNewSingleton(java.lang.Class modClass,
                                          ArgoSingletonModule moduleInstance)
Requests the passed singleton to become the current singleton of the module type requested. Singletons may refuse to be activated. In this case, requestNewSingleton returns false and does not deactivate the current singleton.

Parameters:
modClass - class which identifies the singleton
moduleInstance - the module to make the singleton
Returns:
true if the singleton is activated

getPlugin

public Pluggable getPlugin(java.lang.Class pluginType,
                           java.lang.Object[] context)
Returns a plug-in of a given type. The type of plug-in returned is determined by the class passed.

Parameters:
pluginType - a Class which extends Pluggable and indicates the type of plug-in to return.
context - Additional information used to choose between plugins.
Returns:
A plug-in class which extends the type of class passed as the argument or null if there is some problem.

hasPlugin

public boolean hasPlugin(java.lang.Class pluginType,
                         java.lang.Object[] context)
Indicates whether a requested plug-in is available. This guarantees not to instantiate the plug-in.

Parameters:
pluginType - a Class which extends Pluggable and indicates the type of plug-in to return.
context - Additional information used to choose between plugins.
Returns:
A plug-in class which extends the type of class passed as the argument.

getPlugins

public java.util.ArrayList getPlugins(java.lang.Class pluginType,
                                      java.lang.Object[] context)
Returns all plug-in of a given type. The type of plug-in returned is determined by the class passed.

Parameters:
pluginType - a Class which extends Pluggable and indicates the type of plug-in to return.
context - An object (or null) which allows the plugin to determine if it should be included in a list.
Returns:
A Vector containing all the plugins of the type passed for the passed context, or null if none are available.

getArgoHome

public java.lang.String getArgoHome()
Returns argo home

Returns:
the argo home directory

getArgoRoot

public java.lang.String getArgoRoot()
Returns argo root

Returns:
the argo root directory

classImplements

private boolean classImplements(java.lang.Object implementor,
                                java.lang.Class implemented)

fireEvent

private void fireEvent(int eventType,
                       ArgoModule module)


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