org.apache.any23.plugin
Class Any23PluginManager

java.lang.Object
  extended by org.apache.any23.plugin.Any23PluginManager

public class Any23PluginManager
extends Object

The Any23PluginManager is responsible for inspecting dynamically the classpath and retrieving useful classes.

Author:
Michele Mostarda (mostarda@fbk.eu)

Field Summary
static String CLI_PACKAGE
          Any23 Command Line Interface package.
static String PLUGIN_DIRS_LIST_SEPARATOR
          List separator for the string declaring the plugin list.
static String PLUGIN_DIRS_PROPERTY
          Property where look for plugins.
static String PLUGINS_PACKAGE
          Any23 Plugins package.
 
Method Summary
 ExtractorGroup configureExtractors(ExtractorGroup initialExtractorGroup)
          Configures a new list of extractors containing the extractors declared in initialExtractorGroup and also the extractors detected in classpath specified by the default configuration.
 ExtractorGroup configureExtractors(ExtractorGroup initialExtractorGroup, File... pluginLocations)
          Configures a new list of extractors containing the extractors declared in initialExtractorGroup and also the extractors detected in classpath specified by pluginLocations.
 ExtractorGroup getApplicableExtractors(File... pluginLocations)
          Returns an extractor group containing both the default extractors declared by the ExtractorRegistry and the ExtractorPlugins.
<T> Set<Class<T>>
getClassesInPackage(String packageName, ClassFilter filter)
          Returns all classes within the specified packageName satisfying the given class filter.
static Any23PluginManager getInstance()
           
 Class<ExtractorPlugin>[] getPlugins()
          List of ExtractorPlugin classes declared within the classpath.
 Class<Tool>[] getTools()
          Returns the list of all the Tool classes declared within the classpath.
 boolean loadClassDir(File classDir)
          Loads a classes directory in the classpath.
 Throwable[] loadClassDirs(File... classDirs)
          Loads a list of class dirs in the classpath.
protected
<T> void
loadClassesInPackageFromClasspath(String packageName, ClassFilter filter, Set<Class<T>> result)
          Filters classes by criteria within the initialization classpath.
protected
<T> void
loadClassesInPackageFromDir(File classDir, String packageName, ClassFilter filter, Set<Class<T>> result)
          Filters classes by criteria within a class dir.
protected
<T> void
loadClassesInPackageFromJAR(File jarFile, String packageName, ClassFilter filter, Set<Class<T>> result)
          Filters classes by criteria within a JAR.
 Throwable[] loadFiles(File... files)
          Loads a generic list of files, trying to determine the type of every file.
 boolean loadJAR(File jar)
          Loads a JAR file in the classpath.
 boolean loadJARDir(File jarDir)
          Loads all the JARs detected in a given directory.
 Throwable[] loadJARs(File... jars)
          Loads a list of JARs in the classpath.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLI_PACKAGE

public static final String CLI_PACKAGE
Any23 Command Line Interface package.


PLUGINS_PACKAGE

public static final String PLUGINS_PACKAGE
Any23 Plugins package.


PLUGIN_DIRS_PROPERTY

public static final String PLUGIN_DIRS_PROPERTY
Property where look for plugins.

See Also:
Constant Field Values

PLUGIN_DIRS_LIST_SEPARATOR

public static final String PLUGIN_DIRS_LIST_SEPARATOR
List separator for the string declaring the plugin list.

See Also:
Constant Field Values
Method Detail

getInstance

public static Any23PluginManager getInstance()
Returns:
a singleton instance of Any23PluginManager.

loadJAR

public boolean loadJAR(File jar)
Loads a JAR file in the classpath.

Parameters:
jar - the JAR file to be loaded.
Returns:
true if the JAR is added for the first time to the classpath, false otherwise.
Throws:
MalformedURLException

loadJARs

public Throwable[] loadJARs(File... jars)
Loads a list of JARs in the classpath.

Parameters:
jars - list of JARs to be loaded.
Returns:
list of exceptions raised during the loading.

loadClassDir

public boolean loadClassDir(File classDir)
Loads a classes directory in the classpath.

Parameters:
classDir - the directory to be loaded.
Returns:
true if the directory is added for the first time to the classpath, false otherwise.

loadClassDirs

public Throwable[] loadClassDirs(File... classDirs)
Loads a list of class dirs in the classpath.

Parameters:
classDirs - list of class dirs to be loaded.
Returns:
list of exceptions raised during the loading.

loadJARDir

public boolean loadJARDir(File jarDir)
Loads all the JARs detected in a given directory.

Parameters:
jarDir - directory containing the JARs to be loaded.
Returns:
true if all JARs in dir are loaded.

loadFiles

public Throwable[] loadFiles(File... files)
Loads a generic list of files, trying to determine the type of every file.

Parameters:
files - list of files to be loaded.
Returns:
list of errors occurred during loading.

getClassesInPackage

public <T> Set<Class<T>> getClassesInPackage(String packageName,
                                             ClassFilter filter)
                                  throws IOException
Returns all classes within the specified packageName satisfying the given class filter. The search is performed on the static classpath (the one the application started with) and the dynamic classpath (the one specified using the load methods).

Type Parameters:
T - type of filtered class.
Parameters:
packageName - package name to look at classes, if null all packages will be found.
filter - class filter to select classes, if null all classes will be returned.
Returns:
list of matching classes.
Throws:
IOException

getTools

public Class<Tool>[] getTools()
                       throws IOException
Returns the list of all the Tool classes declared within the classpath.

Returns:
not null list of tool classes.
Throws:
IOException

getPlugins

public Class<ExtractorPlugin>[] getPlugins()
                                    throws IOException
List of ExtractorPlugin classes declared within the classpath.

Returns:
not null list of plugin classes.
Throws:
IOException

configureExtractors

public ExtractorGroup configureExtractors(ExtractorGroup initialExtractorGroup,
                                          File... pluginLocations)
                                   throws IOException,
                                          IllegalAccessException,
                                          InstantiationException
Configures a new list of extractors containing the extractors declared in initialExtractorGroup and also the extractors detected in classpath specified by pluginLocations.

Parameters:
initialExtractorGroup - initial list of extractors.
pluginLocations -
Returns:
full list of extractors.
Throws:
IOException
IllegalAccessException
InstantiationException

configureExtractors

public ExtractorGroup configureExtractors(ExtractorGroup initialExtractorGroup)
                                   throws IOException,
                                          InstantiationException,
                                          IllegalAccessException
Configures a new list of extractors containing the extractors declared in initialExtractorGroup and also the extractors detected in classpath specified by the default configuration.

Parameters:
initialExtractorGroup - initial list of extractors.
Returns:
full list of extractors.
Throws:
IOException
InstantiationException
IllegalAccessException

getApplicableExtractors

public ExtractorGroup getApplicableExtractors(File... pluginLocations)
                                       throws IOException,
                                              IllegalAccessException,
                                              InstantiationException
Returns an extractor group containing both the default extractors declared by the ExtractorRegistry and the ExtractorPlugins.

Parameters:
pluginLocations - optional list of plugin locations.
Returns:
a not null and not empty extractor group.
Throws:
IOException
IllegalAccessException
InstantiationException

loadClassesInPackageFromJAR

protected <T> void loadClassesInPackageFromJAR(File jarFile,
                                               String packageName,
                                               ClassFilter filter,
                                               Set<Class<T>> result)
                                    throws IOException
Filters classes by criteria within a JAR.

Parameters:
jarFile - file addressing the JAR.
packageName - name of package to scan.
filter - filter class, all returned classes must extend the specified one.
result - list for writing result.
Throws:
IOException

loadClassesInPackageFromDir

protected <T> void loadClassesInPackageFromDir(File classDir,
                                               String packageName,
                                               ClassFilter filter,
                                               Set<Class<T>> result)
                                    throws MalformedURLException
Filters classes by criteria within a class dir.

Type Parameters:
T - class types.
Parameters:
classDir - class directory.
packageName - name of package to scan.
filter - filter class, all returned classes must extend the specified one.
result - list for writing result.
Throws:
MalformedURLException

loadClassesInPackageFromClasspath

protected <T> void loadClassesInPackageFromClasspath(String packageName,
                                                     ClassFilter filter,
                                                     Set<Class<T>> result)
                                          throws IOException
Filters classes by criteria within the initialization classpath.

Type Parameters:
T -
Parameters:
packageName - name of package to scan.
filter - filter class, all returned classes must extend the specified one.
result - list for writing result.
Throws:
IOException


Copyright © 2010-2012 The Apache Software Foundation. All Rights Reserved.