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 2014/10/03 18:33:49 UTC

svn commit: r1629252 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/annotation/ main/java/org/apache/webbeans/container/ main/java/org/apache/webbeans/intercept/ test/java/org/apache/webbeans/test/ test/java/org/apache/webbea...

Author: rmannibucau
Date: Fri Oct  3 16:33:49 2014
New Revision: 1629252

URL: http://svn.apache.org/r1629252
Log:
OWB-1004 allow multiple times the same qualifier (almost repeatable of J8, miss the array part to be the exact same one)

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/tests/MultipleTimeTheSameBindingTest.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/AbstractUnitTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/noncontextual/InjectNonContextualTest.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=1629252&r1=1629251&r2=1629252&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 Fri Oct  3 16:33:49 2014
@@ -698,20 +698,10 @@ public final class AnnotationManager
 
     public void checkDecoratorResolverParams(Set<Type> apiTypes, Annotation... qualifiers)
     {
-        if (apiTypes == null || apiTypes.size() == 0)
-        {
-            throw new IllegalArgumentException("Manager.resolveDecorators() method parameter api types argument " +
-                    "can not be empty");
-        }
-
+        checkQualifiersParams(apiTypes, qualifiers);
         Annotation old = null;
-        for (Annotation qualifier : qualifiers)
+        for (final Annotation qualifier : qualifiers)
         {
-            if (!isQualifierAnnotation(qualifier.annotationType()))
-            {
-                throw new IllegalArgumentException("Manager.resolveDecorators() method parameter qualifiers array " +
-                        "can not contain other annotation that is not @Qualifier");
-            }
             if (old == null)
             {
                 old = qualifier;
@@ -731,6 +721,24 @@ public final class AnnotationManager
 
     }
 
+    public void checkQualifiersParams(Set<Type> apiTypes, Annotation... qualifiers)
+    {
+        if (apiTypes == null || apiTypes.size() == 0)
+        {
+            throw new IllegalArgumentException("method parameter api types argument can not be empty");
+        }
+
+        for (final Annotation qualifier : qualifiers)
+        {
+            if (!isQualifierAnnotation(qualifier.annotationType()))
+            {
+                throw new IllegalArgumentException("Manager.resolveDecorators() method parameter qualifiers array " +
+                        "can not contain other annotation that is not @Qualifier");
+            }
+        }
+
+    }
+
 
     /**
      * Check conditions for the new binding.

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=1629252&r1=1629251&r2=1629252&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 Fri Oct  3 16:33:49 2014
@@ -463,14 +463,18 @@ public class BeanManagerImpl implements 
      * {@inheritDoc}
      */
     @Override
-    public List<Decorator<?>> resolveDecorators(Set<Type> types, Annotation... bindingTypes)
+    public List<Decorator<?>> resolveDecorators(final Set<Type> types, final Annotation... bindingTypes)
     {
         webBeansContext.getAnnotationManager().checkDecoratorResolverParams(types, bindingTypes);
-        Set<Decorator<?>> intsSet = webBeansContext.getDecoratorsManager().findDeployedWebBeansDecorator(types, bindingTypes);
+        return unsafeResolveDecorators(types, bindingTypes);
+    }
 
-        List<Decorator<?>> decoratorList = new ArrayList<Decorator<?>>(intsSet);
+    public List<Decorator<?>> unsafeResolveDecorators(final Set<Type> types, final Annotation[] bindingTypes)
+    {
+        webBeansContext.getAnnotationManager().checkQualifiersParams(types, bindingTypes); // checkDecoratorResolverParams is too restrictive for repeatable bindings
+        final Set<Decorator<?>> intsSet = webBeansContext.getDecoratorsManager().findDeployedWebBeansDecorator(types, bindingTypes);
+        final List<Decorator<?>> decoratorList = new ArrayList<Decorator<?>>(intsSet);
         Collections.sort(decoratorList, new DecoratorComparator(webBeansContext));
-
         return decoratorList;
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java?rev=1629252&r1=1629251&r2=1629252&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java Fri Oct  3 16:33:49 2014
@@ -39,7 +39,6 @@ import javax.enterprise.inject.spi.Annot
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedParameter;
 import javax.enterprise.inject.spi.AnnotatedType;
-import javax.enterprise.inject.spi.BeanManager;
 import javax.enterprise.inject.spi.Decorator;
 import javax.enterprise.inject.spi.DeploymentException;
 import javax.enterprise.inject.spi.InterceptionType;
@@ -95,7 +94,7 @@ public class InterceptorResolutionServic
         List<AnnotatedMethod> interceptableAnnotatedMethods = getInterceptableBusinessMethods(annotatedType);
 
         AnnotationManager annotationManager = webBeansContext.getAnnotationManager();
-        BeanManager beanManager = webBeansContext.getBeanManagerImpl();
+        BeanManagerImpl beanManager = webBeansContext.getBeanManagerImpl();
 
 
         // pick up EJB-style interceptors from a class level
@@ -104,7 +103,7 @@ public class InterceptorResolutionServic
         collectEjbInterceptors(classLevelEjbInterceptors, annotatedType, false, beanTypes);
 
         // pick up the decorators
-        List<Decorator<?>> decorators = beanManager.resolveDecorators(beanTypes, AnnotationUtil.asArray(qualifiers));
+        List<Decorator<?>> decorators = beanManager.unsafeResolveDecorators(beanTypes, AnnotationUtil.asArray(qualifiers));
         if (decorators.size() == 0)
         {
             decorators = Collections.emptyList(); // less to store

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/AbstractUnitTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/AbstractUnitTest.java?rev=1629252&r1=1629251&r2=1629252&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/AbstractUnitTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/AbstractUnitTest.java Fri Oct  3 16:33:49 2014
@@ -147,14 +147,19 @@ public abstract class AbstractUnitTest
 
         if (inject)
         {
-            try
-            {
-                OWBInjector.inject(getBeanManager(), this, null);
-            }
-            catch (Exception e)
-            {
-                throw new WebBeansConfigurationException(e);
-            }
+            inject(this);
+        }
+    }
+
+    public void inject(final Object bean)
+    {
+        try
+        {
+            OWBInjector.inject(getBeanManager(), bean, null);
+        }
+        catch (final Exception e)
+        {
+            throw new WebBeansConfigurationException(e);
         }
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/noncontextual/InjectNonContextualTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/noncontextual/InjectNonContextualTest.java?rev=1629252&r1=1629251&r2=1629252&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/noncontextual/InjectNonContextualTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/noncontextual/InjectNonContextualTest.java Fri Oct  3 16:33:49 2014
@@ -33,7 +33,7 @@ import java.util.Collection;
 public class InjectNonContextualTest extends AbstractUnitTest
 {
     @SuppressWarnings("unchecked")
-    public <T> void inject(T instance)
+    public <T> void doInject(T instance)
     {
         BeanManager mgr = WebBeansContext.getInstance().getBeanManagerImpl();
         AnnotatedType<T> annotatedType = mgr.createAnnotatedType((Class<T>) instance.getClass());
@@ -54,7 +54,7 @@ public class InjectNonContextualTest ext
         try
         {
             final NonContextualBean bean = new NonContextualBean();
-            inject(bean);
+            doInject(bean);
             Assert.assertNotNull(bean.getContextual());
         }
         finally

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/tests/MultipleTimeTheSameBindingTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/tests/MultipleTimeTheSameBindingTest.java?rev=1629252&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/tests/MultipleTimeTheSameBindingTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/tests/MultipleTimeTheSameBindingTest.java Fri Oct  3 16:33:49 2014
@@ -0,0 +1,109 @@
+/*
+ * 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.test.tests;
+
+import org.apache.webbeans.annotation.DefaultLiteral;
+import org.apache.webbeans.component.BeanAttributesImpl;
+import org.apache.webbeans.test.AbstractUnitTest;
+import org.apache.webbeans.test.interceptors.extension.BeforeBeanDiscoveryImplTest;
+import org.junit.Test;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessBeanAttributes;
+import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Inject;
+import javax.inject.Qualifier;
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import java.util.HashSet;
+import java.util.Set;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static org.junit.Assert.assertNotNull;
+
+public class MultipleTimeTheSameBindingTest extends AbstractUnitTest
+{
+    @Inject
+    @TheQualifier(1)
+    private TheClass theClass1;
+
+    @Inject
+    @TheQualifier(2)
+    private TheClass theClass2;
+
+    @Test
+    public void run()
+    {
+        addExtension(new TheExtension());
+        startContainer(TheClass.class);
+        inject(this);
+        assertNotNull(theClass1);
+        assertNotNull(theClass2);
+    }
+
+    public static class TheExtension implements Extension
+    {
+        void producerTemplates(@Observes final ProcessBeanAttributes<TheClass> pba)
+        {
+            final Set<Annotation> annotations = new HashSet<Annotation>(pba.getBeanAttributes().getQualifiers());
+            annotations.add(new TheQualifierLitereal(1));
+            annotations.add(new TheQualifierLitereal(2));
+
+            pba.setBeanAttributes(new BeanAttributesImpl<TheClass>(pba.getBeanAttributes(), false) {
+                public Set<Annotation> getQualifiers() {
+                    return annotations;
+                }
+            });
+        }
+    }
+
+    public static class TheClass
+    {
+    }
+
+    public static class TheQualifierLitereal extends AnnotationLiteral<TheQualifier> implements TheQualifier
+    {
+        private final int val;
+
+        public TheQualifierLitereal(final int val)
+        {
+            this.val = val;
+        }
+
+        @Override
+        public int value()
+        {
+            return val;
+        }
+    }
+
+    @Target({ TYPE, FIELD })
+    @Retention(RUNTIME)
+    @Documented
+    @Qualifier
+    public static @interface TheQualifier
+    {
+        int value();
+    }
+}