openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1606685 - 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 Mon, 30 Jun 2014 11:12:34 GMT
Author: rmannibucau
Date: Mon Jun 30 11:12:33 2014
New Revision: 1606685

URL: http://svn.apache.org/r1606685
Log:
keep track of extension which added an annotatedtype

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ContainerEventObserverMethodImpl.java
      - copied, changed from r1606621, openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/ExtensionAware.java
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/AnnotatedTypeWrapper.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/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/portable/events/discovery/AfterBeanDiscoveryImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterTypeDiscoveryImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/BeforeBeanDiscoveryImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.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=1606685&r1=1606684&r2=1606685&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
Mon Jun 30 11:12:33 2014
@@ -759,13 +759,17 @@ public class BeansDeployer
                     }
 
                     // Fires ProcessAnnotatedType
-                    ProcessAnnotatedTypeImpl<?> processAnnotatedEvent =
-                            webBeansContext.getWebBeansUtil().fireProcessAnnotatedTypeEvent(annotatedType);
-
-                    // if veto() is called
-                    if (!processAnnotatedEvent.isVeto())
+                    if (!annotatedType.getJavaClass().isAnnotation())
+                    {
+                        ProcessAnnotatedTypeImpl<?> processAnnotatedEvent = webBeansContext.getWebBeansUtil().fireProcessAnnotatedTypeEvent(annotatedType);
+                        if (!processAnnotatedEvent.isVeto())
+                        {
+                            annotatedTypes.add(processAnnotatedEvent.getAnnotatedType());
+                        }
+                    }
+                    else
                     {
-                        annotatedTypes.add(processAnnotatedEvent.getAnnotatedType());
+                        annotatedTypes.add(annotatedType);
                     }
                 }
                 catch (NoClassDefFoundError ncdfe)
@@ -854,12 +858,12 @@ public class BeansDeployer
         for (AnnotatedType<?> annotatedType : additionalAnnotatedTypes)
         {
             // Fires ProcessAnnotatedType
-            ProcessSyntheticAnnotatedTypeImpl<?> processAnnotatedEvent =
-                    webBeansContext.getWebBeansUtil().fireProcessSyntheticAnnotatedTypeEvent(annotatedType);
+            ProcessSyntheticAnnotatedTypeImpl<?> processAnnotatedEvent = !annotatedType.getJavaClass().isAnnotation()
?
+                    webBeansContext.getWebBeansUtil().fireProcessSyntheticAnnotatedTypeEvent(annotatedType)
: null;
 
-            if (!processAnnotatedEvent.isVeto())
+            if (processAnnotatedEvent == null || !processAnnotatedEvent.isVeto())
             {
-                AnnotatedType<?> changedAnnotatedType = processAnnotatedEvent.getAnnotatedType();
+                AnnotatedType<?> changedAnnotatedType = processAnnotatedEvent == null
? annotatedType : processAnnotatedEvent.getAnnotatedType();
                 if (annotatedTypes.contains(changedAnnotatedType))
                 {
                     annotatedTypes.remove(changedAnnotatedType);

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/AnnotatedTypeWrapper.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/AnnotatedTypeWrapper.java?rev=1606685&r1=1606684&r2=1606685&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/AnnotatedTypeWrapper.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/AnnotatedTypeWrapper.java
Mon Jun 30 11:12:33 2014
@@ -22,18 +22,21 @@ import javax.enterprise.inject.spi.Annot
 import javax.enterprise.inject.spi.AnnotatedField;
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Extension;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 import java.util.Set;
 
 // totally useless but TCKs check AT references creating a new instance for each call...
-class AnnotatedTypeWrapper<T> implements AnnotatedType<T>
+public class AnnotatedTypeWrapper<T> implements AnnotatedType<T>
 {
     private final AnnotatedType<T> original;
+    private final Extension source;
 
-    public AnnotatedTypeWrapper(final AnnotatedType<T> annotatedType)
+    public AnnotatedTypeWrapper(final Extension source, final AnnotatedType<T> annotatedType)
     {
-        original = annotatedType;
+        this.source = source;
+        this.original = annotatedType;
     }
 
     @Override
@@ -89,4 +92,9 @@ class AnnotatedTypeWrapper<T> implements
     {
         return original.isAnnotationPresent(aClass);
     }
+
+    public Extension getSource()
+    {
+        return source;
+    }
 }

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=1606685&r1=1606684&r2=1606685&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
Mon Jun 30 11:12:33 2014
@@ -1090,14 +1090,14 @@ public class BeanManagerImpl implements 
         }
     }
 
-    public void addAdditionalAnnotatedType(AnnotatedType<?> annotatedType)
+    public void addAdditionalAnnotatedType(Object extension, AnnotatedType<?> annotatedType)
     {
-        addAdditionalAnnotatedType(annotatedType, AnnotatedElementFactory.OWB_DEFAULT_KEY);
+        addAdditionalAnnotatedType(extension, annotatedType, AnnotatedElementFactory.OWB_DEFAULT_KEY);
     }
 
-    public <T> void addAdditionalAnnotatedType(AnnotatedType<T> inAnnotatedType,
String id)
+    public <T> void addAdditionalAnnotatedType(Object extension, AnnotatedType<T>
inAnnotatedType, String id)
     {
-        final AnnotatedType<T> annotatedType = new AnnotatedTypeWrapper<T>(inAnnotatedType);
+        final AnnotatedType<T> annotatedType = new AnnotatedTypeWrapper<T>(Extension.class.cast(extension),
inAnnotatedType);
         if (annotatedType.getAnnotation(Vetoed.class) != null)
         {
             // we could check package here too but would be a lost of time 99.99% of the
time

Copied: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ContainerEventObserverMethodImpl.java
(from r1606621, 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/ContainerEventObserverMethodImpl.java?p2=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ContainerEventObserverMethodImpl.java&p1=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java&r1=1606621&r2=1606685&rev=1606685&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/ContainerEventObserverMethodImpl.java
Mon Jun 30 11:12:33 2014
@@ -18,434 +18,35 @@
  */
 package org.apache.webbeans.event;
 
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-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;
-import java.util.logging.Logger;
+import org.apache.webbeans.component.AbstractOwbBean;
+import org.apache.webbeans.portable.events.discovery.ExtensionAware;
 
-import javax.enterprise.context.ContextNotActiveException;
-import javax.enterprise.context.Dependent;
-import javax.enterprise.context.spi.Context;
-import javax.enterprise.context.spi.CreationalContext;
-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.Bean;
-import javax.enterprise.inject.spi.EventMetadata;
-import javax.enterprise.inject.spi.InjectionPoint;
-
-import org.apache.webbeans.component.AbstractOwbBean;
-import org.apache.webbeans.component.WebBeansType;
-import org.apache.webbeans.config.OWBLogConst;
-import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.container.BeanManagerImpl;
-import org.apache.webbeans.context.creational.CreationalContextImpl;
-import org.apache.webbeans.exception.WebBeansException;
-import org.apache.webbeans.inject.impl.InjectionPointFactory;
-import org.apache.webbeans.logger.WebBeansLoggerFacade;
-import org.apache.webbeans.proxy.OwbNormalScopeProxy;
-import org.apache.webbeans.spi.plugins.OpenWebBeansEjbPlugin;
+import java.lang.reflect.InvocationTargetException;
 
-/**
- * Defines observers that are declared in observer methods.
- * <p>
- * Example:
- * <pre>
- *  public class X {
- *      
- *      public void afterLoggedIn(@Observes @Current LoggedInEvent event)
- *      {
- *          .....
- *      }
- *  }
- * </pre>
- * Above class X instance observes for the event with type <code>LoggedInEvent</code>
- * and event qualifier is <code>Current</code>. Whenever event is fired, its
{@link javax.enterprise.inject.spi.ObserverMethod#notify()}
- * method is called.
- * </p>
- * 
- * @version $Rev$ $Date$
- *
- * @param <T> event type
- */
-public class ObserverMethodImpl<T> implements OwbObserverMethod<T>
+public class ContainerEventObserverMethodImpl<T> extends ObserverMethodImpl<T>
 {
-    /**Logger instance*/
-    private final static Logger logger = WebBeansLoggerFacade.getLogger(ObserverMethodImpl.class);
-
-    /**Observer owner bean that defines observer method*/
-    private final AbstractOwbBean<?> bean;
-
-    /**Using existing bean instance or not*/
-    private final boolean ifExist;
-    
-    /** the observed qualifiers */
-    private final Set<Annotation> observedQualifiers;
-
-    /** the type of the observed event */
-    private final Type observedEventType;
-    
-    /** 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;
-        
-        private Object instance;
-        
-        private CreationalContext<Object> creational;
-        
-        private boolean isBean = false;
-    }
-
-    /**
-     * used if the qualifiers and event type are already known, e.g. from the XML.
-     * @param bean
-     * @param annotatedObserverMethod
-     * @param ifExist
-     * @param qualifiers
-     * @param observedEventType
-     */
-    public ObserverMethodImpl(AbstractOwbBean<?> bean, AnnotatedParameter<T>
annotatedObservesParameter)
-    {
-        this.bean = bean;
-        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()))
-        {
-            view = ejbPlugin.resolveViewMethod(bean , annotatedObserverMethod.getJavaMember());
-        }
-        else
-        {
-            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()
+    public ContainerEventObserverMethodImpl(final AbstractOwbBean<?> bean, final AnnotatedParameter<T>
annotatedObservesParameter)
     {
-        return injectionPoints;
+        super(bean, annotatedObservesParameter);
     }
 
-    /**
-     * {@inheritDoc}
-     */
     @Override
-    public void notify(T event)
+    protected void invoke(final Object object, final Object[] args) throws IllegalAccessException,
InvocationTargetException
     {
-        notify(event, null);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    @SuppressWarnings("unchecked")
-    public void notify(T event, EventMetadata metadata)
-    {
-        AbstractOwbBean<Object> component = (AbstractOwbBean<Object>) bean;
-        if (!bean.isEnabled())
-        {
-            return;
-        }
-
-        Object object = null;
-        
-        List<ObserverParams> methodArgsMap = getMethodArguments(event, metadata);
-        
-        BeanManagerImpl manager = bean.getWebBeansContext().getBeanManagerImpl();
-        CreationalContextImpl<Object> creationalContext = manager.createCreationalContext(component);
-        if (metadata != null)
-        {
-            creationalContext.putInjectionPoint(metadata.getInjectionPoint());
-            creationalContext.putEventMetadata(metadata);
-        }
-        
-        ObserverParams[] obargs = null;
-        try
+        ExtensionAware extensionAware = null;
+        if (args.length > 0)
         {
-            obargs = new ObserverParams[methodArgsMap.size()];
-            obargs = methodArgsMap.toArray(obargs);
-            Object[] args = new Object[obargs.length];
-            int i = 0;
-            for(ObserverParams param : obargs)
+            if (ExtensionAware.class.isInstance(args[0]))
             {
-                args[i++] = param.instance;
+                extensionAware = ExtensionAware.class.cast(args[0]);
+                extensionAware.setExtension(object);
             }
-
-            //Static or not
-            if (Modifier.isStatic(view.getModifiers()))
-            {
-                if (!view.isAccessible())
-                {
-                    view.setAccessible(true);
-                }
-                //Invoke Method
-                view.invoke(null, args);
-            }
-            else
-            {
-                Context context;
-                try
-                {
-                    context = manager.getContext(component.getScope());
-                }
-                catch (ContextNotActiveException cnae)
-                {
-                    // 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);
-                    return;
-                }
-                
-
-                // on Reception.IF_EXISTS: ignore this bean if a the contextual instance
doesn't already exist
-                object = context.get(component);
-
-                if (ifExist && object == null)
-                {
-                    return;
-                }
-
-                if (object == null)
-                {
-                    object = context.get(component, creationalContext);
-                }
-
-                if (object == null)
-                {
-                    // this might happen for EJB components.
-                    Type t = component.getBeanClass();
-
-                    // If the bean is an EJB, its beanClass may not be one of
-                    // its types. Instead pick a local interface
-                    if (component.getWebBeansType() == WebBeansType.ENTERPRISE)
-                    {
-                        t = (Type) component.getTypes().toArray()[0];
-                    }
-
-                    object = manager.getReference(component, t, creationalContext);
-
-                }
-
-                if (object != null)
-                {
-                    if (!view.isAccessible())
-                    {
-                        bean.getWebBeansContext().getSecurityService().doPrivilegedSetAccessible(view,
true);
-                    }
-
-                    if (Modifier.isPrivate(view.getModifiers()))
-                    {
-                        // since private methods cannot be intercepted, we have to unwrap
anny possible proxy
-                        if (object instanceof OwbNormalScopeProxy)
-                        {
-                            object = getWebBeansContext().getInterceptorDecoratorProxyFactory().unwrapInstance(object);
-                        }
-                    }
-
-                    //Invoke Method
-                    view.invoke(object, args);
-                }
-            }                        
-        }
-        catch (Exception e)
-        {
-                throw new WebBeansException(e);
         }
-        finally
-        {
-            creationalContext.removeEventMetadata();
-            creationalContext.removeInjectionPoint();
-            //Destory bean instance
-            if (component.getScope().equals(Dependent.class) && object != null)
-            {
-                component.destroy(object, creationalContext);
-            }
-            
-            //Destroy observer method dependent instances
-            if(methodArgsMap != null)
-            {
-                for(ObserverParams param : obargs)
-                {
-                    if(param.isBean && param.bean.getScope().equals(Dependent.class))
-                    {
-                        param.bean.destroy(param.instance, param.creational);
-                    }
-                }
-            }
-        }
-
-    }
-    
-    /**
-     * Gets observer method parameters.
-     * @param event event payload
-     * @return observer method parameters
-     */
-    protected List<ObserverParams> getMethodArguments(Object event, EventMetadata metadata)
-    {
-        List<ObserverParams> list = new ArrayList<ObserverParams>();
-        if (annotatedObservesParameter.getPosition() == 0)
+        super.invoke(object, args);
+        if (extensionAware != null)
         {
-            ObserverParams param = new ObserverParams();
-            param.instance = event;
-            list.add(param);
+            ExtensionAware.class.cast(extensionAware).setExtension(null);
         }
-        final WebBeansContext webBeansContext = bean.getWebBeansContext();
-        final BeanManagerImpl manager = webBeansContext.getBeanManagerImpl();
-
-        for (InjectionPoint injectionPoint: injectionPoints)
-        {
-            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
-            {
-                instance = manager.getReference(injectedBean, null, creational);
-            }
-            finally
-            {
-                creational.removeEventMetadata();
-                creational.removeInjectionPoint();
-                creational.removeInjectionPoint();
-            }
-                                
-            ObserverParams param = new ObserverParams();
-            param.isBean = true;
-            param.creational = creational;
-            param.instance = instance;
-            param.bean = injectedBean;
-            list.add(param);
-
-            if (list.size() == annotatedObservesParameter.getPosition())
-            {
-                param = new ObserverParams();
-                param.instance = event;
-                list.add(param);                 
-            }
-        }
-                
-        return list;
-    }
-
-    /**
-     * Returns observer owner bean.
-     * 
-     * @return the bean
-     */
-    @Override
-    @SuppressWarnings("unchecked")
-    public Class<?> getBeanClass()
-    {
-        return bean.getBeanClass();
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    @Override
-    public Set<Annotation> getObservedQualifiers()
-    {
-        return observedQualifiers;
-    }
-    
-    /** 
-     * {@inheritDoc}
-     */
-    @Override
-    public Type getObservedType()
-    {
-        return observedEventType;
-    }
-
-    /** 
-     * {@inheritDoc}
-     */
-    @Override
-    public Reception getReception()
-    {
-        return ifExist ? Reception.IF_EXISTS : Reception.ALWAYS;
-    }
-
-    @Override
-    public TransactionPhase getTransactionPhase()
-    {
-        return phase;
-    }
-    
-    public AnnotatedMethod<T> getObserverMethod()
-    {
-        return annotatedObserverMethod;
-    }
-
-    protected WebBeansContext getWebBeansContext()
-    {
-        return bean.getWebBeansContext();
-    }
-    
-    /**
-     * Provides a way to set the observer method. This may need to be done for
-     * EJBs so that the method used will be from an interface and not the
-     * EJB class that likely can not be invoked on the EJB proxy
-     * 
-     * @param m method to be invoked as the observer
-     */
-    public void setObserverMethod(AnnotatedMethod<T> m)
-    {
-        annotatedObserverMethod = m;
     }
 }

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=1606685&r1=1606684&r2=1606685&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
Mon Jun 30 11:12:33 2014
@@ -33,7 +33,11 @@ import java.util.concurrent.ConcurrentHa
 
 import javax.enterprise.event.ObserverException;
 import javax.enterprise.event.TransactionPhase;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.AnnotatedCallable;
+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;
@@ -493,7 +497,9 @@ public final class NotificationManager
         Asserts.assertNotNull(annotatedParameter, "annotatedParameter can not be null");
         
         //Observer creation from annotated method
-        ObserverMethodImpl<T> observer = new ObserverMethodImpl(bean, annotatedParameter);
+        ObserverMethodImpl<T> observer = isContainerEvent(annotatedParameter)?
+                new ContainerEventObserverMethodImpl(bean, annotatedParameter) :
+                new ObserverMethodImpl(bean, annotatedParameter);
         
         //Adds this observer
         addObserver(observer, annotatedParameter.getBaseType());
@@ -501,4 +507,15 @@ public final class NotificationManager
         return observer;
     }
 
+    private boolean isContainerEvent(final AnnotatedParameter<?> annotatedParameter)
+    {
+        final AnnotatedCallable<?> method = annotatedParameter.getDeclaringCallable();
+        if (!AnnotatedMethod.class.isInstance(method) || method.getParameters().size() ==
0)
+        {
+            return false;
+        }
+        final Class<?> paramType = AnnotatedMethod.class.cast(method).getJavaMember().getParameterTypes()[0];
+        return paramType == BeforeBeanDiscovery.class || paramType == AfterBeanDiscovery.class;
+    }
+
 }

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=1606685&r1=1606684&r2=1606685&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
Mon Jun 30 11:12:33 2014
@@ -19,6 +19,7 @@
 package org.apache.webbeans.event;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.Type;
@@ -294,7 +295,7 @@ public class ObserverMethodImpl<T> imple
                     }
 
                     //Invoke Method
-                    view.invoke(object, args);
+                    invoke(object, args);
                 }
             }                        
         }
@@ -326,7 +327,12 @@ public class ObserverMethodImpl<T> imple
         }
 
     }
-    
+
+    protected void invoke(final Object object, final Object[] args) throws IllegalAccessException,
InvocationTargetException
+    {
+        view.invoke(object, args);
+    }
+
     /**
      * Gets observer method parameters.
      * @param event event payload

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=1606685&r1=1606684&r2=1606685&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
Mon Jun 30 11:12:33 2014
@@ -54,6 +54,7 @@ public class AfterBeanDiscoveryImpl impl
     
     private static final Logger logger = WebBeansLoggerFacade.getLogger(AfterBeanDiscoveryImpl.class);
     private final WebBeansContext webBeansContext;
+    private Object extension;
 
     public AfterBeanDiscoveryImpl(WebBeansContext webBeansContext)
     {
@@ -194,4 +195,8 @@ public class AfterBeanDiscoveryImpl impl
         return beanManager.getAnnotatedTypes(type);
     }
 
+    public void setExtension(final Object extension)
+    {
+        this.extension = extension;
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterTypeDiscoveryImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterTypeDiscoveryImpl.java?rev=1606685&r1=1606684&r2=1606685&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterTypeDiscoveryImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/AfterTypeDiscoveryImpl.java
Mon Jun 30 11:12:33 2014
@@ -28,12 +28,13 @@ import org.apache.webbeans.config.WebBea
  * OWB fires this event after all AnnotatedTypes from scanned classes
  * got picked up.
  */
-public class AfterTypeDiscoveryImpl implements AfterTypeDiscovery
+public class AfterTypeDiscoveryImpl implements AfterTypeDiscovery, ExtensionAware
 {
     private final WebBeansContext webBeansContext;
     private final List<Class<?>> sortedAlternatives;
     private final List<Class<?>> sortedInterceptors;
     private final List<Class<?>> sortedDecorators;
+    private Object extension;
 
     public AfterTypeDiscoveryImpl(WebBeansContext webBeansContext,
                                   List<Class<?>> sortedInterceptors,
@@ -68,6 +69,12 @@ public class AfterTypeDiscoveryImpl impl
     public void addAnnotatedType(AnnotatedType<?> type, String id)
     {
         //X TODO evaluate and file Extension
-        webBeansContext.getBeanManagerImpl().addAdditionalAnnotatedType(type, id);
+        webBeansContext.getBeanManagerImpl().addAdditionalAnnotatedType(extension, type,
id);
+    }
+
+    @Override
+    public void setExtension(final Object instance)
+    {
+        this.extension = instance;
     }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/BeforeBeanDiscoveryImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/BeforeBeanDiscoveryImpl.java?rev=1606685&r1=1606684&r2=1606685&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/BeforeBeanDiscoveryImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/BeforeBeanDiscoveryImpl.java
Mon Jun 30 11:12:33 2014
@@ -34,11 +34,12 @@ import org.apache.webbeans.deployment.St
  * @version $Rev$ $Date$
  *
  */
-public class BeforeBeanDiscoveryImpl implements BeforeBeanDiscovery
+public class BeforeBeanDiscoveryImpl implements BeforeBeanDiscovery, ExtensionAware
 {
     
     private BeanManagerImpl beanManager = null;
     private final WebBeansContext webBeansContext;
+    private Object extension;
 
     public BeforeBeanDiscoveryImpl(WebBeansContext webBeansContext)
     {
@@ -52,7 +53,7 @@ public class BeforeBeanDiscoveryImpl imp
     @Override
     public void addAnnotatedType(AnnotatedType<?> type)
     {
-        beanManager.addAdditionalAnnotatedType(type);
+        beanManager.addAdditionalAnnotatedType(extension, type);
     }
 
     /**
@@ -100,7 +101,7 @@ public class BeforeBeanDiscoveryImpl imp
      */
     public void addAnnotatedType(AnnotatedType<?> annotatedType, String id)
     {
-        beanManager.addAdditionalAnnotatedType(annotatedType, id);
+        beanManager.addAdditionalAnnotatedType(extension, annotatedType, id);
     }
 
     /**
@@ -119,4 +120,9 @@ public class BeforeBeanDiscoveryImpl imp
     {
         beanManager.addAdditionalQualifier(annotatedType.getJavaClass());
     }
+
+    public void setExtension(final Object extension)
+    {
+        this.extension = extension;
+    }
 }

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/ExtensionAware.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/ExtensionAware.java?rev=1606685&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/ExtensionAware.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/events/discovery/ExtensionAware.java
Mon Jun 30 11:12:33 2014
@@ -0,0 +1,24 @@
+/*
+ * 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.portable.events.discovery;
+
+public interface ExtensionAware
+{
+    void setExtension(Object instance);
+}

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=1606685&r1=1606684&r2=1606685&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
Mon Jun 30 11:12:33 2014
@@ -50,6 +50,7 @@ import org.apache.webbeans.component.cre
 import org.apache.webbeans.component.creation.ProducerFieldBeansBuilder;
 import org.apache.webbeans.component.creation.ProducerMethodBeansBuilder;
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.container.AnnotatedTypeWrapper;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.container.ExternalScope;
 import org.apache.webbeans.container.InjectionResolver;
@@ -949,7 +950,7 @@ public final class WebBeansUtil
      */
     public <T> GProcessSyntheticAnnotatedType fireProcessSyntheticAnnotatedTypeEvent(AnnotatedType<T>
annotatedType)
     {
-        Extension source = null; //X TODO
+        Extension source = AnnotatedTypeWrapper.class.isInstance(annotatedType) ? AnnotatedTypeWrapper.class.cast(annotatedType).getSource()
: null;
         GProcessSyntheticAnnotatedType gProcessSyntheticAnnotatedType = new GProcessSyntheticAnnotatedType(source,
annotatedType);
 
         //Fires ProcessSyntheticAnnotatedType

Modified: openwebbeans/trunk/webbeans-tck/testng-dev.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tck/testng-dev.xml?rev=1606685&r1=1606684&r2=1606685&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-tck/testng-dev.xml (original)
+++ openwebbeans/trunk/webbeans-tck/testng-dev.xml Mon Jun 30 11:12:33 2014
@@ -19,7 +19,7 @@
   <test name="JSR-346 TCK">
     <classes>
       <class
-          name="org.jboss.cdi.tck.tests.extensions.afterBeanDiscovery.annotated.GetAnnotatedTypesTest"
/>
+          name="org.jboss.cdi.tck.tests.extensions.annotated.synthetic.ProcessSyntheticAnnotatedTypeTest"
/>
     </classes>
     <groups>
       <run>



Mime
View raw message