com.mucommander.extension
Class ExtensionManager

java.lang.Object
  extended by com.mucommander.extension.ExtensionManager

public class ExtensionManager
extends java.lang.Object

Manages muCommander's extensions.

Extensions must be stored in getExtensionsFolder() in order for this class to be aware of them. Moreover, the method addExtensionsToClasspath() must have been called before extensions can be used.

Extensions are loaded through a custom ClassLoader. The optimal situation is for that ClassLoader to be the system one, which can only be achieved through setting the java.system.class.loader system property to com.mucommander.file.AbstractFileClassLoader at boot time.
However, if for some reason such is not the case, we'll use a separate instance of that class. This will work in most cases, but might cause conflicts under rare circumstances. Extension writers are advised to load resources through the ClassLoader returned by getClassLoader(), as not doing so might result in using the bootstrap classloader which doesn't have access to resources found in getExtensionsFolder().

This class can also be used to load Swing look and feel from JAR files that aren't in the system's classpath. In order to achieve this, application writers must:

Unfortunately, this is not always sufficient. Some Look&Feels suffer from a peculiar behaviour in Swing that might cause resources to be loaded through the system class loader rather than the one specified at initialisation time. This happens with Look&Feels that extend system ones, such as Quaqua. The only way to get these to load properly is to make sure the system classloader is an instance of AbstractFileClassLoader.

Author:
Nicolas Rinaudo

Field Summary
static java.lang.String DEFAULT_EXTENSIONS_FOLDER_NAME
          Default name of the extensions folder.
 
Method Summary
static void addExtensionsToClasspath()
          Adds all known extensions to the current classpath.
static void addToClassPath(AbstractFile file)
          Adds the specified file to the extension's classpath.
static java.lang.ClassLoader getClassLoader()
          Returns the ClassLoader used to load all extensions.
static AbstractFile getExtensionsFile(java.lang.String filename)
          Returns an AbstractFile to the extension file with the specified filename and located in the extensions folder.
static AbstractFile getExtensionsFolder()
          Returns the folder in which all extensions are stored.
static boolean importLibrary(AbstractFile file, boolean force)
          Imports the specified file in muCommander's libraries.
static boolean isAvailable(AbstractFile file)
          Returns true if the specified file is either in the extension or system classpath.
static boolean isInClasspath(AbstractFile file)
          Returns true if the specified file is in the system classpath.
static boolean isInExtensionsPath(AbstractFile file)
          Returns true if the specified file is in the extension's classloader path.
static void setExtensionsFolder(AbstractFile folder)
          Sets the path to the folder in which all extensions are stored.
static void setExtensionsFolder(java.io.File folder)
          Sets the path to the folder in which all extensions are stored.
static void setExtensionsFolder(java.lang.String path)
          Sets the path to the folder in which all extensions are stored.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_EXTENSIONS_FOLDER_NAME

public static final java.lang.String DEFAULT_EXTENSIONS_FOLDER_NAME
Default name of the extensions folder.

See Also:
Constant Field Values
Method Detail

setExtensionsFolder

public static void setExtensionsFolder(java.io.File folder)
                                throws java.io.IOException
Sets the path to the folder in which all extensions are stored.

If the specified path is not browsable (i.e. a folder or any file that muCommander can treat as such), its parent will be used instead.

Parameters:
folder - path to the folder in which extensions are stored.
Throws:
java.io.IOException - if the specified folder or the specified file's parent couldn't be accessed.
See Also:
setExtensionsFolder(AbstractFile), setExtensionsFolder(String), getExtensionsFolder()

setExtensionsFolder

public static void setExtensionsFolder(AbstractFile folder)
                                throws java.io.IOException
Sets the path to the folder in which all extensions are stored.

If the specified path is not browsable (i.e. a folder or any file that muCommander can treat as such), its parent will be used instead.

Parameters:
folder - path to the folder in which extensions are stored.
Throws:
java.io.IOException - if the specified folder or the specified file's parent couldn't be accessed.
See Also:
setExtensionsFolder(File), setExtensionsFolder(String), getExtensionsFolder()

setExtensionsFolder

public static void setExtensionsFolder(java.lang.String path)
                                throws java.io.IOException
Sets the path to the folder in which all extensions are stored.

If the specified path is not browsable (i.e. a folder or any file that muCommander can treat as such), its parent will be used instead.

Parameters:
path - path to the folder in which extensions are stored.
Throws:
java.io.IOException - if the specified folder or the specified file's parent couldn't be accessed.
See Also:
setExtensionsFolder(File), setExtensionsFolder(String), getExtensionsFolder()

getExtensionsFolder

public static AbstractFile getExtensionsFolder()
                                        throws java.io.IOException
Returns the folder in which all extensions are stored.

Returns:
the folder in which all extensions are stored.
Throws:
java.io.IOException - if an error occured while locating the default extensions folder.
See Also:
setExtensionsFolder(AbstractFile)

getExtensionsFile

public static AbstractFile getExtensionsFile(java.lang.String filename)
                                      throws java.io.IOException
Returns an AbstractFile to the extension file with the specified filename and located in the extensions folder. The returned file may or may not exist.

Parameters:
filename - the extension's filename
Returns:
an AbstractFile to the extension file with the specified filename and located in the extensions folder.
Throws:
java.io.IOException - if the file could not be instanciated.

isInExtensionsPath

public static boolean isInExtensionsPath(AbstractFile file)
Returns true if the specified file is in the extension's classloader path.

Parameters:
file - file whose presence in the extensions path will be checked.
Returns:
true if the specified file is in the extension's classloader path, false otherwise.

isInClasspath

public static boolean isInClasspath(AbstractFile file)
Returns true if the specified file is in the system classpath.

Parameters:
file - file whose presence in the system classpath will be checked.
Returns:
true if the specified file is in the system classpath, false otherwise.

isAvailable

public static boolean isAvailable(AbstractFile file)
Returns true if the specified file is either in the extension or system classpath.

This is a convenience method and is equivalent to calling: isInClasspath(file) || isInExtensionsPath(file).

Parameters:
file - file whose availability will be checked.
Returns:
true if the specified file is either in the extension or system classpath, false otherwise.

importLibrary

public static boolean importLibrary(AbstractFile file,
                                    boolean force)
                             throws java.io.IOException
Imports the specified file in muCommander's libraries.

Parameters:
file - path to the library to import.
force - wether to overwrite eventual existing libraries of the same name.
Returns:
true if the operation was a success, false if a library of the same name already exists and force is set to false.
Throws:
java.io.IOException - if an I/O error occurs.

addToClassPath

public static void addToClassPath(AbstractFile file)
Adds the specified file to the extension's classpath.

Parameters:
file - file to add to the classpath.

addExtensionsToClasspath

public static void addExtensionsToClasspath()
                                     throws java.io.IOException
Adds all known extensions to the current classpath.

This method will create the following new classpath entries:

Throws:
java.io.IOException - if the extensions folder is not accessible.

getClassLoader

public static java.lang.ClassLoader getClassLoader()
Returns the ClassLoader used to load all extensions.

Returns:
the ClassLoader used to load all extensions.


This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard