[webbeans-commits] Webbeans SVN: r250 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/model/bean and 1 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Wed Nov 5 18:40:55 EST 2008


Author: pete.muir at jboss.org
Date: 2008-11-05 18:40:54 -0500 (Wed, 05 Nov 2008)
New Revision: 250

Modified:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/MergedStereotypesModel.java
   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/AbstractClassBeanModel.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/SimpleBeanModel.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/util/Util.java
Log:
Allow the model to take null if the bean isn't specified in xml or java

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/MergedStereotypesModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/MergedStereotypesModel.java	2008-11-05 19:14:38 UTC (rev 249)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/MergedStereotypesModel.java	2008-11-05 23:40:54 UTC (rev 250)
@@ -33,12 +33,12 @@
       requiredTypes = new HashSet<Class<?>>();
       supportedScopes = new HashSet<Class<? extends Annotation>>();
       
-      if (xmlAnnotatedItem.getAnnotations(Stereotype.class).size() > 0)
+      if (xmlAnnotatedItem != null && xmlAnnotatedItem.getAnnotations(Stereotype.class).size() > 0)
       {
          merge(xmlAnnotatedItem.getAnnotations(Stereotype.class), manager);
          isDeclaredInXml = true;
       }
-      else
+      else if (annotatedItem != null)
       {
          merge(annotatedItem.getAnnotations(Stereotype.class), manager);
       }

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-11-05 19:14:38 UTC (rev 249)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractBeanModel.java	2008-11-05 23:40:54 UTC (rev 250)
@@ -1,7 +1,6 @@
 package org.jboss.webbeans.model.bean;
 
 import java.lang.annotation.Annotation;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -24,7 +23,6 @@
 import org.jboss.webbeans.injectable.InjectableMethod;
 import org.jboss.webbeans.injectable.InjectableParameter;
 import org.jboss.webbeans.introspector.AnnotatedItem;
-import org.jboss.webbeans.introspector.impl.SimpleAnnotatedClass;
 import org.jboss.webbeans.model.MergedStereotypesModel;
 import org.jboss.webbeans.util.LoggerUtil;
 import org.jboss.webbeans.util.Reflections;
@@ -67,10 +65,6 @@
       throw new UnsupportedOperationException();
    }
    
-   protected static <T> SimpleAnnotatedClass getEmptyAnnotatedType(Class<T> type) {
-      return new SimpleAnnotatedClass<T>(type, new HashMap<Class<? extends Annotation>, Annotation>());
-   }
-   
    protected void initInjectionPoints()
    {
       injectionPoints = new HashSet<Injectable<?,?>>();
@@ -116,42 +110,43 @@
 
    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);
+      boolean xmlSpecialization = getXmlAnnotatedItem() == null ? false : getXmlAnnotatedItem().isAnnotationPresent(Specializes.class);
+      boolean specialization = getAnnotatedItem() == null ? false : getAnnotatedItem().isAnnotationPresent(Specializes.class);
       
-      if (xmlBindingTypes.size() > 0 || mergedStereotypes.isDeclaredInXml())
+      this.bindingTypes = new HashSet<Annotation>();
+      
+      if (getXmlAnnotatedItem() != null && getXmlAnnotatedItem().getAnnotations(BindingType.class).size() > 0)
       {
          // TODO support producer expression default binding type
+         this.bindingTypes.addAll(getXmlAnnotatedItem().getAnnotations(BindingType.class));
          if (xmlSpecialization)
          {
-            xmlBindingTypes.addAll(bindingTypes);
-            log.finest("Using binding types " + xmlBindingTypes + " specified in XML and specialized type");
+            this.bindingTypes.addAll(bindingTypes);
+            log.finest("Using binding types " + this.bindingTypes + " specified in XML and specialized type");
          }
-         else {
-            log.finest("Using binding types " + xmlBindingTypes + " specified in XML");
+         else 
+         {
+            log.finest("Using binding types " + this.bindingTypes + " specified in XML");
          }
-         this.bindingTypes= xmlBindingTypes;
          return;
       }
-      else
+      else if (!mergedStereotypes.isDeclaredInXml() && getAnnotatedItem() != null)
       {
+         this.bindingTypes.addAll(getAnnotatedItem().getAnnotations(BindingType.class));
          if (specialization)
          {
-            bindingTypes.addAll(getSpecializedType().getBindingTypes());
+            this.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());
+            this.bindingTypes.add(new CurrentAnnotationLiteral());
          }
          else
          {
             log.finest("Using binding types " + bindingTypes + " specified by annotations");
          }
-         this.bindingTypes = bindingTypes;
          return;
       }
    }
@@ -161,32 +156,37 @@
     */
    protected void initScopeType()
    {
-      Set<Annotation> xmlScopes = getXmlAnnotatedItem().getAnnotations(ScopeType.class);
-      if (xmlScopes.size() > 1)
-      {
-         throw new DefinitionException("At most one scope may be specified in XML");
-      }
       
-      if (xmlScopes.size() == 1)
+      if (getXmlAnnotatedItem() != null)
       {
-         this.scopeType = xmlScopes.iterator().next().annotationType();
-         log.finest("Scope " + scopeType + " specified in XML");
-         return;
+         if (getXmlAnnotatedItem().getAnnotations(ScopeType.class).size() > 1)
+         {
+            throw new DefinitionException("At most one scope may be specified in XML");
+         }
+         
+         if (getXmlAnnotatedItem().getAnnotations(ScopeType.class).size() == 1)
+         {
+            this.scopeType = getXmlAnnotatedItem().getAnnotations(ScopeType.class).iterator().next().annotationType();
+            log.finest("Scope " + scopeType + " specified in XML");
+            return;
+         }
       }
       
-      Set<Annotation> scopes = getAnnotatedItem().getAnnotations(ScopeType.class);
-      if (scopes.size() > 1)
+      if (getAnnotatedItem() != null)
       {
-         throw new DefinitionException("At most one scope may be specified");
+         if (getAnnotatedItem().getAnnotations(ScopeType.class).size() > 1)
+         {
+            throw new DefinitionException("At most one scope may be specified");
+         }
+         
+         if (getAnnotatedItem().getAnnotations(ScopeType.class).size() == 1)
+         {
+            this.scopeType = getAnnotatedItem().getAnnotations(ScopeType.class).iterator().next().annotationType();
+            log.finest("Scope " + scopeType + " specified b annotation");
+            return;
+         }
       }
       
-      if (scopes.size() == 1)
-      {
-         this.scopeType = scopes.iterator().next().annotationType();
-         log.finest("Scope " + scopeType + " specified b annotation");
-         return;
-      }
-      
       if (getMergedStereotypes().getPossibleScopeTypes().size() == 1)
       {
          this.scopeType = getMergedStereotypes().getPossibleScopeTypes().iterator().next().annotationType();
@@ -203,10 +203,10 @@
    
    protected void initName()
    {
-      boolean xmlSpecialization = getXmlAnnotatedItem().isAnnotationPresent(Specializes.class);
-      boolean specialization = getAnnotatedItem().isAnnotationPresent(Specializes.class);
+      boolean xmlSpecialization = getXmlAnnotatedItem() == null ? false : getXmlAnnotatedItem().isAnnotationPresent(Specializes.class);
+      boolean specialization = getAnnotatedItem() == null ? false : getAnnotatedItem().isAnnotationPresent(Specializes.class);
       boolean beanNameDefaulted = false;
-      if (getXmlAnnotatedItem().isAnnotationPresent(Named.class))
+      if (getXmlAnnotatedItem() != null && getXmlAnnotatedItem().isAnnotationPresent(Named.class))
       {
          if (xmlSpecialization) 
          {
@@ -225,7 +225,7 @@
             return;
          }
       }
-      else if (getAnnotatedItem().isAnnotationPresent(Named.class))
+      else if (getAnnotatedItem() != null && getAnnotatedItem().isAnnotationPresent(Named.class))
       {
          if (specialization)
          {
@@ -259,48 +259,48 @@
    
    protected void initDeploymentType()
    {
-      Set<Annotation> xmlDeploymentTypes = getXmlAnnotatedItem().getAnnotations(DeploymentType.class);
-      
-      if (xmlDeploymentTypes.size() > 1)
+      if (getXmlAnnotatedItem() != null)
       {
-         throw new RuntimeException("At most one deployment type may be specified (" + xmlDeploymentTypes + " are specified)");
+         Set<Annotation> xmlDeploymentTypes = getXmlAnnotatedItem().getAnnotations(DeploymentType.class);
+         if (xmlDeploymentTypes.size() > 1)
+         {
+            throw new RuntimeException("At most one deployment type may be specified (" + xmlDeploymentTypes + " are specified)");
+         }
+         
+         if (xmlDeploymentTypes.size() == 1)
+         {
+            this.deploymentType = xmlDeploymentTypes.iterator().next().annotationType(); 
+            log.finest("Deployment type " + deploymentType + " specified in XML");
+            return;
+         }
       }
       
-      if (xmlDeploymentTypes.size() == 1)
+      if (getAnnotatedItem() != null)
       {
-         this.deploymentType = xmlDeploymentTypes.iterator().next().annotationType(); 
-         log.finest("Deployment type " + deploymentType + " specified in XML");
-         return;
+         Set<Annotation> deploymentTypes = getAnnotatedItem().getAnnotations(DeploymentType.class);
+         
+         if (deploymentTypes.size() > 1)
+         {
+            throw new DefinitionException("At most one deployment type may be specified (" + deploymentTypes + " are specified) on " + getAnnotatedItem().toString());
+         }
+         if (deploymentTypes.size() == 1)
+         {
+            this.deploymentType = deploymentTypes.iterator().next().annotationType();
+            log.finest("Deployment type " + deploymentType + " specified by annotation");
+            return;
+         }
+         
+         if (getMergedStereotypes().getPossibleDeploymentTypes().size() > 0)
+         {
+            this.deploymentType = getDeploymentType(container.getEnabledDeploymentTypes(), getMergedStereotypes().getPossibleDeploymentTypes());
+            log.finest("Deployment type " + deploymentType + " specified by stereotype");
+            return;
+         }
       }
       
-      
-      Set<Annotation> deploymentTypes = getAnnotatedItem().getAnnotations(DeploymentType.class);
-      
-      if (deploymentTypes.size() > 1)
-      {
-         throw new DefinitionException("At most one deployment type may be specified (" + deploymentTypes + " are specified) on " + getAnnotatedItem().toString());
-      }
-      if (deploymentTypes.size() == 1)
-      {
-         this.deploymentType = deploymentTypes.iterator().next().annotationType();
-         log.finest("Deployment type " + deploymentType + " specified by annotation");
-         return;
-      }
-      
-      if (getMergedStereotypes().getPossibleDeploymentTypes().size() > 0)
-      {
-         this.deploymentType = getDeploymentType(container.getEnabledDeploymentTypes(), getMergedStereotypes().getPossibleDeploymentTypes());
-         log.finest("Deployment type " + deploymentType + " specified by stereotype");
-         return;
-      }
-      
-      // TODO This isn't the right way to check if XML isn't in use
-      if (getXmlAnnotatedItem().getDelegate() != null)
-      {
-         this.deploymentType = Production.class;
-         log.finest("Using default @Production deployment type");
-         return;
-      }
+      this.deploymentType = Production.class;
+      log.finest("Using default @Production deployment type");
+      return;
    }
    
    protected void checkDeploymentType()
@@ -309,8 +309,7 @@
       {
          throw new RuntimeException("type: " + getType() + " must specify a deployment type");
       }
-      
-      if (deploymentType.equals(Standard.class))
+      else if (deploymentType.equals(Standard.class))
       {
          throw new DefinitionException();
       }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractClassBeanModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractClassBeanModel.java	2008-11-05 19:14:38 UTC (rev 249)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractClassBeanModel.java	2008-11-05 23:40:54 UTC (rev 250)
@@ -79,16 +79,16 @@
    protected void initType()
    {
       // TODO This is not the right way to check XML definition
-      if (getAnnotatedItem().getDelegate() != null && getXmlAnnotatedItem().getDelegate() != null && !getAnnotatedItem().getDelegate().equals(getXmlAnnotatedItem().getDelegate()))
+      if (getAnnotatedItem() != null && getXmlAnnotatedItem() != null && !getAnnotatedItem().getDelegate().equals(getXmlAnnotatedItem().getDelegate()))
       {
          throw new IllegalArgumentException("Cannot build a bean which specifies different classes in XML and Java");
       }
-      else if (getXmlAnnotatedItem().getDelegate() != null)
+      else if (getXmlAnnotatedItem() != null)
       {
          log.finest("Bean type specified in XML");
          this.type = getXmlAnnotatedItem().getDelegate();
       }
-      else if (getAnnotatedItem().getDelegate() != null)
+      else if (getAnnotatedItem() != null)
       {
          log.finest("Bean type specified in Java");
          this.type = getAnnotatedItem().getDelegate();

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-11-05 19:14:38 UTC (rev 249)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/EnterpriseBeanModel.java	2008-11-05 23:40:54 UTC (rev 250)
@@ -169,7 +169,7 @@
       Class<?> superclass = getAnnotatedItem().getType().getSuperclass();
       if ( superclass!=null )
       {
-         return new EnterpriseBeanModel(new SimpleAnnotatedClass(superclass), getEmptyAnnotatedType(superclass), container);
+         return new EnterpriseBeanModel(new SimpleAnnotatedClass(superclass), null, container);
       }
       else {
          throw new RuntimeException();

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-11-05 19:14:38 UTC (rev 249)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/SimpleBeanModel.java	2008-11-05 23:40:54 UTC (rev 250)
@@ -129,7 +129,7 @@
       Class<?> superclass = getAnnotatedItem().getType().getSuperclass();
       if ( superclass!=null )
       {
-         return new SimpleBeanModel(new SimpleAnnotatedClass(superclass), getEmptyAnnotatedType(superclass), container);
+         return new SimpleBeanModel(new SimpleAnnotatedClass(superclass), null, container);
       }
       else {
          throw new RuntimeException();

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/util/Util.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/util/Util.java	2008-11-05 19:14:38 UTC (rev 249)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/util/Util.java	2008-11-05 23:40:54 UTC (rev 250)
@@ -19,7 +19,7 @@
 
    public static <T> SimpleBeanModel<T> createSimpleModel(Class<T> clazz, ManagerImpl manager)
    {
-      return new SimpleBeanModel<T>(new SimpleAnnotatedClass<T>(clazz), getEmptyAnnotatedType(clazz), manager);
+      return new SimpleBeanModel<T>(new SimpleAnnotatedClass<T>(clazz), null, manager);
    }
 
    public static <T> SimpleBeanModel<T> createSimpleModel(Class<T> clazz, AnnotatedClass<T> xmlAnnotatedType, ManagerImpl manager)
@@ -37,6 +37,7 @@
       return new EnterpriseBeanModel<T>(new SimpleAnnotatedClass<T>(clazz), xmlAnnotatedType, manager);
    }
       
+   @Deprecated
    public static <T> AnnotatedClass<T> getEmptyAnnotatedType(Class<T> type)
    {
       return new SimpleAnnotatedClass<T>(type, new HashMap<Class<? extends Annotation>, Annotation>());




More information about the weld-commits mailing list