org.instrumentmiddleware.cima.plugin.impl
Class AbstractPlugin

java.lang.Object
  extended by org.instrumentmiddleware.cima.plugin.impl.AbstractPlugin
All Implemented Interfaces:
ICIMAPlugin, IPlugin
Direct Known Subclasses:
AbstractProducer, ExampleOperationPlugin

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

AbstractPlugin has methods to deal with the more mundane aspects of a plugin, such as the id and sequence number management and is intended to be subclassed by all plugins. It also provides default methods that may be overridden by subclasses to provide more functionality, such as start() stop() processParcel(BodyType, Calendar, ISession, ResponseType) This class is also the link between the internal logic for a plugin and the actual plugin implementation. Currently the link is the internalProcessParcel(BodyType, Calendar, org.instrumentmiddleware.cima.parcel.ParcelTypeEnum.Enum, ISession, ResponseType) method which routes an incoming parcel to an appropriate method on the plugin.

Author:
andrew

Field Summary
protected  boolean startOnLoad
           
protected  boolean stopped
           
protected  java.util.List<SubscribeInfo> subscriptions
           
 
Constructor Summary
AbstractPlugin(java.lang.String id)
          Instantiate the plugin The id is checked for non-null-ness and non-emptiness and an exception is thrown if either check fails
 
Method Summary
 void doSubscribe()
           
 org.instrumentmiddleware.cima.parcel.SubscriptionResponseType doSubscribe(SubscribeInfo info)
           
protected  IParcelBodyHandler getBodyHandler(org.instrumentmiddleware.cima.parcel.BodyType body)
           
 java.lang.String getId()
          Get the plugins id.
 org.w3c.dom.Node getInformation()
          Provide access to this plugins information.
 int getSequenceNumber()
          Get the next sequence number for parcels created by this plugin.
 org.instrumentmiddleware.cima.parcel.ResponseType internalProcessParcel(org.instrumentmiddleware.cima.parcel.BodyType body, java.util.Calendar creationTime, org.instrumentmiddleware.cima.parcel.ParcelTypeEnum.Enum type, ISession session, org.instrumentmiddleware.cima.parcel.ResponseType response)
          Process a parcel that was destined for this plugin.
 org.instrumentmiddleware.cima.parcel.ResponseType processParcel(org.instrumentmiddleware.cima.parcel.BodyType body, java.util.Calendar creationTime, ISession session, org.instrumentmiddleware.cima.parcel.ResponseType response)
          Process a parcel of type "plugin".
protected  void processSubscribeResponse(org.instrumentmiddleware.cima.parcel.ParcelDocument.Parcel response)
           
 void setStartOnLoad(boolean startOnLoad)
          This method is used to specify if this plugin will be started automatically after being loaded.
 void setSubscriptions(java.util.List<SubscribeInfo> subs)
           
 void start()
          Start this plugin.
 boolean startOnLoad()
          Returns true if this plugin has been configured to start automatically after being loaded
 void stop()
          Stop this plugin.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

startOnLoad

protected boolean startOnLoad

stopped

protected boolean stopped

subscriptions

protected java.util.List<SubscribeInfo> subscriptions
Constructor Detail

AbstractPlugin

public AbstractPlugin(java.lang.String id)
               throws java.lang.Exception
Instantiate the plugin The id is checked for non-null-ness and non-emptiness and an exception is thrown if either check fails

Parameters:
id - the plugin id
Throws:
java.lang.Exception - if the id is null or the empty string
Method Detail

getId

public final java.lang.String getId()
Description copied from interface: IPlugin
Get the plugins id. Each plugin has a unique identifier with a CIMA instance, and it is obtained via this method.

Specified by:
getId in interface IPlugin
Returns:
the id
See Also:
org.instrumentmiddleware.cima.plugin.Plugin#getId()

start

public void start()
           throws PluginException
Description copied from interface: IPlugin
Start this plugin. This allows a plugin to perform some initialisation and is called when CIMA expects some interaction with this plugin

Specified by:
start in interface IPlugin
Throws:
PluginException
See Also:
org.instrumentmiddleware.cima.plugin.Plugin#start()

stop

public void stop()
          throws PluginException
Description copied from interface: IPlugin
Stop this plugin. This allows a plugin to perform some cleanup and is called when CIMA expects no further interaction with this plugin

Specified by:
stop in interface IPlugin
Throws:
PluginException
See Also:
org.instrumentmiddleware.cima.plugin.Plugin#stop()

getSequenceNumber

public int getSequenceNumber()
Description copied from interface: IPlugin
Get the next sequence number for parcels created by this plugin. Each parcel created by this plugin should have a sequence number to distinguish it from other communications with this plugin. Each sequence number should be unique, so the standard implementation is an incrementing integer. TODO: this description is lame and probably indicates that this method doesn't belong here.

Specified by:
getSequenceNumber in interface IPlugin
Returns:
the next sequence number.
See Also:
org.instrumentmiddleware.cima.plugin.Plugin#getSequenceNumber()

processParcel

public org.instrumentmiddleware.cima.parcel.ResponseType processParcel(org.instrumentmiddleware.cima.parcel.BodyType body,
                                                                       java.util.Calendar creationTime,
                                                                       ISession session,
                                                                       org.instrumentmiddleware.cima.parcel.ResponseType response)
                                                                throws PluginException
Process a parcel of type "plugin". This method is called for parcels of type plugin and is the extension point at which a plugin implementer may interact with a received parcel.

Specified by:
processParcel in interface IPlugin
Parameters:
body - the request body
session - the session the parcel belongs to
response - the partly formed response
Returns:
a response
Throws:
PluginException - if there is a problem while processing the parcel

internalProcessParcel

public org.instrumentmiddleware.cima.parcel.ResponseType internalProcessParcel(org.instrumentmiddleware.cima.parcel.BodyType body,
                                                                               java.util.Calendar creationTime,
                                                                               org.instrumentmiddleware.cima.parcel.ParcelTypeEnum.Enum type,
                                                                               ISession session,
                                                                               org.instrumentmiddleware.cima.parcel.ResponseType response)
                                                                        throws PluginException
Process a parcel that was destined for this plugin. This method is a generic passthrough that uses the type of the given parcel to call a method named "processParcel" where type is replaced by the parcel type with the first letter capitalised. For example, a parcel of type "subscribe" would result in a call to "processSubscribeParcel". The only exception to this rule is the "plugin" parcel type, which is routed to the generic method "processParcel". All methods invoked from this method require the following arguments, a BodyType, a Calendar, an ISession and a ResponseType. All methods invoked from this method should return a ResponseType which should be the same instance as passed via the third argument UNLESS a type change has been performed on the response (see http://xmlbeans.apache.org/docs/2.2.0/reference/org/apache/xmlbeans/XmlObject.html#changeType(org.apache.xmlbeans.SchemaType) for more information) in which case a reference to the new type should be returned. NOTE: This method currently uses reflection to accomplish this, and if the method doesn't exist then there will be no method call. Some may think that reflection is inappropriate for this (and they're welcome to their view) so there's a couple of suggested alternatives below. An alternative implementation might declare appropriate methods in the ICIMAPlugin for each significant CIMA event (eg. subscription) then implement those methods here to pass off to the appropriate method in the plugin. Another alternative might be to use a map and let the plugins populate the map with the parcel types they're interested in and the methods they'd like invoked for each type.

Specified by:
internalProcessParcel in interface ICIMAPlugin
Parameters:
body - The request
type - The type of the request
response - The forming response
Returns:
The response
Throws:
PluginException - if there was a problem processing the parcel

getBodyHandler

protected IParcelBodyHandler getBodyHandler(org.instrumentmiddleware.cima.parcel.BodyType body)

startOnLoad

public boolean startOnLoad()
Description copied from interface: IPlugin
Returns true if this plugin has been configured to start automatically after being loaded

Specified by:
startOnLoad in interface IPlugin
Returns:
true if this plugin has been configured to start automatically after being loaded

setStartOnLoad

public void setStartOnLoad(boolean startOnLoad)
Description copied from interface: IPlugin
This method is used to specify if this plugin will be started automatically after being loaded.

Specified by:
setStartOnLoad in interface IPlugin
Parameters:
startOnLoad - If true, this plugin will start automatically after being loaded

setSubscriptions

public void setSubscriptions(java.util.List<SubscribeInfo> subs)

doSubscribe

public void doSubscribe()

doSubscribe

public org.instrumentmiddleware.cima.parcel.SubscriptionResponseType doSubscribe(SubscribeInfo info)
Specified by:
doSubscribe in interface IPlugin

processSubscribeResponse

protected void processSubscribeResponse(org.instrumentmiddleware.cima.parcel.ParcelDocument.Parcel response)

getInformation

public org.w3c.dom.Node getInformation()
Description copied from interface: IPlugin
Provide access to this plugins information. This is currently represented as a DOM node to allow any XML to be returned to describe the plugin. In practice plugins may choose some well known vocabulary to describe themselves, such as SensorML.

Specified by:
getInformation in interface IPlugin
Returns:
Some XML containing the information for this plugin


Copyright © 2008. All Rights Reserved.