openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1607213 - in /openwebbeans/trunk: webbeans-impl/src/main/java/org/apache/webbeans/config/ webbeans-impl/src/main/java/org/apache/webbeans/container/ webbeans-impl/src/main/java/org/apache/webbeans/event/ webbeans-impl/src/main/java/org/apa...
Date Tue, 01 Jul 2014 23:12:59 GMT
Author: rmannibucau
Date: Tue Jul  1 23:12:58 2014
New Revision: 1607213

URL: http://svn.apache.org/r1607213
Log:
few more hack on generics and events, not that happy of EventMetadataImpl but didn't find
a very good solution to be generic enough tonight

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventImpl.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/portable/EventProducer.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/util/GenericsUtil.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/ExtensionTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/portable/events/ExtensionTest.java
    openwebbeans/trunk/webbeans-tck/testng-dev.xml

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=1607213&r1=1607212&r2=1607213&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
Tue Jul  1 23:12:58 2014
@@ -1360,7 +1360,7 @@ public class BeansDeployer
 
                 //Fires ProcessManagedBean
                 ProcessBeanImpl<T> processBeanEvent = new GProcessManagedBean(managedBean,
annotatedType);
-                beanManager.fireEvent(processBeanEvent);
+                beanManager.fireEvent(processBeanEvent, true);
                 webBeansContext.getWebBeansUtil().inspectErrorStack("There are errors that
are added by ProcessManagedBean event observers for " +
                         "managed beans. Look at logs for further details");
 
@@ -1421,7 +1421,7 @@ public class BeansDeployer
         final ProcessBeanAttributesImpl event = new GProcessBeanAttributes(annotatedType.getJavaClass(),
annotatedType, beanAttributes);
         try
         {
-            webBeansContext.getBeanManagerImpl().fireEvent(event, AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
+            webBeansContext.getBeanManagerImpl().fireEvent(event, true, AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
         }
         catch (final Exception e)
         {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java?rev=1607213&r1=1607212&r2=1607213&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
Tue Jul  1 23:12:58 2014
@@ -407,13 +407,18 @@ public class BeanManagerImpl implements 
      */
     @Override
     public void fireEvent(Object event, Annotation... bindings)
-    {       
+    {
+        fireEvent(event, false, bindings);
+    }
+
+    public void fireEvent(Object event, boolean containerEvent, Annotation... bindings)
+    {
         Type type = event.getClass();
         if (GenericsUtil.hasTypeParameters(type))
         {
             type = GenericsUtil.getParameterizedType(type);
         }
-        fireEvent(event, new EventMetadataImpl(type, null, bindings, webBeansContext), false);
+        fireEvent(event, new EventMetadataImpl(null, type, null, bindings, webBeansContext),
containerEvent);
     }
 
     /**
@@ -423,10 +428,10 @@ public class BeanManagerImpl implements 
      */
     public void fireLifecycleEvent(Object event, Annotation... bindings)
     {
-        fireEvent(event, new EventMetadataImpl(event.getClass(), null, bindings, webBeansContext),
true);
+        fireEvent(event, new EventMetadataImpl(null, event.getClass(), null, bindings, webBeansContext),
true);
     }
 
-    public void fireEvent(Object event, EventMetadata metadata, boolean isLifecycleEvent)
+    public void fireEvent(Object event, EventMetadataImpl metadata, boolean isLifecycleEvent)
     {
         notificationManager.fireEvent(event, metadata, isLifecycleEvent);
     }
@@ -1116,12 +1121,12 @@ public class BeanManagerImpl implements 
     @Override
     public <T> Set<ObserverMethod<? super T>> resolveObserverMethods(T
event, Annotation... qualifiers)
     {
-        return resolveObserverMethods(event, new EventMetadataImpl(event.getClass(), null,
qualifiers, webBeansContext));
+        return resolveObserverMethods(event, new EventMetadataImpl(null, event.getClass(),
null, qualifiers, webBeansContext));
     }
 
-    public <T> Set<ObserverMethod<? super T>> resolveObserverMethods(T
event, EventMetadata metadata) 
+    public <T> Set<ObserverMethod<? super T>> resolveObserverMethods(T
event, EventMetadataImpl metadata)
     {
-        return notificationManager.resolveObservers(event, metadata);
+        return notificationManager.resolveObservers(event, metadata, false);
     }
 
     @Override

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventImpl.java?rev=1607213&r1=1607212&r2=1607213&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventImpl.java
Tue Jul  1 23:12:58 2014
@@ -30,7 +30,6 @@ import javax.enterprise.util.TypeLiteral
 
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.util.Asserts;
-import org.apache.webbeans.util.GenericsUtil;
 
 /**
  * Event implementation.
@@ -69,7 +68,7 @@ public class EventImpl<T> implements Eve
         else
         {
             Set<Annotation> qualifiers = metadata.getQualifiers();
-            return new EventMetadataImpl(metadata.getType(), metadata.getInjectionPoint(),
qualifiers.toArray(new Annotation[qualifiers.size()]), webBeansContext);
+            return new EventMetadataImpl(null, metadata.getType(), metadata.getInjectionPoint(),
qualifiers.toArray(new Annotation[qualifiers.size()]), webBeansContext);
         }
     }
 
@@ -80,10 +79,7 @@ public class EventImpl<T> implements Eve
     public void fire(T event)
     {
         Type eventType = event.getClass();
-        if (GenericsUtil.hasTypeParameters(eventType))
-        {
-            eventType = GenericsUtil.resolveType(GenericsUtil.getParameterizedType(eventType),
metadata.getType());
-        }
+        webBeansContext.getWebBeansUtil().validEventType(eventType.getClass(), metadata.getType());
         webBeansContext.getBeanManagerImpl().fireEvent(event, metadata.select(eventType),
false);
     }
 

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=1607213&r1=1607212&r2=1607213&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 Jul  1 23:12:58 2014
@@ -21,17 +21,25 @@ package org.apache.webbeans.event;
 import java.io.IOException;
 import java.io.Serializable;
 import java.lang.annotation.Annotation;
+import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
 import java.util.Set;
+import java.util.TreeMap;
+import java.util.concurrent.ConcurrentHashMap;
 
 import javax.enterprise.inject.spi.EventMetadata;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.util.TypeLiteral;
 
 import org.apache.webbeans.annotation.AnyLiteral;
+import org.apache.webbeans.config.OwbParametrizedTypeImpl;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.util.ArrayUtil;
 
@@ -40,13 +48,15 @@ public class EventMetadataImpl implement
     private static final long serialVersionUID = -6401875861180683988L;
  
     private final Type type;
+    private final Type selectType;
     private final InjectionPoint injectionPoint;
     private final Set<Annotation> qualifiers;
     private transient WebBeansContext webBeansContext;
     
-    public EventMetadataImpl(Type type, InjectionPoint injectionPoint, Annotation[] qualifiers,
WebBeansContext context)
+    public EventMetadataImpl(Type selectType, Type type, InjectionPoint injectionPoint, Annotation[]
qualifiers, WebBeansContext context)
     {
         context.getAnnotationManager().checkQualifierConditions(qualifiers);
+        this.selectType = selectType;
         this.type = type;
         this.injectionPoint = injectionPoint;
         this.webBeansContext = context;
@@ -73,9 +83,36 @@ public class EventMetadataImpl implement
     @Override
     public Type getType()
     {
+        if (selectType != null
+                && ParameterizedType.class.isInstance(selectType))
+        {
+            final ParameterizedType parameterizedType = ParameterizedType.class.cast(selectType);
+            final Type rawType = parameterizedType.getRawType();
+            if (rawType == type)
+            {
+                return selectType;
+            }
+            else if (rawType == List.class && type == ArrayList.class)
+            {
+                return new OwbParametrizedTypeImpl(parameterizedType.getOwnerType(), type,
parameterizedType.getActualTypeArguments());
+            }
+            else if (rawType == Set.class && type == HashSet.class)
+            {
+                return new OwbParametrizedTypeImpl(parameterizedType.getOwnerType(), type,
parameterizedType.getActualTypeArguments());
+            }
+            else if (rawType == Map.class && (type == HashMap.class || type == ConcurrentHashMap.class
|| type == TreeMap.class))
+            {
+                return new OwbParametrizedTypeImpl(parameterizedType.getOwnerType(), type,
parameterizedType.getActualTypeArguments());
+            } // TODO: better handling of these kind of types, the idea is to check selectType
is a parent of type and param number is ==
+        }
         return type;
     }
-    
+
+    public Type validatedType()
+    {
+        return selectType != null? selectType : type;
+    }
+
     @Override
     public InjectionPoint getInjectionPoint()
     {
@@ -88,18 +125,18 @@ public class EventMetadataImpl implement
         return qualifiers;
     }
     
-    public EventMetadata select(Annotation... bindings)
+    public EventMetadataImpl select(Annotation... bindings)
     {
         return select(type, bindings);
     }
     
-    public EventMetadata select(TypeLiteral<?> subtype, Annotation... bindings)
+    public EventMetadataImpl select(TypeLiteral<?> subtype, Annotation... bindings)
     {
         webBeansContext.getWebBeansUtil().checkTypeVariables(subtype);
         return select(subtype.getType(), bindings);
     }
 
-    public EventMetadata select(Type subtype, Annotation... bindings)
+    public EventMetadataImpl select(Type subtype, Annotation... bindings)
     {
         Set<Annotation> newQualifiers = ArrayUtil.asSet(bindings);
         newQualifiers.addAll(qualifiers);
@@ -107,7 +144,7 @@ public class EventMetadataImpl implement
         {
             throw new IllegalArgumentException("duplicate qualifier");
         }
-        return new EventMetadataImpl(subtype, injectionPoint, newQualifiers.toArray(new Annotation[newQualifiers.size()]),
webBeansContext);
+        return new EventMetadataImpl(type, subtype, injectionPoint, newQualifiers.toArray(new
Annotation[newQualifiers.size()]), webBeansContext);
     }
     
     private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException

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=1607213&r1=1607212&r2=1607213&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 Jul  1 23:12:58 2014
@@ -38,7 +38,6 @@ import javax.enterprise.inject.spi.Annot
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedParameter;
 import javax.enterprise.inject.spi.BeforeBeanDiscovery;
-import javax.enterprise.inject.spi.EventMetadata;
 import javax.enterprise.inject.spi.Extension;
 import javax.enterprise.inject.spi.ObserverMethod;
 import javax.enterprise.inject.spi.ProcessProducer;
@@ -102,12 +101,12 @@ public final class NotificationManager
     }
 
 
-    public <T> Set<ObserverMethod<? super T>> resolveObservers(T event,
EventMetadata metadata)
+    public <T> Set<ObserverMethod<? super T>> resolveObservers(T event,
EventMetadataImpl metadata, boolean isLifecycleEvent)
     {
         EventUtil.checkEventBindings(webBeansContext, metadata.getQualifiers());
 
-        Type eventType = metadata.getType();
-        Set<ObserverMethod<? super T>> observersMethods = filterByType(event,
eventType);
+        Type eventType = metadata.validatedType();
+        Set<ObserverMethod<? super T>> observersMethods = filterByType(event,
eventType, isLifecycleEvent);
 
         observersMethods = filterByQualifiers(observersMethods, metadata.getQualifiers());
 
@@ -120,9 +119,9 @@ public final class NotificationManager
         return observersMethods;
     }
 
-    private <T> Set<ObserverMethod<? super T>> filterByType(T event, Type
declaredEventType)
+    private <T> Set<ObserverMethod<? super T>> filterByType(T event, Type
declaredEventType, boolean isLifecycleEvent)
     {
-        if(WebBeansUtil.isExtensionEventType(declaredEventType))
+        if (isLifecycleEvent)
         {
             return filterByExtensionEventType(event, declaredEventType);
         }
@@ -407,9 +406,14 @@ public final class NotificationManager
         return matching;
     }
 
-    public void fireEvent(Object event, EventMetadata metadata, boolean isLifecycleEvent)
+    public void fireEvent(Object event, EventMetadataImpl metadata, boolean isLifecycleEvent)
     {
-        Set<ObserverMethod<? super Object>> observerMethods = resolveObservers(event,
metadata);
+        if (!isLifecycleEvent && webBeansContext.getWebBeansUtil().isContainerEventType(event))
+        {
+            throw new IllegalArgumentException("Firing container events is forbidden");
+        }
+
+        Set<ObserverMethod<? super Object>> observerMethods = resolveObservers(event,
metadata, isLifecycleEvent);
 
         for (ObserverMethod<? super Object> observer : observerMethods)
         {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java?rev=1607213&r1=1607212&r2=1607213&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java
Tue Jul  1 23:12:58 2014
@@ -105,7 +105,7 @@ public class EventProducer<T> extends Ab
             
             try
             {
-                instance = new EventImpl<T>(new EventMetadataImpl(eventType, injectionPoint,
qualifiers, webBeansContext), webBeansContext);
+                instance = new EventImpl<T>(new EventMetadataImpl(null, eventType,
injectionPoint, qualifiers, webBeansContext), webBeansContext);
             }
             catch (Exception e)
             {

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=1607213&r1=1607212&r2=1607213&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 Jul  1 23:12:58 2014
@@ -72,7 +72,7 @@ public class AfterBeanDiscoveryImpl impl
         
         //Fire Event
         ProcessBean<?> processBeanEvent = new GProcessBean(bean,annotatedType);
-        beanManager.fireEvent(processBeanEvent, AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
+        beanManager.fireEvent(processBeanEvent, true, AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
         
         if(bean instanceof Interceptor)
         {
@@ -175,7 +175,7 @@ public class AfterBeanDiscoveryImpl impl
     public void addObserverMethod(ObserverMethod<?> observerMethod)
     {
         ProcessObserverMethod<?, ?> event = new GProcessObservableMethod(null,observerMethod);
-        beanManager.fireEvent(event, AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
+        beanManager.fireEvent(event, true, AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
         beanManager.getNotificationManager().addObserver(observerMethod, observerMethod.getObservedType());
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java?rev=1607213&r1=1607212&r2=1607213&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java
Tue Jul  1 23:12:58 2014
@@ -84,7 +84,8 @@ public final class GenericsUtil
         }
         else if (requiredType instanceof GenericArrayType)
         {
-            return isAssignableFrom(isDelegate, (GenericArrayType)requiredType, beanType);
+            return Class.class.isInstance(beanType) && Class.class.cast(beanType).isArray()
+                    && isAssignableFrom(isDelegate, (GenericArrayType)requiredType,
beanType);
         }
         else if (requiredType instanceof WildcardType)
         {
@@ -317,9 +318,20 @@ public final class GenericsUtil
         return true;
     }
 
+    // rules are a bit different when in an array so we handle ParameterizedType manually
(not reusing isAssignableFrom)
     private static boolean isAssignableFrom(boolean isDelegate, GenericArrayType injectionPointType,
Type beanType)
     {
-        throw new UnsupportedOperationException("Not yet implementeds");
+        final Type genericComponentType = injectionPointType.getGenericComponentType();
+        final Class componentType = Class.class.cast(beanType).getComponentType();
+        if (Class.class.isInstance(genericComponentType))
+        {
+            return Class.class.cast(genericComponentType).isAssignableFrom(componentType);
+        }
+        if (ParameterizedType.class.isInstance(genericComponentType))
+        {
+            return isAssignableFrom(isDelegate, ParameterizedType.class.cast(genericComponentType).getRawType(),
componentType);
+        }
+        return isAssignableFrom(isDelegate, genericComponentType, componentType);
     }
 
     private static boolean isAssignableFrom(boolean isDelegate, WildcardType injectionPointType,
Type beanType)

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=1607213&r1=1607212&r2=1607213&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 Jul  1 23:12:58 2014
@@ -49,6 +49,8 @@ import org.apache.webbeans.component.cre
 import org.apache.webbeans.component.creation.ObserverMethodsBuilder;
 import org.apache.webbeans.component.creation.ProducerFieldBeansBuilder;
 import org.apache.webbeans.component.creation.ProducerMethodBeansBuilder;
+import org.apache.webbeans.config.OwbParametrizedTypeImpl;
+import org.apache.webbeans.config.OwbWildcardTypeImpl;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.AnnotatedTypeWrapper;
 import org.apache.webbeans.container.BeanManagerImpl;
@@ -121,7 +123,11 @@ public final class WebBeansUtil
     private static final Logger logger = WebBeansLoggerFacade.getLogger(WebBeansUtil.class);
 
     private final WebBeansContext webBeansContext;
+
+    // cache to skip some validations
     private final ConcurrentMap<Type, Boolean> noTypeVariables = new ConcurrentHashMap<Type,
Boolean>();
+    private final ConcurrentMap<EventCacheKey, Boolean> validEventType = new ConcurrentHashMap<EventCacheKey,
Boolean>();
+    private final ConcurrentMap<Type, Boolean> notContainerEvents = new ConcurrentHashMap<Type,
Boolean>();
 
     public WebBeansUtil(WebBeansContext webBeansContext)
     {
@@ -930,7 +936,7 @@ public final class WebBeansUtil
         GProcessAnnotatedType processAnnotatedEvent = new GProcessAnnotatedType(annotatedType);
 
         //Fires ProcessAnnotatedType
-        webBeansContext.getBeanManagerImpl().fireEvent(processAnnotatedEvent,AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
+        webBeansContext.getBeanManagerImpl().fireEvent(processAnnotatedEvent, true, AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
 
         if (processAnnotatedEvent.isModifiedAnnotatedType())
         {
@@ -952,7 +958,7 @@ public final class WebBeansUtil
         GProcessSyntheticAnnotatedType gProcessSyntheticAnnotatedType = new GProcessSyntheticAnnotatedType(source,
annotatedType);
 
         //Fires ProcessSyntheticAnnotatedType
-        webBeansContext.getBeanManagerImpl().fireEvent(gProcessSyntheticAnnotatedType, AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
+        webBeansContext.getBeanManagerImpl().fireEvent(gProcessSyntheticAnnotatedType, true,
AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
 
         if (gProcessSyntheticAnnotatedType.isModifiedAnnotatedType())
         {
@@ -976,7 +982,7 @@ public final class WebBeansUtil
     private GProcessInjectionTarget fireProcessInjectionTargetEvent(GProcessInjectionTarget
processInjectionTargetEvent)
     {
         //Fires ProcessInjectionTarget
-        webBeansContext.getBeanManagerImpl().fireEvent(processInjectionTargetEvent, AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
+        webBeansContext.getBeanManagerImpl().fireEvent(processInjectionTargetEvent, true,
AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
         return processInjectionTargetEvent;
     }
 
@@ -1000,7 +1006,7 @@ public final class WebBeansUtil
     {
         GProcessProducer processProducerEvent = new GProcessProducer(producer, annotatedMember);
         //Fires ProcessProducer
-        webBeansContext.getBeanManagerImpl().fireEvent(processProducerEvent, AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
+        webBeansContext.getBeanManagerImpl().fireEvent(processProducerEvent, true, AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
         webBeansContext.getWebBeansUtil().inspectErrorStack("There are errors that are added
by ProcessProducer event observers. Look at logs for further details");
         return processProducerEvent.getProducer();
     }
@@ -1032,7 +1038,7 @@ public final class WebBeansUtil
 
 
             //Fires ProcessProducer
-            webBeansContext.getBeanManagerImpl().fireEvent(processProducerMethodEvent, AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
+            webBeansContext.getBeanManagerImpl().fireEvent(processProducerMethodEvent, true,
AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
         }
     }
 
@@ -1046,7 +1052,7 @@ public final class WebBeansUtil
             GProcessObservableMethod event = new GProcessObservableMethod(annotatedMethod,
observableMethod);
 
             //Fires ProcessProducer
-            webBeansContext.getBeanManagerImpl().fireEvent(event, AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
+            webBeansContext.getBeanManagerImpl().fireEvent(event, true, AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
         }
     }
 
@@ -1061,7 +1067,7 @@ public final class WebBeansUtil
             GProcessProducerField processProducerFieldEvent = new GProcessProducerField(bean,
field, null);
 
             //Fire ProcessProducer
-            webBeansContext.getBeanManagerImpl().fireEvent(processProducerFieldEvent, AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
+            webBeansContext.getBeanManagerImpl().fireEvent(processProducerFieldEvent, true,
AnnotationUtil.EMPTY_ANNOTATION_ARRAY);
         }
     }
 
@@ -1602,4 +1608,111 @@ public final class WebBeansUtil
         }
         noTypeVariables.putIfAbsent(t, true);
     }
+
+    public void validEventType(final Type eventType, final Type metadataType)
+    {
+        final EventCacheKey key = new EventCacheKey(eventType, metadataType);
+        if (validEventType.containsKey(key))
+        {
+            return;
+        }
+
+        if (GenericsUtil.hasTypeParameters(eventType))
+        {
+            final Type et = GenericsUtil.resolveType(GenericsUtil.getParameterizedType(eventType),
metadataType);
+            if (OwbParametrizedTypeImpl.class.isInstance(et))
+            {
+                for (final Type t : OwbParametrizedTypeImpl.class.cast(et).getActualTypeArguments())
+                {
+                    if (OwbWildcardTypeImpl.class.isInstance(t))
+                    {
+                        throw new IllegalArgumentException("TypeVariable forbidden for events");
+                    }
+                }
+            }
+        }
+        validEventType.putIfAbsent(key, true); // we don't care about the value but that's
thread safe to use this map
+    }
+
+    public boolean isContainerEventType(final Object event)
+    {
+        if (event == null)
+        {
+            return false;
+        }
+
+        final Class<?> eventType = event.getClass();
+        if (notContainerEvents.containsKey(eventType))
+        {
+            return false;
+        }
+
+        if (AfterBeanDiscovery.class.isInstance(event)
+                || AfterDeploymentValidation.class.isInstance(event)
+                || BeforeShutdown.class.isInstance(event)
+                || ProcessAnnotatedType.class.isInstance(event)
+                || ProcessInjectionPoint.class.isInstance(event)
+                || ProcessInjectionTarget.class.isInstance(event)
+                || ProcessBeanAttributes.class.isInstance(event)
+                || ProcessBean.class.isInstance(event)
+                || ProcessObserverMethod.class.isInstance(event)
+                || ProcessSessionBean.class.isInstance(event)
+                || ProcessProducer.class.isInstance(event)
+                || ProcessProducerField.class.isInstance(event)
+                || ProcessProducerMethod.class.isInstance(event)
+                || BeforeBeanDiscovery.class.isInstance(event))
+        {
+            return true;
+        }
+
+        notContainerEvents.putIfAbsent(eventType, true);
+        return false;
+    }
+
+    private static final class EventCacheKey
+    {
+        private final Type event;
+        private final Type metadata;
+        private final int hashCache;
+
+        private EventCacheKey(final Type event, final Type metadata)
+        {
+            this.event = event;
+            this.metadata = metadata;
+
+            int result = event != null ? event.hashCode() : 0;
+            result = 31 * result + (metadata != null ? metadata.hashCode() : 0);
+            this.hashCache = result;
+        }
+
+        @Override
+        public boolean equals(final Object o)
+        {
+            if (this == o)
+            {
+                return true;
+            }
+            if (o == null || EventCacheKey.class != o.getClass())
+            {
+                return false;
+            }
+
+            final EventCacheKey that = EventCacheKey.class.cast(o);
+            if (event != null ? !event.equals(that.event) : that.event != null)
+            {
+                return false;
+            }
+            if (metadata != null ? !metadata.equals(that.metadata) : that.metadata != null)
+            {
+                return false;
+            }
+            return true;
+        }
+
+        @Override
+        public int hashCode()
+        {
+            return hashCache;
+        }
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/ExtensionTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/ExtensionTest.java?rev=1607213&r1=1607212&r2=1607213&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/ExtensionTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/ExtensionTest.java
Tue Jul  1 23:12:58 2014
@@ -28,6 +28,8 @@ import junit.framework.Assert;
 import org.apache.webbeans.annotation.DefaultLiteral;
 import org.apache.webbeans.config.WebBeansContext;
 import javax.enterprise.inject.spi.DefinitionException;
+
+import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.test.AbstractUnitTest;
 import org.apache.webbeans.test.contexts.SerializationTest;
 import org.apache.webbeans.test.portable.alternative.Egg;
@@ -78,7 +80,7 @@ public class ExtensionTest extends Abstr
         Assert.assertTrue(getBeanManager().isPassivatingScope(ExternalTestScoped.class));
         
         //Fire shut down
-        getBeanManager().fireEvent(new BeforeShutdownImpl());
+        BeanManagerImpl.class.cast(getBeanManager()).fireEvent(new BeforeShutdownImpl(),
true);
 
         webBeansContext.getContextFactory().destroyApplicationContext(null);
 

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/portable/events/ExtensionTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/portable/events/ExtensionTest.java?rev=1607213&r1=1607212&r2=1607213&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/portable/events/ExtensionTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/portable/events/ExtensionTest.java
Tue Jul  1 23:12:58 2014
@@ -27,6 +27,7 @@ import javax.enterprise.inject.spi.Bean;
 import junit.framework.Assert;
 
 import org.apache.webbeans.annotation.DefaultLiteral;
+import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.test.AbstractUnitTest;
 import org.apache.webbeans.portable.events.discovery.BeforeShutdownImpl;
 import org.apache.webbeans.test.component.library.BookShop;
@@ -76,7 +77,7 @@ public class ExtensionTest extends Abstr
         Assert.assertNotNull(MyExtension.processProducer);
         
         //Fire shut down
-        getBeanManager().fireEvent(new BeforeShutdownImpl(), new Annotation[0]);
+        BeanManagerImpl.class.cast(getBeanManager()).fireEvent(new BeforeShutdownImpl(),
true);
 
         getWebBeansContext().getContextFactory().destroyApplicationContext(null);
 

Modified: openwebbeans/trunk/webbeans-tck/testng-dev.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tck/testng-dev.xml?rev=1607213&r1=1607212&r2=1607213&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-tck/testng-dev.xml (original)
+++ openwebbeans/trunk/webbeans-tck/testng-dev.xml Tue Jul  1 23:12:58 2014
@@ -18,8 +18,11 @@
 <suite name="JSR-346-TCK" verbose="2" configfailurepolicy="continue">
   <test name="JSR-346 TCK">
     <classes>
-      <class
-          name="org.jboss.cdi.tck.tests.extensions.stereotype.StereotypeExtensionTest" />
+      <class name="org.jboss.cdi.tck.tests.event.observer.wildcardAndTypeVariable.ObserverMethodWithParametertizedTypeTest"
/>
+      <!--
+      <class name="org.jboss.cdi.tck.tests.event.parameterized.ParameterizedEventTest"
/>
+      <class name="org.jboss.cdi.tck.tests.event.fires.FireEventTest" />
+      -->
     </classes>
     <groups>
       <run>



Mime
View raw message