FileDocCategorySizeDatePackage
StatefulRemoveInterceptor.javaAPI DocJBoss 4.2.14594Fri Jul 13 20:53:50 BST 2007org.jboss.ejb3.stateful

StatefulRemoveInterceptor

public class StatefulRemoveInterceptor extends Object implements org.jboss.aop.advice.Interceptor
Handles @Remove on a Stateful bean.
author
Bill Burke

Fields Summary
private static final Logger
log
protected boolean
retainIfException
Constructors Summary
public StatefulRemoveInterceptor(boolean removeOnException)


     
   
      this.retainIfException = removeOnException;
   
Methods Summary
public java.lang.StringgetName()

      return this.getClass().getName();
   
public java.lang.Objectinvoke(org.jboss.aop.joinpoint.Invocation invocation)

      Object rtn = null;
      try
      {
         rtn = invocation.invokeNext();
      }
      catch (Throwable t)
      {
         // don't remove if we're an applicationexception and retain is true
         if (TxUtil.getApplicationException(t.getClass(), invocation) != null && retainIfException) throw t;

         // otherwise, just remove it.
         removeSession(invocation, true);
         throw t;
      }
      removeSession(invocation, false);
      return rtn;
   
protected voidremoveSession(org.jboss.aop.joinpoint.Invocation invocation, boolean exceptionThrown)

      StatefulContainerInvocation ejb = (StatefulContainerInvocation) invocation;
      StatefulBeanContext ctx = (StatefulBeanContext)ejb.getBeanContext();
      if (ctx == null || ctx.isDiscarded() || ctx.isRemoved()) return;
      Object id = ejb.getId();


      StatefulContainer container = (StatefulContainer) ejb.getAdvisor();
      Transaction tx = null;
      try
      {
         tx = TxUtil.getTransactionManager().getTransaction();
      }
      catch (SystemException e)
      {
         throw new RuntimeException(e);
      }
    
      if (tx != null && TxUtils.isActive(tx))
      {
         try
         {
            tx.registerSynchronization(new RemoveSynchronization(container, id, exceptionThrown != true && retainIfException));
         }
         catch (RollbackException e)
         {
            throw new RuntimeException(e);
         }
         catch (SystemException e)
         {
            throw new RuntimeException(e);
         }
      }
      else
      {
         container.getCache().remove(id);
      }