openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1798647 - in /openwebbeans/trunk: webbeans-ee/src/main/java/org/apache/webbeans/ee/event/ webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ webbeans-impl/src/main/java/org/apache/webbeans/configurator/ webbeans-impl/src/m...
Date Tue, 13 Jun 2017 23:12:21 GMT
Author: struberg
Date: Tue Jun 13 23:12:21 2017
New Revision: 1798647

URL: http://svn.apache.org/viewvc?rev=1798647&view=rev
Log:
OWB-1186 epic battle against wrong events

ProcessSyntheticObserverMethod was not known to be an observer event...

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventContextImpl.java   (with props)
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/ObserverMethodConfiguratorAfterBeanDiscoveryTest.java   (with props)
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/broken/
Modified:
    openwebbeans/trunk/webbeans-ee/src/main/java/org/apache/webbeans/ee/event/TransactionalEventNotifier.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/configurator/ObserverMethodConfiguratorImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventMetadataImpl.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/portable/events/ProcessObserverMethodImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessObserverMethod.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessSyntheticObserverMethod.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java

Modified: openwebbeans/trunk/webbeans-ee/src/main/java/org/apache/webbeans/ee/event/TransactionalEventNotifier.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ee/src/main/java/org/apache/webbeans/ee/event/TransactionalEventNotifier.java?rev=1798647&r1=1798646&r2=1798647&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-ee/src/main/java/org/apache/webbeans/ee/event/TransactionalEventNotifier.java (original)
+++ openwebbeans/trunk/webbeans-ee/src/main/java/org/apache/webbeans/ee/event/TransactionalEventNotifier.java Tue Jun 13 23:12:21 2017
@@ -29,7 +29,7 @@ import javax.transaction.Transaction;
 
 import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.event.OwbObserverMethod;
+import org.apache.webbeans.event.EventContextImpl;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
 import org.apache.webbeans.spi.TransactionService;
 
@@ -108,14 +108,7 @@ public final class TransactionalEventNot
         }
         else
         {
-            if (observer instanceof OwbObserverMethod)
-            {
-                ((OwbObserverMethod<? super Object>)observer).notify(event, metadata);
-            }
-            else
-            {
-                observer.notify(event);
-            }
+            observer.notify(new EventContextImpl(event, metadata));
         }
     }
 
@@ -172,14 +165,7 @@ public final class TransactionalEventNot
         {
             try
             {
-                if (observer instanceof OwbObserverMethod)
-                {
-                    ((OwbObserverMethod<T>)observer).notify(event, metadata);
-                }
-                else
-                {
-                    observer.notify(event);
-                }
+                observer.notify(new EventContextImpl(event, metadata));
             }
             catch (Exception e)
             {

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=1798647&r1=1798646&r2=1798647&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 Tue Jun 13 23:12:21 2017
@@ -69,44 +69,21 @@ public class ObserverMethodsBuilder<T>
     /**
      * {@inheritDoc}
      */
-    public Set<ObserverMethod<?>> defineObserverMethods(AbstractOwbBean<T> bean)
+    public Set<ObserverMethod<?>> defineObserverMethods(AbstractOwbBean<T> ownerBean)
     {   
         Set<ObserverMethod<?>> definedObservers = new HashSet<ObserverMethod<?>>();
         for (AnnotatedMethod<?> annotatedMethod : webBeansContext.getAnnotatedElementFactory().getFilteredAnnotatedMethods(annotatedType))
         {
-            List<AnnotatedParameter<?>> parameters = (List<AnnotatedParameter<?>>)(List<?>)annotatedMethod.getParameters();
-            AnnotatedParameter<?> observesParameter = null;
-            for(AnnotatedParameter<?> parameter : parameters)
+            ObserverMethod<?> observerMethod = defineObserverMethod(ownerBean, annotatedMethod);
+            if (observerMethod != null)
             {
-                if(parameter.isAnnotationPresent(Observes.class) || parameter.isAnnotationPresent(ObservesAsync.class))
-                {
-                    if (observesParameter != null)
-                    {
-                        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.getNotificationManager().
-                        getObservableMethodForAnnotatedMethod(annotatedMethod, observesParameter, bean);
-                if (definedObserver != null)
-                {
-                    definedObservers.add(definedObserver);
-                }
+                definedObservers.add(observerMethod);
             }
         }
 
         if (!definedObservers.isEmpty())
         {
-            for (final InjectionPoint ip : bean.getInjectionPoints())
+            for (final InjectionPoint ip : ownerBean.getInjectionPoints())
             {
                 final Set<Annotation> qualifiers = ip.getQualifiers();
                 if (EventMetadata.class == ip.getType()
@@ -121,6 +98,41 @@ public class ObserverMethodsBuilder<T>
         return definedObservers;
     }
 
+    /**
+     * Check whether the given annotatedMethod is an ObserverMethod and verify it
+     * @return the ObserverMethod or {@code null} if this method is not an observer.
+     */
+    public ObserverMethod<?> defineObserverMethod(AbstractOwbBean<T> ownerBean, AnnotatedMethod<?> annotatedMethod)
+    {
+        List<AnnotatedParameter<?>> parameters = (List<AnnotatedParameter<?>>)(List<?>)annotatedMethod.getParameters();
+        AnnotatedParameter<?> observesParameter = null;
+        for(AnnotatedParameter<?> parameter : parameters)
+        {
+            if(parameter.isAnnotationPresent(Observes.class) || parameter.isAnnotationPresent(ObservesAsync.class))
+            {
+                if (observesParameter != null)
+                {
+                    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(ownerBean, observesParameter);
+
+            //Looking for ObserverMethod
+            ObserverMethod<?> definedObserver = webBeansContext.getNotificationManager().
+                    getObservableMethodForAnnotatedMethod(annotatedMethod, observesParameter, ownerBean);
+            return definedObserver;
+        }
+
+        return null;
+    }
+
     private void checkObserverMethodConditions(AbstractOwbBean<?> bean, AnnotatedParameter<?> annotatedParameter)
     {
         Asserts.assertNotNull(annotatedParameter, "annotatedParameter");
@@ -143,7 +155,7 @@ public class ObserverMethodsBuilder<T>
                                                      + " can not annotated with annotation @Disposes");
         }                
 
-        if (bean.getScope().equals(Dependent.class))
+        if (bean != null && bean.getScope().equals(Dependent.class))
         {
             //Check Reception
             Reception reception;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/ObserverMethodConfiguratorImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/ObserverMethodConfiguratorImpl.java?rev=1798647&r1=1798646&r2=1798647&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/ObserverMethodConfiguratorImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/configurator/ObserverMethodConfiguratorImpl.java Tue Jun 13 23:12:21 2017
@@ -18,105 +18,352 @@
  */
 package org.apache.webbeans.configurator;
 
+import javax.annotation.Priority;
+import javax.enterprise.event.Observes;
+import javax.enterprise.event.ObservesAsync;
 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.EventContext;
+import javax.enterprise.inject.spi.Extension;
 import javax.enterprise.inject.spi.ObserverMethod;
 import javax.enterprise.inject.spi.configurator.ObserverMethodConfigurator;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
+import java.lang.reflect.Parameter;
 import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
+import java.util.stream.Collectors;
 
-public class ObserverMethodConfiguratorImpl implements ObserverMethodConfigurator
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.exception.WebBeansException;
+
+
+public class ObserverMethodConfiguratorImpl<T> implements ObserverMethodConfigurator<T>
 {
+    private final WebBeansContext webBeansContext;
+
+    /**
+     * The Extension which added this very ObserverMethod
+     */
+    private final Extension extension;
+
+    private Class<?> beanClass;
+    private Set<Annotation> qualifiers = new HashSet<>();
+    private Type observedType;
+    private Reception reception = Reception.ALWAYS;
+    private TransactionPhase transactionPhase = TransactionPhase.IN_PROGRESS;
+    private int priority = ObserverMethod.DEFAULT_PRIORITY;
+    private boolean async = false;
+
+    private EventConsumer notifyWith;
+
+
+    public ObserverMethodConfiguratorImpl(WebBeansContext webBeansContext, Extension extension, ObserverMethod<T> observerMethod)
+    {
+        this(webBeansContext, extension);
+        read(observerMethod);
+    }
+
+    public ObserverMethodConfiguratorImpl(WebBeansContext webBeansContext, Extension extension)
+    {
+        this.webBeansContext = webBeansContext;
+        this.extension = extension;
+    }
+
+    @Override
+    public ObserverMethodConfigurator<T> read(Method method)
+    {
+        this.qualifiers = getQualifiers(Arrays.asList(method.getAnnotations()));
+        this.beanClass = method.getDeclaringClass();
+
+        for (Parameter parameter : method.getParameters())
+        {
+            Observes observes = parameter.getAnnotation(Observes.class);
+            ObservesAsync observesAsync = parameter.getAnnotation(ObservesAsync.class);
+            if (observes != null || observesAsync != null)
+            {
+                observedType = parameter.getParameterizedType();
+
+                if (observes != null)
+                {
+                    this.reception = observes.notifyObserver();
+                    this.transactionPhase = observes.during();
+                }
+                else
+                    {
+                    this.reception = observesAsync.notifyObserver();
+                    this.transactionPhase = TransactionPhase.IN_PROGRESS;
+                    this.async = true;
+                }
+
+                Priority prio = parameter.getAnnotation(Priority.class);
+                if (prio != null)
+                {
+                    this.priority = prio.value();
+                }
+                break;
+            }
+        }
+
+        //X TODO CDI-2.0
+        return this;
+    }
+
     @Override
-    public ObserverMethodConfigurator read(Method method)
+    public ObserverMethodConfigurator<T> read(AnnotatedMethod annotatedMethod)
+    {
+        this.qualifiers = getQualifiers(annotatedMethod.getAnnotations());
+        this.beanClass = annotatedMethod.getDeclaringType().getJavaClass();
+
+        List<AnnotatedParameter<?>> parameters = annotatedMethod.getParameters();
+        for (AnnotatedParameter parameter : parameters)
+        {
+            Observes observes = parameter.getAnnotation(Observes.class);
+            ObservesAsync observesAsync = parameter.getAnnotation(ObservesAsync.class);
+            if (observes != null || observesAsync != null)
+            {
+                observedType = parameter.getBaseType();
+
+                if (observes != null)
+                {
+                    this.reception = observes.notifyObserver();
+                    this.transactionPhase = observes.during();
+                }
+                else
+                    {
+                    this.reception = observesAsync.notifyObserver();
+                    this.transactionPhase = TransactionPhase.IN_PROGRESS;
+                    this.async = true;
+                }
+
+                Priority prio = parameter.getAnnotation(Priority.class);
+                if (prio != null)
+                {
+                    this.priority = prio.value();
+                }
+                break;
+            }
+        }
+
+        //X TODO CDI-2.0
+        return this;
+    }
+
+    private Set<Annotation> getQualifiers(Collection<Annotation> annotations)
     {
-        throw new UnsupportedOperationException("TODO implement CDI 2.0");
+        BeanManagerImpl bm = webBeansContext.getBeanManagerImpl();
+        return annotations.stream()
+            .filter(a -> bm.isQualifier(a.annotationType()))
+            .collect(Collectors.toSet());
     }
 
     @Override
-    public ObserverMethodConfigurator read(AnnotatedMethod method)
+    public ObserverMethodConfigurator<T> read(ObserverMethod observerMethod)
     {
-        throw new UnsupportedOperationException("TODO implement CDI 2.0");
+        this.beanClass = observerMethod.getBeanClass();
+        this.qualifiers.addAll(observerMethod.getObservedQualifiers());
+        this.observedType = observerMethod.getObservedType();
+        this.reception = observerMethod.getReception();
+        this.transactionPhase = observerMethod.getTransactionPhase();
+        this.priority = observerMethod.getPriority();
+        this.async = observerMethod.isAsync();
+
+        return this;
     }
 
     @Override
-    public ObserverMethodConfigurator read(ObserverMethod method)
+    public ObserverMethodConfigurator<T> beanClass(Class<?> beanClass)
     {
-        throw new UnsupportedOperationException("TODO implement CDI 2.0");
+        this.beanClass = beanClass;
+        return this;
     }
 
     @Override
-    public ObserverMethodConfigurator beanClass(Class type)
+    public ObserverMethodConfigurator<T> observedType(Type type)
     {
-        throw new UnsupportedOperationException("TODO implement CDI 2.0");
+        this.observedType = type;
+        return this;
     }
 
     @Override
-    public ObserverMethodConfigurator observedType(Type type)
+    public ObserverMethodConfigurator<T> addQualifier(Annotation qualifier)
     {
-        throw new UnsupportedOperationException("TODO implement CDI 2.0");
+        this.qualifiers.add(qualifier);
+        return this;
     }
 
     @Override
-    public ObserverMethodConfigurator addQualifier(Annotation qualifier)
+    public ObserverMethodConfigurator<T> addQualifiers(Annotation... qualifiers)
     {
-        throw new UnsupportedOperationException("TODO implement CDI 2.0");
+        for (Annotation qualifier : qualifiers)
+        {
+            this.qualifiers.add(qualifier);
+        }
+        return this;
     }
 
     @Override
-    public ObserverMethodConfigurator addQualifiers(Annotation... qualifiers)
+    public ObserverMethodConfigurator<T> addQualifiers(Set qualifiers)
     {
-        throw new UnsupportedOperationException("TODO implement CDI 2.0");
+        this.qualifiers.addAll(qualifiers);
+        return this;
     }
 
     @Override
-    public ObserverMethodConfigurator addQualifiers(Set qualifiers)
+    public ObserverMethodConfigurator<T> qualifiers(Annotation... qualifiers)
     {
-        throw new UnsupportedOperationException("TODO implement CDI 2.0");
+        this.qualifiers.clear();
+        addQualifiers(qualifiers);
+        return this;
     }
 
     @Override
-    public ObserverMethodConfigurator qualifiers(Annotation... qualifiers)
+    public ObserverMethodConfigurator<T> qualifiers(Set qualifiers)
     {
-        throw new UnsupportedOperationException("TODO implement CDI 2.0");
+        this.qualifiers.clear();
+        addQualifiers(qualifiers);
+        return this;
     }
 
     @Override
-    public ObserverMethodConfigurator qualifiers(Set qualifiers)
+    public ObserverMethodConfigurator<T> reception(Reception reception)
     {
-        throw new UnsupportedOperationException("TODO implement CDI 2.0");
+        this.reception = reception;
+        return this;
     }
 
     @Override
-    public ObserverMethodConfigurator reception(Reception reception)
+    public ObserverMethodConfigurator<T> transactionPhase(TransactionPhase transactionPhase)
     {
-        throw new UnsupportedOperationException("TODO implement CDI 2.0");
+        this.transactionPhase = transactionPhase;
+        return this;
     }
 
     @Override
-    public ObserverMethodConfigurator transactionPhase(TransactionPhase transactionPhase)
+    public ObserverMethodConfigurator<T> priority(int priority)
     {
-        throw new UnsupportedOperationException("TODO implement CDI 2.0");
+        this.priority = priority;
+        return this;
     }
 
     @Override
-    public ObserverMethodConfigurator priority(int priority)
+    public ObserverMethodConfigurator<T> notifyWith(EventConsumer callback)
     {
-        throw new UnsupportedOperationException("TODO implement CDI 2.0");
+        this.notifyWith = callback;
+        return this;
     }
 
     @Override
-    public ObserverMethodConfigurator notifyWith(EventConsumer callback)
+    public ObserverMethodConfigurator<T> async(boolean async)
+    {
+        this.async = async;
+        return this;
+    }
+
+    public <T> ObserverMethod<T> getObserverMethod()
+    {
+        if (observedType ==  null)
+        {
+            String extensionName = extension != null ? "(" + extension.toString() + ") ! " : "! ";
+            WebBeansConfigurationException e = new WebBeansConfigurationException("ObserverMethod observedType is missing "
+                + extensionName
+                + toString());
+            webBeansContext.getBeanManagerImpl().getErrorStack().pushError(e);
+            return null;
+        }
+        return new ConfiguredObserverMethod();
+    }
+
+    public Extension getExtension()
+    {
+        return extension;
+    }
+
+    public class ConfiguredObserverMethod<T> implements ObserverMethod<T>
     {
-        throw new UnsupportedOperationException("TODO implement CDI 2.0");
+        @Override
+        public Class<?> getBeanClass()
+        {
+            return beanClass != null ? beanClass : extension.getClass();
+        }
+
+        @Override
+        public Type getObservedType()
+        {
+            return observedType;
+        }
+
+        @Override
+        public Set<Annotation> getObservedQualifiers()
+        {
+            return qualifiers;
+        }
+
+        @Override
+        public Reception getReception()
+        {
+            return reception;
+        }
+
+        @Override
+        public TransactionPhase getTransactionPhase()
+        {
+            return transactionPhase;
+        }
+
+        @Override
+        public void notify(T event)
+        {
+
+        }
+
+        @Override
+        public void notify(EventContext<T> eventContext)
+        {
+            try
+            {
+                notifyWith.accept(eventContext);
+            }
+            catch (Exception e)
+            {
+                throw new WebBeansException(e);
+            }
+        }
+
+        @Override
+        public boolean isAsync()
+        {
+            return async;
+        }
+
+        @Override
+        public int getPriority()
+        {
+            return priority;
+        }
     }
 
+
     @Override
-    public ObserverMethodConfigurator async(boolean async)
+    public String toString()
     {
-        throw new UnsupportedOperationException("TODO implement CDI 2.0");
+        return "ObserverMethodConfiguratorImpl{" +
+            "beanClass=" + beanClass +
+            ", qualifiers=" + qualifiers +
+            ", observedType=" + observedType +
+            ", reception=" + reception +
+            ", transactionPhase=" + transactionPhase +
+            ", priority=" + priority +
+            ", async=" + async +
+            ", notifyWith=" + notifyWith +
+            '}';
     }
 }

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventContextImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventContextImpl.java?rev=1798647&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventContextImpl.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventContextImpl.java Tue Jun 13 23:12:21 2017
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.event;
+
+import javax.enterprise.inject.spi.EventContext;
+import javax.enterprise.inject.spi.EventMetadata;
+
+public class EventContextImpl<T> implements EventContext<T>
+{
+    private final T event;
+    private final EventMetadata metadata;
+
+    public EventContextImpl(T event, EventMetadata metadata)
+    {
+        this.event = event;
+        this.metadata = metadata;
+    }
+
+    @Override
+    public T getEvent()
+    {
+        return event;
+    }
+
+    @Override
+    public EventMetadata getMetadata()
+    {
+        return metadata;
+    }
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventContextImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventMetadataImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventMetadataImpl.java?rev=1798647&r1=1798646&r2=1798647&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventMetadataImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventMetadataImpl.java Tue Jun 13 23:12:21 2017
@@ -139,12 +139,9 @@ public class EventMetadataImpl implement
 
     public EventMetadataImpl select(Type subtype, Annotation... bindings)
     {
+        webBeansContext.getAnnotationManager().checkQualifierConditions(bindings);
         Set<Annotation> newQualifiers = ArrayUtil.asSet(bindings);
         newQualifiers.addAll(qualifiers);
-        if (newQualifiers.size() != qualifiers.size() + bindings.length)
-        {
-            throw new IllegalArgumentException("duplicate qualifier");
-        }
         return new EventMetadataImpl(type, subtype, injectionPoint, newQualifiers.toArray(new Annotation[newQualifiers.size()]), webBeansContext);
     }
     

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=1798647&r1=1798646&r2=1798647&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 Tue Jun 13 23:12:21 2017
@@ -835,26 +835,19 @@ public final class NotificationManager
         }
     }
 
-    private void invokeObserverMethod(Object event, EventMetadataImpl metadata, ObserverMethod<? super Object> observer)
+    private <T> void invokeObserverMethod(final T event, final EventMetadataImpl metadata, ObserverMethod<?> observer)
     {
-        if (observer instanceof OwbObserverMethod)
-        {
-            ((OwbObserverMethod<? super Object>)observer).notify(event, metadata);
-        }
-        else
-        {
-            observer.notify(event);
-        }
+        observer.notify(new EventContextImpl(event, metadata));
     }
 
     /**
      * Gets observer method from given annotated method.
      * @param <T> bean type info
      * @param annotatedMethod annotated method for observer
-     * @param bean bean instance 
+     * @param ownerBean bean instance
      * @return ObserverMethod
      */
-    public <T> ObserverMethod<?> getObservableMethodForAnnotatedMethod(AnnotatedMethod<?> annotatedMethod, AnnotatedParameter<?> annotatedParameter, AbstractOwbBean<T> bean)
+    public <T> ObserverMethod<?> getObservableMethodForAnnotatedMethod(AnnotatedMethod<?> annotatedMethod, AnnotatedParameter<?> annotatedParameter, AbstractOwbBean<T> ownerBean)
     {
         Asserts.assertNotNull(annotatedParameter, "annotatedParameter");
 
@@ -862,14 +855,14 @@ public final class NotificationManager
         // Observer creation from annotated method
         if (isContainerEvent(annotatedParameter))
         {
-            observer = new ContainerEventObserverMethodImpl(bean, annotatedMethod, annotatedParameter);
+            observer = new ContainerEventObserverMethodImpl(ownerBean, annotatedMethod, annotatedParameter);
             addObserver(observer);
         }
         else
         {
-            observer = new ObserverMethodImpl(bean, annotatedMethod, annotatedParameter);
+            observer = new ObserverMethodImpl(ownerBean, annotatedMethod, annotatedParameter);
 
-            GProcessObserverMethod event = new GProcessObserverMethod(annotatedMethod, observer);
+            GProcessObserverMethod event = new GProcessObserverMethod(webBeansContext, annotatedMethod, observer);
 
             //Fires ProcessObserverMethod
             webBeansContext.getBeanManagerImpl().fireEvent(event, true, AnnotationUtil.EMPTY_ANNOTATION_ARRAY);

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=1798647&r1=1798646&r2=1798647&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 Tue Jun 13 23:12:21 2017
@@ -44,6 +44,7 @@ import javax.enterprise.event.Transactio
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedParameter;
 import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.EventContext;
 import javax.enterprise.inject.spi.EventMetadata;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.ObserverMethod;
@@ -90,7 +91,7 @@ public class ObserverMethodImpl<T> imple
     private static final Logger logger = WebBeansLoggerFacade.getLogger(ObserverMethodImpl.class);
 
     /**Observer owner bean that defines observer method*/
-    private final AbstractOwbBean<?> bean;
+    private final AbstractOwbBean<?> ownerBean;
 
     /**Using existing bean instance or not*/
     private final boolean ifExist;
@@ -132,12 +133,10 @@ public class ObserverMethodImpl<T> imple
 
     /**
      * used if the qualifiers and event type are already known, e.g. from the XML.
-     * @param bean
-     * @param annotatedObserverMethod
      */
-    public ObserverMethodImpl(AbstractOwbBean<?> bean, AnnotatedMethod<T> annotatedObserverMethod, AnnotatedParameter<T> annotatedObservesParameter)
+    public ObserverMethodImpl(AbstractOwbBean<?> ownerBean, AnnotatedMethod<T> annotatedObserverMethod, AnnotatedParameter<T> annotatedObservesParameter)
     {
-        this.bean = bean;
+        this.ownerBean = ownerBean;
         this.annotatedObservesParameter = annotatedObservesParameter;
         this.annotatedObserverMethod = annotatedObserverMethod;
         observedEventType = annotatedObservesParameter.getBaseType();
@@ -164,7 +163,7 @@ public class ObserverMethodImpl<T> imple
         observedQualifiers = new HashSet<Annotation>();
         for (Annotation annotation: annotatedObservesParameter.getAnnotations())
         {
-            if (bean.getWebBeansContext().getAnnotationManager().isQualifierAnnotation(annotation.annotationType()))
+            if (ownerBean.getWebBeansContext().getAnnotationManager().isQualifierAnnotation(annotation.annotationType()))
             {
                 observedQualifiers.add(annotation);
             }
@@ -178,9 +177,9 @@ public class ObserverMethodImpl<T> imple
         }
         
         final OpenWebBeansEjbPlugin ejbPlugin = getWebBeansContext().getPluginLoader().getEjbPlugin();
-        if (ejbPlugin != null && ejbPlugin.isNewSessionBean(bean.getBeanClass()))
+        if (ejbPlugin != null && ejbPlugin.isNewSessionBean(ownerBean.getBeanClass()))
         {
-            view = ejbPlugin.resolveViewMethod(bean , annotatedObserverMethod.getJavaMember());
+            view = ejbPlugin.resolveViewMethod(ownerBean , annotatedObserverMethod.getJavaMember());
         }
         else
         {
@@ -194,7 +193,7 @@ public class ObserverMethodImpl<T> imple
             {
                 Collection<Annotation> qualifierAnnots = getWebBeansContext().getAnnotationManager().getQualifierAnnotations(parameter.getAnnotations());
 
-                injectionPoints.add(InjectionPointFactory.getPartialInjectionPoint(bean, parameter, qualifierAnnots));
+                injectionPoints.add(InjectionPointFactory.getPartialInjectionPoint(ownerBean, parameter, qualifierAnnots));
             }
         }
 
@@ -210,6 +209,12 @@ public class ObserverMethodImpl<T> imple
     }
 
     @Override
+    public AbstractOwbBean<?> getOwnerBean()
+    {
+        return ownerBean;
+    }
+
+    @Override
     public boolean isAsync()
     {
         return isAsync;
@@ -232,11 +237,13 @@ public class ObserverMethodImpl<T> imple
 
     /**
      * {@inheritDoc}
+     *
+     * @deprecated actually. Use the method with the EventContext instead
      */
     @Override
     public void notify(T event)
     {
-        notify(event, null);
+        notify(new EventContextImpl<>(event, null));
     }
 
     /**
@@ -244,10 +251,13 @@ public class ObserverMethodImpl<T> imple
      */
     @Override
     @SuppressWarnings("unchecked")
-    public void notify(T event, EventMetadata metadata)
+    public void notify(EventContext<T> eventContext)
     {
-        AbstractOwbBean<Object> component = (AbstractOwbBean<Object>) bean;
-        if (!bean.isEnabled())
+        T event = eventContext.getEvent();
+        EventMetadata metadata = eventContext.getMetadata();
+
+        AbstractOwbBean<Object> component = (AbstractOwbBean<Object>) ownerBean;
+        if (!ownerBean.isEnabled())
         {
             return;
         }
@@ -256,7 +266,7 @@ public class ObserverMethodImpl<T> imple
         
         List<ObserverParams> methodArgsMap = getMethodArguments(event, metadata);
         
-        BeanManagerImpl manager = bean.getWebBeansContext().getBeanManagerImpl();
+        BeanManagerImpl manager = ownerBean.getWebBeansContext().getBeanManagerImpl();
         CreationalContextImpl<Object> creationalContext = manager.createCreationalContext(component);
         if (metadata != null)
         {
@@ -300,7 +310,7 @@ public class ObserverMethodImpl<T> imple
                         return;
                     }
                     // this may happen if we try to e.g. send an event to a @ConversationScoped bean from a ServletListener
-                    logger.log(Level.INFO, OWBLogConst.INFO_0010, bean);
+                    logger.log(Level.INFO, OWBLogConst.INFO_0010, ownerBean);
                     return;
                 }
                 
@@ -338,7 +348,7 @@ public class ObserverMethodImpl<T> imple
                 {
                     if (!view.isAccessible())
                     {
-                        bean.getWebBeansContext().getSecurityService().doPrivilegedSetAccessible(view, true);
+                        ownerBean.getWebBeansContext().getSecurityService().doPrivilegedSetAccessible(view, true);
                     }
 
                     if (Modifier.isPrivate(view.getModifiers()))
@@ -407,7 +417,7 @@ public class ObserverMethodImpl<T> imple
             param.instance = event;
             list.add(param);
         }
-        final WebBeansContext webBeansContext = bean.getWebBeansContext();
+        final WebBeansContext webBeansContext = ownerBean.getWebBeansContext();
         final BeanManagerImpl manager = webBeansContext.getBeanManagerImpl();
 
         for (InjectionPoint injectionPoint: injectionPoints)
@@ -457,7 +467,7 @@ public class ObserverMethodImpl<T> imple
     @SuppressWarnings("unchecked")
     public Class<?> getBeanClass()
     {
-        return bean.getBeanClass();
+        return ownerBean.getBeanClass();
     }
 
     /** 
@@ -500,7 +510,7 @@ public class ObserverMethodImpl<T> imple
 
     protected WebBeansContext getWebBeansContext()
     {
-        return bean.getWebBeansContext();
+        return ownerBean.getWebBeansContext();
     }
     
     /**

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=1798647&r1=1798646&r2=1798647&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 Tue Jun 13 23:12:21 2017
@@ -20,23 +20,20 @@ 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;
 
+import org.apache.webbeans.component.AbstractOwbBean;
+
 /**
  * This interface fixes an issue of the CDI API. See https://issues.jboss.org/browse/CDI-36
  */
 public interface OwbObserverMethod<T> extends ObserverMethod<T>
 {
+    AbstractOwbBean<?> getOwnerBean();
+
     /**
      * Returns the {@link InjectionPoint}s for the parameters of this observer method.
      */
     Set<InjectionPoint> getInjectionPoints();
-
-    /**
-     * will actually call the underlying observer method with the specified event metadata
-     */
-    void notify(T event, EventMetadata metadata);
-
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ProcessObserverMethodImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ProcessObserverMethodImpl.java?rev=1798647&r1=1798646&r2=1798647&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ProcessObserverMethodImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/ProcessObserverMethodImpl.java Tue Jun 13 23:12:21 2017
@@ -24,6 +24,7 @@ import javax.enterprise.inject.spi.Proce
 import javax.enterprise.inject.spi.configurator.ObserverMethodConfigurator;
 
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.configurator.ObserverMethodConfiguratorImpl;
 
 /**
  * Implementation of  {@link ProcessObserverMethod}.
@@ -35,15 +36,19 @@ import org.apache.webbeans.config.WebBea
  */
 public class ProcessObserverMethodImpl<T,X> extends EventBase implements ProcessObserverMethod<T, X>
 {
+    private final WebBeansContext webBeansContext;
+
     /**Observer annotated method*/
     private final AnnotatedMethod<X> annotatedMethod;
     
     /**ObserverMethod instance*/
     private ObserverMethod<T> observerMethod;
     private boolean vetoed = false;
+    private ObserverMethodConfiguratorImpl observerMethodConfigurator = null;
 
-    public ProcessObserverMethodImpl(AnnotatedMethod<X> annotatedMethod,ObserverMethod<T> observerMethod)
+    public ProcessObserverMethodImpl(WebBeansContext webBeansContext, AnnotatedMethod<X> annotatedMethod,ObserverMethod<T> observerMethod)
     {
+        this.webBeansContext = webBeansContext;
         this.annotatedMethod = annotatedMethod;
         this.observerMethod = observerMethod;
     }
@@ -58,11 +63,11 @@ public class ProcessObserverMethodImpl<T
         WebBeansContext.getInstance().getBeanManagerImpl().getErrorStack().pushError(t);
     }
 
-    //X TODO OWB-1182 CDI 2.0
     @Override
     public ObserverMethodConfigurator<T> configureObserverMethod()
     {
-        throw new UnsupportedOperationException("CDI 2.0 not yet imlemented");
+        this.observerMethodConfigurator = new ObserverMethodConfiguratorImpl(webBeansContext, null, observerMethod);
+        return observerMethodConfigurator;
     }
 
     /**
@@ -82,6 +87,10 @@ public class ProcessObserverMethodImpl<T
     public ObserverMethod<T> getObserverMethod()
     {
         checkState();
+        if (observerMethodConfigurator != null)
+        {
+            return observerMethodConfigurator.getObserverMethod();
+        }
         return observerMethod;
     }
 
@@ -90,6 +99,7 @@ public class ProcessObserverMethodImpl<T
     {
         checkState();
         this.observerMethod = observerMethod;
+        this.observerMethodConfigurator = null;
     }
 
     @Override

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java?rev=1798647&r1=1798646&r2=1798647&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterBeanDiscoveryImpl.java Tue Jun 13 23:12:21 2017
@@ -36,6 +36,7 @@ import org.apache.webbeans.component.Man
 import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.configurator.BeanConfiguratorImpl;
+import org.apache.webbeans.configurator.ObserverMethodConfiguratorImpl;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.intercept.InterceptorsManager;
@@ -63,6 +64,7 @@ public class AfterBeanDiscoveryImpl exte
     private static final Logger logger = WebBeansLoggerFacade.getLogger(AfterBeanDiscoveryImpl.class);
     private final WebBeansContext webBeansContext;
     private Set<BeanConfiguratorImpl<?>> beanConfigurators = new HashSet<>();
+    private Set<ObserverMethodConfiguratorImpl<?>> observerMethodConfigurators = new HashSet<>();
 
     private Extension extension;
 
@@ -209,7 +211,7 @@ public class AfterBeanDiscoveryImpl exte
     public void addObserverMethod(ObserverMethod<?> observerMethod)
     {
         checkState();
-        GProcessSyntheticObserverMethod event = new GProcessSyntheticObserverMethod(null,observerMethod, extension);
+        GProcessSyntheticObserverMethod event = new GProcessSyntheticObserverMethod(webBeansContext, null, observerMethod, extension);
         if (!event.isVetoed())
         {
             beanManager.fireEvent(event, true, AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
@@ -251,11 +253,28 @@ public class AfterBeanDiscoveryImpl exte
     public <T> ObserverMethodConfigurator<T> addObserverMethod()
     {
         checkState();
-        throw new UnsupportedOperationException("CDI 2.0 not yet imlemented");
+        ObserverMethodConfiguratorImpl<T> configurator = new ObserverMethodConfiguratorImpl<>(webBeansContext, extension);
+        observerMethodConfigurators.add(configurator);
+
+        return configurator;
     }
 
     public void deployConfiguredBeans()
     {
         beanConfigurators.forEach(bc -> addBean(bc.getBean()));
+        for (ObserverMethodConfiguratorImpl<?> omc : observerMethodConfigurators)
+        {
+            ObserverMethod<Object> observerMethod = omc.getObserverMethod();
+            if (observerMethod != null)
+            {
+                GProcessSyntheticObserverMethod event = new GProcessSyntheticObserverMethod(webBeansContext, null, observerMethod, omc.getExtension());
+                if (!event.isVetoed())
+                {
+                    beanManager.fireEvent(event, true, AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
+                    ObserverMethod newObserverMethod = event.getObserverMethod();
+                    webBeansContext.getNotificationManager().addObserver(newObserverMethod);
+                }
+            }
+        }
     }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessObserverMethod.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessObserverMethod.java?rev=1798647&r1=1798646&r2=1798647&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessObserverMethod.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessObserverMethod.java Tue Jun 13 23:12:21 2017
@@ -21,6 +21,7 @@ package org.apache.webbeans.portable.eve
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.ObserverMethod;
 
+import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.portable.events.ProcessObserverMethodImpl;
 import org.apache.webbeans.util.ClassUtil;
 
@@ -28,9 +29,9 @@ import org.apache.webbeans.util.ClassUti
 public class GProcessObserverMethod extends ProcessObserverMethodImpl implements GenericProducerObserverEvent
 {
 
-    public GProcessObserverMethod(AnnotatedMethod<?> annotatedMethod, ObserverMethod<?> observerMethod)
+    public GProcessObserverMethod(WebBeansContext webBeansContext, AnnotatedMethod<?> annotatedMethod, ObserverMethod<?> observerMethod)
     {
-        super(annotatedMethod, observerMethod);
+        super(webBeansContext, annotatedMethod, observerMethod);
     }
 
     @Override

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessSyntheticObserverMethod.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessSyntheticObserverMethod.java?rev=1798647&r1=1798646&r2=1798647&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessSyntheticObserverMethod.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/generics/GProcessSyntheticObserverMethod.java Tue Jun 13 23:12:21 2017
@@ -23,17 +23,20 @@ import javax.enterprise.inject.spi.Exten
 import javax.enterprise.inject.spi.ObserverMethod;
 import javax.enterprise.inject.spi.ProcessSyntheticObserverMethod;
 
+import org.apache.webbeans.config.WebBeansContext;
+
 
 @SuppressWarnings("unchecked")
 public class GProcessSyntheticObserverMethod extends GProcessObserverMethod implements ProcessSyntheticObserverMethod
 {
     private final Extension source;
 
-    public GProcessSyntheticObserverMethod(AnnotatedMethod<?> annotatedMethod,
+    public GProcessSyntheticObserverMethod(WebBeansContext webBeansContext,
+                                           AnnotatedMethod<?> annotatedMethod,
                                            ObserverMethod<?> observerMethod,
                                            Extension source)
     {
-        super(annotatedMethod, observerMethod);
+        super(webBeansContext, annotatedMethod, observerMethod);
         this.source = source;
     }
 

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=1798647&r1=1798646&r2=1798647&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 Tue Jun 13 23:12:21 2017
@@ -79,6 +79,7 @@ import org.apache.webbeans.portable.even
 import org.apache.webbeans.portable.events.generics.GProcessProducerMethod;
 import org.apache.webbeans.portable.events.generics.GProcessSessionBean;
 import org.apache.webbeans.portable.events.generics.GProcessSyntheticAnnotatedType;
+import org.apache.webbeans.portable.events.generics.GProcessSyntheticObserverMethod;
 import org.apache.webbeans.spi.plugins.OpenWebBeansEjbPlugin;
 import org.apache.webbeans.spi.plugins.OpenWebBeansPlugin;
 
@@ -122,6 +123,7 @@ import javax.enterprise.inject.spi.Proce
 import javax.enterprise.inject.spi.ProcessProducerMethod;
 import javax.enterprise.inject.spi.ProcessSessionBean;
 import javax.enterprise.inject.spi.ProcessSyntheticAnnotatedType;
+import javax.enterprise.inject.spi.ProcessSyntheticObserverMethod;
 import javax.enterprise.inject.spi.Producer;
 import javax.enterprise.util.TypeLiteral;
 import javax.inject.Inject;
@@ -1281,7 +1283,8 @@ public final class WebBeansUtil
             GProcessProducer.class,
             GProcessProducerField.class,
             GProcessProducerMethod.class,
-            GProcessObserverMethod.class}));
+            GProcessObserverMethod.class,
+            GProcessSyntheticObserverMethod.class}));
     public static boolean isExtensionProducerOrObserverEventType(Type type)
     {
         return EXTENSION_PRODUCER_OR_OBSERVER_EVENT_TYPE.contains(type);
@@ -1292,7 +1295,8 @@ public final class WebBeansUtil
             ProcessProducer.class,
             ProcessProducerField.class,
             ProcessProducerMethod.class,
-            ProcessObserverMethod.class}));
+            ProcessObserverMethod.class,
+            ProcessSyntheticObserverMethod.class}));
     public static boolean isDefaultExtensionProducerOrObserverEventType(Class<?> clazz)
     {
         return DEFAULT_EXTENSION_PRODUCER_OR_OBSERVER_EVENT_TYPE.contains(clazz);

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/ObserverMethodConfiguratorAfterBeanDiscoveryTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/ObserverMethodConfiguratorAfterBeanDiscoveryTest.java?rev=1798647&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/ObserverMethodConfiguratorAfterBeanDiscoveryTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/ObserverMethodConfiguratorAfterBeanDiscoveryTest.java Tue Jun 13 23:12:21 2017
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.test.configurator;
+
+import javax.enterprise.event.Event;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ObserverMethod;
+import javax.enterprise.inject.spi.configurator.ObserverMethodConfigurator;
+import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Qualifier;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.webbeans.test.AbstractUnitTest;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ObserverMethodConfiguratorAfterBeanDiscoveryTest extends AbstractUnitTest
+{
+
+    private static List<String> observedEvents = new ArrayList<>();
+
+    @Test
+    public void testManualObservers()
+    {
+        addExtension(new ObserverAddingExtension());
+        startContainer();
+
+        Set<ObserverMethod<? super MyEvent>> observerMethods = getBeanManager().resolveObserverMethods(new MyEvent());
+        Assert.assertEquals(2, observerMethods.size());
+
+        observedEvents.clear();
+
+        Event<Object> event = getBeanManager().getEvent();
+        Assert.assertNotNull(event);
+
+        event.select(MyEvent.class);
+        event.fire(new MyEvent());
+
+        Assert.assertEquals(2, observedEvents.size());
+        Assert.assertEquals("event1", observedEvents.get(0));
+        Assert.assertEquals("event2", observedEvents.get(1));
+    }
+
+    public static class MyEvent
+    {
+
+    }
+
+    public static class ObserverAddingExtension implements Extension
+    {
+        public void addObserverMethod(@Observes AfterBeanDiscovery abd)
+        {
+            ObserverMethodConfigurator<MyEvent> observerCfg1 = abd.<MyEvent>addObserverMethod();
+            Assert.assertNotNull(observerCfg1);
+
+            observerCfg1
+                .observedType(MyEvent.class)
+                .priority(100)
+                .notifyWith(eventContext ->
+                {
+                    observedEvents.add("event1");
+                });
+
+            ObserverMethodConfigurator<MyEvent> observerCfg2 = abd.<MyEvent>addObserverMethod();
+            Assert.assertNotNull(observerCfg2);
+            observerCfg2
+                .observedType(MyEvent.class)
+                // with default prio
+                .notifyWith(eventContext ->
+                {
+                    observedEvents.add("event2");
+                });
+
+            ObserverMethodConfigurator<MyEvent> observerCfg3 = abd.<MyEvent>addObserverMethod();
+            Assert.assertNotNull(observerCfg3);
+            observerCfg3
+                .observedType(MyEvent.class)
+                .priority(3000)
+                .addQualifier(new AnnotationLiteral<MyQualifier>()
+                    { // with @MyQualifier
+                    })
+                .notifyWith(eventContext ->
+                {
+                    observedEvents.add("event3");
+                });
+        }
+    }
+
+    @Qualifier
+    @Retention(RetentionPolicy.RUNTIME)
+    @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
+    public @interface MyQualifier
+    {
+
+    }
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/configurator/ObserverMethodConfiguratorAfterBeanDiscoveryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message