openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1432766 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/creation/ main/java/org/apache/webbeans/util/ test/java/org/apache/webbeans/newtests/producer/specializes/ test/java/org/apache/webbeans/newtests/s...
Date Sun, 13 Jan 2013 23:39:55 GMT
Author: arne
Date: Sun Jan 13 23:39:55 2013
New Revision: 1432766

URL: http://svn.apache.org/viewvc?rev=1432766&view=rev
Log:
OWB-747: Partially fixed specialization (TCK still failing)

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractProducerBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeanBuilder.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/producer/specializes/SpecializesProducer1Test.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/AlternativeSpecializesProducerTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java?rev=1432766&r1=1432765&r2=1432766&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
Sun Jan 13 23:39:55 2013
@@ -56,7 +56,6 @@ import org.apache.webbeans.event.EventUt
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.exception.helper.ViolationMessageBuilder;
 import org.apache.webbeans.util.AnnotationUtil;
-import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.SecurityUtil;
 import org.apache.webbeans.util.WebBeansUtil;
 
@@ -102,6 +101,11 @@ public abstract class AbstractBeanBuilde
         return scope;
     }
 
+    public String getName()
+    {
+        return beanName;
+    }
+
     protected Set<Class<? extends Annotation>> getStereotypes()
     {
         return stereotypes;
@@ -227,9 +231,9 @@ public abstract class AbstractBeanBuilde
         }
     }
 
-    public void defineName(String name)
+    protected void defineName(Annotated annotated, String name)
     {
-        Annotation[] anns = AnnotationUtil.asArray(getAnnotated().getAnnotations());
+        Annotation[] anns = AnnotationUtil.asArray(annotated.getAnnotations());
         Named nameAnnot = null;
         boolean isDefault = false;
         for (Annotation ann : anns)
@@ -278,16 +282,13 @@ public abstract class AbstractBeanBuilde
         HashSet<Class<? extends Annotation>> qualifiedTypes = new HashSet<Class<?
extends Annotation>>();
         if (annotated.isAnnotationPresent(Specializes.class))
         {
-            // in this case first define qualifiers of supertype
-            Class<?> superclass = ClassUtil.getClass(annotated.getBaseType()).getSuperclass();
-            if (superclass != null)
-            {
-                defineQualifiers(webBeansContext.getAnnotatedElementFactory().getAnnotatedType(superclass),
qualifiedTypes);
-            }
+            defineQualifiers(getSuperAnnotated(), qualifiedTypes);
         }
         defineQualifiers(annotated, qualifiedTypes);
     }
     
+    protected abstract Annotated getSuperAnnotated();
+
     private void defineQualifiers(Annotated annotated, Set<Class<? extends Annotation>>
qualifiedTypes)
     {
         Annotation[] annotations = AnnotationUtil.asArray(annotated.getAnnotations());

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java?rev=1432766&r1=1432765&r2=1432766&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java
Sun Jan 13 23:39:55 2013
@@ -87,12 +87,29 @@ public abstract class AbstractInjectionT
         this.webBeansContext = webBeansContext;
     }
 
+    protected AnnotatedType<? super T> getSuperAnnotated()
+    {
+        Class<? super T> superclass = getAnnotated().getJavaClass().getSuperclass();
+        if (superclass == null)
+        {
+            return null;
+        }
+        return webBeansContext.getAnnotatedElementFactory().getAnnotatedType(superclass);
+    }
+    
     /**
      * {@inheritDoc}
      */
     public void defineName()
     {
-        defineName(WebBeansUtil.getManagedBeanDefaultName(getAnnotated().getJavaClass().getSimpleName()));
+        if (getAnnotated().isAnnotationPresent(Specializes.class))
+        {
+            defineName(getSuperAnnotated(), WebBeansUtil.getManagedBeanDefaultName(getAnnotated().getJavaClass().getSimpleName()));
+        }
+        if (getName() == null)
+        {
+            defineName(getAnnotated(), WebBeansUtil.getManagedBeanDefaultName(getAnnotated().getJavaClass().getSimpleName()));
+        }
     }
 
     protected AnnotatedConstructor<T> getBeanConstructor()
@@ -549,7 +566,7 @@ public abstract class AbstractInjectionT
                     producerFieldBeanCreator.defineScopeType("Annotated producer field: "
+ annotatedField +  "must declare default @Scope annotation");
                     producerFieldBeanCreator.checkUnproxiableApiType();
                     producerFieldBeanCreator.defineQualifiers();
-                    producerFieldBeanCreator.defineName(WebBeansUtil.getProducerDefaultName(annotatedField.getJavaMember().getName()));
+                    producerFieldBeanCreator.defineName();
                     ProducerFieldBean<T> producerFieldBean = producerFieldBeanCreator.getBean();
                     producerFieldBean.setProducerField(field);
                     
@@ -608,7 +625,7 @@ public abstract class AbstractInjectionT
                 
                 producerMethodBeanCreator.addInjectionPoint(annotatedMethod);
                 producerMethodBeanCreator.defineApiType();
-                producerMethodBeanCreator.defineName(WebBeansUtil.getProducerDefaultName(annotatedMethod.getJavaMember().getName()));
+                producerMethodBeanCreator.defineName();
                 ProducerMethodBean<T> producerMethodBean = producerMethodBeanCreator.getBean();
                 producerMethodBean.setCreatorMethod(annotatedMethod.getJavaMember());
                 if (ClassUtil.getClass(annotatedMethod.getBaseType()).isPrimitive())

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractProducerBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractProducerBeanBuilder.java?rev=1432766&r1=1432765&r2=1432766&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractProducerBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractProducerBeanBuilder.java
Sun Jan 13 23:39:55 2013
@@ -23,6 +23,7 @@ import java.lang.reflect.Type;
 import java.util.Set;
 
 import javax.enterprise.inject.spi.AnnotatedMember;
+import javax.enterprise.inject.spi.AnnotatedType;
 
 import org.apache.webbeans.component.AbstractProducerBean;
 import org.apache.webbeans.component.InjectionTargetBean;
@@ -38,6 +39,16 @@ public abstract class AbstractProducerBe
         this.parent = parent;
     }
 
+    protected AnnotatedType<?> getSuperType()
+    {
+        Class<?> superclass = getAnnotated().getDeclaringType().getJavaClass().getSuperclass();
+        if (superclass == null)
+        {
+            return null;
+        }
+        return parent.getWebBeansContext().getAnnotatedElementFactory().getAnnotatedType(superclass);
+    }
+
     protected abstract P createBean(InjectionTargetBean<?> parent,
                                     Set<Type> types,
                                     Set<Annotation> qualifiers,

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeanBuilder.java?rev=1432766&r1=1432765&r2=1432766&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeanBuilder.java
Sun Jan 13 23:39:55 2013
@@ -22,10 +22,12 @@ import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 import java.util.Set;
 
+import javax.enterprise.inject.Specializes;
 import javax.enterprise.inject.spi.AnnotatedField;
 
 import org.apache.webbeans.component.InjectionTargetBean;
 import org.apache.webbeans.component.ProducerFieldBean;
+import org.apache.webbeans.util.WebBeansUtil;
 
 public class ProducerFieldBeanBuilder<T, P extends ProducerFieldBean<T>> extends
AbstractProducerBeanBuilder<T, AnnotatedField<?>, P>
 {
@@ -34,6 +36,21 @@ public class ProducerFieldBeanBuilder<T,
     {
         super(owner, annotated);
     }
+    
+    /**
+     * {@inheritDoc}
+     */
+    public void defineName()
+    {
+        if (getAnnotated().isAnnotationPresent(Specializes.class))
+        {
+            defineName(getSuperAnnotated(), WebBeansUtil.getProducerDefaultName(getSuperAnnotated().getJavaMember().getName()));
+        }
+        if (getName() == null)
+        {
+            defineName(getAnnotated(), WebBeansUtil.getProducerDefaultName(getAnnotated().getJavaMember().getName()));
+        }
+    }
 
     @Override
     protected Class<T> getBeanType()
@@ -41,6 +58,20 @@ public class ProducerFieldBeanBuilder<T,
         return (Class<T>) getAnnotated().getJavaMember().getType();
     }
 
+    protected AnnotatedField<?> getSuperAnnotated()
+    {
+        AnnotatedField<?> thisField = getAnnotated();
+        for (AnnotatedField<?> superField: getSuperType().getFields())
+        {
+            if (thisField.getJavaMember().getName().equals(superField.getJavaMember().getName())
+                && thisField.getBaseType().equals(superField.getBaseType()))
+            {
+                return superField;
+            }
+        }
+        return null;
+    }
+
     @Override
     protected P createBean(InjectionTargetBean<?> owner,
                            Set<Type> types,

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeanBuilder.java?rev=1432766&r1=1432765&r2=1432766&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeanBuilder.java
Sun Jan 13 23:39:55 2013
@@ -26,6 +26,7 @@ import java.util.List;
 import java.util.Set;
 
 import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.Specializes;
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedParameter;
 
@@ -34,10 +35,13 @@ import org.apache.webbeans.component.Pro
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.ClassUtil;
+import org.apache.webbeans.util.WebBeansUtil;
 
 public class ProducerMethodBeanBuilder<T> extends AbstractProducerBeanBuilder<T,
AnnotatedMethod<?>, ProducerMethodBean<T>>
 {
 
+    private boolean specialized;
+
     public ProducerMethodBeanBuilder(InjectionTargetBean<T> parent, AnnotatedMethod<?>
annotatedMethod)
     {
         super(parent, annotatedMethod);
@@ -82,6 +86,51 @@ public class ProducerMethodBeanBuilder<T
         
         getBean().setSpecializedBean(true);        
     }
+    
+    /**
+     * {@inheritDoc}
+     */
+    public void defineName()
+    {
+        if (getAnnotated().isAnnotationPresent(Specializes.class))
+        {
+            specialized = true;
+            defineName(getSuperAnnotated(), WebBeansUtil.getProducerDefaultName(getSuperAnnotated().getJavaMember().getName()));
+        }
+        if (getName() == null)
+        {
+            defineName(getAnnotated(), WebBeansUtil.getProducerDefaultName(getAnnotated().getJavaMember().getName()));
+        }
+    }
+
+    protected AnnotatedMethod<?> getSuperAnnotated()
+    {
+        AnnotatedMethod<?> thisMethod = getAnnotated();
+        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 Class<T> getBeanType()
@@ -100,6 +149,8 @@ public class ProducerMethodBeanBuilder<T
                                                Set<Class<? extends Annotation>>
stereotypes,
                                                boolean alternative)
     {
-        return new ProducerMethodBean<T>(parent, types, qualifiers, scope, name, nullable,
beanClass, stereotypes, alternative);
+        ProducerMethodBean<T> producerMethodBean = new ProducerMethodBean<T>(parent,
types, qualifiers, scope, name, nullable, beanClass, stereotypes, alternative);
+        producerMethodBean.setSpecializedBean(specialized);
+        return producerMethodBean;
     }
 }

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=1432766&r1=1432765&r2=1432766&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 Jan 13 23:39:55 2013
@@ -1395,7 +1395,6 @@ public final class WebBeansUtil
                                 + " may not explicitly declare a bean name");
                     }
 
-//                    comp.setName(superBean.getName());
                     comp.setSpecializedBean(true);
                 }
             }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/specializes/SpecializesProducer1Test.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/specializes/SpecializesProducer1Test.java?rev=1432766&r1=1432765&r2=1432766&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/specializes/SpecializesProducer1Test.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/producer/specializes/SpecializesProducer1Test.java
Sun Jan 13 23:39:55 2013
@@ -39,7 +39,6 @@ import org.junit.Test;
 public class SpecializesProducer1Test extends AbstractUnitTest
 {
 
-    @Ignore
     @Test
     public void testSpecializedProducer1()
     {

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/AlternativeSpecializesProducerTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/AlternativeSpecializesProducerTest.java?rev=1432766&r1=1432765&r2=1432766&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/AlternativeSpecializesProducerTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/AlternativeSpecializesProducerTest.java
Sun Jan 13 23:39:55 2013
@@ -38,7 +38,6 @@ public class AlternativeSpecializesProdu
 
     private static final String PACKAGE_NAME = AlternativeSpecializesProducerTest.class.getPackage().getName();
 
-    @Ignore
     @Test
     @SuppressWarnings("unchecked")
     public void testAlternativeSpecializeBean()



Mime
View raw message