openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1620383 - in /openwebbeans/branches/owb_1.2.x/webbeans-impl/src: main/java/org/apache/webbeans/component/ main/java/org/apache/webbeans/component/creation/ main/java/org/apache/webbeans/config/ test/java/org/apache/webbeans/newtests/produc...
Date Mon, 25 Aug 2014 17:26:23 GMT
Author: struberg
Date: Mon Aug 25 17:26:23 2014
New Revision: 1620383

URL: http://svn.apache.org/r1620383
Log:
OWB-991 disable producer fields/methods of disabled beans

Added:
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/component/producer/specializes/SpecializesProducerParentBean.java
      - copied, changed from r1620323, openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/component/producer/specializes/SpecializesProducer1.java
Modified:
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerFieldBean.java
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeanBuilder.java
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/specializes/SpecializesProducer1Test.java
    openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/component/producer/specializes/superclazz/SpecializesProducer1SuperClazz.java

Modified: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java?rev=1620383&r1=1620382&r2=1620383&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java
(original)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java
Mon Aug 25 17:26:23 2014
@@ -27,7 +27,6 @@ import javax.enterprise.inject.spi.Produ
 
 import org.apache.webbeans.component.spi.BeanAttributes;
 import org.apache.webbeans.component.spi.ProducerFactory;
-import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.util.WebBeansUtil;
 
 
@@ -39,27 +38,33 @@ import org.apache.webbeans.util.WebBeans
  */
 public class AbstractProducerBean<T> extends AbstractOwbBean<T> implements PassivationCapable
 {
-    private Class<T> returnType;
+    private final InjectionTargetBean<?> ownerBean;
+    private final Class<T> returnType;
     private Producer<T> producer;
 
     /**
      * Create a new instance.
      * 
      * @param returnType bean type info
-     * @param ownerBeanClass class which contains this producer method or field
+     * @param ownerComponent bean which contains this producer method or field
      */
-    public AbstractProducerBean(Class<?> ownerBeanClass,
-            WebBeansContext webBeansContext,
+    public AbstractProducerBean(InjectionTargetBean<?> ownerComponent,
             WebBeansType webBeansType,
             BeanAttributes<T> beanAttributes,
             Class<T> returnType,
             ProducerFactory<?> producerFactory)
     {
-        super(webBeansContext, webBeansType, beanAttributes, ownerBeanClass, !returnType.isPrimitive());
+        super(ownerComponent.getWebBeansContext(), webBeansType, beanAttributes, ownerComponent.getBeanClass(),
!returnType.isPrimitive());
+        this.ownerBean = ownerComponent;
         this.returnType = returnType;
         producer = producerFactory.createProducer(this);
     }
 
+    public InjectionTargetBean<?> getOwnerBean()
+    {
+        return ownerBean;
+    }
+
     @Override
     public Producer<T> getProducer()
     {

Modified: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerFieldBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerFieldBean.java?rev=1620383&r1=1620382&r2=1620383&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerFieldBean.java
(original)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerFieldBean.java
Mon Aug 25 17:26:23 2014
@@ -42,7 +42,7 @@ public class ProducerFieldBean<T> extend
      */
     public ProducerFieldBean(InjectionTargetBean<?> ownerComponent, BeanAttributesImpl<T>
beanAttributes, Class<T> returnType, ProducerFactory<T> producerFactory)
     {
-        super(ownerComponent.getBeanClass(), ownerComponent.getWebBeansContext(), WebBeansType.PRODUCERFIELD,
beanAttributes, returnType, producerFactory);
+        super(ownerComponent, WebBeansType.PRODUCERFIELD, beanAttributes, returnType, producerFactory);
     }
 
     /**

Modified: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java?rev=1620383&r1=1620382&r2=1620383&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
(original)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
Mon Aug 25 17:26:23 2014
@@ -53,7 +53,7 @@ public class ProducerMethodBean<T> exten
                                   Class<T> returnType,
                                   MethodProducerFactory<P> producerFactory)
     {
-        super(ownerComponent.getBeanClass(), ownerComponent.getWebBeansContext(), WebBeansType.PRODUCERMETHOD,
beanAttributes, returnType, producerFactory);
+        super(ownerComponent, WebBeansType.PRODUCERMETHOD, beanAttributes, returnType, producerFactory);
     }
 
     /**

Modified: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeanBuilder.java?rev=1620383&r1=1620382&r2=1620383&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeanBuilder.java
(original)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeanBuilder.java
Mon Aug 25 17:26:23 2014
@@ -36,9 +36,6 @@ import org.apache.webbeans.util.ClassUti
 public class ProducerMethodBeanBuilder<T> extends AbstractProducerBeanBuilder<T,
AnnotatedMethod<?>, ProducerMethodBean<T>>
 {
 
-    //X TODO arne: this should get evaluated or deleted if not needed anymore
-    private boolean specialized;
-
     public ProducerMethodBeanBuilder(InjectionTargetBean<T> parent, AnnotatedMethod<?>
annotatedMethod, BeanAttributesImpl<T> beanAttributes)
     {
         super(parent, annotatedMethod, beanAttributes);
@@ -73,35 +70,6 @@ public class ProducerMethodBeanBuilder<T
         bean.setSpecializedBean(true);        
     }
 
-    //X TODO arne: this should get implemented or removed if not needed anymore
-    protected AnnotatedMethod<?> getSuperAnnotated()
-    {
-        AnnotatedMethod<?> thisMethod = annotatedMember;
-        for (AnnotatedMethod<?> superMethod: getSuperType().getMethods())
-        {
-            List<AnnotatedParameter<?>> thisParameters = (List<AnnotatedParameter<?>>)(List<?>)thisMethod.getParameters();
-            if (thisMethod.getJavaMember().getName().equals(superMethod.getJavaMember().getName())
-                && thisMethod.getBaseType().equals(superMethod.getBaseType())
-                && thisParameters.size() == superMethod.getParameters().size())
-            {
-                List<AnnotatedParameter<?>> superParameters = (List<AnnotatedParameter<?>>)(List<?>)superMethod.getParameters();
-                boolean match = true;
-                for (int i = 0; i < thisParameters.size(); i++)
-                {
-                    if (!thisParameters.get(i).getBaseType().equals(superParameters.get(i).getBaseType()))
-                    {
-                        match = false;
-                        break;
-                    }
-                }
-                if (match)
-                {
-                    return superMethod;
-                }
-            }
-        }
-        return null;
-    }
 
     @Override
     protected <P> ProducerMethodBean<T> createBean(InjectionTargetBean<P>
parent, Class<T> beanClass)
@@ -109,7 +77,7 @@ public class ProducerMethodBeanBuilder<T
         AnnotatedMethod<P> annotatedMethod = (AnnotatedMethod<P>) annotatedMember;
         ProducerMethodBean<T> producerMethodBean
             = new ProducerMethodBean<T>(parent, beanAttributes, beanClass, new MethodProducerFactory<P>(annotatedMethod,
parent, parent.getWebBeansContext()));
-        producerMethodBean.setSpecializedBean(specialized);
+        producerMethodBean.setSpecializedBean(false);
         return producerMethodBean;
     }
     

Modified: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java?rev=1620383&r1=1620382&r2=1620383&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
(original)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
Mon Aug 25 17:26:23 2014
@@ -362,7 +362,7 @@ public class BeansDeployer
         manager.fireLifecycleEvent(new AfterBeanDiscoveryImpl(webBeansContext));
 
         webBeansContext.getWebBeansUtil().inspectErrorStack(
-            "There are errors that are added by AfterBeanDiscovery event observers. Look
at logs for further details");
+                "There are errors that are added by AfterBeanDiscovery event observers. Look
at logs for further details");
     }
     
     /**
@@ -818,6 +818,8 @@ public class BeansDeployer
 
             //configure specialized producer beans.
             webBeansContext.getWebBeansUtil().configureProducerMethodSpecializations();
+
+            removeProducersInDisabledBeans();
         }
         catch (DefinitionException e)
         {
@@ -836,7 +838,26 @@ public class BeansDeployer
         logger.fine("Checking Specialization constraints has ended.");
     }
 
-    
+    protected void removeProducersInDisabledBeans()
+    {
+        Iterator<Bean<?>> beanIterator = webBeansContext.getBeanManagerImpl().getBeans().iterator();
+        while (beanIterator.hasNext())
+        {
+            Bean<?> bean = beanIterator.next();
+            if (bean instanceof AbstractProducerBean)
+            {
+                AbstractProducerBean<?> producerBean = (AbstractProducerBean<?>)
bean;
+                if (!producerBean.getOwnerBean().isEnabled())
+                {
+                    // if the parent component is disabled, then we also need to disabled
the producer fields and methods in it as well.
+                    producerBean.setEnabled(false);
+                }
+            }
+        }
+    }
+
+
+
     /**
      * Check passivations.
      */

Modified: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/specializes/SpecializesProducer1Test.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/specializes/SpecializesProducer1Test.java?rev=1620383&r1=1620382&r2=1620383&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/specializes/SpecializesProducer1Test.java
(original)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/specializes/SpecializesProducer1Test.java
Mon Aug 25 17:26:23 2014
@@ -19,18 +19,14 @@
 package org.apache.webbeans.newtests.producer.specializes;
 
 import java.lang.annotation.Annotation;
-import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Set;
-
-import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.util.AnnotationLiteral;
-
 import org.apache.webbeans.newtests.AbstractUnitTest;
 import org.apache.webbeans.test.annotation.binding.Binding1;
 import org.apache.webbeans.test.annotation.binding.Binding2;
 import org.apache.webbeans.test.component.producer.specializes.SpecializesProducer1;
+import org.apache.webbeans.test.component.producer.specializes.SpecializesProducerParentBean;
 import org.apache.webbeans.test.component.producer.specializes.superclazz.SpecializesProducer1SuperClazz;
 import org.junit.Assert;
 import org.junit.Test;
@@ -41,13 +37,7 @@ public class SpecializesProducer1Test ex
     @Test
     public void testSpecializedProducer1()
     {
-        Collection<String> beanXmls = new ArrayList<String>();
-        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
-
-        beanClasses.add(SpecializesProducer1SuperClazz.class);
-        beanClasses.add(SpecializesProducer1.class);
-        
-        startContainer(beanClasses, beanXmls);        
+        startContainer(SpecializesProducer1SuperClazz.class, SpecializesProducer1.class);
         
         Annotation binding1 = new AnnotationLiteral<Binding1>()
         {
@@ -56,16 +46,33 @@ public class SpecializesProducer1Test ex
         {
         };
 
-        Set beans = getBeanManager().getBeans(int.class, new Annotation[] { binding1, binding2
});
-        System.out.print("Size of the bean set is " + beans.size());
-        Assert.assertTrue(beans.size() == 1);
-        Bean<Integer> bean = (Bean<Integer>)beans.iterator().next();
-        CreationalContext<Integer> cc = getBeanManager().createCreationalContext(bean);
-        Integer number = (Integer) getBeanManager().getReference(bean, int.class, cc);
-        
-        Assert.assertEquals(10000, number.intValue());
-        
-        shutDownContainer();       
-        
+        Integer methodNumber = getInstance(int.class, binding1);
+        Assert.assertEquals(10000, methodNumber.intValue());
+
+        Integer fieldNumber = getInstance(int.class, binding2);
+        Assert.assertEquals(4711, fieldNumber.intValue());
+    }
+
+    /**
+     * SpecializesProducerParentBean specializes SpecializesProducer1SuperClazz
+     * Thus all the producer fields and methods in the parent class must be disabled.
+     */
+    @Test
+    public void testDisabledProducerViaSpecialization()
+    {
+        startContainer(SpecializesProducer1SuperClazz.class, SpecializesProducerParentBean.class);
+
+        Annotation binding1 = new AnnotationLiteral<Binding1>()
+        {
+        };
+        Annotation binding2 = new AnnotationLiteral<Binding2>()
+        {
+        };
+
+        Set<Bean<?>> beans = getBeanManager().getBeans(int.class, binding1);
+        Assert.assertEquals(0, beans.size());
+
+        beans = getBeanManager().getBeans(int.class, binding2);
+        Assert.assertEquals(0, beans.size());
     }
 }

Copied: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/component/producer/specializes/SpecializesProducerParentBean.java
(from r1620323, openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/component/producer/specializes/SpecializesProducer1.java)
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/component/producer/specializes/SpecializesProducerParentBean.java?p2=openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/component/producer/specializes/SpecializesProducerParentBean.java&p1=openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/component/producer/specializes/SpecializesProducer1.java&r1=1620323&r2=1620383&rev=1620383&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/component/producer/specializes/SpecializesProducer1.java
(original)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/component/producer/specializes/SpecializesProducerParentBean.java
Mon Aug 25 17:26:23 2014
@@ -18,26 +18,16 @@
  */
 package org.apache.webbeans.test.component.producer.specializes;
 
-import javax.enterprise.inject.Produces;
 import javax.enterprise.inject.Specializes;
-import javax.inject.Named;
-
 import org.apache.webbeans.test.component.producer.specializes.superclazz.SpecializesProducer1SuperClazz;
 
-public class SpecializesProducer1 extends SpecializesProducer1SuperClazz
+/**
+ * Specializing away the parent class means that all the producers defined in
+ * the parent class also get disabled.
+ * See CDI-1.0 §5.1.2.
+ */
+@Specializes
+public class SpecializesProducerParentBean extends SpecializesProducer1SuperClazz
 {
 
-    public SpecializesProducer1()
-    {
-
-    }
-
-    @Produces
-    @Override
-    @Specializes
-    @Named("specializedNumber")
-    public int createMaxNumber()
-    {
-        return 10000;
-    }
 }

Modified: openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/component/producer/specializes/superclazz/SpecializesProducer1SuperClazz.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/component/producer/specializes/superclazz/SpecializesProducer1SuperClazz.java?rev=1620383&r1=1620382&r2=1620383&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/component/producer/specializes/superclazz/SpecializesProducer1SuperClazz.java
(original)
+++ openwebbeans/branches/owb_1.2.x/webbeans-impl/src/test/java/org/apache/webbeans/test/component/producer/specializes/superclazz/SpecializesProducer1SuperClazz.java
Mon Aug 25 17:26:23 2014
@@ -25,15 +25,12 @@ import org.apache.webbeans.test.annotati
 
 public class SpecializesProducer1SuperClazz
 {
-
-    public SpecializesProducer1SuperClazz()
-    {
-
-    }
+    @Produces
+    @Binding2
+    private int producedField = 4711;
 
     @Produces
     @Binding1
-    @Binding2
     public int createMaxNumber()
     {
         return Integer.MAX_VALUE;



Mime
View raw message