Last update: 2011-06-23

org.proteios.core.plugin
Class AbstractPlugin

java.lang.Object
  extended by org.proteios.core.plugin.AbstractPlugin
All Implemented Interfaces:
Plugin

public abstract class AbstractPlugin
extends Object
implements Plugin

This is an abstract base class useful for developing plugins. It's main purpose is to help with validating and storing request parameters into the plugin or job configuration.

Version:
2.0
Author:
Enell, Nicklas
Last modified
$Date: 2009-04-09 08:48:11 +0200 (Thu, 09 Apr 2009) $

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.proteios.core.plugin.Plugin
Plugin.MainType
 
Field Summary
protected  ParameterValues configuration
           
protected  ParameterValues job
           
protected  SessionControl sc
           
 
Constructor Summary
protected AbstractPlugin()
          Create a new AbstractPlugin.
 
Method Summary
 void done()
          Clears the variables set by the init method.
 void init(SessionControl sc, ParameterValues configuration, ParameterValues job)
          Store copies of the session control, plugin and job configuration.
protected
<T> void
storeValue(ParameterValues values, Request request, PluginParameter<T> parameter)
          Copy a parameter value from a Request to a ParameterValues object.
protected
<T> void
storeValues(ParameterValues values, Request request, PluginParameter<T> parameter)
          Copy a list of parameter values from a Request to a ParameterValues object.
protected  List<Throwable> validateRequestParameters(List<PluginParameter<?>> parameters, Request request)
          Validate the parameter values in a request against a list of plugin parameter definitions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.proteios.core.plugin.Plugin
getAbout, getMainType, run
 

Field Detail

sc

protected SessionControl sc

configuration

protected ParameterValues configuration

job

protected ParameterValues job
Constructor Detail

AbstractPlugin

protected AbstractPlugin()
Create a new AbstractPlugin.

Method Detail

init

public void init(SessionControl sc,
                 ParameterValues configuration,
                 ParameterValues job)
          throws BaseException
Store copies of the session control, plugin and job configuration. These are available to subclasses in the sc, configuration and job variables. If a subclass overrides this method it is recommended that it also calls super.init(sc, configuration, job).

Specified by:
init in interface Plugin
Parameters:
sc - A SessionControl object that the plugin can use to communicate with the core.
configuration - The configuration parameters for the plugin
job - The job parameters for the plugin
Throws:
BaseException - if there is an error.

done

public void done()
Clears the variables set by the init method. If a subclass overrides this method it is recommended that it also calls super.done().

Specified by:
done in interface Plugin

validateRequestParameters

protected List<Throwable> validateRequestParameters(List<PluginParameter<?>> parameters,
                                                    Request request)
Validate the parameter values in a request against a list of plugin parameter definitions. The validation is done by calling the ParameterType.validate(String, List) for each parameter in the list of parameter definitions. If all parameters are valid this method returns null, otherwise a list of exceptions that ocurred during the validation. This list can be directly propagated to the Response.setError(String, List) method. For example:
// In Plugin.invoke() method:
List>PluginParameter<?>> parameters = getParametersForCommand(request.getCommand());
List<Throwable> errors = 
   validateRequestParameters(parameters, request);
if (errors != null)
{
   response.setError(errors.size()+
      " invalid parameter(s) were found in the request", errors);
   return;
}

Parameters:
parameters - A list containing the parameter definitions
request - The request
Returns:
A list of exceptions, or null if all parameters are valid

storeValue

protected <T> void storeValue(ParameterValues values,
                              Request request,
                              PluginParameter<T> parameter)
                   throws BaseException
Copy a parameter value from a Request to a ParameterValues object. This method makes it easy for a subclass to directly store a request parameter into either the plugin or job configuration. Use this method when the parameter valus is a single value.

Parameters:
values - The ParameterValues object where the value should be stored, use either configuration or job
request - The Request object
parameter - The ParameterType object for the parameter
Throws:
BaseException - If the parameter value is invalid

storeValues

protected <T> void storeValues(ParameterValues values,
                               Request request,
                               PluginParameter<T> parameter)
                    throws BaseException
Copy a list of parameter values from a Request to a ParameterValues object. This method makes it easy for a subclass to directly store a request parameter into either the plugin or job configuration. Use this method when the parameter value is a list of values.

Parameters:
values - The ParameterValues object where the value should be stored, use either configuration or job
request - The Request object
parameter - The ParameterType object for the parameter
Throws:
BaseException - If the parameter value is invalid

Last update: 2011-06-23