[jboss-cvs] JBossAS SVN: r72023 - in projects/ejb3/trunk/interceptors/src: main/java/org/jboss/ejb3/interceptors/annotation/impl and 10 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Apr 11 10:10:23 EDT 2008


Author: wolfc
Date: 2008-04-11 10:10:23 -0400 (Fri, 11 Apr 2008)
New Revision: 72023

Added:
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/annotation/InterceptorOrderImpl.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/util/
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/util/InterceptorCollection.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/order/
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/order/InterceptorA.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/order/InterceptorB.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/order/InterceptorChainBean.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/order/unit/
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/order/unit/InterceptorChainTestCase.java
   projects/ejb3/trunk/interceptors/src/test/resources/order/
   projects/ejb3/trunk/interceptors/src/test/resources/order/META-INF/
   projects/ejb3/trunk/interceptors/src/test/resources/order/META-INF/ejb-jar.xml
Modified:
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/annotation/impl/InterceptorsImpl.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/BeanInterceptorMetaDataBridge.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/InterceptorMetaDataBridge.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/registry/InterceptorRegistry.java
Log:
EJBTHREE-1261: implemented interceptor order

Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/annotation/impl/InterceptorsImpl.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/annotation/impl/InterceptorsImpl.java	2008-04-11 14:05:35 UTC (rev 72022)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/annotation/impl/InterceptorsImpl.java	2008-04-11 14:10:23 UTC (rev 72023)
@@ -22,11 +22,10 @@
 package org.jboss.ejb3.interceptors.annotation.impl;
 
 import java.lang.annotation.Annotation;
-import java.util.LinkedHashSet;
-import java.util.Set;
 
 import javax.interceptor.Interceptors;
 
+import org.jboss.ejb3.interceptors.util.InterceptorCollection;
 import org.jboss.logging.Logger;
 
 /**
@@ -37,14 +36,12 @@
  * be made after it is in use.
  *
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
  */
-public class InterceptorsImpl implements Interceptors
+public class InterceptorsImpl extends InterceptorCollection implements Interceptors
 {
    private static final Logger log = Logger.getLogger(InterceptorsImpl.class);
 
-   private Set<Class<?>> values = new LinkedHashSet<Class<?>>();
-   
    public boolean add(Interceptors annotation)
    {
       if(annotation == null)
@@ -52,28 +49,13 @@
       boolean result = false;
       for(Class<?> cls : annotation.value())
       {
-         result |= values.add(cls);
+         result |= addValue(cls);
       }
       return result;
    }
    
-   public boolean addValue(Class<?> interceptorClass)
-   {
-      return values.add(interceptorClass);
-   }
-   
    public Class<? extends Annotation> annotationType()
    {
       return Interceptors.class;
    }
-
-   public boolean isEmpty()
-   {
-      return values.isEmpty();
-   }
-
-   public Class<?>[] value()
-   {
-      return values.toArray(new Class<?>[0]);
-   }
 }

Added: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/annotation/InterceptorOrderImpl.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/annotation/InterceptorOrderImpl.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/annotation/InterceptorOrderImpl.java	2008-04-11 14:10:23 UTC (rev 72023)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.interceptors.aop.annotation;
+
+import java.lang.annotation.Annotation;
+
+import org.jboss.ejb3.interceptors.util.InterceptorCollection;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InterceptorOrderImpl extends InterceptorCollection implements InterceptorOrder
+{
+   public Class<? extends Annotation> annotationType()
+   {
+      return InterceptorOrder.class;
+   }
+}

Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/BeanInterceptorMetaDataBridge.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/BeanInterceptorMetaDataBridge.java	2008-04-11 14:05:35 UTC (rev 72022)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/BeanInterceptorMetaDataBridge.java	2008-04-11 14:10:23 UTC (rev 72023)
@@ -26,6 +26,8 @@
 import java.util.Arrays;
 import java.util.List;
 
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
 import javax.ejb.PostActivate;
 import javax.ejb.PrePassivate;
 import javax.interceptor.AroundInvoke;
@@ -33,9 +35,14 @@
 
 import org.jboss.ejb3.interceptors.annotation.impl.InterceptorsImpl;
 import org.jboss.ejb3.interceptors.annotation.impl.PostActivateImpl;
+import org.jboss.ejb3.interceptors.annotation.impl.PostConstructImpl;
+import org.jboss.ejb3.interceptors.annotation.impl.PreDestroyImpl;
 import org.jboss.ejb3.interceptors.annotation.impl.PrePassivateImpl;
 import org.jboss.ejb3.interceptors.aop.annotation.DefaultInterceptors;
 import org.jboss.ejb3.interceptors.aop.annotation.DefaultInterceptorsImpl;
+import org.jboss.ejb3.interceptors.aop.annotation.InterceptorOrder;
+import org.jboss.ejb3.interceptors.aop.annotation.InterceptorOrderImpl;
+import org.jboss.ejb3.interceptors.util.InterceptorCollection;
 import org.jboss.ejb3.metadata.MetaDataBridge;
 import org.jboss.logging.Logger;
 import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
@@ -52,13 +59,13 @@
  * Comment
  *
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
  */
 public class BeanInterceptorMetaDataBridge extends EnvironmentInterceptorMetaDataBridge<JBossEnterpriseBeanMetaData> implements MetaDataBridge<JBossEnterpriseBeanMetaData>
 {
    private static final Logger log = Logger.getLogger(BeanInterceptorMetaDataBridge.class);
 
-   private static boolean add(InterceptorsImpl interceptors, ClassLoader classLoader, InterceptorBindingMetaData binding)
+   private static boolean add(InterceptorCollection interceptors, ClassLoader classLoader, InterceptorBindingMetaData binding)
    {
       boolean result = false;
       InterceptorClassesMetaData interceptorClassesMetaData;
@@ -133,6 +140,31 @@
                return annotationClass.cast(new DefaultInterceptorsImpl(interceptors));
          }
       }
+      else if(annotationClass == InterceptorOrder.class)
+      {
+         InterceptorBindingsMetaData bindings = beanMetaData.getEjbJarMetaData().getAssemblyDescriptor().getInterceptorBindings();
+         if(bindings != null)
+         {
+            InterceptorOrderImpl interceptorOrder = new InterceptorOrderImpl();
+            for(InterceptorBindingMetaData binding : bindings)
+            {
+               // Only for specifying order
+               if(!binding.isTotalOrdering())
+                  continue;
+               
+               // For the method component
+               if(binding.getMethod() != null)
+                  continue;
+               
+               String ejbName = beanMetaData.getEjbName();
+               String bindingEjbName = binding.getEjbName();
+               if(bindingEjbName.equals(ejbName))
+                  add(interceptorOrder, classLoader, binding);
+            }
+            if(!interceptorOrder.isEmpty())
+               return annotationClass.cast(interceptorOrder);
+         }
+      }
       else if(annotationClass == Interceptors.class)
       {
          InterceptorBindingsMetaData bindings = beanMetaData.getEjbJarMetaData().getAssemblyDescriptor().getInterceptorBindings();
@@ -141,6 +173,10 @@
             InterceptorsImpl interceptors = new InterceptorsImpl();
             for(InterceptorBindingMetaData binding : bindings)
             {
+               // Only for specifying order
+               if(binding.isTotalOrdering())
+                  continue;
+               
                // For the method component
                if(binding.getMethod() != null)
                   continue;
@@ -150,7 +186,8 @@
                if(bindingEjbName.equals(ejbName))
                   add(interceptors, classLoader, binding);
             }
-            return annotationClass.cast(interceptors);
+            if(!interceptors.isEmpty())
+               return annotationClass.cast(interceptors);
          }
       }
       return super.retrieveAnnotation(annotationClass, beanMetaData, classLoader);
@@ -175,6 +212,44 @@
                return annotationClass.cast(annotation);
          }
       }
+      else if(annotationClass == InterceptorOrder.class)
+      {
+         InterceptorBindingsMetaData bindings = beanMetaData.getEjbJarMetaData().getAssemblyDescriptor().getInterceptorBindings();
+         if(bindings != null)
+         {
+            InterceptorOrderImpl interceptorOrder = new InterceptorOrderImpl();
+            for(InterceptorBindingMetaData binding : bindings)
+            {
+               // Only for specifying order
+               if(!binding.isTotalOrdering())
+                  continue;
+               
+               // For the bean
+               if(binding.getMethod() == null)
+                  continue;
+               
+               NamedMethodMetaData method = binding.getMethod();
+               
+               // TODO: this is weird, it should have been caught earlier (invalid xml)
+               if(method.getMethodName() == null)
+                  continue;
+               
+               if(method.getMethodName().equals(methodName))
+               {
+                  MethodParametersMetaData methodParams = method.getMethodParams();
+                  if(methodParams == null)
+                     add(interceptorOrder, classLoader, binding);
+                  else
+                  {
+                     if(Arrays.equals(methodParams.toArray(), parameterNames))
+                        add(interceptorOrder, classLoader, binding);
+                  }
+               }
+            }
+            if(!interceptorOrder.isEmpty())
+               return annotationClass.cast(interceptorOrder);
+         }
+      }
       else if(annotationClass == Interceptors.class)
       {
          InterceptorBindingsMetaData bindings = beanMetaData.getEjbJarMetaData().getAssemblyDescriptor().getInterceptorBindings();
@@ -183,6 +258,10 @@
             InterceptorsImpl interceptors = new InterceptorsImpl();
             for(InterceptorBindingMetaData binding : bindings)
             {
+               // Only for specifying order
+               if(binding.isTotalOrdering())
+                  continue;
+               
                // For the bean
                if(binding.getMethod() == null)
                   continue;
@@ -205,7 +284,7 @@
                   }
                }
             }
-            if(interceptors.value().length > 0)
+            if(!interceptors.isEmpty())
                return annotationClass.cast(interceptors);
          }
       }
@@ -218,6 +297,24 @@
                return annotationClass.cast(lifeCycleAnnotation);
          }
       }
+      else if(annotationClass == PostConstruct.class)
+      {
+         if(beanMetaData instanceof JBossSessionBeanMetaData)
+         {
+            PostConstruct lifeCycleAnnotation = getLifeCycleAnnotation(((JBossSessionBeanMetaData) beanMetaData).getPostConstructs(), PostConstructImpl.class, methodName);
+            if(lifeCycleAnnotation != null)
+               return annotationClass.cast(lifeCycleAnnotation);
+         }
+      }
+      else if(annotationClass == PreDestroy.class)
+      {
+         if(beanMetaData instanceof JBossSessionBeanMetaData)
+         {
+            PreDestroy lifeCycleAnnotation = getLifeCycleAnnotation(((JBossSessionBeanMetaData) beanMetaData).getPreDestroys(), PreDestroyImpl.class, methodName);
+            if(lifeCycleAnnotation != null)
+               return annotationClass.cast(lifeCycleAnnotation);
+         }
+      }
       else if(annotationClass == PrePassivate.class)
       {
          if(beanMetaData instanceof JBossSessionBeanMetaData)

Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/InterceptorMetaDataBridge.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/InterceptorMetaDataBridge.java	2008-04-11 14:05:35 UTC (rev 72022)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/InterceptorMetaDataBridge.java	2008-04-11 14:10:23 UTC (rev 72023)
@@ -23,11 +23,15 @@
 
 import java.lang.annotation.Annotation;
 
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
 import javax.ejb.PostActivate;
 import javax.ejb.PrePassivate;
 import javax.interceptor.AroundInvoke;
 
 import org.jboss.ejb3.interceptors.annotation.impl.PostActivateImpl;
+import org.jboss.ejb3.interceptors.annotation.impl.PostConstructImpl;
+import org.jboss.ejb3.interceptors.annotation.impl.PreDestroyImpl;
 import org.jboss.ejb3.interceptors.annotation.impl.PrePassivateImpl;
 import org.jboss.ejb3.metadata.MetaDataBridge;
 import org.jboss.logging.Logger;
@@ -37,7 +41,7 @@
  * Comment
  *
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
  */
 public class InterceptorMetaDataBridge extends EnvironmentInterceptorMetaDataBridge<InterceptorMetaData> implements MetaDataBridge<InterceptorMetaData>
 {
@@ -64,6 +68,18 @@
          if(lifeCycleAnnotation != null)
             return annotationClass.cast(lifeCycleAnnotation);
       }
+      else if(annotationClass == PostConstruct.class)
+      {
+         PostConstruct lifeCycleAnnotation = getLifeCycleAnnotation(interceptorMetaData.getPostConstructs(), PostConstructImpl.class, methodName);
+         if(lifeCycleAnnotation != null)
+            return annotationClass.cast(lifeCycleAnnotation);
+      }
+      else if(annotationClass == PreDestroy.class)
+      {
+         PreDestroy lifeCycleAnnotation = getLifeCycleAnnotation(interceptorMetaData.getPreDestroys(), PreDestroyImpl.class, methodName);
+         if(lifeCycleAnnotation != null)
+            return annotationClass.cast(lifeCycleAnnotation);
+      }
       else if(annotationClass == PrePassivate.class)
       {
          PrePassivate lifeCycleAnnotation = getLifeCycleAnnotation(interceptorMetaData.getPrePassivates(), PrePassivateImpl.class, methodName);

Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/registry/InterceptorRegistry.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/registry/InterceptorRegistry.java	2008-04-11 14:05:35 UTC (rev 72022)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/registry/InterceptorRegistry.java	2008-04-11 14:10:23 UTC (rev 72023)
@@ -23,6 +23,7 @@
 
 import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -34,6 +35,7 @@
 
 import org.jboss.aop.Advisor;
 import org.jboss.ejb3.interceptors.aop.annotation.DefaultInterceptors;
+import org.jboss.ejb3.interceptors.aop.annotation.InterceptorOrder;
 import org.jboss.ejb3.interceptors.lang.ClassHelper;
 import org.jboss.logging.Logger;
 
@@ -141,10 +143,18 @@
             methodApplicableInterceptorClasses.addAll(classInterceptorClasses);
          methodApplicableInterceptorClasses.addAll(methodInterceptorClasses);
          
-         // TODO: remove duplicates
-         // TODO: total ordering (EJB 3 12.8.2.1 and @Interceptors with all)
+         // TODO: remove duplicates?
          
-         applicableInterceptorClasses.put(beanMethod, methodApplicableInterceptorClasses);
+         // Total ordering (EJB 3 12.8.2.1)
+         // TODO: @Interceptors with all?
+         InterceptorOrder order = (InterceptorOrder) advisor.resolveAnnotation(beanMethod, InterceptorOrder.class);
+         if(order == null)
+            order = (InterceptorOrder) advisor.resolveAnnotation(InterceptorOrder.class);
+         // TODO: validate the order to see if all interceptors are listed
+         if(order != null)
+            applicableInterceptorClasses.put(beanMethod, Arrays.asList(order.value()));
+         else
+            applicableInterceptorClasses.put(beanMethod, methodApplicableInterceptorClasses);
       }
    }
    

Added: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/util/InterceptorCollection.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/util/InterceptorCollection.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/util/InterceptorCollection.java	2008-04-11 14:10:23 UTC (rev 72023)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.interceptors.util;
+
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+/**
+ * A collection of interceptor classes.
+ * 
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InterceptorCollection
+{
+   private Set<Class<?>> values = new LinkedHashSet<Class<?>>();
+   
+   public boolean addValue(Class<?> interceptorClass)
+   {
+      return values.add(interceptorClass);
+   }
+   
+   public boolean isEmpty()
+   {
+      return values.isEmpty();
+   }
+
+   public Class<?>[] value()
+   {
+      return values.toArray(new Class<?>[0]);
+   }
+}

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/order/InterceptorA.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/order/InterceptorA.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/order/InterceptorA.java	2008-04-11 14:10:23 UTC (rev 72023)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.interceptors.order;
+
+import java.util.List;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InterceptorA
+{
+   @AroundInvoke
+   public Object aroundInvoke(InvocationContext ctx) throws Exception
+   {
+      List<String> list = (List<String>) ctx.getParameters()[0];
+      list.add("A");
+      return ctx.proceed();
+   }
+}

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/order/InterceptorB.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/order/InterceptorB.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/order/InterceptorB.java	2008-04-11 14:10:23 UTC (rev 72023)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.interceptors.order;
+
+import java.util.List;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InterceptorB
+{
+   @AroundInvoke
+   public Object aroundInvoke(InvocationContext ctx) throws Exception
+   {
+      List<String> list = (List<String>) ctx.getParameters()[0];
+      list.add("B");
+      return ctx.proceed();
+   }
+}

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/order/InterceptorChainBean.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/order/InterceptorChainBean.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/order/InterceptorChainBean.java	2008-04-11 14:10:23 UTC (rev 72023)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.interceptors.order;
+
+import java.util.List;
+
+import javax.interceptor.Interceptors;
+
+import org.jboss.ejb3.interceptors.ManagedObject;
+
+/**
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at ManagedObject
+ at Interceptors({InterceptorA.class, InterceptorB.class})
+public class InterceptorChainBean
+{
+   //@Interceptors({InterceptorA.class, InterceptorB.class})
+   public void createInterceptorChain(List<String> chain)
+   {
+      chain.add("BEAN");
+   }
+}

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/order/unit/InterceptorChainTestCase.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/order/unit/InterceptorChainTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/order/unit/InterceptorChainTestCase.java	2008-04-11 14:10:23 UTC (rev 72023)
@@ -0,0 +1,152 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.interceptors.order.unit;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.AspectXmlLoader;
+import org.jboss.ejb3.interceptors.container.BeanContext;
+import org.jboss.ejb3.interceptors.direct.AbstractDirectContainer;
+import org.jboss.ejb3.interceptors.metadata.BeanInterceptorMetaDataBridge;
+import org.jboss.ejb3.interceptors.metadata.InterceptorComponentMetaDataLoaderFactory;
+import org.jboss.ejb3.interceptors.metadata.InterceptorMetaDataBridge;
+import org.jboss.ejb3.metadata.MetaDataBridge;
+import org.jboss.ejb3.metadata.annotation.AnnotationRepositoryToMetaData;
+import org.jboss.ejb3.test.interceptors.metadata.MetadataBean;
+import org.jboss.ejb3.test.interceptors.order.InterceptorChainBean;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.jboss.JBoss50MetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.spec.EjbJar30MetaData;
+import org.jboss.metadata.ejb.spec.InterceptorMetaData;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
+import org.jboss.xb.builder.JBossXBBuilder;
+import org.w3c.dom.ls.LSInput;
+
+/**
+ * Test ordering of interceptors.
+ * 
+ * There is no special class loader needed, because all invocations
+ * are routed through the direct container.
+ * 
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: 71802 $
+ */
+public class InterceptorChainTestCase extends TestCase
+{
+   private static final Logger log = Logger.getLogger(InterceptorChainTestCase.class);
+   
+   private class MyContainer<T> extends AbstractDirectContainer<T, MyContainer<T>>
+   {
+      public MyContainer(String name, String domainName, Class<? extends T> beanClass, JBossEnterpriseBeanMetaData beanMetaData)
+      {
+         super();
+         
+         ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+         AnnotationRepositoryToMetaData annotations = new AnnotationRepositoryToMetaData(beanClass, beanMetaData, name, classLoader);
+         List<MetaDataBridge<InterceptorMetaData>> interceptorBridges = new ArrayList<MetaDataBridge<InterceptorMetaData>>();
+         interceptorBridges.add(new InterceptorMetaDataBridge());
+         annotations.addComponentMetaDataLoaderFactory(new InterceptorComponentMetaDataLoaderFactory(interceptorBridges));
+         annotations.addMetaDataBridge(new BeanInterceptorMetaDataBridge());
+         
+         initializeAdvisor(name, getDomain(domainName), beanClass, annotations);
+      }
+
+      public void testAdvisor()
+      {
+         MyContainer<?> container = getAdvisor().getContainer();
+         assertNotNull("container not set in managed object advisor", container);
+         assertTrue(container == this);
+      }
+   }
+   
+   protected static SchemaBindingResolver schemaResolverForClass(final Class<?> root)
+   {
+      return new SchemaBindingResolver()
+      {
+         public String getBaseURI()
+         {
+            return null;
+         }
+
+         public SchemaBinding resolve(String nsUri, String baseURI, String schemaLocation)
+         {
+            return JBossXBBuilder.build(root);
+         }
+
+         public LSInput resolveAsLSInput(String nsUri, String baseUri, String schemaLocation)
+         {
+            return null;
+         }
+
+         public void setBaseURI(String baseURI)
+         {
+         }
+      };
+   }
+
+   public void test() throws Throwable
+   {
+      AspectManager.verbose = true;
+      
+      // To make surefire happy
+      Thread.currentThread().setContextClassLoader(MetadataBean.class.getClassLoader());
+      
+      // Bootstrap AOP
+      // FIXME: use the right jboss-aop.xml
+      URL url = Thread.currentThread().getContextClassLoader().getResource("proxy/jboss-aop.xml");
+      log.info("deploying AOP from " + url);
+      AspectXmlLoader.deployXML(url);
+      
+      // Bootstrap metadata
+      UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory.newInstance();
+      Unmarshaller unmarshaller = unmarshallerFactory.newUnmarshaller();
+      url = Thread.currentThread().getContextClassLoader().getResource("order/META-INF/ejb-jar.xml");
+      EjbJar30MetaData metaData = (EjbJar30MetaData) unmarshaller.unmarshal(url.toString(), schemaResolverForClass(EjbJar30MetaData.class));
+      JBoss50MetaData jbossMetaData = new JBoss50MetaData();
+      jbossMetaData.merge(null, metaData);
+      
+      JBossEnterpriseBeanMetaData beanMetaData = jbossMetaData.getEnterpriseBean("InterceptorChainBean");
+      assertNotNull(beanMetaData);
+      
+      MyContainer<InterceptorChainBean> container = new MyContainer<InterceptorChainBean>("InterceptorChainBean", "Test", InterceptorChainBean.class, beanMetaData);
+      container.testAdvisor();
+      
+      BeanContext<InterceptorChainBean> bean = container.construct();
+      
+      List<String> chain = new ArrayList<String>();
+      container.invoke(bean, "createInterceptorChain", chain);
+      
+      assertEquals(Arrays.asList("B", "A", "BEAN"), chain);
+      
+      bean = null;
+   }
+}

Added: projects/ejb3/trunk/interceptors/src/test/resources/order/META-INF/ejb-jar.xml
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/resources/order/META-INF/ejb-jar.xml	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/resources/order/META-INF/ejb-jar.xml	2008-04-11 14:10:23 UTC (rev 72023)
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ejb-jar
+        xmlns="http://java.sun.com/xml/ns/javaee"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+                            http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
+        version="3.0">
+    <display-name>InterceptorsTest</display-name>
+    <!-- Must define a bean here, because we have no annotation on it -->
+    <!-- (Can't use @Stateless within ejb3-interceptors) -->
+    <enterprise-beans>
+    	<session>
+    		<ejb-name>InterceptorChainBean</ejb-name>
+    	</session>
+    </enterprise-beans>
+    <!--
+    <interceptors>
+		<interceptor>
+			<interceptor-class>org.jboss.ejb3.test.interceptors.common.CommonInterceptor</interceptor-class>
+			<around-invoke>
+				<method-name>aroundInvoke</method-name>
+			</around-invoke>
+		</interceptor>	   
+    </interceptors>
+    -->
+    <assembly-descriptor>
+    	<interceptor-binding>
+    		<ejb-name>InterceptorChainBean</ejb-name>
+    		<interceptor-order>
+    			<interceptor-class>org.jboss.ejb3.test.interceptors.order.InterceptorB</interceptor-class>
+    			<interceptor-class>org.jboss.ejb3.test.interceptors.order.InterceptorA</interceptor-class>
+    		</interceptor-order>
+    	</interceptor-binding>
+    </assembly-descriptor>
+</ejb-jar>
\ No newline at end of file




More information about the jboss-cvs-commits mailing list