openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1512896 - in /openwebbeans/trunk: webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/ webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ webbeans-impl/src/main/java/org/apache/webbeans/util/ webbeans-impl/...
Date Sun, 11 Aug 2013 10:38:13 GMT
Author: struberg
Date: Sun Aug 11 10:38:12 2013
New Revision: 1512896

URL: http://svn.apache.org/r1512896
Log:
OWB-891 take info for Alternative detection from AnnotatedType and not from class

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/alternative/WoodEgg.java
Modified:
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanBuilder.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/util/WebBeansUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/ExtensionTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/events/extensions/AlternativeExtension.java

Modified: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanBuilder.java?rev=1512896&r1=1512895&r2=1512896&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanBuilder.java
Sun Aug 11 10:38:12 2013
@@ -75,7 +75,7 @@ public abstract class EjbBeanBuilder<T, 
     
     protected final E createBean(Class<T> beanClass)
     {
-        return createBean(beanClass, webBeansContext.getWebBeansUtil().isBeanEnabled(annotatedType,
annotatedType.getJavaClass(), beanAttributes.getStereotypes()));
+        return createBean(beanClass, webBeansContext.getWebBeansUtil().isBeanEnabled(annotatedType,
beanAttributes.getStereotypes()));
     }
     
     protected abstract E createBean(Class<T> beanClass, boolean beanEnabled);

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=1512896&r1=1512895&r2=1512896&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
Sun Aug 11 10:38:12 2013
@@ -60,7 +60,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, annotatedType.getJavaClass(),
beanAttributes.getStereotypes()));
+        bean.setEnabled(webBeansContext.getWebBeansUtil().isBeanEnabled(annotatedType, bean.getStereotypes()));
         webBeansContext.getWebBeansUtil().checkManagedBeanCondition(annotatedType);
         WebBeansUtil.checkGenericType(annotatedType.getJavaClass(), beanAttributes.getScope());
         webBeansContext.getDeploymentValidationService().validateProxyable(bean);

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=1512896&r1=1512895&r2=1512896&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
Sun Aug 11 10:38:12 2013
@@ -1211,7 +1211,6 @@ public final class WebBeansUtil
     /**
      * Returns <code>ProcessInjectionTarget</code> event.
      * @param <T> bean type
-     * @param bean bean instance
      * @return event
      */
     public <T> ProcessInjectionTarget<T> fireProcessInjectionTargetEvent(InjectionTarget<T>
injectionTarget, AnnotatedType<T> annotatedType)
@@ -1349,41 +1348,29 @@ public final class WebBeansUtil
      */
     public void setInjectionTargetBeanEnableFlag(InjectionTargetBean<?> bean)
     {
-        bean.setEnabled(isBeanEnabled(bean));
+        bean.setEnabled(isBeanEnabled(bean.getAnnotatedType(), bean.getStereotypes()));
     }
 
-    public boolean isBeanEnabled(InjectionTargetBean<?> bean)
-    {
-        Asserts.assertNotNull(bean, "bean can not be null");
-        return isBeanEnabled(bean.getAnnotatedType(), bean.getReturnType(), bean.getStereotypes());
-    }
-    
-    public boolean isBeanEnabled(AnnotatedType<?> at, Class<?> beanType, Set<Class<?
extends Annotation>> stereotypes)
+    public boolean isBeanEnabled(AnnotatedType<?> at, Set<Class<? extends Annotation>>
stereotypes)
     {
-        
-        boolean isAlternative = hasInjectionTargetBeanAnnotatedWithAlternative(beanType,
stereotypes); 
+        boolean isAlternative = hasInjectionTargetBeanAnnotatedWithAlternative(at, stereotypes);
 
-        if(!isAlternative)
-        {
-            isAlternative =  at.getAnnotation(Alternative.class) != null;
-        }
-        
-        return !isAlternative || webBeansContext.getAlternativesManager().isAlternative(beanType,
stereotypes);
+        return !isAlternative || webBeansContext.getAlternativesManager().isAlternative(at.getJavaClass(),
stereotypes);
     }
 
     public static boolean hasInjectionTargetBeanAnnotatedWithAlternative(InjectionTargetBean<?>
bean)
     {
-        return hasInjectionTargetBeanAnnotatedWithAlternative(bean.getReturnType(), bean.getStereotypes());
+        return hasInjectionTargetBeanAnnotatedWithAlternative(bean.getAnnotatedType(), bean.getStereotypes());
     }
     
-    public static boolean hasInjectionTargetBeanAnnotatedWithAlternative(Class<?> beanType,
Set<Class<? extends Annotation>> stereotypes)
+    public static boolean hasInjectionTargetBeanAnnotatedWithAlternative(AnnotatedType<?>
beanType, Set<Class<? extends Annotation>> stereotypes)
     {
         Asserts.assertNotNull(beanType, "bean type can not be null");
         Asserts.assertNotNull(stereotypes, "stereotypes can not be null");
 
         boolean alternative = false;
 
-        if(AnnotationUtil.hasClassAnnotation(beanType, Alternative.class))
+        if(beanType.getAnnotation(Alternative.class) != null)
         {
             alternative = true;
         }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/ExtensionTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/ExtensionTest.java?rev=1512896&r1=1512895&r2=1512896&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/ExtensionTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/ExtensionTest.java
Sun Aug 11 10:38:12 2013
@@ -32,6 +32,7 @@ import org.apache.webbeans.exception.inj
 import org.apache.webbeans.newtests.AbstractUnitTest;
 import org.apache.webbeans.newtests.portable.alternative.Egg;
 import org.apache.webbeans.newtests.portable.alternative.HalfEgg;
+import org.apache.webbeans.newtests.portable.alternative.WoodEgg;
 import org.apache.webbeans.newtests.portable.events.extensions.AlternativeExtension;
 import org.apache.webbeans.newtests.portable.scopeextension.ExternalTestScopeExtension;
 import org.apache.webbeans.newtests.portable.scopeextension.ExternalTestScoped;
@@ -121,18 +122,31 @@ public class ExtensionTest extends Abstr
     @Test
     public void testAlternativeExtenson()
     {
-        Collection<Class<?>> classes = new ArrayList<Class<?>>();
-        classes.add(Egg.class);
-        classes.add(HalfEgg.class);
         addExtension(new AlternativeExtension());
-        startContainer(classes);
+        startContainer(Egg.class, HalfEgg.class);
 
         Egg egg = getInstance(Egg.class);
         Assert.assertTrue(egg instanceof Egg);
+        Assert.assertFalse(egg instanceof HalfEgg);
         Set<Bean<?>> beans = getBeanManager().getBeans(HalfEgg.class);
         Assert.assertTrue(beans == null || beans.size() == 0);
 
         shutDownContainer();
     }
 
+    /**
+     * Test the dynamic removal of an &#064;Alternative annotation
+     * via ProcessAnnotatedType.
+     */
+    @Test
+    public void testRemoveAlternativeExtension()
+    {
+        addExtension(new AlternativeExtension());
+        startContainer(Egg.class, WoodEgg.class);
+
+        Set<Bean<?>> beans = getBeanManager().getBeans(Egg.class);
+        Assert.assertTrue(beans != null && beans.size() == 2);
+
+    }
+
 }

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/alternative/WoodEgg.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/alternative/WoodEgg.java?rev=1512896&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/alternative/WoodEgg.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/alternative/WoodEgg.java
Sun Aug 11 10:38:12 2013
@@ -0,0 +1,32 @@
+/*
+ * 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.newtests.portable.alternative;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Alternative;
+
+/**
+ * An alternative which is not specified in beans.xml.
+ * The Alternative annotation will be dynamically removed via an Extension.
+ */
+@ApplicationScoped
+@Alternative
+public class WoodEgg extends Egg
+{
+}

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/events/extensions/AlternativeExtension.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/events/extensions/AlternativeExtension.java?rev=1512896&r1=1512895&r2=1512896&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/events/extensions/AlternativeExtension.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/portable/events/extensions/AlternativeExtension.java
Sun Aug 11 10:38:12 2013
@@ -25,14 +25,37 @@ import javax.enterprise.inject.spi.Proce
 import javax.enterprise.util.AnnotationLiteral;
 
 import org.apache.webbeans.newtests.portable.alternative.HalfEgg;
+import org.apache.webbeans.newtests.portable.alternative.WoodEgg;
+
+import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Set;
 
 
 public class AlternativeExtension implements Extension
 {
-    public void observeProcessAnnotatedType(@Observes ProcessAnnotatedType<HalfEgg>
pat)
+    public void observeProcessAnnotatedTypeHalfEgg(@Observes ProcessAnnotatedType<HalfEgg>
pat)
     {
         // this just works with OWB and assumes a mutable annotation Set.
         pat.getAnnotatedType().getAnnotations().add(new AnnotationLiteral<Alternative>()
{});
         pat.setAnnotatedType(pat.getAnnotatedType());
-    } 
+    }
+
+    public void observeProcessAnnotatedTypeWoodEgg(@Observes ProcessAnnotatedType<WoodEgg>
pat)
+    {
+        // this just works with OWB and assumes a mutable annotation Set.
+        Set<Annotation> newAnnotations = new HashSet<Annotation>();
+        for (Annotation ann : pat.getAnnotatedType().getAnnotations())
+        {
+            if (!Alternative.class.isAssignableFrom(ann.annotationType()))
+            {
+                 newAnnotations.add(ann);
+            }
+        }
+
+        pat.getAnnotatedType().getAnnotations().clear();
+        pat.getAnnotatedType().getAnnotations().addAll(newAnnotations);
+
+        pat.setAnnotatedType(pat.getAnnotatedType());
+    }
 }



Mime
View raw message