Author: struberg
Date: Sat Jan 19 22:09:19 2013
New Revision: 1435734

URL: http://svn.apache.org/viewvc?rev=1435734&view=rev
Log:
OWB-344 add detection of errors for @AroundInvoke interceptors

Modified:
    
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/AbstractUnitTest.java
    
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/exception/ExceptionComponentTest.java

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=1435734&r1=1435733&r2=1435734&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
 Sat Jan 19 22:09:19 2013
@@ -30,9 +30,11 @@ import javax.enterprise.inject.spi.Injec
 import javax.enterprise.inject.spi.InterceptionType;
 import javax.interceptor.AroundInvoke;
 import javax.interceptor.AroundTimeout;
+import javax.interceptor.InvocationContext;
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -45,6 +47,7 @@ import org.apache.webbeans.config.WebBea
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.inject.impl.InjectionPointFactory;
 import org.apache.webbeans.plugins.OpenWebBeansEjbLCAPlugin;
+import org.apache.webbeans.util.ClassUtil;
 
 
 /**
@@ -191,6 +194,7 @@ public abstract class InterceptorBeanBui
                         {
                             throw new WebBeansConfigurationException("only one 
AroundInvoke allowed per Interceptor");
                         }
+                        checkAroundInvokeConditions(m);
                         aroundInvokeMethod = m;
                     }
 
@@ -288,6 +292,42 @@ public abstract class InterceptorBeanBui
         return interceptorFound;
     }
 
+    private void checkAroundInvokeConditions(AnnotatedMethod method)
+    {
+        AnnotatedType annotatedType = method.getDeclaringType();
+
+        List<AnnotatedParameter<T>> parameters = method.getParameters();
+        List<Class<?>> clazzParameters = new ArrayList<Class<?>>();
+        for(AnnotatedParameter<T> parameter : parameters)
+        {
+            clazzParameters.add(ClassUtil.getClazz(parameter.getBaseType()));
+        }
+
+        Class<?>[] params = clazzParameters.toArray(new 
Class<?>[clazzParameters.size()]);
+
+        if (params.length != 1 || !params[0].equals(InvocationContext.class))
+        {
+            throw new WebBeansConfigurationException("@AroundInvoke annotated 
method : "
+                    + method.getJavaMember().getName() + " in class : " + 
annotatedType.getJavaClass().getName()
+                    + " can not take any formal arguments other than 
InvocationContext");
+        }
+
+        if (!method.getJavaMember().getReturnType().equals(Object.class))
+        {
+            throw new WebBeansConfigurationException("@AroundInvoke annotated 
method : "
+                    + method.getJavaMember().getName()+ " in class : " + 
annotatedType.getJavaClass().getName()
+                    + " must return Object type");
+        }
+
+        if (Modifier.isStatic(method.getJavaMember().getModifiers()) ||
+                Modifier.isFinal(method.getJavaMember().getModifiers()))
+        {
+            throw new WebBeansConfigurationException("@AroundInvoke annotated 
method : "
+                    + method.getJavaMember().getName( )+ " in class : " + 
annotatedType.getJavaClass().getName()
+                    + " can not be static or final");
+        }
+    }
+
     /**
      * @return the a Method array with the native members of the 
AnnotatedMethod list
      */

Modified: 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/AbstractUnitTest.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/AbstractUnitTest.java?rev=1435734&r1=1435733&r2=1435734&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/AbstractUnitTest.java
 (original)
+++ 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/AbstractUnitTest.java
 Sat Jan 19 22:09:19 2013
@@ -193,4 +193,26 @@ public abstract class AbstractUnitTest
     public void addExtension(Extension ext) {
         this.extensions.add(ext);
     }
+
+    /**
+     * Add the given interceptor class to get picked up
+     * by startContainer.
+     * This has the same effect as adding it to the
+     * &lt;interceptors&gt; section in beans.xml.
+     */
+    public void addInterceptor(Class interceptorClass)
+    {
+        interceptors.add(interceptorClass);
+    }
+
+    /**
+     * Add the given interceptor class to get picked up
+     * by startContainer.
+     * This has the same effect as adding it to the
+     * &lt;interceptors&gt; section in beans.xml.
+     */
+    public void addDecorator(Class decoratorClass)
+    {
+        decorators.add(decoratorClass);
+    }
 }

Modified: 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/exception/ExceptionComponentTest.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/exception/ExceptionComponentTest.java?rev=1435734&r1=1435733&r2=1435734&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/exception/ExceptionComponentTest.java
 (original)
+++ 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/exception/ExceptionComponentTest.java
 Sat Jan 19 22:09:19 2013
@@ -295,6 +295,7 @@ public class ExceptionComponentTest exte
     {
         try
         {
+
             startContainer(AroundInvokeWithoutParameterComponent.class);
         }
         catch (WebBeansConfigurationException e)


Reply via email to