org.apache.hivemind.service.impl
Class LoggingInterceptorFactory

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

public class LoggingInterceptorFactory
extends AbstractServiceInterceptorFactory

An interceptor factory that adds logging capability to a service. The logging is based upon the Jakarta commons-logging toolkit, which makes it very transportable.

The interceptor will log entry to each method and exit from the method (with return value), plus log any exceptions thrown by the method. The logger used is the id of the service, which is not necessarily the name of the implementing class. Logging occurs at the debug level.

Author:
Howard Lewis Ship

Constructor Summary
LoggingInterceptorFactory()
           
 
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 createInfrastructure(InterceptorStack stack, ClassFab classFab, java.util.List parameters)
          Invoked in subclasses to create any infrastructure.
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.
 
Methods inherited from class org.apache.hivemind.service.impl.AbstractServiceInterceptorFactory
addToStringMethod, createInterceptor, setFactory, setServiceId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LoggingInterceptorFactory

public LoggingInterceptorFactory()
Method Detail

createInfrastructure

protected void createInfrastructure(InterceptorStack stack,
                                    ClassFab classFab,
                                    java.util.List parameters)
Description copied from class: AbstractServiceInterceptorFactory
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.

Overrides:
createInfrastructure in class AbstractServiceInterceptorFactory
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
Description copied from class: AbstractServiceInterceptorFactory
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.

Overrides:
instantiateInterceptor in class AbstractServiceInterceptorFactory
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)
Description copied from class: AbstractServiceInterceptorFactory
Invoked by AbstractServiceInterceptorFactory.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.

Overrides:
addServiceMethodImplementation in class AbstractServiceInterceptorFactory
Parameters:
classFab - the fabricator for the interceptor class
sig - the method signature for the method

getInterceptorSuperclass

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

Overrides:
getInterceptorSuperclass in class AbstractServiceInterceptorFactory

addServiceMethods

protected void addServiceMethods(InterceptorStack stack,
                                 ClassFab fab,
                                 java.util.List parameters)
Description copied from class: AbstractServiceInterceptorFactory
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)}.

Overrides:
addServiceMethods in class AbstractServiceInterceptorFactory