org.spicefactory.cinnamon.service.factory
Class AbstractMethodInvocationServiceFactory

java.lang.Object
  extended by org.spicefactory.cinnamon.service.factory.AbstractMethodInvocationServiceFactory
All Implemented Interfaces:
ServiceFactory
Direct Known Subclasses:
PlainJavaServiceFactory, SpringServiceFactory

public abstract class AbstractMethodInvocationServiceFactory
extends Object
implements ServiceFactory

Abstract ServiceFactory implementation as a base for all factories that create ServiceInvokers which use reflective method invocation. The only abstract template method is getTargetInstance. Subclasses must implement this method which locates the service instance that should be invoked for a particular request.

Author:
Jens Halm

Constructor Summary
AbstractMethodInvocationServiceFactory()
          Creates a new ServiceFactory instance.
 
Method Summary
 void addServiceConfig(ServiceConfig config)
          Add a configuration for a service that should be handled by this factory.
protected  Map<String,Object> getApplicationMap()
          Returns the Map containing all application attributes.
protected  CinnamonConfig getConfig()
          Return the CinnamonConfig instance associated with this factory.
protected  Map<String,String> getInitMap()
          Returns the Map containing all initialization parameters.
protected  List<MethodInvoker> getMethodCandidates(ServiceRequest request)
          Returns the candidate methods for the given request.
 ServiceInvoker getServiceInvoker(ServiceRequest request)
          Create a ServiceInvoker instance for a particular ServiceRequest.
protected abstract  Object getTargetInstance(ServiceRequest request)
          Returns the target instance that should be invoked for the given request.
 void init(Map<String,String> initMap, Map<String,Object> applicationMap, CinnamonConfig config)
          Initializes the ServiceFactory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractMethodInvocationServiceFactory

public AbstractMethodInvocationServiceFactory()
Creates a new ServiceFactory instance.

Method Detail

init

public void init(Map<String,String> initMap,
                 Map<String,Object> applicationMap,
                 CinnamonConfig config)
Description copied from interface: ServiceFactory
Initializes the ServiceFactory. Will only be called once by the framework at application startup.

Specified by:
init in interface ServiceFactory
Parameters:
initMap - the initialisation parameters (taken from ServletConfig in a web application)
applicationMap - the application attributes (taken from ServletContext in a web application)
config - the Cinnamon configuration

getInitMap

protected Map<String,String> getInitMap()
Returns the Map containing all initialization parameters. In a web application this Map will wrap the ServletConfig initialization parameters.

Returns:
a Map containing all initialization parameters.

getApplicationMap

protected Map<String,Object> getApplicationMap()
Returns the Map containing all application attributes. In a web application this Map will wrap the ServletContext attributes.

Returns:
a Map containing all application attributes.

getConfig

protected CinnamonConfig getConfig()
Return the CinnamonConfig instance associated with this factory.

Returns:
the CinnamonConfig instance associated with this factory

getServiceInvoker

public ServiceInvoker getServiceInvoker(ServiceRequest request)
Description copied from interface: ServiceFactory
Create a ServiceInvoker instance for a particular ServiceRequest. This usually involves analyzing the ServiceRequest instance to locate the service and operation to be invoked and wrap it in a ServiceInvoker instance. Implementations should take into account that the created ServiceInvoker may never be used, for example if a ServiceInterceptor prematurely completed the request.

Specified by:
getServiceInvoker in interface ServiceFactory
Parameters:
request - the request to be processed
Returns:
the ServiceInvoker to be used for the given request

getTargetInstance

protected abstract Object getTargetInstance(ServiceRequest request)
Returns the target instance that should be invoked for the given request. Usually the properties for the service name and operation name in the given request instance are considered when deciding how to locate the target service.

Parameters:
request - the service request
Returns:
the instance that should be invoked for the given request

getMethodCandidates

protected List<MethodInvoker> getMethodCandidates(ServiceRequest request)
Returns the candidate methods for the given request. This implementation matches operation names with method names. Consequently more than one candidate method will be returned for overloaded methods. This implementation leaves the decision which method to invoke to the ServiceInvoker.

Parameters:
request - the service request
Returns:
the list of method candidates for the given request

addServiceConfig

public void addServiceConfig(ServiceConfig config)
Description copied from interface: ServiceFactory
Add a configuration for a service that should be handled by this factory. This method will be invoked once at application startup for every service configuration associated with this factory and before any ServiceInvoker will be requested from this factory.

Specified by:
addServiceConfig in interface ServiceFactory
Parameters:
config - a configuration for a service that should be handled by this factory