openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1655830 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation: CdiInterceptorBeanBuilder.java InterceptorBeanBuilder.java
Date Thu, 29 Jan 2015 19:38:21 GMT
Author: rmannibucau
Date: Thu Jan 29 19:38:21 2015
New Revision: 1655830

URL: http://svn.apache.org/r1655830
Log:
validate @Target for lifecycle only interceptors

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java?rev=1655830&r1=1655829&r2=1655830&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java
Thu Jan 29 19:38:21 2015
@@ -21,9 +21,12 @@ package org.apache.webbeans.component.cr
 
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.BeanAttributes;
+import javax.enterprise.inject.spi.DefinitionException;
 import javax.enterprise.inject.spi.InterceptionType;
 
 import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
 import java.lang.reflect.Method;
 import java.util.Collections;
 import java.util.Map;
@@ -34,6 +37,8 @@ import org.apache.webbeans.config.WebBea
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.util.ArrayUtil;
 
+import static java.util.Arrays.asList;
+
 /**
  * Bean builder for {@link org.apache.webbeans.component.InterceptorBean}s.
  */
@@ -52,6 +57,7 @@ public class CdiInterceptorBeanBuilder<T
         checkInterceptorConditions();
         defineInterceptorMethods();
         defineInterceptorBindings();
+        validateTarget();
 
         // make sure that CDI interceptors do not have any Producer methods or a method with
@Observes
         validateNoProducerOrObserverMethod(annotatedType);
@@ -61,6 +67,30 @@ public class CdiInterceptorBeanBuilder<T
                 Collections.emptySet(), Collections.emptySet(), Collections.emptySet());
     }
 
+    private void validateTarget()
+    {
+        final boolean isLifecycleOnly = ( // spec seems to be more strict but breaks apps
+ does it really makes sense?
+                        interceptionMethods.containsKey(InterceptionType.POST_CONSTRUCT)
+                        || interceptionMethods.containsKey(InterceptionType.PRE_DESTROY))
+                            &&
+                        !(interceptionMethods.containsKey(InterceptionType.AROUND_INVOKE)
+                        || interceptionMethods.containsKey(InterceptionType.AROUND_TIMEOUT)
+                        || interceptionMethods.containsKey(InterceptionType.AROUND_CONSTRUCT));
+        if (isLifecycleOnly && interceptorBindings != null)
+        {
+            for (Annotation a : interceptorBindings)
+            {
+                Target target = a.annotationType().getAnnotation(Target.class);
+                if (target == null || !asList(target.value()).equals(asList(ElementType.TYPE)))
+                {
+                    throw new DefinitionException(
+                            a.annotationType().getName() + " doesn't have strictly @Target(TYPE)
but has lifecycle methods. " +
+                                    "Interceptor: " + annotatedType.getJavaClass().getName());
+                }
+            }
+        }
+    }
+
     @Override
     public boolean isInterceptorEnabled()
     {

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=1655830&r1=1655829&r2=1655830&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
Thu Jan 29 19:38:21 2015
@@ -62,7 +62,7 @@ public abstract class InterceptorBeanBui
     private final Class<? extends Annotation> prePassivateClass;
     private final Class<? extends Annotation> postActivateClass;
 
-    private Map<InterceptionType, Method[]> interceptionMethods;
+    protected Map<InterceptionType, Method[]> interceptionMethods;
 
     protected InterceptorBeanBuilder(WebBeansContext webBeansContext, AnnotatedType<T>
annotatedType, BeanAttributes<T> beanAttributes)
     {



Mime
View raw message