openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1465432 [1/2] - in /openwebbeans/trunk: webbeans-ee/src/main/java/org/apache/webbeans/ee/event/ webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/ webbeans-impl/src/main/java/org/apache/webbeans/annotation/ webbeans-impl/src/m...
Date Sun, 07 Apr 2013 17:26:48 GMT
Author: arne
Date: Sun Apr  7 17:26:47 2013
New Revision: 1465432

URL: http://svn.apache.org/r1465432
Log:
OWB-766 and OWB-815: Implemented EventMetadata and InjectionPoint injection without ThreadLocals

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventMetadata.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/OwbObserverMethod.java
Modified:
    openwebbeans/trunk/webbeans-ee/src/main/java/org/apache/webbeans/ee/event/TransactionalEventNotifier.java
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbValidator.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnyLiteral.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/DefaultLiteral.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.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/EventUtil.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InstanceProducer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/tests/DependentProducerMethodInjectionPointTest.java
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationFilter.java
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.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=1465432&r1=1465431&r2=1465432&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 Sun Apr  7 17:26:47 2013
@@ -26,6 +26,8 @@ import javax.transaction.Transaction;
 
 import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.event.EventMetadata;
+import org.apache.webbeans.event.OwbObserverMethod;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
 import org.apache.webbeans.spi.TransactionService;
 
@@ -45,7 +47,7 @@ public class TransactionalEventNotifier
     /**
      * This will get called by the EJB integration code
      */
-    public static void registerTransactionSynchronization(TransactionPhase phase, ObserverMethod<? super Object> observer, Object event) throws Exception
+    public static void registerTransactionSynchronization(TransactionPhase phase, ObserverMethod<? super Object> observer, Object event, EventMetadata metadata) throws Exception
     {
         TransactionService transactionService = WebBeansContext.currentInstance().getService(TransactionService.class);
         
@@ -59,19 +61,19 @@ public class TransactionalEventNotifier
         {
             if (phase.equals(TransactionPhase.AFTER_COMPLETION))
             {
-                transaction.registerSynchronization(new AfterCompletion(observer, event));
+                transaction.registerSynchronization(new AfterCompletion(observer, event, metadata));
             }
             else if (phase.equals(TransactionPhase.AFTER_SUCCESS))
             {
-                transaction.registerSynchronization(new AfterCompletionSuccess(observer, event));
+                transaction.registerSynchronization(new AfterCompletionSuccess(observer, event, metadata));
             }
             else if (phase.equals(TransactionPhase.AFTER_FAILURE))
             {
-                transaction.registerSynchronization(new AfterCompletionFailure(observer, event));
+                transaction.registerSynchronization(new AfterCompletionFailure(observer, event, metadata));
             }
             else if (phase.equals(TransactionPhase.BEFORE_COMPLETION))
             {
-                transaction.registerSynchronization(new BeforeCompletion(observer, event));
+                transaction.registerSynchronization(new BeforeCompletion(observer, event, metadata));
             }
             else
             {
@@ -85,11 +87,13 @@ public class TransactionalEventNotifier
 
         private final ObserverMethod<T> observer;
         private final T event;
+        private final EventMetadata metadata;
 
-        public AbstractSynchronization(ObserverMethod<T> observer, T event)
+        public AbstractSynchronization(ObserverMethod<T> observer, T event, EventMetadata metadata)
         {
             this.observer = observer;
             this.event = event;
+            this.metadata = metadata;
         }
 
         public void beforeCompletion()
@@ -106,7 +110,14 @@ public class TransactionalEventNotifier
         {
             try
             {
-                observer.notify(event);
+                if (observer instanceof OwbObserverMethod)
+                {
+                    ((OwbObserverMethod<T>)observer).notify(event, metadata);
+                }
+                else
+                {
+                    observer.notify(event);
+                }
             }
             catch (Exception e)
             {
@@ -117,9 +128,9 @@ public class TransactionalEventNotifier
 
     private final static class BeforeCompletion extends AbstractSynchronization
     {
-        private BeforeCompletion(ObserverMethod observer, Object event)
+        private BeforeCompletion(ObserverMethod observer, Object event, EventMetadata metadata)
         {
-            super(observer, event);
+            super(observer, event, metadata);
         }
 
         @Override
@@ -131,9 +142,9 @@ public class TransactionalEventNotifier
 
     private final static class AfterCompletion extends AbstractSynchronization
     {
-        private AfterCompletion(ObserverMethod observer, Object event)
+        private AfterCompletion(ObserverMethod observer, Object event, EventMetadata metadata)
         {
-            super(observer, event);
+            super(observer, event, metadata);
         }
 
         @Override
@@ -145,9 +156,9 @@ public class TransactionalEventNotifier
 
     private final static class AfterCompletionSuccess extends AbstractSynchronization
     {
-        private AfterCompletionSuccess(ObserverMethod observer, Object event)
+        private AfterCompletionSuccess(ObserverMethod observer, Object event, EventMetadata metadata)
         {
-            super(observer, event);
+            super(observer, event, metadata);
         }
 
         @Override
@@ -162,9 +173,9 @@ public class TransactionalEventNotifier
 
     private final static class AfterCompletionFailure extends AbstractSynchronization
     {
-        private AfterCompletionFailure(ObserverMethod observer, Object event)
+        private AfterCompletionFailure(ObserverMethod observer, Object event, EventMetadata metadata)
         {
-            super(observer, event);
+            super(observer, event, metadata);
         }
 
         @Override

Modified: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbValidator.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbValidator.java?rev=1465432&r1=1465431&r2=1465432&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbValidator.java (original)
+++ openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbValidator.java Sun Apr  7 17:26:47 2013
@@ -20,7 +20,6 @@ package org.apache.webbeans.ejb.common.u
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
@@ -28,6 +27,8 @@ import java.util.Set;
 import javax.decorator.Decorator;
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.ObserverMethod;
 import javax.enterprise.inject.spi.SessionBeanType;
 import javax.interceptor.Interceptor;
@@ -35,6 +36,7 @@ import javax.interceptor.Interceptor;
 import org.apache.webbeans.ejb.common.component.BaseEjbBean;
 import org.apache.webbeans.event.ObserverMethodImpl;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.portable.AnnotatedElementFactory;
 import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.Asserts;
 import org.apache.webbeans.util.ClassUtil;
@@ -128,12 +130,12 @@ public final class EjbValidator
         }
     }
     
-    public static void validateObserverMethods(BaseEjbBean<?> bean, Set<ObserverMethod<?>> observers)
+    public static <T> void validateObserverMethods(BaseEjbBean<?> bean, Set<ObserverMethod<T>> observers)
     {
-        for(ObserverMethod<?> observer : observers)
+        for(ObserverMethod<T> observer : observers)
         {
-            ObserverMethodImpl<?> obs = (ObserverMethodImpl<?>)observer;
-            Method method = obs.getObserverMethod();
+            ObserverMethodImpl<T> obs = (ObserverMethodImpl<T>)observer;
+            AnnotatedMethod<T> method = obs.getObserverMethod();
             List<?> locals =  bean.getBusinessLocalInterfaces();
             if(locals != null)
             {
@@ -143,7 +145,7 @@ public final class EjbValidator
                 {
                     Class<?> clazz = (Class<?>)it.next();
                     Method classMethod = bean.getWebBeansContext().getSecurityService().
-                            doPrivilegedGetDeclaredMethod(clazz, method.getName(), method.getParameterTypes());
+                            doPrivilegedGetDeclaredMethod(clazz, method.getJavaMember().getName(), method.getJavaMember().getParameterTypes());
                     if(classMethod == null)
                     {
                         continue;
@@ -151,7 +153,9 @@ public final class EjbValidator
                     else
                     {
                         //Should only be a single method that matches the names & params
-                        obs.setObserverMethod(classMethod);
+                        AnnotatedElementFactory annotatedElementFactory = bean.getWebBeansContext().getAnnotatedElementFactory();
+                        AnnotatedType<T> declaringType = (AnnotatedType<T>) annotatedElementFactory.newAnnotatedType(classMethod.getDeclaringClass());
+                        obs.setObserverMethod(annotatedElementFactory.newAnnotatedMethod(classMethod, declaringType));
                         found = true;
                         break;
                     }
@@ -159,9 +163,9 @@ public final class EjbValidator
                 
                 if(!found)
                 {
-                    if(!Modifier.isStatic(method.getModifiers()))
+                    if(!method.isStatic())
                     {
-                        throw new WebBeansConfigurationException("Observer method : " + method.getName() + " in session bean class : " + 
+                        throw new WebBeansConfigurationException("Observer method : " + method.getJavaMember().getName() + " in session bean class : " + 
                                 bean.getBeanClass() + " must be business method");                                            
                     }
                 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnyLiteral.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnyLiteral.java?rev=1465432&r1=1465431&r2=1465432&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnyLiteral.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnyLiteral.java Sun Apr  7 17:26:47 2013
@@ -18,10 +18,15 @@
  */
 package org.apache.webbeans.annotation;
 
+import java.lang.annotation.Annotation;
+
 import javax.enterprise.inject.Any;
 
 public class AnyLiteral extends EmptyAnnotationLiteral<Any> implements Any
 {
+    public static final AnyLiteral INSTANCE = new AnyLiteral();
+    public static final Annotation[] ARRAY = new Annotation[]{AnyLiteral.INSTANCE};
+
     private static final String TOSTRING = "@javax.enterprise.inject.Any()";
     private static final long serialVersionUID = -8922048102786275371L;
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/DefaultLiteral.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/DefaultLiteral.java?rev=1465432&r1=1465431&r2=1465432&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/DefaultLiteral.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/DefaultLiteral.java Sun Apr  7 17:26:47 2013
@@ -18,6 +18,8 @@
  */
 package org.apache.webbeans.annotation;
 
+import java.lang.annotation.Annotation;
+
 import javax.enterprise.inject.Default;
 
 /**
@@ -28,6 +30,7 @@ import javax.enterprise.inject.Default;
 public class DefaultLiteral extends EmptyAnnotationLiteral<Default> implements Default
 {
     public static final DefaultLiteral INSTANCE = new DefaultLiteral();
+    public static final Annotation[] ARRAY = new Annotation[]{DefaultLiteral.INSTANCE};
 
     private static final String TOSTRING = "@javax.enterprise.inject.Default()";
     private static final long serialVersionUID = 6788272256977634238L;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java?rev=1465432&r1=1465431&r2=1465432&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java Sun Apr  7 17:26:47 2013
@@ -220,7 +220,7 @@ public abstract class BeanAttributesBuil
         //Add @Any support
         if(!hasAnyQualifier())
         {
-            qualifiers.add(new AnyLiteral());
+            qualifiers.add(AnyLiteral.INSTANCE);
         }
         
     }

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=1465432&r1=1465431&r2=1465432&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java Sun Apr  7 17:26:47 2013
@@ -924,7 +924,7 @@ public class BeansDeployer
                 for(ObserverMethod<?> observerMethod : observerMethods)
                 {
                     ObserverMethodImpl<?> impl = (ObserverMethodImpl<?>)observerMethod;
-                    AnnotatedMethod<?> method = webBeansContext.getAnnotatedElementFactory().newAnnotatedMethod(impl.getObserverMethod(), annotatedType);
+                    AnnotatedMethod<?> method = impl.getObserverMethod();
 
                     observerMethodsMap.put(observerMethod, method);
                 }

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=1465432&r1=1465431&r2=1465432&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 Sun Apr  7 17:26:47 2013
@@ -64,6 +64,7 @@ import javax.naming.NamingException;
 import javax.naming.Reference;
 import javax.naming.Referenceable;
 import javax.naming.StringRefAddr;
+
 import org.apache.webbeans.component.AbstractOwbBean;
 import org.apache.webbeans.component.BeanAttributesImpl;
 import org.apache.webbeans.component.EnterpriseBeanMarker;
@@ -77,13 +78,14 @@ import org.apache.webbeans.component.thi
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.decorator.DecoratorComparator;
+import org.apache.webbeans.event.EventMetadata;
+import org.apache.webbeans.event.EventMetadataImpl;
 import org.apache.webbeans.event.NotificationManager;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.exception.definition.DuplicateDefinitionException;
 import org.apache.webbeans.exception.inject.DefinitionException;
 import org.apache.webbeans.plugins.OpenWebBeansJmsPlugin;
 import org.apache.webbeans.portable.AnnotatedElementFactory;
-import org.apache.webbeans.portable.InjectionPointProducer;
 import org.apache.webbeans.portable.InjectionTargetImpl;
 import org.apache.webbeans.portable.events.discovery.ErrorStack;
 import org.apache.webbeans.spi.ScannerService;
@@ -406,13 +408,18 @@ public class BeanManagerImpl implements 
      * {@inheritDoc}
      */
     public void fireEvent(Object event, Annotation... bindings)
+    {       
+        fireEvent(event, new EventMetadataImpl(event.getClass(), null, bindings));
+    }
+
+    public void fireEvent(Object event, EventMetadata metadata)
     {                
         if (ClassUtil.isDefinitionContainsTypeVariables(event.getClass()))
         {
             throw new IllegalArgumentException("Event class : " + event.getClass().getName() + " can not be defined as generic type");
         }
 
-        notificationManager.fireEvent(event, bindings);
+        notificationManager.fireEvent(event, metadata);
     }
 
     public Set<Bean<?>> getComponents()
@@ -627,33 +634,36 @@ public class BeanManagerImpl implements 
             InjectionResolver.injectionPoints.set(injectionPoint);
         }
 
-        boolean ijbSet = false;
-        if (InjectionPointProducer.isStackEmpty())
+        if(WebBeansUtil.isDependent(injectedBean))
         {
-            ijbSet = true;
-            InjectionPointProducer.setThreadLocal(injectionPoint);
-        }
-
-        try
-        {
-            if(WebBeansUtil.isDependent(injectedBean))
+            if (!(ownerCreationalContext instanceof CreationalContextImpl))
+            {
+                ownerCreationalContext = webBeansContext.getCreationalContextFactory().wrappedCreationalContext(ownerCreationalContext, injectionPoint.getBean());
+            }
+            ((CreationalContextImpl<?>)ownerCreationalContext).putInjectionPoint(injectionPoint);
+            //Using owner creational context
+            //Dependents use parent creational context
+            try
             {
-                //Using owner creational context
-                //Dependents use parent creational context
                 instance = getReference(injectedBean, injectionPoint.getType(), ownerCreationalContext);
             }
-            else
+            finally
             {
-                //New creational context for normal scoped beans
-                CreationalContextImpl<Object> injectedCreational = (CreationalContextImpl<Object>)createCreationalContext(injectedBean);
-                instance = getReference(injectedBean, injectionPoint.getType(), injectedCreational);
+                ((CreationalContextImpl<?>)ownerCreationalContext).removeInjectionPoint();
             }
         }
-        finally
+        else
         {
-            if (ijbSet)
+            //New creational context for normal scoped beans
+            CreationalContextImpl<Object> injectedCreational = (CreationalContextImpl<Object>)createCreationalContext(injectedBean);
+            injectedCreational.putInjectionPoint(injectionPoint);
+            try
+            {
+                instance = getReference(injectedBean, injectionPoint.getType(), injectedCreational);
+            }
+            finally
             {
-                InjectionPointProducer.unsetThreadLocal();
+                injectedCreational.removeInjectionPoint();
             }
         }
 
@@ -978,14 +988,19 @@ public class BeanManagerImpl implements 
         return new InjectionTargetImpl<T>(bean.getAnnotatedType(), bean.getInjectionPoints(), webBeansContext, postConstructMethods, preDestroyMethods);
     }
 
-    public <T> Set<ObserverMethod<? super T>> resolveObserverMethods( T event, Annotation... qualifiers ) 
+    public <T> Set<ObserverMethod<? super T>> resolveObserverMethods(T event, Annotation... qualifiers)
+    {
+        return resolveObserverMethods(event, new EventMetadataImpl(event.getClass(), null, qualifiers));
+    }
+
+    public <T> Set<ObserverMethod<? super T>> resolveObserverMethods(T event, EventMetadata metadata) 
     {
-        if(ClassUtil.isDefinitionContainsTypeVariables(event.getClass()))
+        if(ClassUtil.isDefinitionContainsTypeVariables(ClassUtil.getClass(metadata.getType())))
         {
             throw new IllegalArgumentException("Event type can not contain type variables. Event class is : " + event.getClass());
         }
         
-        return notificationManager.resolveObservers(event, qualifiers);
+        return notificationManager.resolveObservers(event, metadata);
     }
 
     public ExpressionFactory wrapExpressionFactory(ExpressionFactory expressionFactory)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java?rev=1465432&r1=1465431&r2=1465432&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java Sun Apr  7 17:26:47 2013
@@ -75,9 +75,6 @@ public class InjectionResolver
      */
     private WebBeansContext webBeansContext;
     
-    private final static Annotation[] DEFAULT_LITERAL_ARRAY = new Annotation[]{DefaultLiteral.INSTANCE};
-    private final static Annotation[] ANY_LITERAL_ARRAY = new Annotation[]{new AnyLiteral()};
-
     /**
      * This Map contains all resolved beans via it's type and qualifiers.
      * If a bean have resolved as not existing, the entry will contain <code>null</code> as value.
@@ -223,8 +220,7 @@ public class InjectionResolver
         Annotation[] qualifiers = qualSet.toArray(new Annotation[qualSet.size()]);
         if (isInstanceOrEventInjection(type))
         {
-            qualifiers = new Annotation[1];
-            qualifiers[0] = new AnyLiteral();
+            qualifiers = AnyLiteral.ARRAY;
         }
 
         Class injectionPointClass = null;
@@ -261,7 +257,7 @@ public class InjectionResolver
         {
             newType = newQualifier.value();
         }
-        Set<Bean<?>> beans = implResolveByType(newType, injectionPoint.getBean().getBeanClass(), new AnyLiteral());
+        Set<Bean<?>> beans = implResolveByType(newType, injectionPoint.getBean().getBeanClass(), AnyLiteral.INSTANCE);
         if (beans.isEmpty())
         {
             beanSet.add(webBeansContext.getWebBeansUtil().createNewComponent(newType));
@@ -470,13 +466,13 @@ public class InjectionResolver
 
         if (isInstanceOrEventInjection(injectionPointType))
         {
-            qualifiers = ANY_LITERAL_ARRAY;
+            qualifiers = AnyLiteral.ARRAY;
         }
         else
         {
             if (qualifiers.length == 0)
             {
-                qualifiers = DEFAULT_LITERAL_ARRAY;
+                qualifiers = DefaultLiteral.ARRAY;
                 currentQualifier = true;
             }
         }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextFactory.java?rev=1465432&r1=1465431&r2=1465432&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextFactory.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextFactory.java Sun Apr  7 17:26:47 2013
@@ -54,7 +54,7 @@ public final class CreationalContextFact
         return new CreationalContextImpl<T>(contextual, webBeansContext);
     }        
     
-    public CreationalContext<T> wrappedCreationalContext(CreationalContext<T> creationalContext, Contextual<T> contextual)
+    public CreationalContextImpl<T> wrappedCreationalContext(CreationalContext<T> creationalContext, Contextual<T> contextual)
     {
         return new WrappedCreationalContext<T>(contextual, creationalContext, webBeansContext);
     }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java?rev=1465432&r1=1465431&r2=1465432&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java Sun Apr  7 17:26:47 2013
@@ -50,7 +50,7 @@ public class CreationalContextImpl<T> im
     /**
      * The injection point object to be injected into injection points of type InjectionPoint
      */
-    private transient Stack<InjectionPoint> injectionPoints;
+    private transient Stack<InjectionPoint> injectionPoints = null;
 
     /**
      * Contextual bean dependent instances

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=1465432&r1=1465431&r2=1465432&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 Sun Apr  7 17:26:47 2013
@@ -33,7 +33,6 @@ import javax.enterprise.inject.spi.Injec
 import javax.enterprise.util.TypeLiteral;
 
 import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.portable.InjectionPointProducer;
 import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.OwbCustomObjectInputStream;
 import org.apache.webbeans.util.WebBeansUtil;
@@ -79,15 +78,7 @@ public class EventImpl<T> implements Eve
      */
     public void fire(T event)
     {
-        InjectionPointProducer.setThreadLocal(injectionPoint);
-        try
-        {
-            webBeansContext.getBeanManagerImpl().fireEvent(event, injectedBindings);
-        }
-        finally
-        {
-            InjectionPointProducer.setThreadLocal(injectionPoint);
-        }
+        webBeansContext.getBeanManagerImpl().fireEvent(event, new EventMetadataImpl(eventType, injectionPoint, injectedBindings));
     }
 
     /**

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventMetadata.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventMetadata.java?rev=1465432&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventMetadata.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventMetadata.java Sun Apr  7 17:26:47 2013
@@ -0,0 +1,50 @@
+/*
+ * 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 java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.InjectionPoint;
+
+/**
+ * This is a preview to CDI 1.1
+ * when we implement CDI 1.1 this interface can be removed
+ */
+public interface EventMetadata
+{
+
+    /**
+     * Get the qualifiers for which event payload was fired.
+     */
+    public Set<Annotation> getQualifiers();
+
+    /**
+     * Get the {@link InjectionPoint} from which the event fired, or
+     * <code>null</code> if it was fired from
+     * {@link javax.enterprise.inject.spi.BeanManager#fireEvent(Object, Annotation...)};
+     */
+    public InjectionPoint getInjectionPoint();
+
+    /**
+     * Returns the resolved event {@link Type}.
+     */
+    public Type getType();
+}

Added: 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=1465432&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventMetadataImpl.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventMetadataImpl.java Sun Apr  7 17:26:47 2013
@@ -0,0 +1,78 @@
+/*
+ * 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 java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.apache.webbeans.annotation.AnyLiteral;
+import org.apache.webbeans.util.AnnotationUtil;
+
+public class EventMetadataImpl implements EventMetadata
+{
+
+    private final Type type;
+    private final InjectionPoint injectionPoint;
+    private final Set<Annotation> qualifiers;
+    
+    public EventMetadataImpl(Type type, InjectionPoint injectionPoint, Annotation... qualifiers)
+    {
+        this.type = type;
+        this.injectionPoint = injectionPoint;
+        Set<Annotation> completeQualifiers;
+        if (qualifiers.length == 0)
+        {
+            completeQualifiers = AnnotationUtil.DEFAULT_AND_ANY_ANNOTATION;
+        }
+        else
+        {
+            completeQualifiers = new HashSet<Annotation>(Arrays.asList(qualifiers));
+            if (completeQualifiers.size() != qualifiers.length)
+            {
+                throw new IllegalArgumentException("duplicate qualifier");
+            }
+            if (!completeQualifiers.contains(AnyLiteral.INSTANCE))
+            {
+                completeQualifiers.add(AnyLiteral.INSTANCE);
+            }
+        }
+        this.qualifiers = Collections.unmodifiableSet(completeQualifiers);
+    }
+
+    public Type getType()
+    {
+        return type;
+    }
+    
+    public InjectionPoint getInjectionPoint()
+    {
+        return injectionPoint;
+    }
+
+    public Set<Annotation> getQualifiers()
+    {
+        return qualifiers;
+    }
+}

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventUtil.java?rev=1465432&r1=1465431&r2=1465432&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventUtil.java Sun Apr  7 17:26:47 2013
@@ -21,13 +21,14 @@ package org.apache.webbeans.event;
 import java.lang.annotation.Annotation;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
-import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
+import java.util.Set;
 
 import javax.enterprise.event.Event;
 import javax.enterprise.event.Observes;
 import javax.enterprise.event.TransactionPhase;
+import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.InjectionPoint;
 
 import org.apache.webbeans.config.WebBeansContext;
@@ -53,7 +54,7 @@ public final class EventUtil
         }
     }
 
-    public static void checkEventBindings(WebBeansContext webBeansContext, Annotation... annotations)
+    public static void checkEventBindings(WebBeansContext webBeansContext, Set<Annotation> annotations)
     {
         for(Annotation ann : annotations)
         {
@@ -70,9 +71,9 @@ public final class EventUtil
         webBeansContext.getAnnotationManager().checkQualifierConditions(annotations);
     }
 
-    public static TransactionPhase getObserverMethodTransactionType(Method observerMethod)
+    public static TransactionPhase getObserverMethodTransactionType(AnnotatedMethod<?> observerMethod)
     {
-        Observes observes = AnnotationUtil.getMethodFirstParameterAnnotation(observerMethod, Observes.class);
+        Observes observes = AnnotationUtil.getAnnotatedMethodFirstParameterAnnotation(observerMethod, Observes.class);
         if (observes != null)
         {
             return observes.during();

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=1465432&r1=1465431&r2=1465432&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java Sun Apr  7 17:26:47 2013
@@ -21,7 +21,6 @@ package org.apache.webbeans.event;
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
@@ -40,7 +39,6 @@ import javax.enterprise.inject.spi.Obser
 import javax.enterprise.inject.spi.ProcessProducer;
 import javax.enterprise.util.TypeLiteral;
 
-import org.apache.webbeans.annotation.AnyLiteral;
 import org.apache.webbeans.component.AbstractOwbBean;
 import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.config.WebBeansContext;
@@ -50,7 +48,6 @@ import org.apache.webbeans.portable.even
 import org.apache.webbeans.portable.events.generics.GenericProducerObserverEvent;
 import org.apache.webbeans.spi.TransactionService;
 import org.apache.webbeans.util.AnnotationUtil;
-import org.apache.webbeans.util.ArrayUtil;
 import org.apache.webbeans.util.Asserts;
 import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.WebBeansUtil;
@@ -101,14 +98,14 @@ public final class NotificationManager
                 ObserverMethod<?> observer = i.next();
                 if (observer instanceof ObserverMethodImpl)
                 {
-                    Method observerMethod = ((ObserverMethodImpl<?>)observer).getObserverMethod();
+                    AnnotatedMethod<?> observerMethod = ((ObserverMethodImpl<?>)observer).getObserverMethod();
 
                     // we only remove methods from a superclass
-                    if (!observerMethod.getDeclaringClass().equals(subClass))
+                    if (!observerMethod.getJavaMember().getDeclaringClass().equals(subClass))
                     {
                         try
                         {
-                            subClass.getMethod(observerMethod.getName(), observerMethod.getParameterTypes());
+                            subClass.getMethod(observerMethod.getJavaMember().getName(), observerMethod.getJavaMember().getParameterTypes());
                             i.remove();
                         }
                         catch(NoSuchMethodException nsme)
@@ -123,39 +120,38 @@ public final class NotificationManager
         }
     }
 
-    public <T> Set<ObserverMethod<? super T>> resolveObservers(T event, Annotation... eventQualifiers)
+    public <T> Set<ObserverMethod<? super T>> resolveObservers(T event, EventMetadata metadata)
     {
-        EventUtil.checkEventBindings(webBeansContext, eventQualifiers);
+        EventUtil.checkEventBindings(webBeansContext, metadata.getQualifiers());
 
-        Set<Annotation> qualifiers = ArrayUtil.asSet(eventQualifiers);
+        Type eventType = metadata.getType();
+        Set<ObserverMethod<? super T>> observersMethods = filterByType(event, eventType);
 
-        Class<T> eventType = (Class<T>) event.getClass();
-        Set<ObserverMethod<? super T>> observersMethods = filterByType(event,eventType);
-
-        observersMethods = filterByQualifiers(observersMethods, qualifiers);
+        observersMethods = filterByQualifiers(observersMethods, metadata.getQualifiers());
 
         return observersMethods;
     }
 
-    private <T> Set<ObserverMethod<? super T>> filterByType(T event, Class<T> eventType)
+    private <T> Set<ObserverMethod<? super T>> filterByType(T event, Type eventType)
     {
         if(WebBeansUtil.isExtensionEventType(eventType))
         {
             return filterByExtensionEventType(event, eventType);
         }
+        Class<?> eventClass = ClassUtil.getClass(eventType);
         
         Set<ObserverMethod<? super T>> matching = new HashSet<ObserverMethod<? super T>>();
 
         Set<Type> types = new HashSet<Type>();
         types.add(eventType);
         
-        Type superClazz = eventType.getGenericSuperclass();
+        Type superClazz = eventClass.getGenericSuperclass();
         if(superClazz != null)
         {
             types.add(superClazz);    
         }
         
-        Type[] genericInts = eventType.getGenericInterfaces();
+        Type[] genericInts = eventClass.getGenericInterfaces();
         
         if(genericInts != null && genericInts.length > 0)
         {
@@ -186,8 +182,9 @@ public final class NotificationManager
         return matching;
     }
     
-    private <T> Set<ObserverMethod<? super T>> filterByExtensionEventType(T event, Class<T> eventType)
+    private <T> Set<ObserverMethod<? super T>> filterByExtensionEventType(T event, Type eventType)
     {
+        Class<?> eventClass = ClassUtil.getClazz(eventType);
         Set<ObserverMethod<? super T>> matching = new HashSet<ObserverMethod<? super T>>();        
         Set<Type> keySet = observers.keySet();
         for (Type type : keySet)
@@ -197,7 +194,7 @@ public final class NotificationManager
             
             if(observerClass != null)
             {
-                if(observerClass.isAssignableFrom(eventType))
+                if(observerClass.isAssignableFrom(eventClass))
                 {
                     //ProcessBean,ProcessAnnotateType, ProcessInjectionTarget
                     if(WebBeansUtil.isExtensionBeanEventType(eventType))
@@ -241,7 +238,7 @@ public final class NotificationManager
                                 addToMatching(type, matching);
                             }
                         }
-                        else if(observerClass.isAssignableFrom(eventType))
+                        else if(observerClass.isAssignableFrom(eventClass))
                         {
                             if(ClassUtil.isParametrizedType(type))
                             {
@@ -257,7 +254,7 @@ public final class NotificationManager
                     //BeforeShutDown Events
                     else
                     {
-                        if(observerClass.isAssignableFrom(eventType))
+                        if(observerClass.isAssignableFrom(eventClass))
                         {                
                             addToMatching(type, matching);
                         }
@@ -399,8 +396,6 @@ public final class NotificationManager
      */
     private <T> Set<ObserverMethod<? super T>> filterByQualifiers(Set<ObserverMethod<? super T>> observers, Set<Annotation> eventQualifiers)
     {
-        eventQualifiers.add(new AnyLiteral());
-                
         Set<ObserverMethod<? super T>> matching = new HashSet<ObserverMethod<? super T>>();
 
         search: for (ObserverMethod<? super T> ob : observers)
@@ -437,9 +432,9 @@ public final class NotificationManager
         return matching;
     }
 
-    public void fireEvent(Object event, Annotation... qualifiers)
+    public void fireEvent(Object event, EventMetadata metadata)
     {
-        Set<ObserverMethod<? super Object>> observerMethods = resolveObservers(event, qualifiers);
+        Set<ObserverMethod<? super Object>> observerMethods = resolveObservers(event, metadata);
 
         for (ObserverMethod<? super Object> observer : observerMethods)
         {
@@ -456,12 +451,26 @@ public final class NotificationManager
                     }
                     else
                     {
-                        observer.notify(event);
+                        if (observer instanceof OwbObserverMethod)
+                        {
+                            ((OwbObserverMethod<? super Object>)observer).notify(event, metadata);
+                        }
+                        else
+                        {
+                            observer.notify(event);
+                        }
                     }                    
                 }
                 else
                 {
-                    observer.notify(event);
+                    if (observer instanceof OwbObserverMethod)
+                    {
+                        ((OwbObserverMethod<? super Object>)observer).notify(event, metadata);
+                    }
+                    else
+                    {
+                        observer.notify(event);
+                    }
                 }
             }
             catch (WebBeansException e)
@@ -525,8 +534,7 @@ public final class NotificationManager
         Type type = AnnotationUtil.getAnnotatedMethodFirstParameterWithAnnotation(annotatedMethod, Observes.class);
         
         //Observer creation from annotated method
-        ObserverMethodImpl<T> observer = new ObserverMethodImpl(bean, annotatedMethod.getJavaMember(), ifExist, observerQualifiers, type);
-        observer.setAnnotatedMethod((AnnotatedMethod<T>)annotatedMethod);
+        ObserverMethodImpl<T> observer = new ObserverMethodImpl(bean, annotatedMethod, ifExist, observerQualifiers, type);
         
         //Adds this observer
         addObserver(observer, type);

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=1465432&r1=1465431&r2=1465432&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java Sun Apr  7 17:26:47 2013
@@ -19,7 +19,6 @@
 package org.apache.webbeans.event;
 
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
@@ -40,13 +39,10 @@ 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.AnnotatedType;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.ObserverMethod;
 
 import org.apache.webbeans.annotation.AnnotationManager;
-import org.apache.webbeans.annotation.DefaultLiteral;
 import org.apache.webbeans.component.AbstractOwbBean;
 import org.apache.webbeans.component.InjectionTargetBean;
 import org.apache.webbeans.component.WebBeansType;
@@ -57,12 +53,8 @@ import org.apache.webbeans.context.creat
 import org.apache.webbeans.exception.WebBeansException;
 import org.apache.webbeans.inject.impl.InjectionPointFactory;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
-import org.apache.webbeans.portable.AnnotatedElementFactory;
-import org.apache.webbeans.portable.InjectionPointProducer;
 import org.apache.webbeans.proxy.OwbNormalScopeProxy;
 import org.apache.webbeans.util.AnnotationUtil;
-import org.apache.webbeans.util.ClassUtil;
-import org.apache.webbeans.util.WebBeansUtil;
 
 /**
  * Defines observers that are declared in observer methods.
@@ -78,7 +70,7 @@ import org.apache.webbeans.util.WebBeans
  *  }
  * </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 ObserverMethod#notify()}
+ * and event qualifier is <code>Current</code>. Whenever event is fired, its {@link javax.enterprise.inject.spi.ObserverMethod#notify()}
  * method is called.
  * </p>
  * 
@@ -86,7 +78,7 @@ import org.apache.webbeans.util.WebBeans
  *
  * @param <T> event type
  */
-public class ObserverMethodImpl<T> implements ObserverMethod<T>
+public class ObserverMethodImpl<T> implements OwbObserverMethod<T>
 {
     /**Logger instance*/
     private final static Logger logger = WebBeansLoggerFacade.getLogger(ObserverMethodImpl.class);
@@ -94,9 +86,6 @@ public class ObserverMethodImpl<T> imple
     /**Observer owner bean that defines observer method*/
     private final AbstractOwbBean<?> bean;
 
-    /**Event observer method*/
-    private Method observerMethod;
-
     /**Using existing bean instance or not*/
     private final boolean ifExist;
     
@@ -110,7 +99,7 @@ public class ObserverMethodImpl<T> imple
     private final TransactionPhase phase;
     
     /**Annotated method*/
-    private AnnotatedMethod<T> annotatedMethod = null;
+    private AnnotatedMethod<T> observerMethod;
     
     private static class ObserverParams
     {
@@ -122,35 +111,6 @@ public class ObserverMethodImpl<T> imple
         
         private boolean isBean = false;
     }
-    
-    /**
-     * Creates a new bean observer instance.
-     * 
-     * @param bean owner
-     * @param observerMethod method
-     * @param ifExist if exist parameter
-     */
-    public ObserverMethodImpl(AbstractOwbBean<?> bean, Method observerMethod, boolean ifExist)
-    {
-        this.bean = bean;
-        this.observerMethod = observerMethod;
-        this.ifExist = ifExist;
-
-        Annotation[] qualifiers =
-            getWebBeansContext().getAnnotationManager().getMethodFirstParameterQualifierWithGivenAnnotation(
-                observerMethod, Observes.class);
-        getWebBeansContext().getAnnotationManager().checkQualifierConditions(qualifiers);
-        observedQualifiers = new HashSet<Annotation>(qualifiers.length);
-        
-        for (Annotation qualifier : qualifiers)
-        {
-            observedQualifiers.add(qualifier);
-        }
-
-        observedEventType = AnnotationUtil.getTypeOfParameterWithGivenAnnotation(observerMethod, Observes.class);
-
-        phase = EventUtil.getObserverMethodTransactionType(observerMethod);
-    }
 
     /**
      * used if the qualifiers and event type are already known, e.g. from the XML.
@@ -160,7 +120,7 @@ public class ObserverMethodImpl<T> imple
      * @param qualifiers
      * @param observedEventType
      */
-    public ObserverMethodImpl(AbstractOwbBean<?> bean, Method observerMethod, boolean ifExist,
+    public ObserverMethodImpl(AbstractOwbBean<?> bean, AnnotatedMethod<T> observerMethod, boolean ifExist,
                                  Annotation[] qualifiers, Type observedEventType)
     {
         this.bean = bean;
@@ -175,21 +135,20 @@ public class ObserverMethodImpl<T> imple
         phase = EventUtil.getObserverMethodTransactionType(observerMethod);
 
     }
-    
+
     /**
-     * Sets annotated method.
-     * @param annotatedMethod annotated method
+     * {@inheritDoc}
      */
-    public void setAnnotatedMethod(AnnotatedMethod<T> annotatedMethod)
+    public void notify(T event)
     {
-        this.annotatedMethod = annotatedMethod;
+        notify(event, null);
     }
 
     /**
      * {@inheritDoc}
      */
     @SuppressWarnings("unchecked")
-    public void notify(T event)
+    public void notify(T event, EventMetadata metadata)
     {
         AbstractOwbBean<Object> component = (AbstractOwbBean<Object>) bean;
         if (!bean.isEnabled())
@@ -199,19 +158,14 @@ public class ObserverMethodImpl<T> imple
 
         Object object = null;
         
-        List<ObserverParams> methodArgsMap;
-        if(annotatedMethod == null)
-        {
-            methodArgsMap = getMethodArguments(event);
-        }
-        else
-        {
-            methodArgsMap = getAnnotatedMethodArguments(event);
-        }
+        List<ObserverParams> methodArgsMap = getMethodArguments(event, metadata);
 
         BeanManagerImpl manager = bean.getWebBeansContext().getBeanManagerImpl();
-        CreationalContext<Object> creationalContext = manager.createCreationalContext(component);
-
+        CreationalContextImpl<Object> creationalContext = manager.createCreationalContext(component);
+        if (metadata != null)
+        {
+            creationalContext.putInjectionPoint(metadata.getInjectionPoint());
+        }
 
         ObserverParams[] obargs = null;
         try
@@ -226,14 +180,14 @@ public class ObserverMethodImpl<T> imple
             }
             
             //Static or not
-            if (Modifier.isStatic(observerMethod.getModifiers()))
+            if (observerMethod.isStatic())
             {
-                if (!observerMethod.isAccessible())
+                if (!observerMethod.getJavaMember().isAccessible())
                 {
-                    observerMethod.setAccessible(true);
+                    observerMethod.getJavaMember().setAccessible(true);
                 }
                 //Invoke Method
-                observerMethod.invoke(null, args);
+                observerMethod.getJavaMember().invoke(null, args);
             }
             else
             {
@@ -281,12 +235,12 @@ public class ObserverMethodImpl<T> imple
 
                 if (object != null)
                 {
-                    if (!observerMethod.isAccessible())
+                    if (!observerMethod.getJavaMember().isAccessible())
                     {
-                        bean.getWebBeansContext().getSecurityService().doPrivilegedSetAccessible(observerMethod, true);
+                        bean.getWebBeansContext().getSecurityService().doPrivilegedSetAccessible(observerMethod.getJavaMember(), true);
                     }
 
-                    if (Modifier.isPrivate(observerMethod.getModifiers()))
+                    if (Modifier.isPrivate(observerMethod.getJavaMember().getModifiers()))
                     {
                         // since private methods cannot be intercepted, we have to unwrap anny possible proxy
                         if (object instanceof OwbNormalScopeProxy)
@@ -296,7 +250,7 @@ public class ObserverMethodImpl<T> imple
                     }
 
                     //Invoke Method
-                    observerMethod.invoke(object, args);
+                    observerMethod.getJavaMember().invoke(object, args);
                 }
             }                        
         }
@@ -306,6 +260,7 @@ public class ObserverMethodImpl<T> imple
         }
         finally
         {
+            creationalContext.removeInjectionPoint();
             //Destory bean instance
             if (component.getScope().equals(Dependent.class) && object != null)
             {
@@ -326,122 +281,19 @@ public class ObserverMethodImpl<T> imple
         }
 
     }
-
-    /**
-     * Returns list of observer method parameters.
-     * 
-     * @param event event instance
-     * @return list of observer method parameters
-     */
-    @SuppressWarnings("unchecked")
-    protected List<ObserverParams> getMethodArguments(Object event)
-    {
-        WebBeansContext webBeansContext = bean.getWebBeansContext();
-        AnnotatedElementFactory annotatedElementFactory = webBeansContext.getAnnotatedElementFactory();
-        AnnotationManager annotationManager = webBeansContext.getAnnotationManager();
-
-        Type[] types = observerMethod.getGenericParameterTypes();
-        Annotation[][] annots = observerMethod.getParameterAnnotations();
-        List<ObserverParams> list = new ArrayList<ObserverParams>();
-
-        BeanManagerImpl manager = webBeansContext.getBeanManagerImpl();
-        ObserverParams param;
-        if (types.length > 0)
-        {
-            int i = 0;
-            for (Type type : types)
-            {
-                Annotation[] annot = annots[i];
-
-                boolean observesAnnotation = false;
-
-                if (annot.length == 0)
-                {
-                    annot = new Annotation[1];
-                    annot[0] = DefaultLiteral.INSTANCE;
-                }
-                else
-                {
-                    for (Annotation observersAnnot : annot)
-                    {
-                        if (observersAnnot.annotationType().equals(Observes.class))
-                        {
-                            param = new ObserverParams();
-                            param.instance = event;
-                            list.add(param); 
-                            observesAnnotation = true;
-                            break;
-                        }
-                    }
-                }
-
-                if (!observesAnnotation)
-                {
-                    boolean injectionPointBeanLocalSetOnStack = false;
-                    
-                    //Get parameter annotations
-                    Annotation[] bindingTypes = annotationManager.getQualifierAnnotations(annot);
-
-                    //Define annotated parameter
-                    AnnotatedType<T> annotatedType = (AnnotatedType<T>) annotatedElementFactory.newAnnotatedType(bean.getReturnType());
-                    AnnotatedMethod<T> newAnnotatedMethod = annotatedElementFactory.newAnnotatedMethod(observerMethod, annotatedType);
-
-                    //Annotated parameter
-                    AnnotatedParameter<T> annotatedParameter = newAnnotatedMethod.getParameters().get(i);
-                    
-                    //Creating injection point
-                    InjectionPoint point = InjectionPointFactory.getPartialInjectionPoint(bean, type, annotatedParameter, bindingTypes);
-                    
-                    //Injected Bean
-                    Bean<Object> injectedBean = (Bean<Object>)getWebBeansContext().getBeanManagerImpl().getInjectionResolver().getInjectionPointBean(point);
-                    
-                    //Set for @Inject InjectionPoint
-                    if(WebBeansUtil.isDependent(injectedBean))
-                    {
-                        if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(point.getType())))
-                        {
-                            injectionPointBeanLocalSetOnStack = InjectionPointProducer.setThreadLocal(point);
-                        }
-                    }
-                    
-                    CreationalContextImpl<Object> creational = manager.createCreationalContext(injectedBean);
-                    if (isEventProviderInjection(point))
-                    {
-                        creational.putInjectionPoint(point);
-                    }
-                    Object instance = manager.getReference(injectedBean, null, creational);
-                    if (injectionPointBeanLocalSetOnStack)
-                    {
-                        InjectionPointProducer.unsetThreadLocal();
-                    }
-
-                    param = new ObserverParams();
-                    param.isBean = true;
-                    param.creational = creational;
-                    param.instance = instance;
-                    param.bean = injectedBean;
-                    list.add(param);
-                }
-                
-                i++;
-            }
-        }
-
-        return list;
-    }
     
     /**
      * Gets observer method parameters.
      * @param event event payload
      * @return observer method parameters
      */
-    protected List<ObserverParams> getAnnotatedMethodArguments(Object event)
+    protected List<ObserverParams> getMethodArguments(Object event, EventMetadata metadata)
     {
         final WebBeansContext webBeansContext = bean.getWebBeansContext();
         final AnnotationManager annotationManager = webBeansContext.getAnnotationManager();
         final BeanManagerImpl manager = webBeansContext.getBeanManagerImpl();
         List<ObserverParams> list = new ArrayList<ObserverParams>();
-        List<AnnotatedParameter<T>> parameters = annotatedMethod.getParameters();
+        List<AnnotatedParameter<T>> parameters = observerMethod.getParameters();
         ObserverParams param = null;
         for(AnnotatedParameter<T> parameter : parameters)
         {
@@ -453,8 +305,6 @@ public class ObserverMethodImpl<T> imple
             }
             else
             {
-                boolean injectionPointBeanLocalSetOnStack = false;
-                
                 //Get parameter annotations
                 Annotation[] bindingTypes =
                     annotationManager.getQualifierAnnotations(AnnotationUtil.
@@ -465,27 +315,19 @@ public class ObserverMethodImpl<T> imple
                 //Get observer parameter instance
                 @SuppressWarnings("unchecked")
                 Bean<Object> injectedBean = (Bean<Object>)getWebBeansContext().getBeanManagerImpl().getInjectionResolver().getInjectionPointBean(point);
-
-                //Set for @Inject InjectionPoint
-                if(WebBeansUtil.isDependent(injectedBean))
-                {
-                    if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(point.getType())))
-                    {
-                        injectionPointBeanLocalSetOnStack = InjectionPointProducer.setThreadLocal(point);
-                    }
-                }                    
-
                 
                 CreationalContextImpl<Object> creational = manager.createCreationalContext(injectedBean);
-                if (isEventProviderInjection(point))
+                creational.putInjectionPoint(metadata.getInjectionPoint());
+                creational.putInjectionPoint(point);
+                Object instance;
+                try
                 {
-                    creational.putInjectionPoint(point);
+                    instance = manager.getReference(injectedBean, null, creational);
                 }
-                Object instance = manager.getReference(injectedBean, null, creational);
-                
-                if (injectionPointBeanLocalSetOnStack)
+                finally
                 {
-                    InjectionPointProducer.unsetThreadLocal();
+                    creational.removeInjectionPoint();
+                    creational.removeInjectionPoint();
                 }
                                     
                 param = new ObserverParams();
@@ -559,7 +401,7 @@ public class ObserverMethodImpl<T> imple
         return phase;
     }
     
-    public Method getObserverMethod()
+    public AnnotatedMethod<T> getObserverMethod()
     {
         return observerMethod;
     }
@@ -576,7 +418,7 @@ public class ObserverMethodImpl<T> imple
      * 
      * @param m method to be invoked as the observer
      */
-    public void setObserverMethod(Method m)
+    public void setObserverMethod(AnnotatedMethod<T> m)
     {
         observerMethod = m;
     }

Added: 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=1465432&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/OwbObserverMethod.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/OwbObserverMethod.java Sun Apr  7 17:26:47 2013
@@ -0,0 +1,34 @@
+/*
+ * 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.ObserverMethod;
+
+/**
+ * This interface fixes an issue of the CDI API. See https://issues.jboss.org/browse/CDI-36
+ */
+public interface OwbObserverMethod<T> extends ObserverMethod<T>
+{
+
+    /**
+     * will actually call the underlying observer method with the specified event metadata
+     */
+    public void notify(T event, EventMetadata metadata);    
+
+}

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java?rev=1465432&r1=1465431&r2=1465432&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java Sun Apr  7 17:26:47 2013
@@ -20,18 +20,14 @@ package org.apache.webbeans.inject;
 
 import java.io.Serializable;
 import java.lang.reflect.Member;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.List;
 
 import javax.enterprise.context.spi.Contextual;
-import javax.enterprise.event.Event;
 import javax.enterprise.inject.IllegalProductException;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.Producer;
-import javax.inject.Provider;
 
 import org.apache.webbeans.component.AbstractProducerBean;
 import org.apache.webbeans.component.OwbBean;
@@ -39,8 +35,6 @@ import org.apache.webbeans.config.WebBea
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.container.InjectionResolver;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
-import org.apache.webbeans.portable.InjectionPointProducer;
-import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.WebBeansUtil;
 
 /**
@@ -81,56 +75,35 @@ public abstract class AbstractInjectable
         InjectionResolver instance = beanManager.getInjectionResolver();
 
         Bean<?> injectedBean = instance.getInjectionPointBean(injectionPoint);
-        if (isInstanceProviderInjection(injectionPoint) || isEventProviderInjection(injectionPoint))
-        {
-            creationalContext.putInjectionPoint(injectionPoint);
-        }
         
-        boolean injectionPointBeanLocalSetOnStack = false;
-        try 
+        //Injection for dependent instance InjectionPoint fields
+        boolean dependentProducer = false;
+        if(WebBeansUtil.isDependent(injectedBean))
         {
-            //Injection for dependent instance InjectionPoint fields
-            boolean dependentProducer = false;
-            if(WebBeansUtil.isDependent(injectedBean))
+            if(!injectionPoint.isTransient())
             {
-                if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(injectionPoint.getType())))
-                {
-                    injectionPointBeanLocalSetOnStack = InjectionPointProducer.setThreadLocal(injectionPoint);
-                }
-
-                if(!injectionPoint.isTransient())
+                if(injectedBean instanceof AbstractProducerBean)
                 {
-                    if(injectedBean instanceof AbstractProducerBean)
+                    if((creationalContext.getBean() instanceof OwbBean) && ((OwbBean<?>) creationalContext.getBean()).isPassivationCapable())
                     {
-                        if((creationalContext.getBean() instanceof OwbBean) && ((OwbBean<?>) creationalContext.getBean()).isPassivationCapable())
-                        {
-                            dependentProducer = true;   
-                        }
+                        dependentProducer = true;   
                     }
                 }
-            }        
+            }
+        }        
 
-            //Gets injectable reference for injected bean
-            injected = (T) beanManager.getInjectableReference(injectionPoint, creationalContext);
+        //Gets injectable reference for injected bean
+        injected = (T) beanManager.getInjectableReference(injectionPoint, creationalContext);
 
-            /*X TODO see spec issue CDI-140 */
-            if(dependentProducer)
-            {
-                if(injected != null && !Serializable.class.isAssignableFrom(injected.getClass()))
-                {
-                    throw new IllegalProductException("If a producer method or field of scope @Dependent returns an serializable object for injection " +
-                                                    "into an injection point "+ injectionPoint +" that requires a passivation capable dependency");
-                }
-            }
-        } 
-        finally
+        /*X TODO see spec issue CDI-140 */
+        if(dependentProducer)
         {
-            if (injectionPointBeanLocalSetOnStack)
+            if(injected != null && !Serializable.class.isAssignableFrom(injected.getClass()))
             {
-                InjectionPointProducer.unsetThreadLocal();
+                throw new IllegalProductException("If a producer method or field of scope @Dependent returns an serializable object for injection " +
+                        "into an injection point "+ injectionPoint +" that requires a passivation capable dependency");
             }
         }
-        
 
         return injected;
     }
@@ -162,41 +135,4 @@ public abstract class AbstractInjectable
         }
         return injectionPoints;
     }
-
-    private boolean isInstanceProviderInjection(InjectionPoint injectionPoint)
-    {
-        Type type = injectionPoint.getType();
-        
-        if (type instanceof ParameterizedType)
-        {
-            ParameterizedType pt = (ParameterizedType) type;            
-            Class<?> clazz = (Class<?>) pt.getRawType();
-            
-            if(Provider.class.isAssignableFrom(clazz))
-            {
-                return true;
-            }
-        }
-        
-        return false;
-    }
-    
-    
-    private boolean isEventProviderInjection(InjectionPoint injectionPoint)
-    {
-        Type type = injectionPoint.getType();
-        
-        if (type instanceof ParameterizedType)
-        {
-            ParameterizedType pt = (ParameterizedType) type;            
-            Class<?> clazz = (Class<?>) pt.getRawType();
-            
-            if(clazz.isAssignableFrom(Event.class))
-            {
-                return true;
-            }
-        }
-        
-        return false;
-    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java?rev=1465432&r1=1465431&r2=1465432&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java Sun Apr  7 17:26:47 2013
@@ -37,7 +37,7 @@ import javax.enterprise.util.TypeLiteral
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.container.InjectionResolver;
-import org.apache.webbeans.portable.InjectionPointProducer;
+import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.InjectionExceptionUtil;
 import org.apache.webbeans.util.OwbCustomObjectInputStream;
@@ -65,7 +65,7 @@ public class InstanceImpl<T> implements 
 
     private WebBeansContext webBeansContext;
 
-    private CreationalContext<?> parentCreationalContext;
+    private CreationalContextImpl<?> parentCreationalContext;
 
     /**
      * Creates new instance.
@@ -77,7 +77,7 @@ public class InstanceImpl<T> implements 
      * @param annotations qualifier annotations
      */
     public InstanceImpl(Type injectionClazz, InjectionPoint injectionPoint, WebBeansContext webBeansContext,
-                 CreationalContext<?> creationalContext, Annotation... annotations)
+                 CreationalContextImpl<?> creationalContext, Annotation... annotations)
     {
         this.injectionClazz = injectionClazz;
         this.injectionPoint = injectionPoint;
@@ -100,39 +100,43 @@ public class InstanceImpl<T> implements 
     {
         T instance;
 
-        InjectionPointProducer.setThreadLocal(injectionPoint);
-        try
-        {
-            Annotation[] anns = new Annotation[qualifierAnnotations.size()];
-            anns = qualifierAnnotations.toArray(anns);
-        
-            Set<Bean<?>> beans = resolveBeans();
+        Annotation[] anns = new Annotation[qualifierAnnotations.size()];
+        anns = qualifierAnnotations.toArray(anns);
 
-            BeanManagerImpl beanManager = webBeansContext.getBeanManagerImpl();
+        Set<Bean<?>> beans = resolveBeans();
 
-            Bean<?> bean = beanManager.resolve(beans);
-            
-            if (bean == null)
-            {
-                InjectionExceptionUtil.throwUnsatisfiedResolutionException(ClassUtil.getClazz(injectionClazz), injectionPoint, anns);
-            }
+        BeanManagerImpl beanManager = webBeansContext.getBeanManagerImpl();
+
+        Bean<?> bean = beanManager.resolve(beans);
+
+        if (bean == null)
+        {
+            InjectionExceptionUtil.throwUnsatisfiedResolutionException(ClassUtil.getClazz(injectionClazz), injectionPoint, anns);
+        }
 
-            // since Instance<T> is Dependent, we we gonna use the parent CreationalContext by default
-            CreationalContext<?> creationalContext = parentCreationalContext;
+        // since Instance<T> is Dependent, we we gonna use the parent CreationalContext by default
+        CreationalContext<?> creationalContext = parentCreationalContext;
 
-            boolean isDependentBean = WebBeansUtil.isDependent(bean);
+        boolean isDependentBean = WebBeansUtil.isDependent(bean);
 
-            if (!isDependentBean)
-            {
-                // but for all NormalScoped beans we will need to create a fresh CreationalContext
-                creationalContext = beanManager.createCreationalContext(bean);
-            }
+        if (!isDependentBean)
+        {
+            // but for all NormalScoped beans we will need to create a fresh CreationalContext
+            creationalContext = beanManager.createCreationalContext(bean);
+        }
+        if (!(creationalContext instanceof CreationalContextImpl))
+        {
+            creationalContext = webBeansContext.getCreationalContextFactory().wrappedCreationalContext(creationalContext, bean);
+        }
 
+        ((CreationalContextImpl<?>)creationalContext).putInjectionPoint(injectionPoint);
+        try
+        {
             instance = (T) beanManager.getReference(bean, null, creationalContext);
         }
         finally
         {
-            InjectionPointProducer.removeThreadLocal();
+            ((CreationalContextImpl<?>)creationalContext).removeInjectionPoint();
         }
 
         return instance;
@@ -259,7 +263,7 @@ public class InstanceImpl<T> implements 
     {
         Set<Bean<?>> beans = resolveBeans();
         Set<T> instances = new HashSet<T>();
-        InjectionPointProducer.setThreadLocal(injectionPoint);
+        parentCreationalContext.putInjectionPoint(injectionPoint);
         try
         {
             for(Bean<?> bean : beans)
@@ -270,7 +274,7 @@ public class InstanceImpl<T> implements 
         }
         finally
         {
-            InjectionPointProducer.removeThreadLocal();
+            parentCreationalContext.removeInjectionPoint();
         }
         
         return instances.iterator();

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java?rev=1465432&r1=1465431&r2=1465432&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java Sun Apr  7 17:26:47 2013
@@ -18,16 +18,14 @@
  */
 package org.apache.webbeans.portable;
 
-import java.util.Stack;
-
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.InjectionPoint;
 
+import org.apache.webbeans.context.creational.CreationalContextImpl;
+import org.apache.webbeans.util.ClassUtil;
+
 public class InjectionPointProducer extends AbstractProducer<InjectionPoint>
 {
-
-    //X TODO refactor. public static variables are utterly ugly
-    private static ThreadLocal<Stack<InjectionPoint>> localThreadlocalStack = new ThreadLocal<Stack<InjectionPoint>>();
     
     /**
      * {@inheritDoc}
@@ -35,53 +33,30 @@ public class InjectionPointProducer exte
     @Override
     public InjectionPoint produce(CreationalContext<InjectionPoint> creationalContext)
     {
-        return getStackOfInjectionPoints().peek();
-    }
-
-    @Override
-    public void dispose(InjectionPoint ip)
-    {
-        removeThreadLocal();
-    }
-
-    private static Stack<InjectionPoint> getStackOfInjectionPoints()
-    {
-        Stack<InjectionPoint> stackIP = localThreadlocalStack.get();
-        if (null == stackIP)
+        if (!(creationalContext instanceof CreationalContextImpl))
         {
-            stackIP = new Stack<InjectionPoint>();
+            return null;
         }
-        return stackIP;
-    }
-
-    public static boolean setThreadLocal(InjectionPoint ip)
-    {
-        Stack<InjectionPoint> stackIP = getStackOfInjectionPoints();
-        stackIP.push(ip);
-        localThreadlocalStack.set(stackIP);
-        return true;
-    }
-    
-    public static void unsetThreadLocal()
-    {
-        Stack<InjectionPoint> stackIP = getStackOfInjectionPoints();
-        if (!stackIP.isEmpty())
+        // the first injection point on the stack is of type InjectionPoint, so we need the second one
+        CreationalContextImpl<InjectionPoint> creationalContextImpl = (CreationalContextImpl<InjectionPoint>)creationalContext;
+        InjectionPoint first = creationalContextImpl.removeInjectionPoint();
+        if (!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(first.getType())))
         {
-            stackIP.pop();
+            throw new IllegalStateException("Inconsistent injection point stack");
+        }
+        try
+        {
+            return creationalContextImpl.getInjectionPoint();
+        }
+        finally
+        {
+            creationalContextImpl.putInjectionPoint(first);
         }
     }
-    
-    /**
-     * Removes the ThreadLocal from the ThreadMap to prevent memory leaks.
-     */
-    public static void removeThreadLocal()
-    {
-        getStackOfInjectionPoints().clear();
-        localThreadlocalStack.remove();
-    }
-    
-    public static boolean isStackEmpty()
+
+    @Override
+    public void dispose(InjectionPoint ip)
     {
-        return getStackOfInjectionPoints().isEmpty();
+        // nothing to do
     }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InstanceProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InstanceProducer.java?rev=1465432&r1=1465431&r2=1465432&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InstanceProducer.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InstanceProducer.java Sun Apr  7 17:26:47 2013
@@ -27,6 +27,7 @@ import javax.enterprise.context.spi.Crea
 import javax.enterprise.inject.Instance;
 import javax.enterprise.inject.spi.InjectionPoint;
 
+import org.apache.webbeans.component.InstanceBean;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.inject.instance.InstanceImpl;
@@ -50,11 +51,17 @@ public class InstanceProducer<T> extends
         try
         {
             InjectionPoint injectionPoint = null;
-            //TODO What should we do here if creationalContext is not instanceof CreationalContextImpl?
+            CreationalContextImpl<Instance<T>> creationalContextImpl = null;
             if (creationalContext instanceof CreationalContextImpl)
             {
-                injectionPoint = ((CreationalContextImpl<Instance<T>>)creationalContext).getInjectionPoint();
+                creationalContextImpl = (CreationalContextImpl<Instance<T>>)creationalContext;
             }
+            else
+            {
+                InstanceBean<Object> instanceBean = webBeansContext.getWebBeansUtil().getInstanceBean();
+                creationalContextImpl = webBeansContext.getCreationalContextFactory().wrappedCreationalContext(creationalContext, instanceBean);
+            }
+            injectionPoint = creationalContextImpl.getInjectionPoint();
             Set<Annotation> qualifiers;
             Type type;
 
@@ -70,7 +77,7 @@ public class InstanceProducer<T> extends
                 type = this.returnType;
             }
 
-            Instance<T> instance = new InstanceImpl<T>(type, injectionPoint, webBeansContext, creationalContext, qualifiers.toArray(new Annotation[qualifiers.size()]));
+            Instance<T> instance = new InstanceImpl<T>(type, injectionPoint, webBeansContext, creationalContextImpl, qualifiers.toArray(new Annotation[qualifiers.size()]));
             
             return instance;
         }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java?rev=1465432&r1=1465431&r2=1465432&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java Sun Apr  7 17:26:47 2013
@@ -49,7 +49,8 @@ public final class AnnotationUtil
 
     public static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
     
-    public static final Set<Annotation> DEFAULT_AND_ANY_ANNOTATION = Collections.unmodifiableSet(new HashSet<Annotation>(Arrays.asList(DefaultLiteral.INSTANCE, new AnyLiteral())));
+    public static final Set<Annotation> DEFAULT_AND_ANY_ANNOTATION
+        = Collections.unmodifiableSet(new HashSet<Annotation>(Arrays.<Annotation>asList(DefaultLiteral.INSTANCE, AnyLiteral.INSTANCE)));
 
     // No instantiate
     private AnnotationUtil()
@@ -245,37 +246,6 @@ public final class AnnotationUtil
         }
         return result;
     }
-
-    /**
-     * Gets the method first found parameter annotation with given type.
-     * 
-     * @param method method
-     * @param clazz checking annotation
-     * @return annotation
-     */
-    public static <T extends Annotation> T getMethodFirstParameterAnnotation(Method method, Class<T> clazz)
-    {
-        Asserts.assertNotNull(method, "Method argument can not be null");
-        Asserts.nullCheckForClass(clazz);
-
-        Annotation[][] parameterAnns = method.getParameterAnnotations();
-
-        for (Annotation[] parameters : parameterAnns)
-        {
-            for (Annotation param : parameters)
-            {
-                Class<? extends Annotation> btype = param.annotationType();
-                if (btype.equals(clazz))
-                {
-                    return clazz.cast(param);
-                }
-
-            }
-
-        }
-
-        return null;
-    }    
     
     public static <X,T extends Annotation> T getAnnotatedMethodFirstParameterAnnotation(AnnotatedMethod<X> annotatedMethod, Class<T> clazz)
     {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java?rev=1465432&r1=1465431&r2=1465432&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java Sun Apr  7 17:26:47 2013
@@ -931,8 +931,9 @@ public final class ClassUtil
      * @return true if there are type parameters
      * @since 1.1.1
      */
-    public static boolean isDefinitionContainsTypeVariables(Class<?> clazz)
+    public static boolean isDefinitionContainsTypeVariables(Type type)
     {
+        Class<?> clazz = ClassUtil.getClass(type);
         Asserts.nullCheckForClass(clazz);
         
         return (clazz.getTypeParameters().length > 0) ? true : false;



Mime
View raw message