FileDocCategorySizeDatePackage
TxInterceptorFactory.javaAPI DocJBoss 4.2.14522Fri Jul 13 20:53:54 BST 2007org.jboss.ejb3.tx

TxInterceptorFactory

public class TxInterceptorFactory extends org.jboss.aspects.tx.TxInterceptorFactory
This interceptor handles transactions for AOP
author
Bill Burke
version
$Revision: 60233 $

Fields Summary
private static final Logger
log
Constructors Summary
Methods Summary
public java.lang.ObjectcreatePerJoinpoint(org.jboss.aop.Advisor advisor, org.jboss.aop.joinpoint.Joinpoint jp)

      // We have to do this until AOP supports matching based on annotation attributes
      TransactionManagementType type = TxUtil.getTransactionManagementType(advisor);
      if (type == TransactionManagementType.BEAN)
         return new BMTInterceptor(TxUtil.getTransactionManager(), !(advisor instanceof StatefulContainer));

      Method method = ((MethodJoinpoint) jp).getMethod();
      int timeout = resolveTransactionTimeout(advisor, method);

      if (policy == null);
         super.initialize();

      String txType = resolveTxType(advisor, jp).toUpperCase();
      if (txType.equals("REQUIRED"))
      {
         return new TxInterceptor.Required(TxUtil.getTransactionManager(), policy, timeout);
      }
      else if (txType.equals("REQUIRESNEW"))
      {
         return new TxInterceptor.RequiresNew(TxUtil.getTransactionManager(), policy, timeout);
      }
      else
      {
         return super.createPerJoinpoint(advisor, jp);
      }
   
public java.lang.StringgetName()

      return getClass().getName();
   
protected voidinitializePolicy()

      policy = new Ejb3TxPolicy();
   
protected intresolveTransactionTimeout(org.jboss.aop.Advisor advisor, java.lang.reflect.Method method)

      TransactionTimeout annotation = (TransactionTimeout)advisor.resolveAnnotation(method, TransactionTimeout.class);
      
      if (annotation == null)
         annotation = (TransactionTimeout)advisor.resolveAnnotation(TransactionTimeout.class);
      
      if (annotation != null)
      {
         return annotation.value();
      }

      return -1;
   
protected java.lang.StringresolveTxType(org.jboss.aop.Advisor advisor, org.jboss.aop.joinpoint.Joinpoint jp)


        
   
      Method method = ((MethodJoinpoint) jp).getMethod();
      TransactionAttribute tx = (TransactionAttribute) advisor.resolveAnnotation(method, TransactionAttribute.class);

      if (tx == null)
         tx = (TransactionAttribute) advisor.resolveAnnotation(TransactionAttribute.class);

      String value = "REQUIRED";
      if (tx != null)
      {
         TransactionAttributeType type = tx.value();

         if (type == null)
         {
            value = "REQUIRED";
         }
         else if (type == TransactionAttributeType.NOT_SUPPORTED)
         {
            value = "NOTSUPPORTED";
         }
         else if (type == TransactionAttributeType.REQUIRES_NEW)
         {
            value = "REQUIRESNEW";
         }
         else
         {
            value = type.name();
         }
      }

      return value;