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

EJB3InterceptorsFactory

public class EJB3InterceptorsFactory extends Object implements org.jboss.aop.advice.AspectFactory
author
Kabir Khan
version
$Revision: 60823 $

Fields Summary
static Logger
log
static final long
MESSAGE_LISTENER_ON_MESSAGE
Constructors Summary
Methods Summary
public java.lang.ObjectcreatePerClass(org.jboss.aop.Advisor advisor)

      throw new RuntimeException("NOT ALLOWED");
   
public java.lang.ObjectcreatePerInstance(org.jboss.aop.Advisor advisor, org.jboss.aop.InstanceAdvisor instanceAdvisor)

      throw new RuntimeException("NOT ALLOWED");
   
public java.lang.ObjectcreatePerJoinpoint(org.jboss.aop.Advisor advisor, org.jboss.aop.InstanceAdvisor instanceAdvisor, org.jboss.aop.joinpoint.Joinpoint jp)

      throw new RuntimeException("NOT ALLOWED");
   
public java.lang.ObjectcreatePerJoinpoint(org.jboss.aop.Advisor advisor, org.jboss.aop.joinpoint.Joinpoint jp)

      if (jp instanceof MethodJoinpoint)
      {
         EJBContainer container = (EJBContainer) advisor;
         Class beanClass = container.getBeanClass();

         try
         {
            Method method = ((MethodJoinpoint) jp).getMethod();
            if (isBusinessMethod(container, method))
            {
               InterceptorInfo[] infos = container.getInterceptorRepository().getBusinessInterceptors(container, method);
               Method[] beanAroundInvoke = container.getInterceptorRepository().getBeanClassAroundInvokes(container);
               log.debug("Bound interceptors for joinpoint: " + method + " - " + infos);
               return new EJB3InterceptorsInterceptor(infos, beanAroundInvoke);
            }
         }
         catch (RuntimeException e)
         {
            throw new RuntimeException("An exception occurred initialising interceptors for " + beanClass + "." + ((MethodJoinpoint) jp).getMethod().getName(), e);
         }
      }
      return new EJB3InterceptorsInterceptor(new InterceptorInfo[0], null);
   
public java.lang.ObjectcreatePerVM()

      throw new RuntimeException("NOT ALLOWED");
   
private java.util.ArrayListgetBusinessInterfaces(org.jboss.ejb3.EJBContainer container)

      ArrayList<Class> interfaces = new ArrayList<Class>();
      if (container instanceof ConsumerContainer)
      {
         Producers producers = (Producers) container.resolveAnnotation(Producers.class);
         if (producers != null)
         {
            for (Producer producer : producers.value())
            {
               interfaces.add(producer.producer());
            }
         }

         Producer producer = (Producer) container.resolveAnnotation(Producer.class);
         if (producer != null)
         {
            interfaces.add(producer.producer());
         }

         for (Class implIf : container.getBeanClass().getInterfaces())
         {
            if (implIf.getAnnotation(Producer.class) != null)
            {
               interfaces.add(implIf);
            }
         }
      }
      else if (container instanceof MDB)
      {
         interfaces.add(((MDB)container).getMessagingType());
      }
      else
      {
         Class[] remotes = ProxyFactoryHelper.getRemoteInterfaces(container);
         Class[] locals = ProxyFactoryHelper.getLocalInterfaces(container);
         if (remotes != null)
         {
            interfaces.addAll(Arrays.asList(remotes));
         }
         if (locals != null)
         {
            interfaces.addAll(Arrays.asList(locals));
         }

         if (container instanceof ServiceContainer)
         {
            Management man = (Management) container.resolveAnnotation(Management.class);
            if (man != null)
            {
               Class iface = man.value();
               if (iface != null)
               {
                  interfaces.add(iface);
               }
            }

            Class[] implIfaces = container.getBeanClass().getInterfaces();
            for (Class iface : implIfaces)
            {
               if (iface.getAnnotation(Management.class) != null)
               {
                  interfaces.add(iface);
               }
            }
         }
      }

      return interfaces;
   
public java.lang.StringgetName()


   
   
      try
      {
         Class clazz = MessageListener.class;
         Method m = clazz.getDeclaredMethod("onMessage", new Class[]{javax.jms.Message.class});
         MESSAGE_LISTENER_ON_MESSAGE = MethodHashing.calculateHash(m);
      }
      catch (Exception e)
      {
         throw new RuntimeException("Error initialising hash for MessageListener.onMessage()", e);
      }
   
      return getClass().getName();
   
private booleanisBusinessMethod(org.jboss.ejb3.EJBContainer container, java.lang.reflect.Method method)

      long hash = MethodHashing.calculateHash(method);
      ArrayList<Class> businessInterfaces = getBusinessInterfaces(container);
      for (Class businessInterface : businessInterfaces)
      {
         for (Method interfaceMethod : businessInterface.getMethods())
         {
            if (MethodHashing.calculateHash(interfaceMethod) == hash)
            {
               return true;
            }
         }
      }

      return false;