[webbeans-commits] Webbeans SVN: r214 - in ri/trunk/webbeans-ri/src: test/java/org/jboss/webbeans/test and 2 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Fri Oct 31 21:12:54 EDT 2008


Author: gavin.king at jboss.com
Date: 2008-10-31 21:12:54 -0400 (Fri, 31 Oct 2008)
New Revision: 214

Added:
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/HeavyDuty.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Modern.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Motorized.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Plough.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Tractor.java
Modified:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractBeanModel.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/EnterpriseBeanModel.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/EventBeanModel.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/ProducerMethodBeanModel.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/SimpleBeanModel.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SimpleBeanModelTest.java
Log:
made start on specialization: inherit name and binding types

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractBeanModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractBeanModel.java	2008-10-31 19:00:18 UTC (rev 213)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractBeanModel.java	2008-11-01 01:12:54 UTC (rev 214)
@@ -14,6 +14,7 @@
 import javax.webbeans.Named;
 import javax.webbeans.Production;
 import javax.webbeans.ScopeType;
+import javax.webbeans.Specializes;
 import javax.webbeans.Standard;
 
 import org.jboss.webbeans.ManagerImpl;
@@ -43,21 +44,27 @@
    private Set<Class<?>> apiTypes;
    protected Set<Injectable<?, ?>> injectionPoints;
    private boolean primitive;
+   protected ManagerImpl container;
    
    protected void init(ManagerImpl container)
    {
+      this.container = container;
       mergedStereotypes = new MergedStereotypesModel<T, E>(getAnnotatedItem(), getXmlAnnotatedItem(), container);
       initType();
       initPrimitive();
       log.fine("Building Web Bean bean metadata for " +  getType());
       initBindingTypes();
       initName();
-      initDeploymentType(container);
+      initDeploymentType();
       checkDeploymentType();
       initScopeType();
       initApiTypes();
    }
    
+   protected AbstractClassBeanModel<? extends T> getSpecializedType() {
+      throw new UnsupportedOperationException();
+   }
+   
    protected void initInjectionPoints()
    {
       injectionPoints = new HashSet<Injectable<?,?>>();
@@ -103,20 +110,34 @@
 
    protected void initBindingTypes()
    {
+      Set<Annotation> bindingTypes = getAnnotatedItem().getAnnotations(BindingType.class);
       Set<Annotation> xmlBindingTypes = getXmlAnnotatedItem().getAnnotations(BindingType.class);
+      boolean xmlSpecialization = getXmlAnnotatedItem().isAnnotationPresent(Specializes.class);
+      boolean specialization = getAnnotatedItem().isAnnotationPresent(Specializes.class);
+      
       if (xmlBindingTypes.size() > 0 || mergedStereotypes.isDeclaredInXml())
       {
          // TODO support producer expression default binding type
-         log.finest("Using binding types " + xmlBindingTypes + " specified in XML");
+         if (xmlSpecialization)
+         {
+            xmlBindingTypes.addAll(bindingTypes);
+            log.finest("Using binding types " + xmlBindingTypes + " specified in XML and specialized type");
+         }
+         else {
+            log.finest("Using binding types " + xmlBindingTypes + " specified in XML");
+         }
          this.bindingTypes= xmlBindingTypes;
          return;
       }
       else
       {
-         Set<Annotation> bindingTypes = getAnnotatedItem().getAnnotations(BindingType.class);
-         
-         if (bindingTypes.size() == 0)
+         if (specialization)
          {
+            bindingTypes.addAll(getSpecializedType().getBindingTypes());
+            log.finest("Using binding types " + bindingTypes + " specified by annotations and specialized supertype");
+         }
+         else if (bindingTypes.size() == 0)
+         {
             log.finest("Adding default @Current binding type");
             bindingTypes.add(new CurrentAnnotationLiteral());
          }
@@ -176,9 +197,15 @@
    
    protected void initName()
    {
+      boolean xmlSpecialization = getXmlAnnotatedItem().isAnnotationPresent(Specializes.class);
+      boolean specialization = getAnnotatedItem().isAnnotationPresent(Specializes.class);
       boolean beanNameDefaulted = false;
       if (getXmlAnnotatedItem().isAnnotationPresent(Named.class))
       {
+         if (xmlSpecialization) 
+         {
+            throw new DefinitionException("Name specified for specialized bean (declared in XML)");
+         }
          String xmlName = getXmlAnnotatedItem().getAnnotation(Named.class).value();
          if ("".equals(xmlName))
          {
@@ -194,6 +221,10 @@
       }
       else if (getAnnotatedItem().isAnnotationPresent(Named.class))
       {
+         if (specialization)
+         {
+            throw new DefinitionException("Name specified for specialized bean");
+         }
          String javaName = getAnnotatedItem().getAnnotation(Named.class).value();
          if ("".equals(javaName))
          {
@@ -202,11 +233,17 @@
          }
          else
          {
-            log.finest("Using name " + javaName + " specified in XML");
+            log.finest("Using name " + javaName + " specified by annotations");
             this.name = javaName;
             return;
          }
       }
+      else if (specialization)
+      {
+         this.name = getSpecializedType().getName();
+         log.finest("Using supertype name");
+         return;
+      }
       if (beanNameDefaulted || getMergedStereotypes().isBeanNameDefaulted())
       {
          this.name = getDefaultName();
@@ -214,7 +251,7 @@
       }
    }
    
-   protected void initDeploymentType(ManagerImpl container)
+   protected void initDeploymentType()
    {
       Set<Annotation> xmlDeploymentTypes = getXmlAnnotatedItem().getAnnotations(DeploymentType.class);
       

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/EnterpriseBeanModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/EnterpriseBeanModel.java	2008-10-31 19:00:18 UTC (rev 213)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/EnterpriseBeanModel.java	2008-11-01 01:12:54 UTC (rev 214)
@@ -12,6 +12,8 @@
 import org.jboss.webbeans.injectable.InjectableMethod;
 import org.jboss.webbeans.injectable.InjectableParameter;
 import org.jboss.webbeans.introspector.AnnotatedType;
+import org.jboss.webbeans.introspector.SimpleAnnotatedType;
+import org.jboss.webbeans.test.util.Util;
 import org.jboss.webbeans.util.Reflections;
 
 public class EnterpriseBeanModel<T> extends AbstractEnterpriseBeanModel<T>
@@ -116,5 +118,20 @@
          }
       }
    }
+   
+   @Override
+   protected AbstractClassBeanModel<? extends T> getSpecializedType()
+   {
+      //TODO: lots of validation!
+      Class<?> superclass = getAnnotatedItem().getType().getSuperclass();
+      if ( superclass!=null )
+      {
+         return new EnterpriseBeanModel( new SimpleAnnotatedType( superclass ), Util.getEmptyAnnotatedType( getAnnotatedItem().getType().getSuperclass() ), container );
+      }
+      else {
+         throw new RuntimeException();
+      }
+      
+   }
 
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/EventBeanModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/EventBeanModel.java	2008-10-31 19:00:18 UTC (rev 213)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/EventBeanModel.java	2008-11-01 01:12:54 UTC (rev 214)
@@ -111,7 +111,7 @@
    }
 
    @Override
-   protected void initDeploymentType(ManagerImpl container)
+   protected void initDeploymentType()
    {
       // This is always @Standard per 7.4
       this.deploymentType = Standard.class;

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/ProducerMethodBeanModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/ProducerMethodBeanModel.java	2008-10-31 19:00:18 UTC (rev 213)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/ProducerMethodBeanModel.java	2008-11-01 01:12:54 UTC (rev 214)
@@ -66,9 +66,9 @@
    }
    
    @Override
-   protected void initDeploymentType(ManagerImpl container)
+   protected void initDeploymentType()
    {
-      super.initDeploymentType(container);
+      super.initDeploymentType();
       if (getDeploymentType() == null)
       {
          if (getDeclaringBean() == null)

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/SimpleBeanModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/SimpleBeanModel.java	2008-10-31 19:00:18 UTC (rev 213)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/SimpleBeanModel.java	2008-11-01 01:12:54 UTC (rev 214)
@@ -11,6 +11,8 @@
 import org.jboss.webbeans.injectable.InjectableParameter;
 import org.jboss.webbeans.injectable.SimpleConstructor;
 import org.jboss.webbeans.introspector.AnnotatedType;
+import org.jboss.webbeans.introspector.SimpleAnnotatedType;
+import org.jboss.webbeans.test.util.Util;
 import org.jboss.webbeans.util.LoggerUtil;
 import org.jboss.webbeans.util.Reflections;
 
@@ -118,5 +120,20 @@
       }
       return location;
    }
-   
+
+   @Override
+   protected AbstractClassBeanModel<? extends T> getSpecializedType()
+   {
+      //TODO: lots of validation!
+      Class<?> superclass = getAnnotatedItem().getType().getSuperclass();
+      if ( superclass!=null )
+      {
+         return new SimpleBeanModel( new SimpleAnnotatedType( superclass ), Util.getEmptyAnnotatedType( getAnnotatedItem().getType().getSuperclass() ), container );
+      }
+      else {
+         throw new RuntimeException();
+      }
+   }
+
+
 }

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SimpleBeanModelTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SimpleBeanModelTest.java	2008-10-31 19:00:18 UTC (rev 213)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SimpleBeanModelTest.java	2008-11-01 01:12:54 UTC (rev 214)
@@ -5,6 +5,7 @@
 
 import java.util.Iterator;
 
+import javax.webbeans.AnnotationLiteral;
 import javax.webbeans.DefinitionException;
 import javax.webbeans.NonexistentConstructorException;
 import javax.webbeans.manager.Bean;
@@ -14,6 +15,8 @@
 import org.jboss.webbeans.injectable.SimpleConstructor;
 import org.jboss.webbeans.introspector.SimpleAnnotatedType;
 import org.jboss.webbeans.model.bean.SimpleBeanModel;
+import org.jboss.webbeans.test.annotations.HeavyDuty;
+import org.jboss.webbeans.test.annotations.Motorized;
 import org.jboss.webbeans.test.beans.Animal;
 import org.jboss.webbeans.test.beans.Chicken;
 import org.jboss.webbeans.test.beans.Cow;
@@ -25,6 +28,7 @@
 import org.jboss.webbeans.test.beans.Sheep;
 import org.jboss.webbeans.test.beans.Spider;
 import org.jboss.webbeans.test.beans.Tarantula;
+import org.jboss.webbeans.test.beans.Tractor;
 import org.jboss.webbeans.test.beans.Turkey;
 import org.jboss.webbeans.test.beans.broken.ParameterizedBean;
 import org.jboss.webbeans.test.beans.broken.OuterBean.InnerBean;
@@ -257,13 +261,18 @@
    @Test(groups="specialization") @SpecAssertion(section="3.2.6")
    public void testSpecializedClassInheritsBindingTypes()
    {
-      assert false;
+      SimpleBeanModel<Tractor> bean = new SimpleBeanModel<Tractor>(new SimpleAnnotatedType<Tractor>(Tractor.class), getEmptyAnnotatedType(Tractor.class), manager);
+      assert bean.getBindingTypes().size()==2;
+      assert bean.getBindingTypes().contains( new AnnotationLiteral<Motorized>() {} );
+      assert bean.getBindingTypes().contains( new AnnotationLiteral<HeavyDuty>() {} );
    }
    
    @Test(groups="specialization") @SpecAssertion(section="3.2.6")
    public void testSpecializedClassInheritsName()
    {
-      assert false;
+      SimpleBeanModel<Tractor> bean = new SimpleBeanModel<Tractor>(new SimpleAnnotatedType<Tractor>(Tractor.class), getEmptyAnnotatedType(Tractor.class), manager);
+      assert bean.getName()!=null;
+      assert bean.getName().equals("plough");
    }
    
    @Test(groups="specialization") @SpecAssertion(section="3.2.6")

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/HeavyDuty.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/HeavyDuty.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/HeavyDuty.java	2008-11-01 01:12:54 UTC (rev 214)
@@ -0,0 +1,21 @@
+package org.jboss.webbeans.test.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.webbeans.BindingType;
+
+ at Target( { TYPE, METHOD, PARAMETER })
+ at Retention(RUNTIME)
+ at Documented
+ at BindingType
+public @interface HeavyDuty
+{
+
+}

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Modern.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Modern.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Modern.java	2008-11-01 01:12:54 UTC (rev 214)
@@ -0,0 +1,20 @@
+package org.jboss.webbeans.test.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.webbeans.DeploymentType;
+
+ at Target( { TYPE, METHOD })
+ at Retention(RUNTIME)
+ at Documented
+ at DeploymentType
+public @interface Modern
+{
+
+}

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Motorized.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Motorized.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Motorized.java	2008-11-01 01:12:54 UTC (rev 214)
@@ -0,0 +1,21 @@
+package org.jboss.webbeans.test.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.webbeans.BindingType;
+
+ at Target( { TYPE, METHOD, PARAMETER })
+ at Retention(RUNTIME)
+ at Documented
+ at BindingType
+public @interface Motorized
+{
+
+}

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Plough.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Plough.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Plough.java	2008-11-01 01:12:54 UTC (rev 214)
@@ -0,0 +1,12 @@
+package org.jboss.webbeans.test.beans;
+
+import javax.webbeans.Named;
+
+import org.jboss.webbeans.test.annotations.HeavyDuty;
+
+ at HeavyDuty
+ at Named("plough")
+public class Plough
+{
+
+}

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Tractor.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Tractor.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Tractor.java	2008-11-01 01:12:54 UTC (rev 214)
@@ -0,0 +1,12 @@
+package org.jboss.webbeans.test.beans;
+
+import javax.webbeans.Specializes;
+
+import org.jboss.webbeans.test.annotations.Modern;
+import org.jboss.webbeans.test.annotations.Motorized;
+
+ at Modern @Motorized @Specializes
+public class Tractor extends Plough
+{
+
+}




More information about the weld-commits mailing list