org.apache.hivemind.service.impl
Class AbstractServiceInterceptorFactory

java.lang.Object
  |
  +--org.apache.hivemind.service.impl.AbstractServiceInterceptorFactory
All Implemented Interfaces:
ServiceInterceptorFactory
Direct Known Subclasses:
LoggingInterceptorFactory

public abstract class AbstractServiceInterceptorFactory
extends java.lang.Object
implements ServiceInterceptorFactory

Base class for creating new service interceptors. Most implementations merely have to implement #addServiceMethodImplementation(ClassFab, String, Class, Class[], Class[]). This is only suitable for interceptors which do not use parameters.

Implementations of this service must be configured with:

Author:
Howard Lewis Ship

Constructor Summary
AbstractServiceInterceptorFactory()
           
 
Method Summary
protected  void addServiceMethodImplementation(ClassFab classFab, MethodSignature sig)
          Invoked by addServiceMethods(InterceptorStack, ClassFab, List) for each method in the service interface to allow the factory to construct the corresponding method in the interceptor.
protected  void addServiceMethods(InterceptorStack stack, ClassFab fab, java.util.List parameters)
          Invoked from {@link #createInterceptor(InterceptorStack, Module, List) to add the service methods to the interceptor class.
protected  void addToStringMethod(InterceptorStack stack, ClassFab fab)
          Creates a toString() method that identify the interceptor service id, the intercepted service id, and the service interface class name).
protected  void createInfrastructure(InterceptorStack stack, ClassFab classFab, java.util.List parameters)
          Invoked in subclasses to create any infrastructure.
 void createInterceptor(InterceptorStack stack, Module contributingModule, java.util.List parameters)
          Creates the interceptor.
protected  java.lang.Class getInterceptorSuperclass()
          Overridden in subclasses to identify the super-class for the interceptor.
protected  java.lang.Object instantiateInterceptor(InterceptorStack stack, java.lang.Class interceptorClass, java.util.List parameters)
          Used to instantiate the interceptor.
 void setFactory(ClassFactory factory)
           
 void setServiceId(java.lang.String string)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractServiceInterceptorFactory

public AbstractServiceInterceptorFactory()
Method Detail

createInterceptor

public void createInterceptor(InterceptorStack stack,
                              Module contributingModule,
                              java.util.List parameters)
Creates the interceptor. Expects that the parameters list is empty. The class that is created is cached; if an interceptor is requested for the same extension point, then the previously constructed class is reused (this can happen with the threaded service model, for example, when a thread-local service implementation is created for different threads).

Specified by:
createInterceptor in interface ServiceInterceptorFactory

getInterceptorSuperclass

protected java.lang.Class getInterceptorSuperclass()
Overridden in subclasses to identify the super-class for the interceptor. This implementation returns java.lang.Object.


createInfrastructure

protected void createInfrastructure(InterceptorStack stack,
                                    ClassFab classFab,
                                    java.util.List parameters)
Invoked in subclasses to create any infrastructure.

This implementation adds a field, _inner whose type is the actual type of the top object on the stack (which, of course, implements the service interface). A constructor is created to set the field.

Parameters:
stack - the interceptor stack (used to obtain the service interface and extension point id)
classFab - the interceptor class being constructed
parameters - parameters provided to the interceptor factory

instantiateInterceptor

protected java.lang.Object instantiateInterceptor(InterceptorStack stack,
                                                  java.lang.Class interceptorClass,
                                                  java.util.List parameters)
                                           throws java.lang.Exception
Used to instantiate the interceptor. This implementation passes the top object on the interceptor stack to the interceptorClass' constructor. Subclasses that defined a different constructor (in #createInfrastructure(InterceptorStack, ClassFab)) will need to override this method as well.

Parameters:
stack - the interceptor stack on which the returned interceptor will be placed.
interceptorClass - the generated class for the interceptor.
Throws:
java.lang.Exception - if there is an error getting or invoking the constructor
See Also:
#createInfrastructure(InterceptorStack, ClassFab)

addServiceMethodImplementation

protected void addServiceMethodImplementation(ClassFab classFab,
                                              MethodSignature sig)
Invoked by addServiceMethods(InterceptorStack, ClassFab, List) for each method in the service interface to allow the factory to construct the corresponding method in the interceptor. This implementation does nothing, and must be overridden. More sophisticated interceptors will override addServiceMethods() and may by implemented in such a way that this method is not invoked.

Parameters:
classFab - the fabricator for the interceptor class
sig - the method signature for the method

addServiceMethods

protected void addServiceMethods(InterceptorStack stack,
                                 ClassFab fab,
                                 java.util.List parameters)
Invoked from #createInterceptor(InterceptorStack, Module, List) to add the service methods to the interceptor class. This implementation ignores the parameters, and invokes {@link #addServiceMethodImplementation(ClassFab, String, Class, Class[], Class[])} for each method in the service interface. It also may invoke {@link #addToStringMethod(InterceptorStack, ClassFab)}.


addToStringMethod

protected void addToStringMethod(InterceptorStack stack,
                                 ClassFab fab)
Creates a toString() method that identify the interceptor service id, the intercepted service id, and the service interface class name).


setServiceId

public void setServiceId(java.lang.String string)

setFactory

public void setFactory(ClassFactory factory)