[jboss-cvs] jboss-seam/src/main/org/jboss/seam/interceptors ...

Gavin King gavin.king at jboss.com
Wed Jul 26 19:22:37 EDT 2006


  User: gavin   
  Date: 06/07/26 19:22:37

  Modified:    src/main/org/jboss/seam/interceptors  
                        SeamInvocationContext.java Interceptor.java
  Log:
  support @PostConstruct and @PreDestroy on seam interceptors
  
  Revision  Changes    Path
  1.7       +12 -6     jboss-seam/src/main/org/jboss/seam/interceptors/SeamInvocationContext.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SeamInvocationContext.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/interceptors/SeamInvocationContext.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- SeamInvocationContext.java	26 Jul 2006 21:51:05 -0000	1.6
  +++ SeamInvocationContext.java	26 Jul 2006 23:22:37 -0000	1.7
  @@ -1,4 +1,4 @@
  -//$Id: SeamInvocationContext.java,v 1.6 2006/07/26 21:51:05 gavin Exp $
  +//$Id: SeamInvocationContext.java,v 1.7 2006/07/26 23:22:37 gavin Exp $
   package org.jboss.seam.interceptors;
   
   import java.lang.reflect.Method;
  @@ -7,9 +7,6 @@
   
   import javax.interceptor.InvocationContext;
   
  -import org.jboss.seam.Component;
  -import org.jboss.seam.InterceptorType;
  -
   /**
    * Adapts from EJB interception to Seam component interceptors
    * 
  @@ -18,14 +15,16 @@
   public class SeamInvocationContext implements InvocationContext
   {
      
  +   private final EventType eventType;
      private final InvocationContext ejbInvocationContext;
      private final List<Interceptor> interceptors;
      int location = 0;
   
  -   public SeamInvocationContext(InvocationContext ejbInvocationContext, List<Interceptor> interceptors)
  +   public SeamInvocationContext(InvocationContext ejbInvocationContext, EventType type, List<Interceptor> interceptors)
      {
         this.ejbInvocationContext = ejbInvocationContext;
         this.interceptors = interceptors;
  +      this.eventType = type;
      }
      
      public Object getTarget()
  @@ -56,7 +55,14 @@
         }
         else
         {
  -         return interceptors.get(location++).aroundInvoke(this);
  +         Interceptor interceptor = interceptors.get(location++);
  +         switch(eventType)
  +         {
  +            case AROUND_INVOKE: return interceptor.aroundInvoke(this);
  +            case POST_CONSTRUCT: return interceptor.postConstruct(this);
  +            case PRE_DESTORY: return interceptor.preDestroy(this);
  +            default: throw new IllegalArgumentException("no InvocationType");
  +         }
         }
      }
   
  
  
  
  1.11      +30 -9     jboss-seam/src/main/org/jboss/seam/interceptors/Interceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Interceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/interceptors/Interceptor.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -b -r1.10 -r1.11
  --- Interceptor.java	26 Jul 2006 21:51:05 -0000	1.10
  +++ Interceptor.java	26 Jul 2006 23:22:37 -0000	1.11
  @@ -1,9 +1,11 @@
  -//$Id: Interceptor.java,v 1.10 2006/07/26 21:51:05 gavin Exp $
  +//$Id: Interceptor.java,v 1.11 2006/07/26 23:22:37 gavin Exp $
   package org.jboss.seam.interceptors;
   
   import java.lang.annotation.Annotation;
   import java.lang.reflect.Method;
   
  +import javax.annotation.PostConstruct;
  +import javax.annotation.PreDestroy;
   import javax.interceptor.AroundInvoke;
   import javax.interceptor.Interceptors;
   import javax.interceptor.InvocationContext;
  @@ -21,6 +23,8 @@
   {
      private final Object userInterceptor;
      private Method aroundInvokeMethod;
  +   private Method postConstructMethod;
  +   private Method preDestroyMethod;
      private InterceptorType type;
      
      public Object getUserInterceptor()
  @@ -77,6 +81,15 @@
            {
               aroundInvokeMethod = method;
            }
  +         if ( method.isAnnotationPresent(PostConstruct.class) )
  +         {
  +            postConstructMethod = method;
  +         }
  +         if ( method.isAnnotationPresent(PreDestroy.class) )
  +         {
  +            preDestroyMethod = method;
  +         }
  +
            Class[] params = method.getParameterTypes();
            //if there is a method that takes the annotation, call it, to pass initialization info
            if ( annotation!=null && params.length==1 && params[0]==annotation.annotationType() )
  @@ -89,13 +102,6 @@
               Reflections.invokeAndWrap(method, userInterceptor, component);
            }
         }
  -      if (aroundInvokeMethod==null) 
  -      {
  -         throw new IllegalArgumentException(
  -               "no @AroundInvoke method found: " + 
  -               userInterceptor.getClass().getName()
  -            );
  -      }
   
         type = interceptorClass.isAnnotationPresent(org.jboss.seam.annotations.Interceptor.class) ?
               interceptorClass.getAnnotation(org.jboss.seam.annotations.Interceptor.class).type() :
  @@ -104,6 +110,21 @@
      
      public Object aroundInvoke(InvocationContext invocation) throws Exception
      {
  -      return Reflections.invoke( aroundInvokeMethod, userInterceptor, invocation );
  +      return aroundInvokeMethod==null ?
  +            invocation.proceed() :
  +            Reflections.invoke( aroundInvokeMethod, userInterceptor, invocation );
  +   }
  +   public Object postConstruct(InvocationContext invocation) throws Exception
  +   {
  +      return postConstructMethod==null ?
  +            invocation.proceed() :
  +            Reflections.invoke( aroundInvokeMethod, userInterceptor, invocation );
      }
  +   public Object preDestroy(InvocationContext invocation) throws Exception
  +   {
  +      return preDestroyMethod==null ?
  +            invocation.proceed() :
  +            Reflections.invoke( aroundInvokeMethod, userInterceptor, invocation );
  +   }
  +   
   }
  
  
  



More information about the jboss-cvs-commits mailing list