Author: arne
Date: Fri Jan  4 07:09:40 2013
New Revision: 1428732

URL: http://svn.apache.org/viewvc?rev=1428732&view=rev
Log:
OWB-745: Aligned methods checkCommonsAnnotationCriterias

Modified:
    
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
    
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptorBean.java
    
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java

Modified: 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java?rev=1428732&r1=1428731&r2=1428732&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
 (original)
+++ 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
 Fri Jan  4 07:09:40 2013
@@ -290,13 +290,13 @@ public final class WebBeansInterceptorCo
                 // interceptor binding
                 
webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor, 
annotatedType,
                                                                              
AroundInvoke.class, true,
-                                                                             
false, stack, null);
+                                                                             
false, stack, null, true);
                 
webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor, 
annotatedType,
                                                                              
PostConstruct.class, true,
-                                                                             
false, stack, null);
+                                                                             
false, stack, null, true);
                 
webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor, 
annotatedType,
                                                                              
PreDestroy.class, true,
-                                                                             
false, stack, null);
+                                                                             
false, stack, null, true);
 
                 if (null != ejbPlugin)
                 {
@@ -304,12 +304,12 @@ public final class WebBeansInterceptorCo
                                                                                
  annotatedType,
                                                                                
  prePassivateClass,
                                                                                
  true, false, stack,
-                                                                               
  null);
+                                                                               
  null, true);
                     
webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor,
                                                                                
  annotatedType,
                                                                                
  postActivateClass,
                                                                                
  true, false, stack,
-                                                                               
  null);
+                                                                               
  null, true);
 
                 }
             }
@@ -553,17 +553,17 @@ public final class WebBeansInterceptorCo
                                                                                
      interAnnoType,
                                                                                
      AroundInvoke.class,
                                                                                
      true, true, stack,
-                                                                               
      method);
+                                                                               
      method, true);
                         
webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor,
                                                                                
      interAnnoType,
                                                                                
      PostConstruct.class,
                                                                                
      true, true, stack,
-                                                                               
      method);
+                                                                               
      method, true);
                         
webBeansContext.getWebBeansUtil().configureInterceptorMethods(interceptor,
                                                                                
      interAnnoType,
                                                                                
      PreDestroy.class,
                                                                                
      true, true, stack,
-                                                                               
      method);
+                                                                               
      method, true);
                     }
                 }
             }

Modified: 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptorBean.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptorBean.java?rev=1428732&r1=1428731&r2=1428732&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptorBean.java
 (original)
+++ 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptorBean.java
 Fri Jan  4 07:09:40 2013
@@ -268,9 +268,8 @@ public class WebBeansInterceptorBean<T> 
         {
             Class<? extends Annotation> interceptorTypeAnnotationClazz =
                 
webBeansContext.getInterceptorUtil().getInterceptorAnnotationClazz(type);
-            method = 
getWebBeansContext().getWebBeansUtil().checkCommonAnnotationCriterias(getClazz(),
-                                                                               
                      interceptorTypeAnnotationClazz,
-                                                                               
                      true);
+            method
+                = 
getWebBeansContext().getWebBeansUtil().checkCommonAnnotationCriterias(getClazz(),
 interceptorTypeAnnotationClazz, true);
         }
         
         return method;

Modified: 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=1428732&r1=1428731&r2=1428732&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
 (original)
+++ 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
 Fri Jan  4 07:09:40 2013
@@ -819,7 +819,7 @@ public final class WebBeansUtil
         Class<?> clazz = annotatedType.getJavaClass();
 
         Method result = null;
-        boolean found = false;
+        Set<Class<?>> foundInClass = new HashSet<Class<?>>();
         Set<AnnotatedMethod<? super T>> methods = annotatedType.getMethods();
         for(AnnotatedMethod<? super T> methodA : methods)
         {
@@ -832,33 +832,18 @@ public final class WebBeansUtil
                     continue;
                 }
 
-                if (found)
+                if (foundInClass.contains(method.getDeclaringClass()))
                 {
                     throw new WebBeansConfigurationException("@" + 
commonAnnotation.getSimpleName()
                             + " annotation is declared more than one method in 
the class : " + clazz.getName());
                 }
-                found = true;
+                foundInClass.add(method.getDeclaringClass());
                 result = method;
 
                 // Check method criterias
-                if (methodB.getParameters().isEmpty())
+                if (!methodB.getParameters().isEmpty())
                 {
-                    if (!invocationContext)
-                    {
-                        throw new WebBeansConfigurationException("@" + 
commonAnnotation.getSimpleName()
-                                + " annotated method : " + method.getName() + 
" in class : " + clazz.getName()
-                                + " can not take any formal arguments");
-                    }
-
-                    List<AnnotatedParameter<T>> parameters = 
methodB.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))
+                    if (methodB.getParameters().size() != 1 || 
!ClassUtil.getClass(methodB.getParameters().get(0).getBaseType()).equals(InvocationContext.class))
                     {
                         throw new WebBeansConfigurationException("@" + 
commonAnnotation.getSimpleName()
                                 + " annotated method : " + method.getName() + 
" in class : " + clazz.getName()
@@ -867,9 +852,8 @@ public final class WebBeansUtil
                 }
                 else if(invocationContext)
                 {
-                    throw new WebBeansConfigurationException("@" + 
commonAnnotation.getSimpleName()
-                            + " annotated method : " + method.getName() + " in 
class : " + clazz.getName()
-                            + " must take a parameter with class type 
javax.interceptor.InvocationContext.");
+                    // Maybe it just intercepts itself, but we were looking at 
it like an @Interceptor
+                    return null;
                 }
 
                 if (!method.getReturnType().equals(Void.TYPE))
@@ -1116,7 +1100,8 @@ public final class WebBeansUtil
                                                  boolean 
definedInInterceptorClass,
                                                  boolean definedInMethod,
                                                  List<InterceptorData> stack,
-                                                 Method 
annotatedInterceptorClassMethod)
+                                                 Method 
annotatedInterceptorClassMethod,
+                                                 boolean 
defineWithInterceptorBinding)
     {
         InterceptorData intData;
         Method method = null;
@@ -1131,6 +1116,20 @@ public final class WebBeansUtil
             postActivateClass  = ejbPlugin.getPostActivateClass();
         }
 
+        //Check for default constructor of EJB based interceptor
+        if(webBeansInterceptor == null)
+        {
+            if(definedInInterceptorClass)
+            {
+                Constructor<?> ct = 
getNoArgConstructor(annotatedType.getJavaClass());
+                if (ct == null)
+                {
+                    throw new WebBeansConfigurationException("class : " + 
annotatedType.getJavaClass().getName()
+                            + " must have no-arg constructor");
+                }
+            }
+        }
+
         if (annotation.equals(AroundInvoke.class) ||
                 annotation.equals(AroundTimeout.class))
         {
@@ -1144,14 +1143,18 @@ public final class WebBeansUtil
 
         if (method != null)
         {
-            intData = new InterceptorDataImpl(true, webBeansContext);
+            intData = new InterceptorDataImpl(defineWithInterceptorBinding, 
webBeansContext);
             intData.setDefinedInInterceptorClass(definedInInterceptorClass);
             intData.setDefinedInMethod(definedInMethod);
             
intData.setInterceptorBindingMethod(annotatedInterceptorClassMethod);
             intData.setWebBeansInterceptor(webBeansInterceptor);
-            intData.setInterceptorMethod(method, annotation);
-            intData.setInterceptorClass(webBeansInterceptor.getBeanClass());
 
+            if (definedInInterceptorClass)
+            {
+                intData.setInterceptorClass(annotatedType.getJavaClass());
+            }
+
+            intData.setInterceptorMethod(method, annotation);
             stack.add(intData);
         }
     }


Reply via email to