openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1432224 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/ main/java/org/apache/webbeans/component/creation/ test/java/org/apache/webbeans/newtests/interceptors/resolution/
Date Fri, 11 Jan 2013 18:51:16 GMT
Author: struberg
Date: Fri Jan 11 18:51:15 2013
New Revision: 1432224

URL: http://svn.apache.org/viewvc?rev=1432224&view=rev
Log:
OWB-344 interceptor checks continued

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InterceptorBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorBeanBuilderTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InterceptorBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InterceptorBean.java?rev=1432224&r1=1432223&r2=1432224&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InterceptorBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InterceptorBean.java
Fri Jan 11 18:51:15 2013
@@ -25,6 +25,7 @@ import javax.enterprise.inject.spi.Inter
 import javax.interceptor.InvocationContext;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
+import java.util.Collections;
 import java.util.Map;
 import java.util.Set;
 
@@ -50,7 +51,7 @@ public abstract class InterceptorBean<T>
         super(webBeansContext, WebBeansType.INTERCEPTOR, annotatedType.getJavaClass(), annotatedType);
     }
 
-    private Set<InterceptionType> intercepts;
+    private Set<InterceptionType> intercepts = Collections.EMPTY_SET;
 
     /**
      * The Methods to be called for InterceptionType.AROUND_INVOKE.
@@ -147,7 +148,7 @@ public abstract class InterceptorBean<T>
      * @param interceptionType
      * @return the underlying interceptor method for the given InterceptionType or <code>null</code>
      */
-    protected Method[] getInterceptorMethods(InterceptionType interceptionType)
+    public Method[] getInterceptorMethods(InterceptionType interceptionType)
     {
         if (InterceptionType.AROUND_INVOKE.equals(interceptionType))
         {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java?rev=1432224&r1=1432223&r2=1432224&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
Fri Jan 11 18:51:15 2013
@@ -26,6 +26,7 @@ import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.Type;
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -115,6 +116,23 @@ public abstract class AbstractBeanBuilde
     }
 
     /**
+     * @return the Type hierarchy in the order subclass first. Object.class is <b>not</b>
included!
+     */
+    protected List<Class> getClassHierarchy()
+    {
+        List<Class> hierarchy = new ArrayList<Class>();
+        Class clazz = getBeanType();
+        while (clazz != Object.class)
+        {
+            hierarchy.add(clazz);
+            clazz = clazz.getSuperclass();
+        }
+
+        return hierarchy;
+    }
+
+
+    /**
      * {@inheritDoc}
      */
     public void defineApiType()

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java?rev=1432224&r1=1432223&r2=1432224&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java
Fri Jan 11 18:51:15 2013
@@ -22,7 +22,11 @@ import javax.enterprise.context.Dependen
 import javax.enterprise.inject.Produces;
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.InterceptionType;
+import javax.interceptor.AroundInvoke;
 
+import java.lang.reflect.Method;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -35,10 +39,12 @@ import org.apache.webbeans.exception.Web
  */
 public abstract class InterceptorBeanBuilder<T> extends AbstractInjectionTargetBeanBuilder<T>
 {
+    private final InterceptorBean<T> bean;
 
     protected InterceptorBeanBuilder(InterceptorBean<T> bean)
     {
         super(bean, Dependent.class);
+        this.bean = bean;
     }
 
     /**
@@ -68,10 +74,62 @@ public abstract class InterceptorBeanBui
 
     protected void defineInterceptorRules()
     {
+        defineInterceptorMethods();
         defineInjectedMethods();
         defineInjectedFields();
     }
 
+    /**
+     * grab all methods which act as interceptors for the various
+     * {@link javax.enterprise.inject.spi.InterceptionType}s.
+     * This method will also check some rules, e.g. that there must not be
+     * more than a single {@link javax.interceptor.AroundInvoke} method
+     * on a class.
+     */
+    protected void defineInterceptorMethods()
+    {
+        List<Class> classHierarchy = getClassHierarchy();
+
+        AnnotatedMethod aroundInvokeMethod = null;
+
+        Set<AnnotatedMethod<? super T>> methods = getAnnotated().getMethods();
+
+        for (Class clazz : classHierarchy)
+        {
+
+            for (AnnotatedMethod m : methods)
+            {
+                if (clazz == m.getDeclaringType().getJavaClass())
+                {
+
+                    // we only take methods from this very class and not sub- or superclasses
+                    if (m.getAnnotation(AroundInvoke.class) != null)
+                    {
+                        if (aroundInvokeMethod != null)
+                        {
+                            throw new WebBeansConfigurationException("only one AroundInvoke
allowed per Interceptor");
+                        }
+                        aroundInvokeMethod = m;
+                    }
+
+
+                }
+            }
+        }
+
+        // and now for setting the bean info
+
+        Set<InterceptionType> intercepts = new HashSet<InterceptionType>();
+
+        if (aroundInvokeMethod != null)
+        {
+            bean.setAroundInvokeMethods(new Method[]{aroundInvokeMethod.getJavaMember()});
+            intercepts.add(InterceptionType.AROUND_INVOKE);
+        }
+
+
+        bean.setIntercepts(intercepts);
+    }
 
 
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorBeanBuilderTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorBeanBuilderTest.java?rev=1432224&r1=1432223&r2=1432224&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorBeanBuilderTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorBeanBuilderTest.java
Fri Jan 11 18:51:15 2013
@@ -20,6 +20,7 @@ package org.apache.webbeans.newtests.int
 
 
 import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.InterceptionType;
 import javax.enterprise.inject.spi.Interceptor;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -68,9 +69,14 @@ public class InterceptorBeanBuilderTest 
             ibb.defineCdiInterceptorRules();
             Interceptor<TransactionalInterceptor> bean = ibb.getBean();
             Assert.assertNotNull(bean);
+
             Assert.assertNotNull(bean.getInterceptorBindings());
             Assert.assertEquals(1, bean.getInterceptorBindings().size());
 
+            Assert.assertTrue(bean.intercepts(InterceptionType.AROUND_INVOKE));
+            Assert.assertFalse(bean.intercepts(InterceptionType.AROUND_TIMEOUT));
+            Assert.assertFalse(bean.intercepts(InterceptionType.POST_CONSTRUCT));
+
         }
 
         shutDownContainer();



Mime
View raw message