artofillusion
Class PluginRegistry

java.lang.Object
  extended by artofillusion.PluginRegistry

public class PluginRegistry
extends java.lang.Object


Nested Class Summary
static class PluginRegistry.PluginResource
          A PluginResource represents a resource that was loaded from a plugin.
 
Constructor Summary
PluginRegistry()
           
 
Method Summary
static void addCategory(java.lang.Class category)
          Define a new category of plugins.
static java.util.List<java.lang.Class> getCategories()
          Get all categories of plugins that have been defined.
static java.util.List<java.lang.String> getExportedMethodIds()
          Get a list of the identifiers of all exported methods which have been registered.
static java.util.List<java.lang.ClassLoader> getPluginClassLoaders()
          Get the ClassLoaders for all jar files in the Plugins directory.
static java.lang.Object getPluginObject(java.lang.String classname)
          Get the registered plugin object of a particular class.
static
<T> java.util.List<T>
getPlugins(java.lang.Class<T> category)
          Get all registered plugins in a particular category.
static PluginRegistry.PluginResource getResource(java.lang.String type, java.lang.String id)
          Get the PluginResource with a particular type and id, or null if there is no such resource.
static java.util.List<PluginRegistry.PluginResource> getResources(java.lang.String type)
          Get a list of all registered PluginResources of a particular type.
static java.util.List<java.lang.String> getResourceTypes()
          Get a list of all type identifiers for which there are PluginResources available.
static java.lang.Object invokeExportedMethod(java.lang.String id, java.lang.Object... args)
          Invoke an exported method of a plugin object.
static void registerExportedMethod(java.lang.Object plugin, java.lang.String method, java.lang.String id)
          Register a method which may be invoked on a plugin object.
static void registerPlugin(java.lang.Object plugin)
          Register a new plugin.
static void registerResource(java.lang.String type, java.lang.String id, java.lang.ClassLoader loader, java.lang.String name, java.util.Locale locale)
          Register a new resource.
static void scanPlugins()
          Scan all files in the Plugins directory, read in their indices, and record all plugins contained in them.
static void scanPlugins(java.util.List<java.lang.ClassLoader> loaders)
          Process a set of ClassLoaders corresponding to jar files, read in their indices, and record all plugins contained in them.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PluginRegistry

public PluginRegistry()
Method Detail

scanPlugins

public static void scanPlugins()
Scan all files in the Plugins directory, read in their indices, and record all plugins contained in them.


scanPlugins

public static void scanPlugins(java.util.List<java.lang.ClassLoader> loaders)
Process a set of ClassLoaders corresponding to jar files, read in their indices, and record all plugins contained in them.


getPluginClassLoaders

public static java.util.List<java.lang.ClassLoader> getPluginClassLoaders()
Get the ClassLoaders for all jar files in the Plugins directory. There is one ClassLoader for every jar.


addCategory

public static void addCategory(java.lang.Class category)
Define a new category of plugins. A category is specified by a class or interface. After adding a category, any call to registerPlugin(Object) will check the registered object to see if it is an instance of the specified class. If so, it is added to the list of plugins in that category.


getCategories

public static java.util.List<java.lang.Class> getCategories()
Get all categories of plugins that have been defined.


registerPlugin

public static void registerPlugin(java.lang.Object plugin)
Register a new plugin. The specified object is checked against every defined category of plugins by seeing if it is an instance of the class or interface defining each category. If so, it is added to the list of plugins in that category.


getPlugins

public static <T> java.util.List<T> getPlugins(java.lang.Class<T> category)
Get all registered plugins in a particular category.


getPluginObject

public static java.lang.Object getPluginObject(java.lang.String classname)
Get the registered plugin object of a particular class. Unlike getPlugins(Class), the specified class name must be the exact class of the object, not a superclass or interface. If multiple plugins of the same class have been registered, this returns the most recently registered one.

Parameters:
classname - the fully qualified name of the class of the plugin object to return
Returns:
the plugin object of the specified class, or null if no matching plugin has been registered

registerResource

public static void registerResource(java.lang.String type,
                                    java.lang.String id,
                                    java.lang.ClassLoader loader,
                                    java.lang.String name,
                                    java.util.Locale locale)
                             throws java.lang.IllegalArgumentException
Register a new resource. You can then call getResource(String, String) to look up a particular resource, or getResources(String) to find all registered resources of a particular type.

Parameters:
type - the type of resource being registered
id - the id of this resource
loader - the ClassLoader with which to load the resource
name - the fully qualified name of the resource, that should be passed to loader.getResource() to load it
locale - the locale this resource represents (may be null)
Throws:
java.lang.IllegalArgumentException - if there is already a registered resource with the same type, id, and locale

getResourceTypes

public static java.util.List<java.lang.String> getResourceTypes()
Get a list of all type identifiers for which there are PluginResources available.


getResources

public static java.util.List<PluginRegistry.PluginResource> getResources(java.lang.String type)
Get a list of all registered PluginResources of a particular type.


getResource

public static PluginRegistry.PluginResource getResource(java.lang.String type,
                                                        java.lang.String id)
Get the PluginResource with a particular type and id, or null if there is no such resource.


registerExportedMethod

public static void registerExportedMethod(java.lang.Object plugin,
                                          java.lang.String method,
                                          java.lang.String id)
                                   throws java.lang.IllegalArgumentException
Register a method which may be invoked on a plugin object. This allows external code to easily use features of a plugin without needing to directly import that plugin or use reflection. Use getExportedMethodIds() to get a list of all exported methods that have been registered, and invokeExportedMethod(String, Object[]) to invoke one.

Parameters:
plugin - the plugin object on which the method should be invoked
method - the name of the method to invoke
id - a unique identifier which may be passed to invokeExportedMethod() to identify this method
Throws:
java.lang.IllegalArgumentException

getExportedMethodIds

public static java.util.List<java.lang.String> getExportedMethodIds()
Get a list of the identifiers of all exported methods which have been registered.


invokeExportedMethod

public static java.lang.Object invokeExportedMethod(java.lang.String id,
                                                    java.lang.Object... args)
                                             throws java.lang.NoSuchMethodException,
                                                    java.lang.reflect.InvocationTargetException
Invoke an exported method of a plugin object.

Parameters:
id - the unique identifier of the method to invoke
args - the list of arguments to pass to the method. If the method has no arguments, this may be null.
Returns:
the value returned by the method after it was invoked
Throws:
java.lang.NoSuchMethodException - if there is no exported method with the specified ID, or if there is no form of the exported method whose arguments are compatible with the specified args array.
java.lang.reflect.InvocationTargetException - if the method threw an exception when it was invoked.


Copyright © 1999-2011 by Peter Eastman.