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

Gavin King gavin.king at jboss.com
Sat Sep 23 11:41:39 EDT 2006


  User: gavin   
  Date: 06/09/23 11:41:39

  Modified:    src/main/org/jboss/seam    Seam.java ComponentType.java
                        Component.java
  Log:
  support @PrePassivate, @PostActivate, @PostConstruct for JavaBean components
  fix bug in replication of Seam-managed PC used by SFSB
  more efficient replication of extended Seam-managed PCs
  
  Revision  Changes    Path
  1.23      +41 -1     jboss-seam/src/main/org/jboss/seam/Seam.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Seam.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/Seam.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -b -r1.22 -r1.23
  --- Seam.java	25 Jul 2006 19:51:43 -0000	1.22
  +++ Seam.java	23 Sep 2006 15:41:39 -0000	1.23
  @@ -1,4 +1,4 @@
  -//$Id: Seam.java,v 1.22 2006/07/25 19:51:43 gavin Exp $
  +//$Id: Seam.java,v 1.23 2006/09/23 15:41:39 gavin Exp $
   package org.jboss.seam;
   
   import static org.jboss.seam.ComponentType.ENTITY_BEAN;
  @@ -17,6 +17,7 @@
   import org.jboss.seam.annotations.Role;
   import org.jboss.seam.annotations.Scope;
   import org.jboss.seam.contexts.Contexts;
  +import org.jboss.seam.contexts.Lifecycle;
   import org.jboss.seam.util.Strings;
   
   /**
  @@ -108,6 +109,21 @@
         return null;
      }
      
  +   /**
  +    * Get the bean class from a container-generated proxy
  +    * class
  +    */
  +   public static Class getEntityClass(Class<?> clazz)
  +   {
  +      while ( clazz!=null && !Object.class.equals(clazz) )
  +      {
  +         Entity name = clazz.getAnnotation(Entity.class);
  +         if ( name!=null ) return clazz;
  +         clazz = clazz.getSuperclass();
  +      }
  +      return null;
  +   }
  +   
      public static String getEjbName(Class<?> clazz)
      {
         switch ( getComponentType(clazz) )
  @@ -179,4 +195,28 @@
         return isSessionInvalid!=null && isSessionInvalid;
      }
   
  +   /**
  +    * Get the Seam component, even if no application context
  +    * is associated with the current thread.
  +    */
  +   public static Component componentForName(String name)
  +   {
  +      if ( Contexts.isApplicationContextActive() )
  +      {
  +         return Component.forName(name);
  +      }
  +      else
  +      {
  +         Lifecycle.beginApplication();
  +         try
  +         {
  +            return Component.forName(name);
  +         }
  +         finally
  +         {
  +            Lifecycle.endApplication();
  +         }
  +      }
  +   }
  +
   }
  
  
  
  1.5       +6 -1      jboss-seam/src/main/org/jboss/seam/ComponentType.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ComponentType.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/ComponentType.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- ComponentType.java	9 Jun 2006 05:55:18 -0000	1.4
  +++ ComponentType.java	23 Sep 2006 15:41:39 -0000	1.5
  @@ -1,4 +1,4 @@
  -//$Id: ComponentType.java,v 1.4 2006/06/09 05:55:18 gavin Exp $
  +//$Id: ComponentType.java,v 1.5 2006/09/23 15:41:39 gavin Exp $
   package org.jboss.seam;
   
   import static org.jboss.seam.ScopeType.CONVERSATION;
  @@ -22,6 +22,11 @@
         return this!=JAVA_BEAN;
      }
      
  +   public boolean isSessionBean()
  +   {
  +      return this==STATELESS_SESSION_BEAN || this==STATEFUL_SESSION_BEAN;
  +   }
  +   
      public ScopeType getDefaultScope()
      {
         switch (this)
  
  
  
  1.162     +111 -5    jboss-seam/src/main/org/jboss/seam/Component.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Component.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/Component.java,v
  retrieving revision 1.161
  retrieving revision 1.162
  diff -u -b -r1.161 -r1.162
  --- Component.java	18 Sep 2006 22:30:41 -0000	1.161
  +++ Component.java	23 Sep 2006 15:41:39 -0000	1.162
  @@ -22,7 +22,11 @@
   import java.util.Map;
   import java.util.Set;
   
  +import javax.annotation.PostConstruct;
  +import javax.annotation.PreDestroy;
   import javax.ejb.Local;
  +import javax.ejb.PostActivate;
  +import javax.ejb.PrePassivate;
   import javax.ejb.Remote;
   import javax.ejb.Remove;
   import javax.faces.application.Application;
  @@ -32,6 +36,7 @@
   import javax.faces.el.ValueBinding;
   import javax.interceptor.Interceptors;
   import javax.servlet.ServletRequest;
  +import javax.servlet.http.HttpSessionActivationListener;
   
   import net.sf.cglib.proxy.Enhancer;
   import net.sf.cglib.proxy.Factory;
  @@ -71,6 +76,7 @@
   import org.jboss.seam.interceptors.Interceptor;
   import org.jboss.seam.interceptors.JavaBeanInterceptor;
   import org.jboss.seam.interceptors.OutcomeInterceptor;
  +import org.jboss.seam.interceptors.PassivationInterceptor;
   import org.jboss.seam.interceptors.RemoveInterceptor;
   import org.jboss.seam.interceptors.RollbackInterceptor;
   import org.jboss.seam.interceptors.TransactionInterceptor;
  @@ -88,7 +94,7 @@
    *
    * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
    * @author Gavin King
  - * @version $Revision: 1.161 $
  + * @version $Revision: 1.162 $
    */
   @Scope(ScopeType.APPLICATION)
   public class Component
  @@ -110,6 +116,10 @@
      private Method destroyMethod;
      private Method createMethod;
      private Method unwrapMethod;
  +   private Method preDestroyMethod;
  +   private Method postConstructMethod;
  +   private Method prePassivateMethod;
  +   private Method postActivateMethod;
      private Set<Method> removeMethods = new HashSet<Method>();
      private Set<Method> validateMethods = new HashSet<Method>();
      private Set<Method> inMethods = new HashSet<Method>();
  @@ -422,6 +432,22 @@
               {
                  parameterSetters.add(method);
               }
  +            if ( method.isAnnotationPresent(PrePassivate.class) )
  +            {
  +               prePassivateMethod = method;
  +            }
  +            if ( method.isAnnotationPresent(PostActivate.class) )
  +            {
  +               prePassivateMethod = method;
  +            }
  +            if ( method.isAnnotationPresent(PostConstruct.class) )
  +            {
  +               postConstructMethod = method;
  +            }
  +            if ( method.isAnnotationPresent(PreDestroy.class) )
  +            {
  +               preDestroyMethod = method;
  +            }
   
               for ( Annotation ann: method.getAnnotations() )
               {
  @@ -654,6 +680,7 @@
         {
            addInterceptor( new Interceptor( new EJBExceptionInterceptor(), this ) );
         }*/
  +      addInterceptor( new Interceptor( new PassivationInterceptor(), this ) );
      }
   
      public Class<?> getBeanClass()
  @@ -743,6 +770,26 @@
         return validateMethods;
      }
   
  +   public boolean hasPreDestroyMethod()
  +   {
  +      return preDestroyMethod!=null;
  +   }
  +
  +   public boolean hasPostConstructMethod()
  +   {
  +      return postConstructMethod!=null;
  +   }
  +
  +   public boolean hasPrePassivateMethod()
  +   {
  +      return preDestroyMethod!=null;
  +   }
  +
  +   public boolean hasPostActivateMethod()
  +   {
  +      return postConstructMethod!=null;
  +   }
  +
      public boolean hasDestroyMethod()
      {
         return destroyMethod!=null;
  @@ -813,6 +860,7 @@
                 {
                    Object bean = beanClass.newInstance();
                    initialize(bean);
  +                 callPostConstructMethod(bean);
                    return bean;
                 }
                 else
  @@ -820,6 +868,7 @@
                    Factory bean = factory.newInstance();
                    initialize(bean);
                    bean.setCallback( 0, new JavaBeanInterceptor(this) );
  +                 callPostConstructMethod(bean);
                    return bean;
                 }
              case ENTITY_BEAN:
  @@ -1534,6 +1583,38 @@
         }
      }
   
  +   public void callPreDestroyMethod(Object instance)
  +   {
  +      if ( hasPreDestroyMethod() )
  +      {
  +         callComponentMethod( instance, getPreDestroyMethod() );
  +      }
  +   }
  +
  +   public void callPostConstructMethod(Object instance)
  +   {
  +      if ( hasPostConstructMethod() )
  +      {
  +         callComponentMethod( instance, getPostConstructMethod() );
  +      }
  +   }
  +
  +   public void callPrePassivateMethod(Object instance)
  +   {
  +      if ( hasPrePassivateMethod() )
  +      {
  +         callComponentMethod( instance, getPrePassivateMethod() );
  +      }
  +   }
  +
  +   public void callPostActivateMethod(Object instance)
  +   {
  +      if ( hasPostActivateMethod() )
  +      {
  +         callComponentMethod( instance, getPostActivateMethod() );
  +      }
  +   }
  +
      public Object callComponentMethod(Object instance, Method method) {
         Class[] paramTypes = method.getParameterTypes();
         String createMethodName = method.getName();
  @@ -1551,7 +1632,7 @@
         catch (NoSuchMethodException e)
         {
            String message = "method not found: " + method.getName() + " for component: " + name;
  -         if ( getType()==ComponentType.STATELESS_SESSION_BEAN || getType()==ComponentType.STATEFUL_SESSION_BEAN )
  +         if ( getType().isSessionBean() )
            {
                message += " (check that it is declared on the session bean business interface)";
            }
  @@ -1646,11 +1727,16 @@
         en.setInterceptDuringConstruction(false);
         en.setCallbackType(MethodInterceptor.class);
         en.setSuperclass( type==ComponentType.JAVA_BEAN ? beanClass : Object.class );
  -      Set<Class> interfaces = getBusinessInterfaces();
  -      if (interfaces.size()>0)
  +      Set<Class> interfaces = new HashSet<Class>();
  +      if ( type.isSessionBean() )
         {
  -         en.setInterfaces( interfaces.toArray( new Class[0] ) );
  +         interfaces.addAll( getBusinessInterfaces() );
  +      }
  +      else
  +      {
  +         interfaces.add(HttpSessionActivationListener.class);
         }
  +      en.setInterfaces( interfaces.toArray( new Class[0] ) );
         return (Class<Factory>) en.createClass();
      }
   
  @@ -1769,4 +1855,24 @@
         
      }
   
  +   public Method getPostActivateMethod()
  +   {
  +      return postActivateMethod;
  +   }
  +
  +   public Method getPrePassivateMethod()
  +   {
  +      return prePassivateMethod;
  +   }
  +
  +   public Method getPostConstructMethod()
  +   {
  +      return postConstructMethod;
  +   }
  +
  +   public Method getPreDestroyMethod()
  +   {
  +      return preDestroyMethod;
  +   }
  +
   }
  
  
  



More information about the jboss-cvs-commits mailing list