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

Gavin King gavin.king at jboss.com
Sat Sep 23 08:29:18 EDT 2006


  User: gavin   
  Date: 06/09/23 08:29:18

  Modified:    src/main/org/jboss/seam/ejb  SeamInterceptor.java
  Log:
  fix JBSEAM-338
  
  Revision  Changes    Path
  1.43      +49 -19    jboss-seam/src/main/org/jboss/seam/ejb/SeamInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SeamInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/ejb/SeamInterceptor.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -b -r1.42 -r1.43
  --- SeamInterceptor.java	3 Aug 2006 14:44:53 -0000	1.42
  +++ SeamInterceptor.java	23 Sep 2006 12:29:18 -0000	1.43
  @@ -19,7 +19,7 @@
   import org.apache.commons.logging.LogFactory;
   import org.jboss.seam.Component;
   import org.jboss.seam.InterceptorType;
  -import org.jboss.seam.Seam;
  +import org.jboss.seam.annotations.Name;
   import org.jboss.seam.contexts.Contexts;
   import org.jboss.seam.contexts.Lifecycle;
   import org.jboss.seam.interceptors.EventType;
  @@ -30,7 +30,7 @@
    * for a session bean component
    * 
    * @author Gavin King
  - * @version $Revision: 1.42 $
  + * @version $Revision: 1.43 $
    */
   public class SeamInterceptor implements Serializable
   {
  @@ -43,33 +43,55 @@
      private transient Component component;
      
      /**
  -    * Called when instatiated by EJB container
  +    * Called when instatiated by EJB container.
  +    * (In this case it might be a Seam component,
  +    * but we won't know until postConstruct() is
  +    * called.)
       */
      public SeamInterceptor()
      {
         type = InterceptorType.SERVER;
  -      component = null;
      }
      
      /**
  -    * Called when instantiated by Seam
  +    * Called when instantiated by Seam.
  +    * (In this case it is always a Seam
  +    * component.)
       */
      public SeamInterceptor(InterceptorType type, Component component)
      {
         this.type = type;
         this.component = component;
         isSeamComponent = true;
  +      componentName = component.getName();
      }
      
      @PostConstruct
      public void postConstruct(InvocationContext invocation)
      {
  -      //if instantiated by the EJB container, we 
  -      //still need to init the component reference
         Object bean = invocation.getTarget();
  -      if ( isSeamComponent(bean) )
  +
  +      // if it is a session bean instantiated by the EJB 
  +      // container, we still need to init the component 
  +      // reference
  +      if (component==null) //ie. if it was instantiated by the EJB container
  +      {
  +         Class<?> beanClass = bean.getClass();
  +         if ( beanClass.isAnnotationPresent(Name.class) ) //for session beans, this is a safe test
  +         {
  +            isSeamComponent = true;
  +            componentName = beanClass.getAnnotation(Name.class).value();
  +            component = componentForName(componentName);
  +         }
  +         else
  +         {
  +            isSeamComponent = false;
  +         }
  +      }
  +      
  +      // initialize the bean instance
  +      if (isSeamComponent)
         {
  -         component = getSeamComponent(bean);
            try
            {
               component.initialize(bean);
  @@ -82,7 +104,6 @@
            {
               throw new RuntimeException("exception initializing EJB component", e);
            }
  -         isSeamComponent = true;
         }
         
         invokeAndHandle(invocation, EventType.POST_CONSTRUCT);
  @@ -98,13 +119,12 @@
      public void prePassivate(InvocationContext invocation)
      {
         invokeAndHandle(invocation, EventType.PRE_PASSIVATE);
  -      if (isSeamComponent) componentName = component.getName();
      }
      
      @PostActivate
      public void postActivate(InvocationContext invocation)
      {
  -      if (isSeamComponent) component = Component.forName(componentName);
  +      if (isSeamComponent) component = componentForName(componentName);
         invokeAndHandle(invocation, EventType.POST_ACTIVATE);
      }
      
  @@ -183,14 +203,24 @@
         return component!=null && component.getInterceptionType().isActive();
      }
   
  -   private boolean isSeamComponent(Object bean)
  +   private Component componentForName(String name)
      {
  -      return isSeamComponent || Seam.getBeanClass( bean.getClass() )!=null;
  +      if ( Contexts.isApplicationContextActive() )
  +      {
  +         return Component.forName(name);
      }
  -   
  -   private Component getSeamComponent(Object bean)
  +      else
  +      {
  +         Lifecycle.beginApplication();
  +         try
      {
  -      return component==null ? Component.forName( Seam.getComponentName( bean.getClass() ) ) : component;
  +            return Component.forName(name);
  +         }
  +         finally
  +         {
  +            Lifecycle.endApplication();
  +         }
  +      }
      }
      
   }
  
  
  



More information about the jboss-cvs-commits mailing list