net.sourceforge.stripes.controller
Class BeforeAfterMethodInterceptor

java.lang.Object
  extended by net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor
All Implemented Interfaces:
Interceptor

@Intercepts(value={RequestInit,ActionBeanResolution,HandlerResolution,BindingAndValidation,CustomValidation,EventHandling,ResolutionExecution,RequestComplete})
public class BeforeAfterMethodInterceptor
extends Object
implements Interceptor

Interceptor that inspects ActionBeans for Before and After annotations and runs the annotated methods at the requested point in the request lifecycle. There is no limit on the number of methods within an ActionBean that can be marked with @Before and @After annotations, and individual methods may be marked with one or both annotations.

To configure the BeforeAfterMethodInterceptor for use you will need to add the following to your web.xml (assuming no other interceptors are yet configured):

 <init-param>
     <param-name>Interceptor.Classes</param-name>
     <param-value>net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor</param-value>
 </init-param>
 

If one or more interceptors are already configured in your web.xml simply separate the fully qualified names of the interceptors with commas (additional whitespace is ok).

Since:
Stripes 1.3
Author:
Jeppe Cramon
See Also:
Before, After

Nested Class Summary
protected static class BeforeAfterMethodInterceptor.FilterMethods
          Helper class used to collect Before and After methods for a class and provide easy and rapid access to them by LifecycleStage.
 
Constructor Summary
BeforeAfterMethodInterceptor()
           
 
Method Summary
protected  BeforeAfterMethodInterceptor.FilterMethods getFilterMethods(Class<? extends ActionBean> beanClass)
          Gets the Before/After methods for the ActionBean.
 Resolution intercept(ExecutionContext context)
          Does the main work of the interceptor as described in the class level javadoc.
protected  Resolution invoke(ActionBean bean, Method m, LifecycleStage stage, Class<? extends Annotation> when)
          Helper method that will invoke the supplied method and manage any exceptions and returns from the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeforeAfterMethodInterceptor

public BeforeAfterMethodInterceptor()
Method Detail

intercept

public Resolution intercept(ExecutionContext context)
                     throws Exception
Does the main work of the interceptor as described in the class level javadoc. Executed the before and after methods for the ActionBean as appropriate for the current lifecycle stage. Lazily examines the ActionBean to determine the set of methods to execute, if it has not yet been examined.

Specified by:
intercept in interface Interceptor
Parameters:
context - the current ExecutionContext
Returns:
a resolution if one of the Before or After methods returns one, or if the nested interceptors return one
Throws:
Exception - if one of the before/after methods raises an exception

invoke

protected Resolution invoke(ActionBean bean,
                            Method m,
                            LifecycleStage stage,
                            Class<? extends Annotation> when)
                     throws Exception
Helper method that will invoke the supplied method and manage any exceptions and returns from the object. Specifically it will log any exceptions except for InvocationTargetExceptions which it will attempt to unwrap and rethrow. If the method returns a Resolution it will be returned; returns of other types will be ignored.

Throws:
Exception

getFilterMethods

protected BeforeAfterMethodInterceptor.FilterMethods getFilterMethods(Class<? extends ActionBean> beanClass)
Gets the Before/After methods for the ActionBean. Lazily examines the ActionBean and stores the information in a cache. Looks for all non-abstract, no-arg methods that are annotated with either @Before or @After.

Parameters:
beanClass - The action bean class to get methods for.
Returns:
The before and after methods for the ActionBean


? Copyright 2005-2006, Stripes Development Team.