[webbeans-commits] Webbeans SVN: r1184 - tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/inheritance/specialization/producer/method and 1 other directory.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Thu Jan 22 19:47:32 EST 2009


Author: pete.muir at jboss.org
Date: 2009-01-22 19:47:31 -0500 (Thu, 22 Jan 2009)
New Revision: 1184

Modified:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
   tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/inheritance/specialization/producer/method/HighSchool_Broken.java
   tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/inheritance/specialization/producer/method/ProducerMethodSpecializationTest.java
Log:
Specialization and tests

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java	2009-01-23 00:46:28 UTC (rev 1183)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java	2009-01-23 00:47:31 UTC (rev 1184)
@@ -128,6 +128,12 @@
    protected void init()
    {
       mergedStereotypes = new MergedStereotypes<T, E>(getAnnotatedItem().getMetaAnnotations(Stereotype.class));
+      if (isSpecializing())
+      {
+         preCheckSpecialization();
+         initSpecialization();
+         postCheckSpecialization();
+      }
       initType();
       initPrimitive();
       log.debug("Building Web Bean bean metadata for " + getType());
@@ -139,12 +145,6 @@
       initTypes();
       initProxyable();
       checkRequiredTypesImplemented();
-      if (isSpecializing())
-      {
-         preCheckSpecialization();
-         initSpecialization();
-         postCheckSpecialization();
-      }
    }
 
    /**

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java	2009-01-23 00:46:28 UTC (rev 1183)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java	2009-01-23 00:47:31 UTC (rev 1184)
@@ -29,7 +29,6 @@
 import javax.webbeans.DefinitionException;
 import javax.webbeans.Dependent;
 import javax.webbeans.Interceptor;
-import javax.webbeans.Specializes;
 
 import org.jboss.webbeans.ManagerImpl;
 import org.jboss.webbeans.bean.proxy.EnterpriseBeanProxyMethodHandler;
@@ -89,10 +88,6 @@
    protected EnterpriseBean(AnnotatedClass<T> type, ManagerImpl manager)
    {
       super(type, manager);
-      if (type.isAnnotationPresent(Specializes.class))
-      {
-         this.specializedBean = EnterpriseBean.of(type.getSuperclass(), manager);
-      }
       init();
    }
 

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java	2009-01-23 00:46:28 UTC (rev 1183)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java	2009-01-23 00:47:31 UTC (rev 1184)
@@ -24,6 +24,7 @@
 import javax.webbeans.DefinitionException;
 import javax.webbeans.Disposes;
 import javax.webbeans.Observes;
+import javax.webbeans.Specializes;
 
 import org.jboss.webbeans.ManagerImpl;
 import org.jboss.webbeans.MetaDataCache;
@@ -213,10 +214,25 @@
    }
    
    @Override
+   protected void preCheckSpecialization()
+   {
+      // Need to do getDeclaredMethod!
+      if (declaringBean.getAnnotatedItem().getSuperclass().getMethod(getAnnotatedItem().getAnnotatedMethod()) == null)
+      {
+         throw new DefinitionException("Specialized producer method does not override a method on the direct superclass");
+      }
+   }
+   
+   @Override
+   protected void initSpecialization()
+   {
+      this.specializedBean = ProducerMethodBean.of(declaringBean.getAnnotatedItem().getSuperclass().getMethod(getAnnotatedItem().getAnnotatedMethod()), SimpleBean.of(declaringBean.getAnnotatedItem().getSuperclass(), manager), manager);
+   }
+   
+   @Override
    public boolean isSpecializing()
    {
-      // TODO Auto-generated method stub
-      return false;
+      return getAnnotatedItem().isAnnotationPresent(Specializes.class);
    }
 
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java	2009-01-23 00:46:28 UTC (rev 1183)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java	2009-01-23 00:47:31 UTC (rev 1184)
@@ -30,7 +30,6 @@
 import javax.webbeans.ExecutionException;
 import javax.webbeans.Initializer;
 import javax.webbeans.InjectionPoint;
-import javax.webbeans.Specializes;
 
 import org.jboss.webbeans.ManagerImpl;
 import org.jboss.webbeans.MetaDataCache;
@@ -105,10 +104,6 @@
    protected SimpleBean(AnnotatedClass<T> type, ManagerImpl manager)
    {
       super(type, manager);
-      if (type.isAnnotationPresent(Specializes.class))
-      {
-         this.specializedBean = SimpleBean.of(type.getSuperclass(), manager);
-      }
       init();
    }
 
@@ -352,7 +347,7 @@
    protected void preCheckSpecialization()
    {
       super.preCheckSpecialization();
-      if (manager.getEjbDescriptorCache().containsKey(getSpecializedBean().getType()))
+      if (manager.getEjbDescriptorCache().containsKey(getAnnotatedItem().getSuperclass().getType()))
       {
          throw new DefinitionException("Simple bean must specialize a simple bean");
       }

Modified: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/inheritance/specialization/producer/method/HighSchool_Broken.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/inheritance/specialization/producer/method/HighSchool_Broken.java	2009-01-23 00:46:28 UTC (rev 1183)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/inheritance/specialization/producer/method/HighSchool_Broken.java	2009-01-23 00:47:31 UTC (rev 1184)
@@ -1,12 +1,13 @@
 package org.jboss.webbeans.tck.unit.inheritance.specialization.producer.method;
 
+import javax.webbeans.Named;
 import javax.webbeans.Produces;
 import javax.webbeans.Specializes;
 
 class HighSchool_Broken extends School
 {
    
-   @Override @Produces @Specializes @AnotherDeploymentType
+   @Override @Produces @Specializes @AnotherDeploymentType @Named
    public Pupil getStarPupil()
    {
       return super.getStarPupil();

Modified: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/inheritance/specialization/producer/method/ProducerMethodSpecializationTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/inheritance/specialization/producer/method/ProducerMethodSpecializationTest.java	2009-01-23 00:46:28 UTC (rev 1183)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/inheritance/specialization/producer/method/ProducerMethodSpecializationTest.java	2009-01-23 00:47:31 UTC (rev 1184)
@@ -32,7 +32,7 @@
       return deploymentTypes;
    }
 
-   @Test(groups="broken") @SpecAssertion(section = {"4.3.1", "3.4.5"})
+   @Test @SpecAssertion(section = {"4.3.1", "3.4.5"})
    public void testSpecializingBeanHasBindingsOfSpecializedAndSpecializingBean()
    {
       deployBeans(JewelryShop.class);
@@ -41,7 +41,7 @@
       assert annotationSetMatches( manager.resolveByType(Product.class, EXPENSIVE_LITERAL).iterator().next().getBindings(), Expensive.class, Sparkly.class);
    }
    
-   @Test(groups="broken") @SpecAssertion(section = {"4.3.1", "3.4.5"})
+   @Test @SpecAssertion(section = {"4.3.1", "3.4.5"})
    public void testSpecializingBeanHasNameOfSpecializedBean()
    {
       deployBeans(JewelryShop.class);
@@ -49,39 +49,48 @@
       assert manager.resolveByType(Product.class, new AnnotationLiteral<Sparkly>(){}).iterator().next().getName().equals("expensiveGift");
    }
    
-   @Test(groups="broken", expectedExceptions=DefinitionException.class) @SpecAssertion(section = "4.3.1")
+   @Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section = "4.3.1")
    public void testSpecializingAndSpecializedBeanHasName()
    {
-      //deployBeans(HighSchool_Broken.class);
+      deployBeans(HighSchool_Broken.class);
    }
    
-   @Test(groups="broken") @SpecAssertion(section={"4.3.1", "3.4.5"})
-   public void testSpecializedBeanNotInstantiated()
+   @Test @SpecAssertion(section={"4.3.1", "3.4.5"})
+   public void testSpecializedBeanNotInstantiated() throws Exception
    {
       deployBeans(JewelryShop.class, Shop.class);
-      Product product = manager.getInstanceByType(Product.class, EXPENSIVE_LITERAL);
-      assert product instanceof Necklace;
+      new RunInDependentContext()
+      {
+         
+         @Override
+         protected void execute() throws Exception
+         {
+            Product product = manager.getInstanceByType(Product.class, EXPENSIVE_LITERAL);
+            assert product instanceof Necklace;
+         }
+         
+      }.run();
    }
    
-   @Test(groups="broken", expectedExceptions=InconsistentSpecializationException.class) @SpecAssertion(section="4.3.1")
+   @Test(expectedExceptions=InconsistentSpecializationException.class) @SpecAssertion(section="4.3.1")
    public void testSpecializingBeanDoesNotHaveHigherPrecedenceThanSpecializedBean()
    {
       deployBeans(ClothesShop_Broken.class);
    }
    
-   @Test(groups="broken", expectedExceptions=InconsistentSpecializationException.class) @SpecAssertion(section="4.3.1")
+   @Test(expectedExceptions=InconsistentSpecializationException.class) @SpecAssertion(section="4.3.1")
    public void testTwoBeansSpecializeTheSameBean()
    {
       deployBeans(PictureShop_Broken.class, Bookshop_Broken.class);
    }
    
-   @Test(groups="broken", expectedExceptions=DefinitionException.class) @SpecAssertion(section="3.4.5")
+   @Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="3.4.5")
    public void testSpecializedStaticMethod()
    {
       deployBeans(FurnitureShop_Broken.class);
    }
    
-   @Test(groups="broken", expectedExceptions=DefinitionException.class) @SpecAssertion(section="3.4.5")
+   @Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="3.4.5")
    public void testSpecializedMethodDoesNotOverrideAnotherProducerMethod()
    {
       deployBeans(FurnitureShop_Broken.class);




More information about the weld-commits mailing list