You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ta...@apache.org on 2013/12/18 19:20:42 UTC

svn commit: r1552050 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java test/java/org/apache/webbeans/newtests/specalization/multiple/MultipleSpecializationTest.java

Author: tandraschko
Date: Wed Dec 18 18:20:42 2013
New Revision: 1552050

URL: http://svn.apache.org/r1552050
Log:
OWB-917 - Multiple specialization doesn't work

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/multiple/MultipleSpecializationTest.java

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=1552050&r1=1552049&r2=1552050&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 Wed Dec 18 18:20:42 2013
@@ -511,8 +511,15 @@ public abstract class BeanAttributesBuil
         {
             if (getAnnotated().isAnnotationPresent(Specializes.class))
             {
-                AnnotatedType<? super C> superAnnotated = getSuperAnnotated();
-                defineName(superAnnotated, WebBeansUtil.getManagedBeanDefaultName(superAnnotated.getJavaClass().getSimpleName()));
+                Class<? super C> classToSpecialize = getAnnotated().getJavaClass().getSuperclass();
+                
+                while (classToSpecialize.isAnnotationPresent(Specializes.class))
+                {
+                    classToSpecialize = classToSpecialize.getSuperclass();
+                }
+
+                AnnotatedType<? super C> annotatedToSpecialize = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(classToSpecialize);
+                defineName(annotatedToSpecialize, WebBeansUtil.getManagedBeanDefaultName(classToSpecialize.getSimpleName()));
             }
             if (name == null)
             {

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/multiple/MultipleSpecializationTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/multiple/MultipleSpecializationTest.java?rev=1552050&r1=1552049&r2=1552050&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/multiple/MultipleSpecializationTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/multiple/MultipleSpecializationTest.java Wed Dec 18 18:20:42 2013
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import junit.framework.Assert;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.exception.inject.DefinitionException;
 import org.apache.webbeans.exception.inject.InconsistentSpecializationException;
 import org.apache.webbeans.newtests.AbstractUnitTest;
 import org.junit.Test;
@@ -31,7 +32,7 @@ public class MultipleSpecializationTest 
     /**
      * Tests that multiple specialization must be possible
      */
-    //@Test
+    @Test
     public void testMultipleSpecialization()
     {
         Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
@@ -53,9 +54,11 @@ public class MultipleSpecializationTest 
     /**
      * Tests that a specialization must not have a @Named annotation
      */
-    //@Test
+    @Test
     public void testFailMultipleSpecializationWithNamed()
     {
+        Exception occuredException = null;
+        
         try
         {
             Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
@@ -68,10 +71,13 @@ public class MultipleSpecializationTest 
         }
         catch (Exception e)
         {
-            Assert.assertEquals(WebBeansConfigurationException.class.getName(), e.getClass().getName());
-            Assert.assertEquals(InconsistentSpecializationException.class.getName(), e.getCause().getClass().getName());
+            occuredException = e;
         }
 
+        Assert.assertNotNull(occuredException);
+        Assert.assertEquals(WebBeansConfigurationException.class.getName(), occuredException.getClass().getName());
+        Assert.assertEquals(DefinitionException.class.getName(), occuredException.getCause().getClass().getName());
+        
         shutDownContainer();
     }
 }



Re: svn commit: r1552050 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java test/java/org/apache/webbeans/newtests/specalization/multiple/MultipleSpecializationTest.java

Posted by Joseph Bergmark <be...@gmail.com>.
That looks closer to what the previous code was doing as it appears to be
building a new AnnotatedType from the class.

I'm not sure building a new AnnotatedType is the right thing to do either,
as it seems we would want to get the AnnotatedType that was potentially set
via the event earlier.  In any case that was the previous behavior as well
so I think its fine for now.


On Wed, Dec 18, 2013 at 5:12 PM, Thomas Andraschko <
andraschko.thomas@gmail.com> wrote:

> Ahh i see!
>
> To be honest, i'm not very experiences in this area too!
>
> I tried it with this code:
>
>                 AnnotatedType<? super C> annotatedToSpecialize =
>
>
> webBeansContext.getAnnotatedElementFactory().newAnnotatedType(getAnnotated().getJavaClass().getSuperclass());
>
>                 while
> (annotatedToSpecialize.isAnnotationPresent(Specializes.class))
>                 {
>                     annotatedToSpecialize =
>
> webBeansContext.getAnnotatedElementFactory().newAnnotatedType(annotatedToSpecialize.getJavaClass().getSuperclass());
>                 }
>
>                 defineName(annotatedToSpecialize,
>
> WebBeansUtil.getManagedBeanDefaultName(annotatedToSpecialize.getJavaClass().getSimpleName()));
>
> and its working fine too.
> All unit tests passing.
>
> Should i commit it?
>
>
>
> 2013/12/18 Joseph Bergmark <be...@gmail.com>
>
> > Sorry, I'll try to be more clear.  Again, I'm not very experienced in
> this
> > area of OWB, so my interpretation could be wrong or this could be handled
> > in a different code path entirely.
> >
> > The new code is looking directly at the Class itself for the @Specializes
> > annotation.  I'm suggesting that perhaps instead it should be looking at
> > the AnnotatedType for the annotation
> (AnnotatedType.isAnnotatationPresent)
> > in case a portable extension has called setAnnotatedType during a
> > ProcessAnnotatedType event and has added @Specializes.
> >
> >
> > On Wed, Dec 18, 2013 at 4:14 PM, Thomas Andraschko <
> > andraschko.thomas@gmail.com> wrote:
> >
> > > Hey,
> > >
> > > i'm not exactly sure if understand your question correctly but i will
> > > explain you my code change.
> > >
> > > I think specialization per se was working fine but the old code just
> > looked
> > > for a @Named on the direct parent.
> > >
> > > e.g.
> > >
> > > @Named BeanA
> > > @Specializes BeanB extends BeanA
> > > @Specializes BeanC extends BeanC
> > >
> > > It tried to extract the name for BeanC from BeanB but actually it must
> > look
> > > for @Named on BeanA.
> > >
> > >
> > > 2013/12/18 Joseph Bergmark <be...@gmail.com>
> > >
> > > > I'll be the first to admit I'm not very familiar with this code area,
> > but
> > > > is it possible that this change could mean that we miss @Specializes
> > > added
> > > > to the AnnotatedType classes in the super class hierarchy, as you are
> > > > walking up the class objects themselves looking for the annotation?
> > > >
> > >
> >
>

Re: svn commit: r1552050 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java test/java/org/apache/webbeans/newtests/specalization/multiple/MultipleSpecializationTest.java

Posted by Gerhard Petracek <ge...@gmail.com>.
imo section 4.1 of the cdi spec is pretty clear.

regards,
gerhard



2013/12/18 Thomas Andraschko <an...@gmail.com>

> Ahh i see!
>
> To be honest, i'm not very experiences in this area too!
>
> I tried it with this code:
>
>                 AnnotatedType<? super C> annotatedToSpecialize =
>
>
> webBeansContext.getAnnotatedElementFactory().newAnnotatedType(getAnnotated().getJavaClass().getSuperclass());
>
>                 while
> (annotatedToSpecialize.isAnnotationPresent(Specializes.class))
>                 {
>                     annotatedToSpecialize =
>
> webBeansContext.getAnnotatedElementFactory().newAnnotatedType(annotatedToSpecialize.getJavaClass().getSuperclass());
>                 }
>
>                 defineName(annotatedToSpecialize,
>
> WebBeansUtil.getManagedBeanDefaultName(annotatedToSpecialize.getJavaClass().getSimpleName()));
>
> and its working fine too.
> All unit tests passing.
>
> Should i commit it?
>
>
>
> 2013/12/18 Joseph Bergmark <be...@gmail.com>
>
> > Sorry, I'll try to be more clear.  Again, I'm not very experienced in
> this
> > area of OWB, so my interpretation could be wrong or this could be handled
> > in a different code path entirely.
> >
> > The new code is looking directly at the Class itself for the @Specializes
> > annotation.  I'm suggesting that perhaps instead it should be looking at
> > the AnnotatedType for the annotation
> (AnnotatedType.isAnnotatationPresent)
> > in case a portable extension has called setAnnotatedType during a
> > ProcessAnnotatedType event and has added @Specializes.
> >
> >
> > On Wed, Dec 18, 2013 at 4:14 PM, Thomas Andraschko <
> > andraschko.thomas@gmail.com> wrote:
> >
> > > Hey,
> > >
> > > i'm not exactly sure if understand your question correctly but i will
> > > explain you my code change.
> > >
> > > I think specialization per se was working fine but the old code just
> > looked
> > > for a @Named on the direct parent.
> > >
> > > e.g.
> > >
> > > @Named BeanA
> > > @Specializes BeanB extends BeanA
> > > @Specializes BeanC extends BeanC
> > >
> > > It tried to extract the name for BeanC from BeanB but actually it must
> > look
> > > for @Named on BeanA.
> > >
> > >
> > > 2013/12/18 Joseph Bergmark <be...@gmail.com>
> > >
> > > > I'll be the first to admit I'm not very familiar with this code area,
> > but
> > > > is it possible that this change could mean that we miss @Specializes
> > > added
> > > > to the AnnotatedType classes in the super class hierarchy, as you are
> > > > walking up the class objects themselves looking for the annotation?
> > > >
> > >
> >
>

Re: svn commit: r1552050 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java test/java/org/apache/webbeans/newtests/specalization/multiple/MultipleSpecializationTest.java

Posted by Thomas Andraschko <an...@gmail.com>.
Ahh i see!

To be honest, i'm not very experiences in this area too!

I tried it with this code:

                AnnotatedType<? super C> annotatedToSpecialize =

webBeansContext.getAnnotatedElementFactory().newAnnotatedType(getAnnotated().getJavaClass().getSuperclass());

                while
(annotatedToSpecialize.isAnnotationPresent(Specializes.class))
                {
                    annotatedToSpecialize =
webBeansContext.getAnnotatedElementFactory().newAnnotatedType(annotatedToSpecialize.getJavaClass().getSuperclass());
                }

                defineName(annotatedToSpecialize,
WebBeansUtil.getManagedBeanDefaultName(annotatedToSpecialize.getJavaClass().getSimpleName()));

and its working fine too.
All unit tests passing.

Should i commit it?



2013/12/18 Joseph Bergmark <be...@gmail.com>

> Sorry, I'll try to be more clear.  Again, I'm not very experienced in this
> area of OWB, so my interpretation could be wrong or this could be handled
> in a different code path entirely.
>
> The new code is looking directly at the Class itself for the @Specializes
> annotation.  I'm suggesting that perhaps instead it should be looking at
> the AnnotatedType for the annotation (AnnotatedType.isAnnotatationPresent)
> in case a portable extension has called setAnnotatedType during a
> ProcessAnnotatedType event and has added @Specializes.
>
>
> On Wed, Dec 18, 2013 at 4:14 PM, Thomas Andraschko <
> andraschko.thomas@gmail.com> wrote:
>
> > Hey,
> >
> > i'm not exactly sure if understand your question correctly but i will
> > explain you my code change.
> >
> > I think specialization per se was working fine but the old code just
> looked
> > for a @Named on the direct parent.
> >
> > e.g.
> >
> > @Named BeanA
> > @Specializes BeanB extends BeanA
> > @Specializes BeanC extends BeanC
> >
> > It tried to extract the name for BeanC from BeanB but actually it must
> look
> > for @Named on BeanA.
> >
> >
> > 2013/12/18 Joseph Bergmark <be...@gmail.com>
> >
> > > I'll be the first to admit I'm not very familiar with this code area,
> but
> > > is it possible that this change could mean that we miss @Specializes
> > added
> > > to the AnnotatedType classes in the super class hierarchy, as you are
> > > walking up the class objects themselves looking for the annotation?
> > >
> >
>

Re: svn commit: r1552050 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java test/java/org/apache/webbeans/newtests/specalization/multiple/MultipleSpecializationTest.java

Posted by Joseph Bergmark <be...@gmail.com>.
Sorry, I'll try to be more clear.  Again, I'm not very experienced in this
area of OWB, so my interpretation could be wrong or this could be handled
in a different code path entirely.

The new code is looking directly at the Class itself for the @Specializes
annotation.  I'm suggesting that perhaps instead it should be looking at
the AnnotatedType for the annotation (AnnotatedType.isAnnotatationPresent)
in case a portable extension has called setAnnotatedType during a
ProcessAnnotatedType event and has added @Specializes.


On Wed, Dec 18, 2013 at 4:14 PM, Thomas Andraschko <
andraschko.thomas@gmail.com> wrote:

> Hey,
>
> i'm not exactly sure if understand your question correctly but i will
> explain you my code change.
>
> I think specialization per se was working fine but the old code just looked
> for a @Named on the direct parent.
>
> e.g.
>
> @Named BeanA
> @Specializes BeanB extends BeanA
> @Specializes BeanC extends BeanC
>
> It tried to extract the name for BeanC from BeanB but actually it must look
> for @Named on BeanA.
>
>
> 2013/12/18 Joseph Bergmark <be...@gmail.com>
>
> > I'll be the first to admit I'm not very familiar with this code area, but
> > is it possible that this change could mean that we miss @Specializes
> added
> > to the AnnotatedType classes in the super class hierarchy, as you are
> > walking up the class objects themselves looking for the annotation?
> >
>

Re: svn commit: r1552050 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java test/java/org/apache/webbeans/newtests/specalization/multiple/MultipleSpecializationTest.java

Posted by Thomas Andraschko <an...@gmail.com>.
Hey,

i'm not exactly sure if understand your question correctly but i will
explain you my code change.

I think specialization per se was working fine but the old code just looked
for a @Named on the direct parent.

e.g.

@Named BeanA
@Specializes BeanB extends BeanA
@Specializes BeanC extends BeanC

It tried to extract the name for BeanC from BeanB but actually it must look
for @Named on BeanA.


2013/12/18 Joseph Bergmark <be...@gmail.com>

> I'll be the first to admit I'm not very familiar with this code area, but
> is it possible that this change could mean that we miss @Specializes added
> to the AnnotatedType classes in the super class hierarchy, as you are
> walking up the class objects themselves looking for the annotation?
>

Re: svn commit: r1552050 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java test/java/org/apache/webbeans/newtests/specalization/multiple/MultipleSpecializationTest.java

Posted by Joseph Bergmark <be...@gmail.com>.
I'll be the first to admit I'm not very familiar with this code area, but
is it possible that this change could mean that we miss @Specializes added
to the AnnotatedType classes in the super class hierarchy, as you are
walking up the class objects themselves looking for the annotation?

On Wed, Dec 18, 2013 at 1:20 PM, <ta...@apache.org> wrote:

> Author: tandraschko
> Date: Wed Dec 18 18:20:42 2013
> New Revision: 1552050
>
> URL: http://svn.apache.org/r1552050
> Log:
> OWB-917 - Multiple specialization doesn't work
>
> Modified:
>
> openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java
>
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/multiple/MultipleSpecializationTest.java
>
> 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=1552050&r1=1552049&r2=1552050&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
> Wed Dec 18 18:20:42 2013
> @@ -511,8 +511,15 @@ public abstract class BeanAttributesBuil
>          {
>              if (getAnnotated().isAnnotationPresent(Specializes.class))
>              {
> -                AnnotatedType<? super C> superAnnotated =
> getSuperAnnotated();
> -                defineName(superAnnotated,
> WebBeansUtil.getManagedBeanDefaultName(superAnnotated.getJavaClass().getSimpleName()));
> +                Class<? super C> classToSpecialize =
> getAnnotated().getJavaClass().getSuperclass();
> +
> +                while
> (classToSpecialize.isAnnotationPresent(Specializes.class))
> +                {
> +                    classToSpecialize = classToSpecialize.getSuperclass();
> +                }
> +
> +                AnnotatedType<? super C> annotatedToSpecialize =
> webBeansContext.getAnnotatedElementFactory().newAnnotatedType(classToSpecialize);
> +                defineName(annotatedToSpecialize,
> WebBeansUtil.getManagedBeanDefaultName(classToSpecialize.getSimpleName()));
>              }
>              if (name == null)
>              {
>
> Modified:
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/multiple/MultipleSpecializationTest.java
> URL:
> http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/multiple/MultipleSpecializationTest.java?rev=1552050&r1=1552049&r2=1552050&view=diff
>
> ==============================================================================
> ---
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/multiple/MultipleSpecializationTest.java
> (original)
> +++
> openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/specalization/multiple/MultipleSpecializationTest.java
> Wed Dec 18 18:20:42 2013
> @@ -22,6 +22,7 @@ import java.util.ArrayList;
>  import java.util.Collection;
>  import junit.framework.Assert;
>  import org.apache.webbeans.exception.WebBeansConfigurationException;
> +import org.apache.webbeans.exception.inject.DefinitionException;
>  import
> org.apache.webbeans.exception.inject.InconsistentSpecializationException;
>  import org.apache.webbeans.newtests.AbstractUnitTest;
>  import org.junit.Test;
> @@ -31,7 +32,7 @@ public class MultipleSpecializationTest
>      /**
>       * Tests that multiple specialization must be possible
>       */
> -    //@Test
> +    @Test
>      public void testMultipleSpecialization()
>      {
>          Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
> @@ -53,9 +54,11 @@ public class MultipleSpecializationTest
>      /**
>       * Tests that a specialization must not have a @Named annotation
>       */
> -    //@Test
> +    @Test
>      public void testFailMultipleSpecializationWithNamed()
>      {
> +        Exception occuredException = null;
> +
>          try
>          {
>              Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
> @@ -68,10 +71,13 @@ public class MultipleSpecializationTest
>          }
>          catch (Exception e)
>          {
> -
>  Assert.assertEquals(WebBeansConfigurationException.class.getName(),
> e.getClass().getName());
> -
>  Assert.assertEquals(InconsistentSpecializationException.class.getName(),
> e.getCause().getClass().getName());
> +            occuredException = e;
>          }
>
> +        Assert.assertNotNull(occuredException);
> +
>  Assert.assertEquals(WebBeansConfigurationException.class.getName(),
> occuredException.getClass().getName());
> +        Assert.assertEquals(DefinitionException.class.getName(),
> occuredException.getCause().getClass().getName());
> +
>          shutDownContainer();
>      }
>  }
>
>
>