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

Gavin King gavin.king at jboss.com
Wed Oct 4 19:42:53 EDT 2006


  User: gavin   
  Date: 06/10/04 19:42:53

  Modified:    src/main/org/jboss/seam/ejb  SeamInterceptor.java
  Log:
  fix bug where components of non-default role got initialized with values from the default role
  
  Revision  Changes    Path
  1.47      +38 -15    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.46
  retrieving revision 1.47
  diff -u -b -r1.46 -r1.47
  --- SeamInterceptor.java	3 Oct 2006 17:16:45 -0000	1.46
  +++ SeamInterceptor.java	4 Oct 2006 23:42:52 -0000	1.47
  @@ -32,11 +32,12 @@
    * for a session bean component
    * 
    * @author Gavin King
  - * @version $Revision: 1.46 $
    */
   public class SeamInterceptor implements Serializable
   {
      
  +   public static ThreadLocal<Component> COMPONENT = new ThreadLocal<Component>();
  +   
      private static final Log log = LogFactory.getLog(SeamInterceptor.class);
      
      private final InterceptorType type;
  @@ -64,9 +65,14 @@
      public SeamInterceptor(InterceptorType type, Component component)
      {
         this.type = type;
  +      init(component);
  +   }
  +
  +   private void init(Component component)
  +   {
  +      isSeamComponent = true;
         this.component = component;
         userInterceptors = component.createUserInterceptors(type);
  -      isSeamComponent = true;
         componentName = component.getName();
      }
      
  @@ -80,18 +86,7 @@
         // 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 = Seam.componentForName(componentName);
  -            userInterceptors = component.createUserInterceptors(type);
  -         }
  -         else
  -         {
  -            isSeamComponent = false;
  -         }
  +         initSessionBean(bean);
         }
         
         // initialize the bean instance
  @@ -114,6 +109,29 @@
         invokeAndHandle(invocation, EventType.POST_CONSTRUCT);
      }
      
  +   private void initSessionBean(Object bean)
  +   {
  +      Component invokingComponent = COMPONENT.get();
  +      if ( invokingComponent!=null )
  +      {
  +         //the session bean was obtained by the application by
  +         //calling Component.getInstance(), could be a role
  +         //other than the default role
  +         init(invokingComponent);
  +      }
  +      else if ( bean.getClass().isAnnotationPresent(Name.class) )
  +      {
  +         //the session bean was obtained by the application from
  +         //JNDI, so assume the default role
  +         String defaultComponentName = bean.getClass().getAnnotation(Name.class).value();
  +         init( Seam.componentForName( defaultComponentName ) );
  +      }
  +      else
  +      {
  +         isSeamComponent = false;
  +      }
  +   }
  +
      @PreDestroy
      public void preDestroy(InvocationContext invocation)
      {
  @@ -208,4 +226,9 @@
         return component!=null && component.getInterceptionType().isActive();
      }
      
  +   public Component getComponent()
  +   {
  +      return component;
  +   }
  +   
   }
  
  
  



More information about the jboss-cvs-commits mailing list