openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1436797 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: annotation/AnnotationManager.java component/creation/ProducerMethodProducerBuilder.java portable/ProducerMethodProducer.java
Date Tue, 22 Jan 2013 08:41:47 GMT
Author: arne
Date: Tue Jan 22 08:41:46 2013
New Revision: 1436797

URL: http://svn.apache.org/viewvc?rev=1436797&view=rev
Log:
OWB-755: Fixed definition of disposal methods

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodProducerBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java?rev=1436797&r1=1436796&r2=1436797&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
Tue Jan 22 08:41:46 2013
@@ -332,6 +332,11 @@ public final class AnnotationManager
         return result;
     }
 
+    public Set<Annotation> getQualifierAnnotations(Set<Annotation> annotations)
+    {
+        return new HashSet<Annotation>(Arrays.asList(getQualifierAnnotations(annotations.toArray(new
Annotation[annotations.size()]))));
+    }
+
     /**
      * Gets the array of qualifier annotations on the given array.
      *

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodProducerBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodProducerBuilder.java?rev=1436797&r1=1436796&r2=1436797&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodProducerBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodProducerBuilder.java
Tue Jan 22 08:41:46 2013
@@ -18,17 +18,22 @@
  */
 package org.apache.webbeans.component.creation;
 
+import java.lang.annotation.Annotation;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
+import javax.enterprise.inject.Default;
 import javax.enterprise.inject.Disposes;
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedParameter;
 import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Named;
 
 import org.apache.webbeans.component.OwbBean;
 import org.apache.webbeans.component.ProducerMethodBean;
 import org.apache.webbeans.portable.ProducerMethodProducer;
+import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.Asserts;
 
 public class ProducerMethodProducerBuilder<T, P>
@@ -55,7 +60,20 @@ public class ProducerMethodProducerBuild
 
     private void defineDisposalMethod()
     {
-        Set<AnnotatedMethod<? super P>> annotatedMethods = producerMethod.getDeclaringType().getMethods();
+        Set<Annotation> producerQualifiers = bean.getWebBeansContext().getAnnotationManager().getQualifierAnnotations(producerMethod.getAnnotations());
+        if (producerQualifiers.size() == 1 && producerQualifiers.iterator().next().annotationType().equals(Default.class))
+        {
+            producerQualifiers = Collections.<Annotation>emptySet();
+        }
+        Set<Annotation> producerQualifiersWithoutNamed = new HashSet<Annotation>();
+        for (Annotation qualifier: producerQualifiers)
+        {
+            if (!qualifier.annotationType().equals(Named.class))
+            {
+                producerQualifiersWithoutNamed.add(qualifier);
+            }
+        }
+        Set<AnnotatedMethod<? super P>> annotatedMethods = producerMethod.getDeclaringType().getMethods();
       
         for (AnnotatedMethod<? super P> annotatedMethod : annotatedMethods)
         {            
             if (annotatedMethod.getDeclaringType().equals(producerMethod.getDeclaringType()))
@@ -64,6 +82,43 @@ public class ProducerMethodProducerBuild
                 {
                     if (annotatedParameter.isAnnotationPresent(Disposes.class))
                     {
+                        Set<Annotation> producerQualifiersToCompare = producerQualifiers;
+                        Set<Annotation> disposalQualifiers = bean.getWebBeansContext().getAnnotationManager().getQualifierAnnotations(annotatedParameter.getAnnotations());
+                        if (disposalQualifiers.size() == 1 && disposalQualifiers.iterator().next().annotationType().equals(Default.class))
+                        {
+                            disposalQualifiers = Collections.<Annotation>emptySet();
+                        }
+                        if (disposalQualifiers.size() == producerQualifiersToCompare.size()
- 1)
+                        {
+                            // when @Named is present at the producer it may be ignored at
the disposal
+                            producerQualifiersToCompare = producerQualifiersWithoutNamed;
+                        }
+                        if (disposalQualifiers.size() != producerQualifiersToCompare.size())
+                        {
+                            continue;
+                        }
+                        boolean same = true;
+                        for (Annotation disposalQualifier: disposalQualifiers)
+                        {
+                            boolean found = false;
+                            for (Annotation producerQualifier: producerQualifiers)
+                            {
+                                if (AnnotationUtil.isCdiAnnotationEqual(producerQualifier,
disposalQualifier))
+                                {
+                                    found = true;
+                                    break;
+                                }
+                            }
+                            if (!found)
+                            {
+                                same = false;
+                                break;
+                            }
+                        }
+                        if (!same)
+                        {
+                            continue;
+                        }
                         disposalMethod = (AnnotatedMethod<P>)annotatedMethod;
                         break;
                     }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java?rev=1436797&r1=1436796&r2=1436797&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java
Tue Jan 22 08:41:46 2013
@@ -72,7 +72,7 @@ public class ProducerMethodProducer<T, P
                 parentInstance = (P)webBeansContext.getBeanManagerImpl().getReference(owner,
owner.getBeanClass(), parentCreationalContext);
             }
             
-            m = new InjectableMethod<T>(producerMethod.getJavaMember(), parentInstance,
this, (CreationalContextImpl<T>) parentCreationalContext);
+            m = new InjectableMethod<T>(producerMethod.getJavaMember(), parentInstance,
this, (CreationalContextImpl<T>) creationalContext);
             
             return m.doInjection();
 



Mime
View raw message