FileDocCategorySizeDatePackage
LifecycleInterceptorHandler.javaAPI DocJBoss 4.2.16721Fri Jul 13 20:53:52 BST 2007org.jboss.ejb3.interceptor

LifecycleInterceptorHandler

public class LifecycleInterceptorHandler extends Object
author
Kabir Khan
version
$Revision: 60233 $

Fields Summary
private static final Logger
log
private org.jboss.ejb3.EJBContainer
container
private InterceptorInfo[]
postConstructs
private InterceptorInfo[]
postActivates
private InterceptorInfo[]
prePassivates
private InterceptorInfo[]
preDestroys
private Method[]
beanPostConstructs
private Method[]
beanPostActivates
private Method[]
beanPrePassivates
private Method[]
beanPreDestroys
private Method
timeoutCallbackMethod
private long
timeoutCalllbackHash
Constructors Summary
public LifecycleInterceptorHandler(org.jboss.ejb3.EJBContainer container, Class[] handledCallbacks)


       
   
      this.container = container;
      InterceptorInfoRepository repostitory = container.getInterceptorRepository();
      for (Class clazz : handledCallbacks)
      {
         if (clazz == PostConstruct.class)
         {
            postConstructs = repostitory.getPostConstructInterceptors(container);
            beanPostConstructs = repostitory.getBeanClassPostConstructs(container);
         }
         else if (clazz == PostActivate.class)
         {
            postActivates = repostitory.getPostActivateInterceptors(container);
            beanPostActivates = repostitory.getBeanClassPostActivates(container);
         }
         else if (clazz == PrePassivate.class)
         {
            prePassivates = repostitory.getPrePassivateInterceptors(container);
            beanPrePassivates = repostitory.getBeanClassPrePassivates(container);
         }
         else if (clazz == PreDestroy.class)
         {
            preDestroys = repostitory.getPreDestroyInterceptors(container);
            beanPreDestroys = repostitory.getBeanClassPreDestroys(container);
         }
         else if (clazz == Timeout.class)
         {
            resolveTimeoutCallback();
         }
      }
   
Methods Summary
public java.lang.reflect.MethodgetTimeoutCallback()

      return timeoutCallbackMethod;
   
public longgetTimeoutCalllbackHash()

      return timeoutCalllbackHash;
   
public voidpostActivate(org.jboss.ejb3.BeanContext ctx)

      try
      {
         InvocationContext ic = LifecycleInvocationContextImpl.getLifecycleInvocationContext(
               PostActivate.class,
               ctx,
               postActivates,
               beanPostActivates);
         ic.proceed();
      }
      catch (Exception e)
      {
         throw new RuntimeException(e);
      }
   
public voidpostConstruct(org.jboss.ejb3.BeanContext ctx)

      try
      {
         InvocationContext ic = LifecycleInvocationContextImpl.getLifecycleInvocationContext(
               PostConstruct.class,
               ctx,
               postConstructs,
               beanPostConstructs);
         ic.proceed();
      }
      catch (Exception e)
      {
         throw new RuntimeException(e);
      }
   
public voidpreDestroy(org.jboss.ejb3.BeanContext ctx)

      Object id = null;
      if (ctx instanceof StatefulBeanContext)
      {
         id = ((StatefulBeanContext)ctx).getId();
      }
      try
      {
         InvocationContext ic = LifecycleInvocationContextImpl.getLifecycleInvocationContext(
               PreDestroy.class,
               ctx,
               preDestroys,
               beanPreDestroys);
         ic.proceed();
      }
      catch (Exception e)
      {
         throw new RuntimeException(e);
      }
   
public voidprePassivate(org.jboss.ejb3.BeanContext ctx)

      try
      {
         InvocationContext ic = LifecycleInvocationContextImpl.getLifecycleInvocationContext(
               PrePassivate.class,
               ctx,
               prePassivates,
               beanPrePassivates);
         ic.proceed();
      }
      catch (Exception e)
      {
         throw new RuntimeException(e);
      }
   
private voidresolveTimeoutCallback()

      for (Method method : container.getBeanClass().getMethods())
      {
         if (container.resolveAnnotation(method, Timeout.class) != null)
         {
            if (Modifier.isPublic(method.getModifiers()) &&
                  method.getReturnType().equals(Void.TYPE) &&
                  method.getParameterTypes().length == 1 &&
                  method.getParameterTypes()[0].equals(Timer.class))
            {
               timeoutCallbackMethod = method;
            }
            else
            {
               throw new RuntimeException("@Timeout methods must have the signature: public void <METHOD>(javax.ejb.Timer timer) - " + method);
            }
         }
      }

      try
      {
         if (timeoutCallbackMethod == null && javax.ejb.TimedObject.class.isAssignableFrom(container.getBeanClass()))
         {
            Class[] params = new Class[]{Timer.class};
            timeoutCallbackMethod = container.getBeanClass().getMethod("ejbTimeout", params);
         }
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }

      if (timeoutCallbackMethod != null)
      {
         timeoutCalllbackHash = MethodHashing.calculateHash(timeoutCallbackMethod);
      }