openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1730181 - in /openwebbeans/trunk: webbeans-impl/src/main/java/org/apache/webbeans/component/ webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ webbeans-impl/src/main/java/org/apache/webbeans/component/third/ webbeans-impl...
Date Sat, 13 Feb 2016 11:12:21 GMT
Author: struberg
Date: Sat Feb 13 11:12:20 2016
New Revision: 1730181

URL: http://svn.apache.org/viewvc?rev=1730181&view=rev
Log:
OWB-1116 cleanup of Alternatives, Specializes and BeanAttributes handling

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/BeanAttributesImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerFieldBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.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/component/creation/ManagedBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/third/ThirdpartyBeanImpl.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/InjectionResolver.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/alternative/AlternativeTest.java
    openwebbeans/trunk/webbeans-tck/testng-dev.xml

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java?rev=1730181&r1=1730180&r2=1730181&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
Sat Feb 13 11:12:20 2016
@@ -68,11 +68,6 @@ public abstract class AbstractOwbBean<T>
     protected boolean enabled = true;
 
     /**
-     * cached value for {@link #isAlternative()}
-     */
-    protected Boolean isAlternative = null;
-
-    /**
      * This string will be used for passivating the Bean.
      * It will be created on the first use.
      * @see #getId()
@@ -312,20 +307,6 @@ public abstract class AbstractOwbBean<T>
         return specializedBean;
     }
     
-     /**
-     * {@inheritDoc}
-     */    
-    @Override
-    public boolean isAlternative()
-    {
-        if (isAlternative == null)
-        {
-            isAlternative = webBeansContext.getAlternativesManager().isAlternative(getBeanClass(),
getStereotypes());
-        }
-
-        return isAlternative;
-    }
-    
     /**
      * {@inheritDoc}
      */

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java?rev=1730181&r1=1730180&r2=1730181&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java
Sat Feb 13 11:12:20 2016
@@ -21,13 +21,11 @@ package org.apache.webbeans.component;
 import java.io.Serializable;
 import java.lang.reflect.Modifier;
 
-import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.PassivationCapable;
 import javax.enterprise.inject.spi.Producer;
 
 import javax.enterprise.inject.spi.BeanAttributes;
 import javax.enterprise.inject.spi.ProducerFactory;
-import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.util.WebBeansUtil;
 
 
@@ -41,23 +39,23 @@ public class AbstractProducerBean<T> ext
 {
     private Class<T> returnType;
     private Producer<T> producer;
+    private InjectionTargetBean<?> ownerComponent;
 
     /**
      * Create a new instance.
      * 
      * @param returnType bean type info
-     * @param ownerBeanClass class which contains this producer method or field
      */
-    public AbstractProducerBean(Class<?> ownerBeanClass,
-            WebBeansContext webBeansContext,
-            WebBeansType webBeansType,
-            BeanAttributes<T> beanAttributes,
-            Class<T> returnType,
-            ProducerFactory<?> producerFactory)
+    public AbstractProducerBean(InjectionTargetBean<?> ownerComponent,
+                                WebBeansType webBeansType,
+                                BeanAttributes<T> beanAttributes,
+                                Class<T> returnType,
+                                ProducerFactory<?> producerFactory)
     {
-        super(webBeansContext, webBeansType, beanAttributes, ownerBeanClass, !returnType.isPrimitive());
+        super(ownerComponent.webBeansContext, webBeansType, beanAttributes, ownerComponent.getBeanClass(),
!returnType.isPrimitive());
         this.returnType = returnType;
         producer = producerFactory.createProducer(this);
+        this.ownerComponent = ownerComponent;
     }
 
     @Override
@@ -72,14 +70,11 @@ public class AbstractProducerBean<T> ext
         return returnType;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public void dispose(T instance, CreationalContext<T> creationalContext)
+    public InjectionTargetBean<?> getOwnerComponent()
     {
-        // Do nothing
+        return ownerComponent;
     }
-    
+
     /**
      * Check null control.
      * 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/BeanAttributesImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/BeanAttributesImpl.java?rev=1730181&r1=1730180&r2=1730181&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/BeanAttributesImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/BeanAttributesImpl.java
Sat Feb 13 11:12:20 2016
@@ -26,7 +26,6 @@ import java.util.Set;
 
 import javax.enterprise.context.Dependent;
 import javax.enterprise.inject.spi.Bean;
-
 import javax.enterprise.inject.spi.BeanAttributes;
 import org.apache.webbeans.util.AnnotationUtil;
 
@@ -41,7 +40,8 @@ public class BeanAttributesImpl<T> imple
     private final boolean alternative;
 
     /**
-     * TODO This constructor can be removed, when we move to CDI 1.1 since {@link Bean} extends
BeanAttributes.
+     * do not remove, this ct is used from within TomEE for example.
+     * @deprecated
      */
     public BeanAttributesImpl(Bean<T> bean)
     {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java?rev=1730181&r1=1730180&r2=1730181&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
Sat Feb 13 11:12:20 2016
@@ -72,7 +72,6 @@ public class InjectionTargetBean<T> exte
         this.annotatedType = annotatedType;
         injectionTarget = factory.createInjectionTarget(this);
         setEnabled(true);
-        this.isAlternative = beanAttributes.isAlternative();
     }
 
     // call it only if you know what you do, basically only useful when creating a bean manually
and not using child classes

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerFieldBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerFieldBean.java?rev=1730181&r1=1730180&r2=1730181&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerFieldBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerFieldBean.java
Sat Feb 13 11:12:20 2016
@@ -43,7 +43,7 @@ public class ProducerFieldBean<T> extend
      */
     public ProducerFieldBean(InjectionTargetBean<?> ownerComponent, BeanAttributes<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/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java?rev=1730181&r1=1730180&r2=1730181&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
Sat Feb 13 11:12:20 2016
@@ -52,7 +52,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/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=1730181&r1=1730180&r2=1730181&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
Sat Feb 13 11:12:20 2016
@@ -30,10 +30,8 @@ import java.util.Set;
 import javax.decorator.Decorator;
 import javax.enterprise.context.Dependent;
 import javax.enterprise.context.NormalScope;
-import javax.enterprise.inject.Alternative;
 import javax.enterprise.inject.Any;
 import javax.enterprise.inject.Specializes;
-import javax.enterprise.inject.Stereotype;
 import javax.enterprise.inject.Typed;
 import javax.enterprise.inject.spi.Annotated;
 import javax.enterprise.inject.spi.AnnotatedField;
@@ -56,7 +54,6 @@ import org.apache.webbeans.config.WebBea
 import org.apache.webbeans.container.ExternalScope;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 
-import org.apache.webbeans.inject.AlternativesManager;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
 import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.Asserts;
@@ -86,7 +83,7 @@ public abstract class BeanAttributesBuil
 
     protected boolean nullable;
 
-    protected Set<Class<? extends Annotation>> stereotypes = new HashSet<Class<?
extends Annotation>>();
+    protected Set<Class<? extends Annotation>> stereotypes;
 
     protected boolean alternative;
     
@@ -109,7 +106,7 @@ public abstract class BeanAttributesBuil
     public BeanAttributesImpl<T> build()
     {
         // we need to check the stereotypes first because we might need it to determine the
scope
-        defineStereotypes();
+        stereotypes = defineStereotypes(annotated);
 
         defineScope();
         if (scope == null)
@@ -511,9 +508,10 @@ public abstract class BeanAttributesBuil
     /**
      * {@inheritDoc}
      */
-    protected void defineStereotypes()
+    protected Set<Class<? extends Annotation>> defineStereotypes(Annotated annot)
     {
-        Annotation[] anns = AnnotationUtil.asArray(annotated.getAnnotations());
+        Set<Class<? extends Annotation>> stereos  = null;
+        Annotation[] anns = AnnotationUtil.asArray(annot.getAnnotations());
         final AnnotationManager annotationManager = webBeansContext.getAnnotationManager();
         if (annotationManager.hasStereoTypeMetaAnnotation(anns))
         {
@@ -522,45 +520,24 @@ public abstract class BeanAttributesBuil
 
             for (Annotation stereo : steroAnns)
             {
-                stereotypes.add(stereo.annotationType());
+                if (stereos == null)
+                {
+                    stereos = new HashSet<Class<? extends Annotation>>();
+                }
+                stereos.add(stereo.annotationType());
             }
         }
+
+        return stereos != null ? stereos : Collections.EMPTY_SET;
     }
 
     // these alternatives can be not activated
     protected void defineAlternative()
     {
-        final AlternativesManager alternativesManager = webBeansContext.getAlternativesManager();
-        alternative = alternativesManager.isAlternative(getType(), Collections.<Class<?
extends Annotation>>emptySet());
-        if (alternative)
-        {
-            alternative = true;
-            return;
-        }
-
-        for (final Annotation a : annotated.getAnnotations())
-        {
-            final Class<? extends Annotation> annotationType = a.annotationType();
-            if (annotationType == Alternative.class)
-            {
-                alternative = true;
-                return;
-            }
-
-            if (annotationType.getAnnotation(Stereotype.class) != null)
-            {
-                for (final Annotation aa : annotationType.getAnnotations())
-                {
-                    if (aa.annotationType() == Alternative.class)
-                    {
-                        alternative = true;
-                        return;
-                    }
-                }
-            }
-        }
+        alternative = WebBeansUtil.isAlternative(annotated, stereotypes);
     }
 
+
     protected abstract Class<?> getType();
     
     public static class BeanAttributesBuilderFactory
@@ -809,7 +786,6 @@ public abstract class BeanAttributesBuil
 
     private abstract static class AnnotatedMemberBeanAttributesBuilder<M, A extends AnnotatedMember<M>>
extends BeanAttributesBuilder<M, A>
     {
-
         protected AnnotatedMemberBeanAttributesBuilder(WebBeansContext webBeansContext, A
annotated)
         {
             super(webBeansContext, annotated);

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ManagedBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ManagedBeanBuilder.java?rev=1730181&r1=1730180&r2=1730181&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ManagedBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ManagedBeanBuilder.java
Sat Feb 13 11:12:20 2016
@@ -62,7 +62,7 @@ public class ManagedBeanBuilder<T, M ext
     public M getBean()
     {
         M bean = (M) new ManagedBean<T>(webBeansContext, WebBeansType.MANAGED, annotatedType,
beanAttributes, annotatedType.getJavaClass());
-        bean.setEnabled(webBeansContext.getWebBeansUtil().isBeanEnabled(annotatedType, bean.getStereotypes()));
+        bean.setEnabled(webBeansContext.getWebBeansUtil().isBeanEnabled(beanAttributes, annotatedType,
bean.getStereotypes()));
         webBeansContext.getWebBeansUtil().checkManagedBeanCondition(annotatedType);
         WebBeansUtil.checkGenericType(annotatedType.getJavaClass(), beanAttributes.getScope());
         webBeansContext.getWebBeansUtil().validateBeanInjection(bean);

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/third/ThirdpartyBeanImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/third/ThirdpartyBeanImpl.java?rev=1730181&r1=1730180&r2=1730181&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/third/ThirdpartyBeanImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/third/ThirdpartyBeanImpl.java
Sat Feb 13 11:12:20 2016
@@ -31,7 +31,6 @@ import org.apache.webbeans.component.Bea
 import org.apache.webbeans.component.WebBeansType;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
-import org.apache.webbeans.inject.AlternativesManager;
 
 public class ThirdpartyBeanImpl<T> extends AbstractOwbBean<T> implements Bean<T>
 {
@@ -41,7 +40,7 @@ public class ThirdpartyBeanImpl<T> exten
     {
         super(webBeansContext,
               WebBeansType.THIRDPARTY,
-              new BeanAttributesImpl<T>(bean),
+              new BeanAttributesImpl<T>(bean, false),
               bean.getBeanClass(),
               bean.isNullable());
         
@@ -140,18 +139,7 @@ public class ThirdpartyBeanImpl<T> exten
     @Override
     public boolean isAlternative()
     {
-        boolean alternative = super.isAlternative();
-        if(alternative)
-        {
-            AlternativesManager manager = getWebBeansContext().getAlternativesManager();
-            //Class alternative
-            if (manager.isAlternative(getBeanClass(), bean.getStereotypes()))
-            {
-                return true;
-            }
-        }
-        
-        return false;
+        return bean.isAlternative();
     }
 
     /**

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=1730181&r1=1730180&r2=1730181&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
Sat Feb 13 11:12:20 2016
@@ -19,6 +19,7 @@
 package org.apache.webbeans.config;
 
 import org.apache.webbeans.annotation.AnnotationManager;
+import org.apache.webbeans.annotation.AnyLiteral;
 import org.apache.webbeans.component.AbstractProducerBean;
 import org.apache.webbeans.component.BeanAttributesImpl;
 import org.apache.webbeans.component.BuiltInOwbBean;
@@ -298,8 +299,9 @@ public class BeansDeployer
                 
                 // We are finally done with our bean discovery
                 fireAfterBeanDiscoveryEvent();
-                
-                // Validate injection Points
+
+                validateAlternatives(beanAttributesPerBda);
+
                 validateInjectionPoints();
                 validateDisposeParameters();
 
@@ -722,7 +724,68 @@ public class BeansDeployer
         packageVetoCache.clear(); // no more needed, free the memory
         event.setStarted();
     }
-    
+
+    /**
+     * Check if all XML configured alternatives end up as alternative beans
+     * @param beanAttributesPerBda
+     */
+    private void validateAlternatives(Map<BeanArchiveInformation, Map<AnnotatedType<?>,
ExtendedBeanAttributes<?>>> beanAttributesPerBda)
+    {
+        Set<Class<?>> xmlConfiguredAlternatives = webBeansContext.getAlternativesManager().getXmlConfiguredAlternatives();
+        InjectionResolver injectionResolver = webBeansContext.getBeanManagerImpl().getInjectionResolver();
+
+        for (Class<?> alternativeClass : xmlConfiguredAlternatives)
+        {
+            if (AnnotationUtil.hasClassAnnotation(alternativeClass, Alternative.class) ||
+                AnnotationUtil.hasMetaAnnotation(alternativeClass.getAnnotations(), Alternative.class))
+            {
+                continue;
+            }
+
+            boolean foundAlternativeClass = false;
+
+            Set<Bean<?>> beans = injectionResolver.implResolveByType(false, alternativeClass,
AnyLiteral.INSTANCE);
+            if (beans == null || beans.isEmpty())
+            {
+                out:
+                for (Map<AnnotatedType<?>, ExtendedBeanAttributes<?>> annotatedTypeExtendedBeanAttributesMap
: beanAttributesPerBda.values())
+                {
+                    for (Map.Entry<AnnotatedType<?>, ExtendedBeanAttributes<?>>
exType : annotatedTypeExtendedBeanAttributesMap.entrySet())
+                    {
+                        if (alternativeClass.equals(exType.getKey().getJavaClass()))
+                        {
+                            if (exType.getValue().beanAttributes.isAlternative() ||
+                                exType.getKey().getAnnotation(Alternative.class) != null)
+                            {
+                                foundAlternativeClass = true;
+                                break out; // all fine, continue with the next
+                            }
+                        }
+                    }
+                }
+            }
+            else
+            {
+                for (Bean<?> bean : beans)
+                {
+                    if (bean.isAlternative())
+                    {
+                        foundAlternativeClass = true;
+                        break;
+                    }
+                }
+            }
+            if (!foundAlternativeClass)
+            {
+                throw new WebBeansDeploymentException("Given alternative class : " + alternativeClass.getName()
+
+                    " is not annotated wih @Alternative or not an enabled bean");
+            }
+
+        }
+
+    }
+
+
     /**
      * Validate all injection points.
      */
@@ -1298,27 +1361,7 @@ public class BeansDeployer
                 }
                 else
                 {
-                    if (AnnotationUtil.hasClassAnnotation(clazz, Alternative.class) ||
-                            AnnotationUtil.hasMetaAnnotation(clazz.getAnnotations(), Alternative.class))
-                    {
-                        manager.addXmlClazzAlternative(clazz);
-                    }
-                    else
-                    {
-                        AnnotatedType annotatedType = annotatedElementFactory.getAnnotatedType(clazz);
-                        if (annotatedType != null)
-                        {
-                            if (annotatedType.getAnnotation(Alternative.class) != null)
-                            {
-                                manager.addXmlClazzAlternative(clazz);
-                                break;
-                            }
-                            else
-                            {
-                                throw new WebBeansDeploymentException("Given alternative
class : " + clazz.getName() + " is not decorated wih @Alternative");
-                            }
-                        }
-                    }
+                    manager.addXmlClazzAlternative(clazz);
                 }
             }
         }

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=1730181&r1=1730180&r2=1730181&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
Sat Feb 13 11:12:20 2016
@@ -631,7 +631,9 @@ public class InjectionResolver
 
         for (Bean<? extends X> bean : beans)
         {
-            if (bean.isAlternative())
+            if (bean.isAlternative() ||
+                (bean instanceof AbstractProducerBean &&
+                    ((AbstractProducerBean) bean).getOwnerComponent().isAlternative()))
             {
                 alternativeSet.add(bean);
             }
@@ -653,6 +655,8 @@ public class InjectionResolver
             return alternativeSet;
         }
 
+        //
+
         return enableSet;
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java?rev=1730181&r1=1730180&r2=1730181&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AlternativesManager.java
Sat Feb 13 11:12:20 2016
@@ -163,7 +163,15 @@ public class AlternativesManager
 
         return false;
     }
-    
+
+    /**
+     * @return all the alternative classes declared in beans.xml files
+     */
+    public Set<Class<?>> getXmlConfiguredAlternatives()
+    {
+        return configuredAlternatives;
+    }
+
     public void clear()
     {
         configuredAlternatives.clear();

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=1730181&r1=1730180&r2=1730181&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
Sat Feb 13 11:12:20 2016
@@ -1176,6 +1176,13 @@ public final class WebBeansUtil
         bean.setEnabled(isBeanEnabled(bean.getAnnotatedType(), bean.getStereotypes()));
     }
 
+    public boolean isBeanEnabled(BeanAttributes<?> beanAttributes, AnnotatedType<?>
at, Set<Class<? extends Annotation>> stereotypes)
+    {
+        boolean isAlternative = beanAttributes.isAlternative();
+
+        return !isAlternative || isBeanEnabled(at, stereotypes);
+    }
+
     public boolean isBeanEnabled(AnnotatedType<?> at, Set<Class<? extends Annotation>>
stereotypes)
     {
         boolean isAlternative = isAlternative(at, stereotypes);
@@ -1183,14 +1190,14 @@ public final class WebBeansUtil
         return !isAlternative || webBeansContext.getAlternativesManager().isAlternative(at.getJavaClass(),
stereotypes);
     }
 
-    public static boolean isAlternative(AnnotatedType<?> beanType, Set<Class<?
extends Annotation>> stereotypes)
+    public static boolean isAlternative(Annotated annotated, Set<Class<? extends Annotation>>
stereotypes)
     {
-        Asserts.assertNotNull(beanType, "bean type");
+        Asserts.assertNotNull(annotated, "annotated");
         Asserts.assertNotNull(stereotypes, "stereotypes");
 
         boolean alternative = false;
 
-        if(beanType.getAnnotation(Alternative.class) != null)
+        if(annotated.getAnnotation(Alternative.class) != null)
         {
             alternative = true;
         }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/alternative/AlternativeTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/alternative/AlternativeTest.java?rev=1730181&r1=1730180&r2=1730181&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/alternative/AlternativeTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/alternative/AlternativeTest.java
Sat Feb 13 11:12:20 2016
@@ -69,5 +69,22 @@ public class AlternativeTest extends Abs
         WebBeansContext.getInstance().getPluginLoader().shutDown();
         
     }
-    
+
+    @Test
+    public void testNotEnabledAlternative()
+    {
+        startContainer(AlternativeComponent.class, NotAlternativeComponent.class, AlternativeInjector.class);
+
+        AlternativeInjector instance = getInstance(AlternativeInjector.class);
+
+        Assert.assertNotNull(instance);
+
+        IAlternative alternative = instance.getAlternative();
+
+        Assert.assertTrue(alternative instanceof NotAlternativeComponent);
+
+        WebBeansContext.getInstance().getPluginLoader().shutDown();
+
+    }
+
 }

Modified: openwebbeans/trunk/webbeans-tck/testng-dev.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tck/testng-dev.xml?rev=1730181&r1=1730180&r2=1730181&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-tck/testng-dev.xml (original)
+++ openwebbeans/trunk/webbeans-tck/testng-dev.xml Sat Feb 13 11:12:20 2016
@@ -18,7 +18,7 @@
 <suite name="JSR-346-TCK" verbose="2" configfailurepolicy="continue">
   <test name="JSR-346 TCK">
     <classes>
-          <class name="org.jboss.cdi.tck.tests.extensions.beanManager.bootstrap.unavailable.methods.UnavailableMethodsDuringApplicationInitializationTest"
/>
+          <class name="org.jboss.cdi.tck.tests.alternative.broken.not.alternative.ClassIsNotAlternativeTest"
/>
       <!--
       <class name="org.jboss.cdi.tck.tests.event.parameterized.ParameterizedEventTest"
/>
       <class name="org.jboss.cdi.tck.tests.event.fires.FireEventTest" />



Mime
View raw message