openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1606601 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: annotation/ component/creation/ config/ container/ event/ inject/impl/ util/
Date Sun, 29 Jun 2014 20:39:51 GMT
Author: arne
Date: Sun Jun 29 20:39:51 2014
New Revision: 1606601

URL: http://svn.apache.org/r1606601
Log:
OWB-981: Implemented validation of observer method injection points and for duplicate @Delegate
injection points

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/DefaultLiteral.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventUtil.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/OwbObserverMethod.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java?rev=1606601&r1=1606600&r2=1606601&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
Sun Jun 29 20:39:51 2014
@@ -22,7 +22,9 @@ import org.apache.webbeans.component.Abs
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
+
 import javax.enterprise.inject.spi.DefinitionException;
+
 import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.ArrayUtil;
 import org.apache.webbeans.util.Asserts;
@@ -42,12 +44,14 @@ import javax.inject.Named;
 import javax.inject.Qualifier;
 import javax.inject.Scope;
 import javax.interceptor.InterceptorBinding;
+
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -69,12 +73,6 @@ public final class AnnotationManager
     private final BeanManagerImpl beanManagerImpl;
     private final WebBeansContext webBeansContext;
 
-    private final static Annotation[] ONLY_DEFAULT_ANNOTATION = new Annotation[1];
-    static
-    {
-        ONLY_DEFAULT_ANNOTATION[0] = DefaultLiteral.INSTANCE;
-    }
-
     // No instantiate
 
     public AnnotationManager(WebBeansContext context)
@@ -342,9 +340,10 @@ public final class AnnotationManager
         return result;
     }
 
-    public Set<Annotation> getQualifierAnnotations(Set<Annotation> annotations)
+    public Annotation[] getQualifierAnnotations(Annotation... annotations)
     {
-        return new HashSet<Annotation>(Arrays.asList(getQualifierAnnotations(annotations.toArray(new
Annotation[annotations.size()]))));
+        Set<Annotation> qualifiers = getQualifierAnnotations(Arrays.asList(annotations));
+        return qualifiers.toArray(new Annotation[qualifiers.size()]);
     }
 
     /**
@@ -353,13 +352,13 @@ public final class AnnotationManager
      * @param annotations annotation array
      * @return array containing qualifier anns
      */
-    public Annotation[] getQualifierAnnotations(Annotation... annotations)
+    public Set<Annotation> getQualifierAnnotations(Collection<Annotation> annotations)
     {
         Asserts.assertNotNull(annotations, "Annotations argument can not be null");
 
-        if (annotations.length == 0)
+        if (annotations.isEmpty())
         {
-            return ONLY_DEFAULT_ANNOTATION;
+            return DefaultLiteral.SET;
         }
 
         Set<Annotation> set = new HashSet<Annotation>();
@@ -373,16 +372,15 @@ public final class AnnotationManager
         }
 
         //Add the default qualifier if no others exist.  Section 3.10, OWB-142///
-        if(set.size() == 0)
+        if(set.isEmpty())
         {
-            return ONLY_DEFAULT_ANNOTATION;
+            return DefaultLiteral.SET;
         }
         ////////////////////////////////////////////////////////////////////////
 
         Annotation[] a = new Annotation[set.size()];
-        a = set.toArray(a);
 
-        return a;
+        return set;
     }
 
     public void checkQualifierConditions(Annotation... qualifierAnnots)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/DefaultLiteral.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/DefaultLiteral.java?rev=1606601&r1=1606600&r2=1606601&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/DefaultLiteral.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/DefaultLiteral.java
Sun Jun 29 20:39:51 2014
@@ -19,6 +19,8 @@
 package org.apache.webbeans.annotation;
 
 import java.lang.annotation.Annotation;
+import java.util.Collections;
+import java.util.Set;
 
 import javax.enterprise.inject.Default;
 
@@ -31,6 +33,7 @@ public class DefaultLiteral extends Empt
 {
     public static final DefaultLiteral INSTANCE = new DefaultLiteral();
     public static final Annotation[] ARRAY = new Annotation[]{DefaultLiteral.INSTANCE};
+    public static final Set<Annotation> SET = Collections.<Annotation>singleton(INSTANCE);

 
     private static final String TOSTRING = "@javax.enterprise.inject.Default()";
     private static final long serialVersionUID = 6788272256977634238L;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java?rev=1606601&r1=1606600&r2=1606601&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java
Sun Jun 29 20:39:51 2014
@@ -18,7 +18,6 @@
  */
 package org.apache.webbeans.component.creation;
 
-import java.lang.reflect.Method;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -69,74 +68,68 @@ public class ObserverMethodsBuilder<T, I
     public Set<ObserverMethod<?>> defineObserverMethods(AbstractOwbBean<T>
bean)
     {   
         Set<ObserverMethod<?>> definedObservers = new HashSet<ObserverMethod<?>>();
-        Set<AnnotatedMethod<? super T>> annotatedMethods = annotatedType.getMethods();
   
-        for (AnnotatedMethod<? super T> annotatedMethod : annotatedMethods)
+        for (AnnotatedMethod<?> annotatedMethod : annotatedType.getMethods())
         {
-            AnnotatedMethod<T> annt = (AnnotatedMethod<T>)annotatedMethod;
-            List<AnnotatedParameter<T>> parameters = annt.getParameters();
-            boolean found = false;
-            for(AnnotatedParameter<T> parameter : parameters)
+            List<AnnotatedParameter<?>> parameters = (List<AnnotatedParameter<?>>)(List<?>)annotatedMethod.getParameters();
+            AnnotatedParameter<?> observesParameter = null;
+            for(AnnotatedParameter<?> parameter : parameters)
             {
                 if(parameter.isAnnotationPresent(Observes.class))
                 {
-                    found = true;
-                    break;
-                }
-            }
-            
-            if(found)
-            {
-                checkObserverMethodConditions((AnnotatedMethod<T>) annotatedMethod,
annotatedMethod.getDeclaringType().getJavaClass());
-                if (bean.getScope().equals(Dependent.class))
-                {
-                    //Check Reception
-                    AnnotatedParameter<?> annotatedParameter = AnnotationUtil.getFirstAnnotatedParameter(annotatedMethod,
Observes.class);
-                    
-                    Observes observes = annotatedParameter.getAnnotation(Observes.class);
-                    Reception reception = observes.notifyObserver();
-                    if(reception.equals(Reception.IF_EXISTS))
+                    if (observesParameter != null)
                     {
-                        throw new WebBeansConfigurationException("Dependent Bean : " + annotatedType.getJavaClass()
+ " can not define observer method with @Receiver = IF_EXIST");
+                        throw new WebBeansConfigurationException("Observer method : " + annotatedMethod.getJavaMember().getName()

+                                + " in class : " + annotatedMethod.getJavaMember().getDeclaringClass().getName()
+                                + " must not define two parameters that are annotated with
@Observes");
                     }
+                    observesParameter = parameter;
                 }
+            }            
+            
+            if(observesParameter != null)
+            {
+                checkObserverMethodConditions(bean, observesParameter);
                 
                 //Looking for ObserverMethod
-                ObserverMethod<?> definedObserver = webBeansContext.getBeanManagerImpl().getNotificationManager().getObservableMethodForAnnotatedMethod(annotatedMethod,
bean);
-                if(definedObserver != null)
-                {
-                    definedObservers.add(definedObserver);
-                }
+                ObserverMethod<?> definedObserver = webBeansContext.getBeanManagerImpl().getNotificationManager().getObservableMethodForAnnotatedMethod(observesParameter,
bean);
+                definedObservers.add(definedObserver);
             }
         }
         
         return definedObservers;
     }
 
-    private void checkObserverMethodConditions(AnnotatedMethod<T> annotatedMethod,
Class<?> clazz)
+    private void checkObserverMethodConditions(AbstractOwbBean<?> bean, AnnotatedParameter<?>
annotatedParameter)
     {
-        Asserts.assertNotNull(annotatedMethod, "annotatedMethod parameter can not be null");
-        Asserts.nullCheckForClass(clazz);
+        Asserts.assertNotNull(annotatedParameter, "annotatedParameter can not be null");
         
-        Method candidateObserverMethod = annotatedMethod.getJavaMember();
-        
-        if (AnnotationUtil.hasAnnotatedMethodMultipleParameterAnnotation(annotatedMethod,
Observes.class))
-        {
-            throw new WebBeansConfigurationException("Observer method : " + candidateObserverMethod.getName()
+ " in class : " + clazz.getName()
-                                                     + " can not define two parameters with
annotated @Observes");
-        }
+        AnnotatedMethod<?> annotatedMethod = (AnnotatedMethod<?>)annotatedParameter.getDeclaringCallable();
 
         if (annotatedMethod.isAnnotationPresent(Produces.class) 
                 || annotatedMethod.isAnnotationPresent(Inject.class))
         {
-            throw new WebBeansConfigurationException("Observer method : " + candidateObserverMethod.getName()
+ " in class : " + clazz.getName()
+            throw new WebBeansConfigurationException("Observer method : " + annotatedMethod.getJavaMember().getName()
+ " in class : " 
+                                                     + annotatedMethod.getJavaMember().getDeclaringClass().getName()
                                                      + " can not annotated with annotation
in the list {@Produces, @Initializer, @Destructor}");
 
         }
 
         if (AnnotationUtil.hasAnnotatedMethodParameterAnnotation(annotatedMethod, Disposes.class))
         {
-            throw new WebBeansConfigurationException("Observer method : " + candidateObserverMethod.getName()
+ " in class : "
-                                                     + clazz.getName() + " can not annotated
with annotation @Disposes");
+            throw new WebBeansConfigurationException("Observer method : " + annotatedMethod.getJavaMember().getName()
+ " in class : "
+                                                     + annotatedMethod.getJavaMember().getDeclaringClass().getName()
+                                                     + " can not annotated with annotation
@Disposes");
         }                
+
+        if (bean.getScope().equals(Dependent.class))
+        {
+            //Check Reception
+            Observes observes = annotatedParameter.getAnnotation(Observes.class);
+            Reception reception = observes.notifyObserver();
+            if(reception.equals(Reception.IF_EXISTS))
+            {
+                throw new WebBeansConfigurationException("Dependent Bean : " + annotatedType.getJavaClass()
+ " can not define observer method with @Receiver = IF_EXIST");
+            }
+        }
     }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java?rev=1606601&r1=1606600&r2=1606601&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
Sun Jun 29 20:39:51 2014
@@ -43,6 +43,7 @@ import org.apache.webbeans.corespi.se.De
 import org.apache.webbeans.decorator.DecoratorsManager;
 import org.apache.webbeans.deployment.StereoTypeModel;
 import org.apache.webbeans.event.ObserverMethodImpl;
+import org.apache.webbeans.event.OwbObserverMethod;
 import org.apache.webbeans.portable.events.ProcessBeanAttributesImpl;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.exception.WebBeansDeploymentException;
@@ -54,6 +55,7 @@ import javax.enterprise.inject.Vetoed;
 import javax.enterprise.inject.spi.BeanAttributes;
 import javax.enterprise.inject.spi.DefinitionException;
 import javax.enterprise.inject.spi.DeploymentException;
+
 import org.apache.webbeans.inject.AlternativesManager;
 import org.apache.webbeans.intercept.InterceptorsManager;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
@@ -94,6 +96,7 @@ import javax.enterprise.inject.spi.Decor
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.Interceptor;
 import javax.enterprise.inject.spi.ObserverMethod;
+
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
@@ -510,39 +513,33 @@ public class BeansDeployer
         webBeansContext.getDecoratorsManager().validateDecoratorClasses();
         webBeansContext.getInterceptorsManager().validateInterceptorClasses();
 
-        Set<Bean<?>> beans = new HashSet<Bean<?>>();
-        
         //Adding decorators to validate
         Set<Decorator<?>> decorators = webBeansContext.getDecoratorsManager().getDecorators();
 
-        beans.addAll(decorators);
-
-        
         logger.fine("Validation of the decorator's injection points has started.");
         
         //Validate Decorators
-        validate(beans);
-        
-        beans.clear();
+        validate(decorators);
         
         //Adding interceptors to validate
         List<javax.enterprise.inject.spi.Interceptor<?>> interceptors = webBeansContext.getInterceptorsManager().getCdiInterceptors();
-        for(javax.enterprise.inject.spi.Interceptor interceptor : interceptors)
-        {
-            beans.add(interceptor);
-        }
         
         logger.fine("Validation of the interceptor's injection points has started.");
         
         //Validate Interceptors
-        validate(beans);
+        validate(interceptors);
+
+        logger.fine("Validation of the beans' injection points has started.");
+
+        Set<Bean<?>> beans = webBeansContext.getBeanManagerImpl().getBeans();
         
-        beans.clear();
+        //Validate Others
+        validate(beans);
         
-        beans = webBeansContext.getBeanManagerImpl().getBeans();
+        logger.fine("Validation of the observer methods' injection points has started.");
         
-        //Validate Others
-        validate(beans);                
+        //Validate Observers
+        validateObservers(webBeansContext.getBeanManagerImpl().getNotificationManager().getObserverMethods());
 
         logger.info(OWBLogConst.INFO_0003);
     }
@@ -552,7 +549,7 @@ public class BeansDeployer
      * 
      * @param beans deployed beans
      */
-    private <T> void validate(Set<Bean<?>> beans)
+    private <T, B extends Bean<?>> void validate(Collection<B> beans)
     {
         BeanManagerImpl manager = webBeansContext.getBeanManagerImpl();
         
@@ -617,23 +614,7 @@ public class BeansDeployer
                 //Check injection points
                 if(injectionPoints != null)
                 {
-                    for (InjectionPoint injectionPoint : injectionPoints)
-                    {
-                        if(!injectionPoint.isDelegate())
-                        {
-                            manager.validate(injectionPoint);   
-                        }
-                        else
-                        {
-                            if(!bean.getBeanClass().isAnnotationPresent(javax.decorator.Decorator.class)
-                                    && !webBeansContext.getDecoratorsManager().containsCustomDecoratorClass(bean.getBeanClass()))
-                            {
-                                throw new WebBeansConfigurationException(
-                                        "Delegate injection points can not defined by beans
that are not decorator. Injection point : "
-                                        + injectionPoint);
-                            }
-                        }
-                    }                    
+                    validate(injectionPoints, bean instanceof Decorator);               
    
                 }
             }
             
@@ -646,6 +627,49 @@ public class BeansDeployer
         }
         
     }
+    
+    private void validateObservers(Collection<ObserverMethod<?>> observerMethods)
+    {
+        for (ObserverMethod<?> observerMethod: observerMethods)
+        {
+            if (observerMethod instanceof OwbObserverMethod)
+            {
+                OwbObserverMethod<?> owbObserverMethod = (OwbObserverMethod<?>)observerMethod;
+                validate(owbObserverMethod.getInjectionPoints(), false);
+            }
+        }
+    }
+
+    private void validate(Set<InjectionPoint> injectionPoints, boolean isDecorator)
+    {
+        boolean delegateFound = false;
+        for (InjectionPoint injectionPoint : injectionPoints)
+        {
+            if (!injectionPoint.isDelegate())
+            {
+                webBeansContext.getBeanManagerImpl().validate(injectionPoint);   
+            }
+            else
+            {
+                if (!isDecorator)
+                {
+                    throw new WebBeansConfigurationException(
+                            "Delegate injection points can not defined by beans that are
not decorator. Injection point : "
+                            + injectionPoint);
+                }
+                else if (delegateFound)
+                {
+                    throw new WebBeansConfigurationException(
+                            "Only one Delegate injection point can be defined by decorator.
Decorator : "
+                            + injectionPoint.getBean());
+                }
+                else
+                {
+                    delegateFound = true;
+                }
+            }
+        }
+    }
 
     private void validateBeanNames(Stack<String> beanNames)
     {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java?rev=1606601&r1=1606600&r2=1606601&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
Sun Jun 29 20:39:51 2014
@@ -135,6 +135,11 @@ public class InjectionResolver
             throw new WebBeansConfigurationException("Injection point type : " + injectionPoint
+ " can not define Type Variable generic type");
         }
 
+        //Check for raw event type (10.3.2)
+        if (type == Event.class)
+        {
+            throw new WebBeansConfigurationException("Injection point type : " + injectionPoint
+ " needs to define type argument for javax.enterprise.event.Event");
+        }
     }
 
     /**

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventUtil.java?rev=1606601&r1=1606600&r2=1606601&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventUtil.java
Sun Jun 29 20:39:51 2014
@@ -26,14 +26,10 @@ import java.lang.reflect.Type;
 import java.util.Set;
 
 import javax.enterprise.event.Event;
-import javax.enterprise.event.Observes;
-import javax.enterprise.event.TransactionPhase;
-import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.InjectionPoint;
 
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
-import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.ClassUtil;
 
 public final class EventUtil
@@ -63,17 +59,6 @@ public final class EventUtil
         webBeansContext.getAnnotationManager().checkQualifierConditions(annotations);
     }
 
-    public static TransactionPhase getObserverMethodTransactionType(AnnotatedMethod<?>
observerMethod)
-    {
-        Observes observes = AnnotationUtil.getFirstAnnotatedParameter(observerMethod, Observes.class).getAnnotation(Observes.class);
-        if (observes != null)
-        {
-            return observes.during();
-        }
-        
-        return null;
-    }
-
     public static boolean checkObservableInjectionPointConditions(InjectionPoint injectionPoint)
     {
         Type type = injectionPoint.getType();

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java?rev=1606601&r1=1606600&r2=1606601&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
Sun Jun 29 20:39:51 2014
@@ -24,16 +24,15 @@ import java.lang.reflect.InvocationTarge
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
+import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.enterprise.event.ObserverException;
-import javax.enterprise.event.Observes;
-import javax.enterprise.event.Reception;
 import javax.enterprise.event.TransactionPhase;
-import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedParameter;
 import javax.enterprise.inject.spi.EventMetadata;
 import javax.enterprise.inject.spi.Extension;
@@ -65,6 +64,19 @@ public final class NotificationManager
     {
         this.webBeansContext = webBeansContext;
     }
+    
+    public List<ObserverMethod<?>> getObserverMethods()
+    {
+        List<ObserverMethod<?>> observerMethods = new ArrayList<ObserverMethod<?>>();
+        for (Set<ObserverMethod<?>> methods: observers.values())
+        {
+            for (ObserverMethod<?> method: methods)
+            {
+                observerMethods.add(method);
+            }
+        }
+        return observerMethods;
+    }
 
     public <T> void addObserver(ObserverMethod<T> observer, Type eventType)
     {
@@ -476,35 +488,15 @@ public final class NotificationManager
      * @param bean bean instance 
      * @return ObserverMethod
      */
-    public <T> ObserverMethod<?> getObservableMethodForAnnotatedMethod(AnnotatedMethod<?>
annotatedMethod, AbstractOwbBean<T> bean)
+    public <T> ObserverMethod<?> getObservableMethodForAnnotatedMethod(AnnotatedParameter<?>
annotatedParameter, AbstractOwbBean<T> bean)
     {
-        Asserts.assertNotNull(annotatedMethod, "annotatedMethod parameter can not be null");
-
-        AnnotatedParameter<?> annotatedParameter = AnnotationUtil.getFirstAnnotatedParameter(annotatedMethod,
Observes.class);
-        Observes observes = annotatedParameter.getAnnotation(Observes.class);
-        boolean ifExist = false;
-        if(observes != null)
-        {
-            if (observes.notifyObserver().equals(Reception.IF_EXISTS))
-            {
-                ifExist = true;
-            }            
-        }
-        
-        //Looking for qualifiers
-        Annotation[] observerQualifiers =
-            bean.getWebBeansContext().getAnnotationManager().getAnnotatedMethodFirstParameterQualifierWithGivenAnnotation(
-                annotatedMethod, Observes.class);
-        
-        //Getting observer event type
-        Type type = annotatedParameter.getBaseType();
+        Asserts.assertNotNull(annotatedParameter, "annotatedParameter can not be null");
         
         //Observer creation from annotated method
-        ObserverMethodImpl<T> observer = new ObserverMethodImpl(bean, annotatedMethod,
ifExist, observerQualifiers, type);
+        ObserverMethodImpl<T> observer = new ObserverMethodImpl(bean, annotatedParameter);
         
         //Adds this observer
-        addObserver(observer, type);
-        
+        addObserver(observer, annotatedParameter.getBaseType());
 
         return observer;
     }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java?rev=1606601&r1=1606600&r2=1606601&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
Sun Jun 29 20:39:51 2014
@@ -21,11 +21,11 @@ package org.apache.webbeans.event;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
-import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
-import java.util.Collections;
+import java.util.Collection;
 import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.logging.Level;
@@ -35,7 +35,6 @@ import javax.enterprise.context.ContextN
 import javax.enterprise.context.Dependent;
 import javax.enterprise.context.spi.Context;
 import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.event.Event;
 import javax.enterprise.event.Observes;
 import javax.enterprise.event.Reception;
 import javax.enterprise.event.TransactionPhase;
@@ -45,7 +44,6 @@ import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.EventMetadata;
 import javax.enterprise.inject.spi.InjectionPoint;
 
-import org.apache.webbeans.annotation.AnnotationManager;
 import org.apache.webbeans.component.AbstractOwbBean;
 import org.apache.webbeans.component.WebBeansType;
 import org.apache.webbeans.config.OWBLogConst;
@@ -57,7 +55,6 @@ import org.apache.webbeans.inject.impl.I
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
 import org.apache.webbeans.proxy.OwbNormalScopeProxy;
 import org.apache.webbeans.spi.plugins.OpenWebBeansEjbPlugin;
-import org.apache.webbeans.util.AnnotationUtil;
 
 /**
  * Defines observers that are declared in observer methods.
@@ -100,12 +97,18 @@ public class ObserverMethodImpl<T> imple
     
     /** the transaction phase */
     private final TransactionPhase phase;
+    
+    /** the injection points */
+    private final Set<InjectionPoint> injectionPoints;
 
     private final Method view;
 
     /**Annotated method*/
     private AnnotatedMethod<T> annotatedObserverMethod;
     
+    /**\@Observes parameter*/
+    private AnnotatedParameter<T> annotatedObservesParameter;
+    
     private static class ObserverParams
     {
         private Bean<Object> bean;
@@ -125,17 +128,24 @@ public class ObserverMethodImpl<T> imple
      * @param qualifiers
      * @param observedEventType
      */
-    public ObserverMethodImpl(AbstractOwbBean<?> bean, AnnotatedMethod<T> annotatedObserverMethod,
boolean ifExist,
-                                 Annotation[] qualifiers, Type observedEventType)
+    public ObserverMethodImpl(AbstractOwbBean<?> bean, AnnotatedParameter<T>
annotatedObservesParameter)
     {
         this.bean = bean;
-        this.annotatedObserverMethod = annotatedObserverMethod;
-        this.ifExist = ifExist;
-        observedQualifiers = new HashSet<Annotation>(qualifiers.length);
-        Collections.addAll(observedQualifiers, qualifiers);
-        this.observedEventType = observedEventType;
-        phase = EventUtil.getObserverMethodTransactionType(annotatedObserverMethod);
-
+        this.annotatedObservesParameter = annotatedObservesParameter;
+        annotatedObserverMethod = (AnnotatedMethod<T>)annotatedObservesParameter.getDeclaringCallable();
+        observedEventType = annotatedObservesParameter.getBaseType();
+        Observes observes = annotatedObservesParameter.getAnnotation(Observes.class);
+        ifExist = observes.notifyObserver() == Reception.IF_EXISTS;
+        phase = observes.during();
+        observedQualifiers = new HashSet<Annotation>();
+        for (Annotation annotation: annotatedObservesParameter.getAnnotations())
+        {
+            if (bean.getWebBeansContext().getAnnotationManager().isQualifierAnnotation(annotation.annotationType()))
+            {
+                observedQualifiers.add(annotation);
+            }
+        }
+        
         final OpenWebBeansEjbPlugin ejbPlugin = getWebBeansContext().getPluginLoader().getEjbPlugin();
         if (ejbPlugin != null && ejbPlugin.isNewSessionBean(bean.getBeanClass()))
         {
@@ -146,6 +156,25 @@ public class ObserverMethodImpl<T> imple
             view = annotatedObserverMethod.getJavaMember();
         }
 
+        injectionPoints = new LinkedHashSet<InjectionPoint>();
+        for (AnnotatedParameter<?> parameter: annotatedObserverMethod.getParameters())
+        {
+            if (parameter != annotatedObservesParameter)
+            {
+                Collection<Annotation> qualifierAnnots = getWebBeansContext().getAnnotationManager().getQualifierAnnotations(parameter.getAnnotations());
+
+                injectionPoints.add(InjectionPointFactory.getPartialInjectionPoint(bean,
parameter, qualifierAnnots));
+            }
+        }
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Set<InjectionPoint> getInjectionPoints()
+    {
+        return injectionPoints;
     }
 
     /**
@@ -305,77 +334,52 @@ public class ObserverMethodImpl<T> imple
      */
     protected List<ObserverParams> getMethodArguments(Object event, EventMetadata metadata)
     {
+        List<ObserverParams> list = new ArrayList<ObserverParams>();
+        if (annotatedObservesParameter.getPosition() == 0)
+        {
+            ObserverParams param = new ObserverParams();
+            param.instance = event;
+            list.add(param);
+        }
         final WebBeansContext webBeansContext = bean.getWebBeansContext();
-        final AnnotationManager annotationManager = webBeansContext.getAnnotationManager();
         final BeanManagerImpl manager = webBeansContext.getBeanManagerImpl();
-        List<ObserverParams> list = new ArrayList<ObserverParams>();
-        List<AnnotatedParameter<T>> parameters = annotatedObserverMethod.getParameters();
-        ObserverParams param = null;
-        for(AnnotatedParameter<T> parameter : parameters)
+
+        for (InjectionPoint injectionPoint: injectionPoints)
         {
-            if(parameter.isAnnotationPresent(Observes.class))
+            Bean<Object> injectedBean = (Bean<Object>)manager.getInjectionResolver().getInjectionPointBean(injectionPoint);
+            
+            CreationalContextImpl<Object> creational = manager.createCreationalContext(injectedBean);
+            creational.putInjectionPoint(metadata.getInjectionPoint());
+            creational.putInjectionPoint(injectionPoint);
+            creational.putEventMetadata(metadata);
+            Object instance;
+            try
             {
-                param = new ObserverParams();
-                param.instance = event;
-                list.add(param);                 
+                instance = manager.getReference(injectedBean, null, creational);
             }
-            else
+            finally
             {
-                //Get parameter annotations
-                Annotation[] bindingTypes =
-                    annotationManager.getQualifierAnnotations(AnnotationUtil.
-                            asArray(parameter.getAnnotations()));
-
-                InjectionPoint point = InjectionPointFactory.getPartialInjectionPoint(bean,
parameter, bindingTypes);
-
-                //Get observer parameter instance
-                @SuppressWarnings("unchecked")
-                Bean<Object> injectedBean = (Bean<Object>)getWebBeansContext().getBeanManagerImpl().getInjectionResolver().getInjectionPointBean(point);
-                
-                CreationalContextImpl<Object> creational = manager.createCreationalContext(injectedBean);
-                creational.putInjectionPoint(metadata.getInjectionPoint());
-                creational.putInjectionPoint(point);
-                creational.putEventMetadata(metadata);
-                Object instance;
-                try
-                {
-                    instance = manager.getReference(injectedBean, null, creational);
-                }
-                finally
-                {
-                    creational.removeEventMetadata();
-                    creational.removeInjectionPoint();
-                    creational.removeInjectionPoint();
-                }
-                                    
-                param = new ObserverParams();
-                param.isBean = true;
-                param.creational = creational;
-                param.instance = instance;
-                param.bean = injectedBean;
-                list.add(param);
+                creational.removeEventMetadata();
+                creational.removeInjectionPoint();
+                creational.removeInjectionPoint();
             }
-        }
-                
-        return list;
-    }
-    
-    private boolean isEventProviderInjection(InjectionPoint injectionPoint)
-    {
-        Type type = injectionPoint.getType();
-
-        if (type instanceof ParameterizedType)
-        {
-            ParameterizedType pt = (ParameterizedType) type;
-            Class<?> clazz = (Class<?>) pt.getRawType();
+                                
+            ObserverParams param = new ObserverParams();
+            param.isBean = true;
+            param.creational = creational;
+            param.instance = instance;
+            param.bean = injectedBean;
+            list.add(param);
 
-            if (clazz.isAssignableFrom(Event.class))
+            if (list.size() == annotatedObservesParameter.getPosition())
             {
-                return true;
+                param = new ObserverParams();
+                param.instance = event;
+                list.add(param);                 
             }
         }
-
-        return false;
+                
+        return list;
     }
 
     /**

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/OwbObserverMethod.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/OwbObserverMethod.java?rev=1606601&r1=1606600&r2=1606601&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/OwbObserverMethod.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/OwbObserverMethod.java
Sun Jun 29 20:39:51 2014
@@ -18,7 +18,10 @@
  */
 package org.apache.webbeans.event;
 
+import java.util.Set;
+
 import javax.enterprise.inject.spi.EventMetadata;
+import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.ObserverMethod;
 
 /**
@@ -26,6 +29,10 @@ import javax.enterprise.inject.spi.Obser
  */
 public interface OwbObserverMethod<T> extends ObserverMethod<T>
 {
+    /**
+     * Returns the {@link InjectionPoint}s for the parameters of this observer method.
+     */
+    public Set<InjectionPoint> getInjectionPoints();
 
     /**
      * will actually call the underlying observer method with the specified event metadata

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java?rev=1606601&r1=1606600&r2=1606601&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/impl/InjectionPointFactory.java
Sun Jun 29 20:39:51 2014
@@ -164,9 +164,9 @@ public class InjectionPointFactory
         }
     }
 
-    public static InjectionPoint getPartialInjectionPoint(Bean<?> owner, AnnotatedParameter<?>
parameter, Annotation...bindings)
+    public static InjectionPoint getPartialInjectionPoint(Bean<?> owner, AnnotatedParameter<?>
parameter, Collection<Annotation> bindings)
     {
-        return new InjectionPointImpl(owner, Arrays.asList(bindings), parameter);
+        return new InjectionPointImpl(owner, bindings, parameter);
     }
 
     /**

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java?rev=1606601&r1=1606600&r2=1606601&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
Sun Jun 29 20:39:51 2014
@@ -24,7 +24,6 @@ import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -48,8 +47,10 @@ public final class AnnotationUtil
 
     public static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
     
-    public static final Set<Annotation> DEFAULT_AND_ANY_ANNOTATION
-        = Collections.unmodifiableSet(new HashSet<Annotation>(Arrays.<Annotation>asList(DefaultLiteral.INSTANCE,
AnyLiteral.INSTANCE)));
+    public static final Annotation[] DEFAULT_AND_ANY_ANNOTATION_ARRAY = new Annotation[]
{DefaultLiteral.INSTANCE, AnyLiteral.INSTANCE};
+
+    public static final Set<Annotation> DEFAULT_AND_ANY_ANNOTATION = Collections.unmodifiableSet(ArrayUtil.asSet(DEFAULT_AND_ANY_ANNOTATION_ARRAY));
+    
 
     // No instantiate
     private AnnotationUtil()



Mime
View raw message