You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2015/03/05 10:05:21 UTC

svn commit: r1664284 - /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/LazyInterceptorDefinedInjectionTarget.java

Author: rmannibucau
Date: Thu Mar  5 09:05:20 2015
New Revision: 1664284

URL: http://svn.apache.org/r1664284
Log:
supporting interceptors when we can for unmanagedinstance

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/LazyInterceptorDefinedInjectionTarget.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/LazyInterceptorDefinedInjectionTarget.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/LazyInterceptorDefinedInjectionTarget.java?rev=1664284&r1=1664283&r2=1664284&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/LazyInterceptorDefinedInjectionTarget.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/LazyInterceptorDefinedInjectionTarget.java Thu Mar  5 09:05:20 2015
@@ -19,6 +19,7 @@
 package org.apache.webbeans.portable;
 
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
 
 import javax.enterprise.context.spi.CreationalContext;
@@ -26,11 +27,15 @@ import javax.enterprise.inject.spi.Annot
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.InjectionPoint;
+import java.lang.annotation.Annotation;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
 public class LazyInterceptorDefinedInjectionTarget<T> extends InjectionTargetImpl<T>
 {
+    private volatile boolean init;
+
     public LazyInterceptorDefinedInjectionTarget(final AnnotatedType<T> annotatedType,
                                                  final Set<InjectionPoint> injectionPoints,
                                                  final WebBeansContext webBeansContext,
@@ -40,16 +45,45 @@ public class LazyInterceptorDefinedInjec
         super(annotatedType, injectionPoints, webBeansContext, postConstructMethods, preDestroyMethods);
     }
 
-    @Override // TODO: this is not thread safe
+    @Override
     public T produce(final CreationalContext<T> creationalContext)
     {
-        interceptorInfo = null;
-        proxyClass = null;
-        final CreationalContextImpl<T> creationalContextImpl = (CreationalContextImpl<T>) creationalContext;
-        final Bean<T> bean = creationalContextImpl.getBean();
-        if (bean != null)
+        if (!init)
         {
-            defineInterceptorStack(bean, annotatedType, webBeansContext);
+            synchronized (this)
+            {
+                if (!init)
+                {
+                    final CreationalContextImpl<T> creationalContextImpl = (CreationalContextImpl<T>) creationalContext;
+                    Bean<T> bean = creationalContextImpl.getBean();
+                    if (bean == null) // try to find it
+                    {
+                        final BeanManagerImpl bm = webBeansContext.getBeanManagerImpl();
+                        final Set<Annotation> annotations = new HashSet<Annotation>();
+                        for (final Annotation a : annotatedType.getAnnotations())
+                        {
+                            if (bm.isQualifier(a.annotationType()))
+                            {
+                                annotations.add(a);
+                            }
+                        }
+                        try
+                        {
+                            final Set<Bean<?>> beans = bm.getBeans(annotatedType.getJavaClass(), annotations.toArray(new Annotation[annotations.size()]));
+                            bean = (Bean<T>) bm.resolve(beans);
+                        }
+                        catch (final Exception e)
+                        {
+                            // no-op: whatever can be thrown we don't want it
+                        }
+                    }
+                    if (bean != null)
+                    {
+                        defineInterceptorStack(bean, annotatedType, webBeansContext);
+                    }
+                    init = true;
+                }
+            }
         }
         return super.produce(creationalContext);
     }