magoffin.matt.ma2.support
Class AbstractPlugin

java.lang.Object
  extended by magoffin.matt.ma2.support.AbstractPlugin
All Implemented Interfaces:
Plugin
Direct Known Subclasses:
AbstractJdbcBrowseModePlugin

public abstract class AbstractPlugin
extends java.lang.Object
implements Plugin

Abstract base Plugin implementation that provides a standardized Spring initialization method.

The initialize(ApplicationContext) method works in the following way:

  1. Calls the getConfigName() method to determine the base config name to look for.
  2. Looks for a classpath resource named base config nameContext.xml. For example, if the base config name is MyPlugin then this looks for a file named MyPluginContext.xml.
  3. If the previous step does not find the resource, it looks for a classpath resource named META-INF/base config nameContext.xml. This is the fall-back default configuration, that should ship with the plugin code. The first resource path is a way for the user to customize their plugin configuration, while this resource path is the fallback default.
  4. Creates a new ClassPathXmlApplicationContext from the resource found in either step #1 or #2, above.
  5. Calls AbstractApplicationContext.setParent(ApplicationContext), passing in the ApplicationContext passed to this method.
  6. Calls AbstractApplicationContext.refresh() to initialize the context. This context should define a bean named the full class name of this plugin implementation. This bean should be a fully-configured instance of this plugin.
  7. Gets the class-plugin bean from the ClassPathXmlApplicationContext and uses BeanUtils.copyProperties(Object, Object) to copy the properties of that instance onto this instance.
  8. Calls the init(ApplicationContext) method, for the implementation to perform any custom initialization.

In this way, plugins can easily configure themselves by providing a Spring configuration of themselves.

Version:
$Revision: 51 $ $Date: 2007-11-08 18:52:26 +1300 (Thu, 08 Nov 2007) $
Author:
matt

Field Summary
protected  org.apache.log4j.Logger log
          A class-level logger.
 
Constructor Summary
AbstractPlugin()
           
 
Method Summary
protected  java.lang.String getConfigName()
          Get the base name for this plugin's Spring configuration.
protected  void init(org.springframework.context.ApplicationContext application)
          Initialization hook for subclasses.
 void initialize(org.springframework.context.ApplicationContext application)
          Initialize the plugin.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface magoffin.matt.ma2.plugin.Plugin
getMessageResourceNames, getPluginType
 

Field Detail

log

protected final org.apache.log4j.Logger log
A class-level logger.

Constructor Detail

AbstractPlugin

public AbstractPlugin()
Method Detail

initialize

public final void initialize(org.springframework.context.ApplicationContext application)
Description copied from interface: Plugin
Initialize the plugin.

Specified by:
initialize in interface Plugin
Parameters:
application - the Spring application context

getConfigName

protected java.lang.String getConfigName()
Get the base name for this plugin's Spring configuration.

This method must return the base name of the Spring configuration file. The base name will have Context.xml appended to it, and possibly a path prefix.

This default method returns the name of this class, without any packages.

Returns:
a Spring configuration resource base name

init

protected void init(org.springframework.context.ApplicationContext application)
Initialization hook for subclasses.

This method will be called at the end of the initialize(org.springframework.context.ApplicationContext) method.

Parameters:
application - the ApplicationContext