[webbeans-commits] Webbeans SVN: r144 - in ri/trunk: webbeans-ri/src/main/java/org/jboss/webbeans and 9 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Fri Oct 24 20:13:08 EDT 2008


Author: pete.muir at jboss.org
Date: 2008-10-24 20:13:08 -0400 (Fri, 24 Oct 2008)
New Revision: 144

Added:
   ri/trunk/webbeans-api/src/main/java/javax/webbeans/ExecutionException.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ListComparator.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NameBasedResolutionTest.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/ChunkyAnnotationLiteral.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Plaice.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/ScottishFishFarmer.java
Removed:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/BeanMap.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/util/EmptyAnnotatedType.java
Modified:
   ri/trunk/webbeans-api/src/main/java/javax/webbeans/AnnotationLiteral.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BasicContext.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BeanImpl.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ResolutionManager.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/Injectable.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/InjectableParameterWrapper.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/InjectableWrapper.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/SimpleInjectable.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AbstractAnnotatedItem.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedConstructor.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedField.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedItem.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedMethod.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedType.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractComponentModel.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/SimpleComponentModel.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ContextTest.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InjectableTest.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Chunky.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Cod.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/FishFarm.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Salmon.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Sole.java
Log:
implement name based resolution, resolution index rebuild when a bean is added, use of parameterized types and annotation members when doing typesafe resolution

Modified: ri/trunk/webbeans-api/src/main/java/javax/webbeans/AnnotationLiteral.java
===================================================================
--- ri/trunk/webbeans-api/src/main/java/javax/webbeans/AnnotationLiteral.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-api/src/main/java/javax/webbeans/AnnotationLiteral.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -27,6 +27,8 @@
  *            the annotation type
  */
 import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 
@@ -35,6 +37,7 @@
 {
    
    private Class<T> annotationType;
+   private Method[] members;
 
    protected AnnotationLiteral()
    {
@@ -43,12 +46,15 @@
       {
          throw new RuntimeException(getClass() + "is not a subclass of AnnotationLiteral ");
       }
+      
       annotationType = getTypeParameter(annotationLiteralSubclass);
+      
       if (annotationType == null)
       {
          throw new RuntimeException(getClass() + " is missing type parameter in AnnotationLiteral");
-
       }
+      
+      this.members = annotationType.getDeclaredMethods();
    }
    
    @SuppressWarnings("unchecked")
@@ -93,7 +99,17 @@
    @Override
    public String toString()
    {
-      return "@" + annotationType().getName() + "()";
+     String string = "@" + annotationType().getName() + "(";
+     for (int i = 0; i < members.length; i++)
+     {
+        string += members[i].getName() + "=";
+        string += invoke(members[i], this);
+        if (i < members.length - 1)
+        {
+           string += ",";
+        }
+     }
+     return string + ")";
    }
    
    @Override
@@ -102,17 +118,58 @@
       if (other instanceof Annotation)
       {
          Annotation that = (Annotation) other;
-         return this.annotationType().equals(that.annotationType());
+         if (this.annotationType().equals(that.annotationType()))
+         {
+            for (Method member : members)
+            {
+               Object thisValue = invoke(member, this);
+               Object thatValue = invoke(member, that);
+               if (!thisValue.equals(thatValue))
+               {
+                  return false;
+               }
+            }
+            return true;
+         }
       }
-      else
-      {
-         return false;
-      }
+      return false;
    }
    
    @Override
+   /*
+    * The hash code of a primitive value v is equal to WrapperType.valueOf(v).hashCode(), where WrapperType is the wrapper type corresponding to the primitive type of v (Byte, Character, Double, Float, Integer, Long, Short, or Boolean).
+    * The hash code of a string, enum, class, or annotation member-value I v is computed as by calling v.hashCode(). (In the case of annotation member values, this is a recursive definition.)
+    * The hash code of an array member-value is computed by calling the appropriate overloading of Arrays.hashCode on the value. (There is one overloading for each primitive type, and one for object reference types.)
+    */
    public int hashCode()
    {
-      return 0;
+      int hashCode = 0;
+      for (Method member : members)
+      {
+         int memberNameHashCode = 127 * member.getName().hashCode();
+         int memberValueHashCode = invoke(member, this).hashCode();
+         hashCode += memberNameHashCode ^ memberValueHashCode;
+      }       
+      return hashCode;
    }
+   
+   private static Object invoke(Method method, Object instance)
+   {
+      try
+      {
+         return method.invoke(instance);
+      }
+      catch (IllegalArgumentException e)
+      {
+         throw new ExecutionException("Error checking value of member method " + method.getName() + " on " + method.getDeclaringClass(), e);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new ExecutionException("Error checking value of member method " + method.getName() + " on " + method.getDeclaringClass(), e);
+      }
+      catch (InvocationTargetException e)
+      {
+         throw new ExecutionException("Error checking value of member method " + method.getName() + " on " + method.getDeclaringClass(), e);
+      }
+   }
 }

Added: ri/trunk/webbeans-api/src/main/java/javax/webbeans/ExecutionException.java
===================================================================
--- ri/trunk/webbeans-api/src/main/java/javax/webbeans/ExecutionException.java	                        (rev 0)
+++ ri/trunk/webbeans-api/src/main/java/javax/webbeans/ExecutionException.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -0,0 +1,26 @@
+package javax.webbeans;
+
+public class ExecutionException extends RuntimeException
+{
+
+   public ExecutionException()
+   {
+      super();
+   }
+
+   public ExecutionException(String message, Throwable throwable)
+   {
+      super(message, throwable);
+   }
+
+   public ExecutionException(String message)
+   {
+      super(message);
+   }
+
+   public ExecutionException(Throwable throwable)
+   {
+      super(throwable);
+   }
+   
+}


Property changes on: ri/trunk/webbeans-api/src/main/java/javax/webbeans/ExecutionException.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BasicContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BasicContext.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BasicContext.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -1,30 +1,49 @@
 package org.jboss.webbeans;
 
 import java.lang.annotation.Annotation;
+import java.util.HashMap;
 
 import javax.webbeans.ContextNotActiveException;
 import javax.webbeans.manager.Bean;
 import javax.webbeans.manager.Context;
 import javax.webbeans.manager.Manager;
+import org.jboss.webbeans.util.MapWrapper;
 
-import org.jboss.webbeans.util.BeanMap;
-
 /**
  * Basic implementation of javax.webbeans.Context, backed by a HashMap
  * 
  * @author Shane Bryzak
  * @author Nicklas Karlsson (nickarls at gmail.com)
+ * @author Pete\ Muir
+ * @
  */
 public class BasicContext implements Context
 {
-   private BeanMap<Object> beans;
+   
+   private class BeanMap extends MapWrapper<Bean<? extends Object>, Object>
+   {
+
+      public BeanMap()
+      {
+         super(new HashMap<Bean<? extends Object>, Object>());
+      }
+      
+      @SuppressWarnings("unchecked")
+      public <T extends Object> T get(Bean<? extends T> key)
+      {
+         return (T) super.get(key);
+      }
+
+   }
+   
+   private BeanMap beans;
    private Class<? extends Annotation> scopeType;
    private boolean active;
 
    public BasicContext(Class<? extends Annotation> scopeType)
    {
       this.scopeType = scopeType;
-      beans = new BeanMap<Object>();
+      beans = new BeanMap();
       active = true;
    }
 

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BeanImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BeanImpl.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BeanImpl.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -84,5 +84,10 @@
    {
       return model.toString();
    }
+   
+   public AbstractComponentModel<T, ?> getModel()
+   {
+      return model;
+   }
 
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -2,6 +2,8 @@
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -19,13 +21,17 @@
 import javax.webbeans.manager.Interceptor;
 import javax.webbeans.manager.Manager;
 
+import org.jboss.webbeans.bindings.CurrentAnnotationLiteral;
 import org.jboss.webbeans.ejb.EjbManager;
 import org.jboss.webbeans.event.EventBus;
+import org.jboss.webbeans.injectable.Injectable;
 import org.jboss.webbeans.injectable.SimpleInjectable;
 
 public class ManagerImpl implements Manager
 {
 
+   private static final Annotation[] DEFAULT_BINDING = {new CurrentAnnotationLiteral()};
+   
    private List<Class<? extends Annotation>> enabledDeploymentTypes;
    private ModelManager modelManager;
    private EjbManager ejbLookupManager;
@@ -66,6 +72,7 @@
 
    public Manager addBean(Bean<?> bean)
    {
+      getResolutionManager().clear();
       beans.add(bean);
       return this;
    }
@@ -104,8 +111,39 @@
    public <T> Set<Bean<T>> resolveByType(Class<T> apiType,
          Annotation... bindingTypes)
    {
-      Set<Bean<T>> beans = getResolutionManager().get(
-            new SimpleInjectable<T>(apiType, bindingTypes));
+      return resolveByType(apiType, bindingTypes, new Type[0]);
+   }
+
+   public <T> Set<Bean<T>> resolveByType(TypeLiteral<T> apiType,
+         Annotation... bindingTypes)
+   {
+      if (apiType.getType() instanceof ParameterizedType)
+      {
+         return resolveByType(apiType.getRawType(), bindingTypes, ((ParameterizedType) apiType.getType()).getActualTypeArguments());
+      }
+      else
+      {
+         return resolveByType(apiType.getRawType(), bindingTypes, new Type[0]);
+      }
+      
+   }
+   
+   private <T> Set<Bean<T>> resolveByType(Class<T> apiType, Annotation[] bindingTypes, Type[] actualTypeArguements)
+   {
+      if (bindingTypes.length == 0)
+      {
+         bindingTypes = DEFAULT_BINDING;
+      }
+      Injectable<T, ?> injectable = null;
+      if (actualTypeArguements.length > 0)
+      {
+         injectable = new SimpleInjectable<T>(apiType, bindingTypes, actualTypeArguements);
+      }
+      else
+      {
+         injectable = new SimpleInjectable<T>(apiType, bindingTypes);
+      }
+      Set<Bean<T>> beans = getResolutionManager().get(injectable);
       if (beans == null)
       {
          return new HashSet<Bean<T>>();
@@ -114,14 +152,9 @@
       {
          return beans;
       }
+      
    }
 
-   public <T> Set<Bean<T>> resolveByType(TypeLiteral<T> apiType,
-         Annotation... bindingTypes)
-   {
-      return resolveByType(apiType.getRawType(), bindingTypes);
-   }
-
    public ResolutionManager getResolutionManager()
    {
       return resolutionManager;
@@ -223,8 +256,7 @@
 
    public Set<Bean<?>> resolveByName(String name)
    {
-      // TODO Auto-generated method stub
-      return null;
+      return getResolutionManager().get(name);
    }
 
    public List<Decorator> resolveDecorators(Set<Class<?>> types,

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ResolutionManager.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ResolutionManager.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ResolutionManager.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -1,25 +1,59 @@
 package org.jboss.webbeans;
 
+import java.lang.annotation.Annotation;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
 
 import javax.webbeans.manager.Bean;
 
 import org.jboss.webbeans.injectable.Injectable;
+import org.jboss.webbeans.util.ListComparator;
+import org.jboss.webbeans.util.MapWrapper;
 
 public class ResolutionManager
 {
+
+   // TODO Why can't we generify Set?
    
-   private Map<Injectable<?, ?>, Set<?>> resolvedInjectionPoints;
+   @SuppressWarnings("unchecked")
+   private class InjectableMap extends MapWrapper<Injectable<?, ?>, Set>
+   {
+
+      public InjectableMap()
+      {
+         super(new HashMap<Injectable<?, ?>, Set>());
+      }
+      
+      @SuppressWarnings("unchecked")
+      public <T> Set<Bean<T>> get(Injectable<T, ?> key)
+      {
+         return (Set<Bean<T>>) super.get(key);
+      }
+
+   }
+
+   
+   private InjectableMap resolvedInjectionPoints;
    private Set<Injectable<?, ?>> injectionPoints;
+   
+   private Map<String, Set<Bean<?>>> resolvedNames;
+   
    private ManagerImpl manager;
    
+   private boolean rebuildRequired = true;
+   
    public ResolutionManager(ManagerImpl manager)
    {
-      this.resolvedInjectionPoints = new HashMap<Injectable<?, ?>, Set<?>>();
+      this.resolvedInjectionPoints = new InjectableMap();
       this.injectionPoints = new HashSet<Injectable<?,?>>();
+      
+      this.resolvedNames = new HashMap<String, Set<Bean<?>>>();
+      
       this.manager = manager;
    }
    
@@ -28,23 +62,75 @@
       injectionPoints.add(injectable);
    }
    
-   public void registerInjectionPoint(Injectable<?, ?> injectable)
+   private void registerInjectionPoint(Injectable<?, ?> injectable)
    {
-	  resolvedInjectionPoints.put(injectable, injectable.getPossibleBeans(manager.getBeans())); 
+	   resolvedInjectionPoints.put(injectable, retainHighestPrecedenceBeans(injectable.getMatchingBeans(manager.getBeans()), manager.getEnabledDeploymentTypes())); 
    }
    
-   public void registerInjectionPoints()
+   public void clear()
    {
-      for (Injectable<?, ?> injectable : injectionPoints)
+      rebuildRequired = true;
+      resolvedInjectionPoints.clear();
+      resolvedNames.clear();
+   }
+   
+   private void resolveBeans()
+   {
+      if (rebuildRequired)
       {
-         registerInjectionPoint(injectable);
+         for (Injectable<?, ?> injectable : injectionPoints)
+         {
+            registerInjectionPoint(injectable);
+         }
+         rebuildRequired = false;
       }
-      injectionPoints.clear();
    }
    
    public <T> Set<Bean<T>> get(Injectable<T, ?> key)
    {
-      return (Set<Bean<T>>) resolvedInjectionPoints.get(key);
+      resolveBeans();
+      return resolvedInjectionPoints.get(key);
    }
+   
+   public Set<Bean<?>> get(String name)
+   {
+      if (resolvedNames.containsKey(name))
+      {
+         return resolvedNames.get(name);
+      }
+      else
+      {
+         Set<Bean<?>> beans = new HashSet<Bean<?>>();
+         for (Bean<?> bean : manager.getBeans())
+         {
+            if ( (bean.getName() == null && name == null) || (bean.getName() != null && bean.getName().equals(name)))
+            {
+               beans.add(bean);
+            }
+         }
+         resolvedNames.put(name, retainHighestPrecedenceBeans(beans, manager.getEnabledDeploymentTypes()));
+         return beans;
+      }
+   }
+   
+   private static Set<Bean<?>> retainHighestPrecedenceBeans(Set<Bean<?>> beans, List<Class<? extends Annotation>> enabledDeploymentTypes)
+   {
+      SortedSet<Class<? extends Annotation>> possibleDeploymentTypes = new TreeSet<Class<? extends Annotation>>(new ListComparator<Class<? extends Annotation>>(enabledDeploymentTypes));
+      for (Bean<?> bean : beans)
+      {
+         possibleDeploymentTypes.add(bean.getDeploymentType());
+      }
+      possibleDeploymentTypes.retainAll(enabledDeploymentTypes);
+      Class<? extends Annotation> highestPrecedencePossibleDeploymentType = possibleDeploymentTypes.last();
+      Set<Bean<?>> trimmed = new HashSet<Bean<?>>();
+      for (Bean<?> bean : beans)
+      {
+         if (bean.getDeploymentType().equals(highestPrecedencePossibleDeploymentType))
+         {
+            trimmed.add(bean);
+         }
+      }
+      return trimmed;
+   }
 
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/Injectable.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/Injectable.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/Injectable.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -1,9 +1,7 @@
 package org.jboss.webbeans.injectable;
 
 import java.lang.annotation.Annotation;
-import java.util.ArrayList;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Set;
 
 import javax.webbeans.BindingType;
@@ -31,7 +29,7 @@
 
    public Set<Annotation> getBindingTypes()
    {
-      return annotatedItem.getAnnotations();
+      return annotatedItem.getAnnotations(BindingType.class);
    }
    
    protected Injectable() {}
@@ -39,7 +37,7 @@
    @Override
    public String toString()
    {
-      return getType() + " with binding types " + getBindingTypes();
+      return getClass().getSimpleName() + "[" + getAnnotatedItem().toString() + "]";
    }
 
    public T getValue(ManagerImpl manager)
@@ -57,33 +55,27 @@
       return annotatedItem;
    }
    
-   public Set<Bean<?>> getPossibleBeans(Set<Bean<?>> beans)
+   public Set<Bean<?>> getMatchingBeans(Set<Bean<?>> beans)
    {
       Set<Bean<?>> resolvedBeans = new HashSet<Bean<?>>();
       for (Bean<?> bean : beans)
       {
-         if (bean.getTypes().contains(getType()))
+         if (getAnnotatedItem().isAssignableFrom(bean.getTypes()) && bean.getBindingTypes().containsAll(getBindingTypes()))
          {
-            List<Annotation> beanBindingTypes = new ArrayList<Annotation>(bean.getBindingTypes());
-            if (beanBindingTypes.containsAll(annotatedItem.getAnnotations()))
-            {
-               // TODO inspect annotation parameters
-               // TODO inspect deployment types
-               resolvedBeans.add(bean);
-            }
+            resolvedBeans.add(bean);
          }
       }
-     return resolvedBeans;
+      return resolvedBeans;
    }
    
    @Override
    public boolean equals(Object other)
    {
-      // TODO Currently you must have any annotation literals on other for this to work, probably need to iterate over the set and check both directions
+      // TODO Do we need to check the other direction too?
       if (other instanceof Injectable)
       {
          Injectable<?, ?> that = (Injectable<?, ?>) other;
-         return this.getAnnotatedItem().getType().isAssignableFrom(that.getAnnotatedItem().getType()) &&
+         return this.getAnnotatedItem().isAssignableFrom(that.getAnnotatedItem()) &&
             that.getAnnotatedItem().getAnnotations(BindingType.class).equals(this.getAnnotatedItem().getAnnotations(BindingType.class));
       }
       else
@@ -95,7 +87,10 @@
    @Override
    public int hashCode()
    {
+      // TODO Implement this!
       return 0;
    }
    
+   
+   
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/InjectableParameterWrapper.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/InjectableParameterWrapper.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/InjectableParameterWrapper.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -24,9 +24,9 @@
    }
 
    @Override
-   public Set<Bean<?>> getPossibleBeans(Set<Bean<?>> possibleBeans)
+   public Set<Bean<?>> getMatchingBeans(Set<Bean<?>> possibleBeans)
    {
-      return delegate.getPossibleBeans(possibleBeans);
+      return delegate.getMatchingBeans(possibleBeans);
    }
 
    @Override

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/InjectableWrapper.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/InjectableWrapper.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/InjectableWrapper.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -24,9 +24,9 @@
    }
 
    @Override
-   public Set<Bean<?>> getPossibleBeans(Set<Bean<?>> possibleBeans)
+   public Set<Bean<?>> getMatchingBeans(Set<Bean<?>> possibleBeans)
    {
-      return delegate.getPossibleBeans(possibleBeans);
+      return delegate.getMatchingBeans(possibleBeans);
    }
 
    @Override

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/SimpleInjectable.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/SimpleInjectable.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/SimpleInjectable.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -1,6 +1,7 @@
 package org.jboss.webbeans.injectable;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
 
 import org.jboss.webbeans.introspector.SimpleAnnotatedItem;
 
@@ -11,5 +12,10 @@
    {
       super(new SimpleAnnotatedItem<T, Object>(bindingTypes, type));
    }
+   
+   public SimpleInjectable(Class<T> type, Annotation[] bindingTypes, Type ... actualTypeArguements)
+   {
+      super(new SimpleAnnotatedItem<T, Object>(bindingTypes, type, actualTypeArguements));
+   }
 
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AbstractAnnotatedItem.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AbstractAnnotatedItem.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AbstractAnnotatedItem.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -2,12 +2,16 @@
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Type;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 import java.util.Map.Entry;
 
+import org.jboss.webbeans.util.Reflections;
+
 public abstract class AbstractAnnotatedItem<T, S> implements AnnotatedItem<T, S>
 {
 
@@ -113,10 +117,53 @@
       return false;
    }
    
+   public boolean isAssignableFrom(AnnotatedItem<?, ?> that)
+   {
+      return isAssignableFrom(that.getType(), that.getActualTypeArguements());
+   }
+   
+   public boolean isAssignableFrom(Set<Class<?>> types)
+   {
+      for (Class<?> type : types)
+      {
+         if (isAssignableFrom(type, Reflections.getActualTypeArguements(type)))
+         {
+            return true;
+         }
+      }
+      return false;
+   }
+   
+   private boolean isAssignableFrom(Class<?> type, Type[] actualTypeArguements)
+   {
+      return getType().isAssignableFrom(type) && Arrays.equals(getActualTypeArguements(), actualTypeArguements);
+   }
+   
    @Override
    public int hashCode()
    {
       return getType().hashCode();
    }
+   
+   @Override
+   public String toString()
+   {
+      String string = getType().toString();
+      if (getActualTypeArguements().length > 0)
+      {
+         string += "<";
+         for (int i = 0; i < getActualTypeArguements().length; i++)
+         {
+            string += getActualTypeArguements()[i].toString();
+            if (i < getActualTypeArguements().length - 1)
+            {
+               string += ",";
+            }
+         }
+         string += ">";
+      }
+      string += getAnnotations();
+      return string;
+   }
 
 }
\ No newline at end of file

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -1,6 +1,7 @@
 package org.jboss.webbeans.introspector;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
 import java.util.Set;
 
 
@@ -48,5 +49,11 @@
    public S getDelegate();
    
    public Class<? extends T> getType();
+   
+   public boolean isAssignableFrom(AnnotatedItem<?, ?> that);
+   
+   public boolean isAssignableFrom(Set<Class<?>> types);
+   
+   public Type[] getActualTypeArguements();
 
 }
\ No newline at end of file

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedConstructor.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedConstructor.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedConstructor.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -1,9 +1,12 @@
 package org.jboss.webbeans.introspector;
 
 import java.lang.reflect.Constructor;
+import java.lang.reflect.Type;
 
 public class SimpleAnnotatedConstructor<T> extends AbstractAnnotatedItem<T, Constructor<T>> implements AnnotatedConstructor<T>
 {
+
+   private static final Type[] actualTypeArguements = new Type[0];
    
    private Constructor<T> constructor;
    
@@ -17,12 +20,6 @@
    {
       return constructor;
    }
-   
-   @Override
-   public String toString()
-   {
-      return constructor.toGenericString();
-   }
 
    public Constructor<T> getDelegate()
    {
@@ -33,5 +30,10 @@
    {
       return constructor.getDeclaringClass();
    }
+   
+   public Type[] getActualTypeArguements()
+   {
+      return actualTypeArguements;
+   }
 
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedField.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedField.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedField.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -1,28 +1,31 @@
 package org.jboss.webbeans.introspector;
 
 import java.lang.reflect.Field;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 
 public class SimpleAnnotatedField<T> extends AbstractAnnotatedItem<T, Field> implements AnnotatedField<T>
 {
    
+   private Type[] actualTypeArguements = new Type[0];
+   
    private Field field;
    
    public SimpleAnnotatedField(Field field)
    {
       super(buildAnnotationMap(field));
       this.field = field;
+      if (field.getGenericType() instanceof ParameterizedType)
+      {
+         ParameterizedType type = (ParameterizedType) field.getGenericType();
+         actualTypeArguements = type.getActualTypeArguments();
+      }
    }
 
    public Field getAnnotatedField()
    {
       return field;
    }
-   
-   @Override
-   public String toString()
-   {
-      return field + " " + getAnnotatedField().toString();
-   }
 
    public Field getDelegate()
    {
@@ -33,5 +36,10 @@
    {
       return (Class<T>) field.getType();
    }
+   
+   public Type[] getActualTypeArguements()
+   {
+      return actualTypeArguements;
+   }
 
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedItem.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedItem.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedItem.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -1,11 +1,15 @@
 package org.jboss.webbeans.introspector;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
 import java.util.Map;
 
 public class SimpleAnnotatedItem<T, S> extends AbstractAnnotatedItem<T, S>
 {
 
+   private Type[] actualTypeArguements = new Type[0];
+   
+   
    private Class<? extends T> type;
    
    public SimpleAnnotatedItem(Map<Class<? extends Annotation>, Annotation> annotationMap)
@@ -19,6 +23,12 @@
       this.type = type;
    }
    
+   public SimpleAnnotatedItem(Map<Class<? extends Annotation>, Annotation> annotationMap, Class<? extends T> type, Type[] actualTypeArguements)
+   {
+      this(annotationMap, type);
+      this.actualTypeArguements = actualTypeArguements;
+   }
+   
    public SimpleAnnotatedItem(Annotation[] annotations)
    {
       this(annotations, null);
@@ -28,6 +38,11 @@
    {
       this(buildAnnotationMap(annotations), type);
    }
+   
+   public SimpleAnnotatedItem(Annotation[] annotations, Class<? extends T> type, Type[] actualTypeArguements)
+   {
+      this(buildAnnotationMap(annotations), type, actualTypeArguements);
+   }
 
    public S getDelegate()
    {
@@ -39,4 +54,9 @@
       return type;
    }
 
+   public Type[] getActualTypeArguements()
+   {
+      return actualTypeArguements;
+   }
+   
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedMethod.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedMethod.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedMethod.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -1,10 +1,13 @@
 package org.jboss.webbeans.introspector;
 
 import java.lang.reflect.Method;
+import java.lang.reflect.Type;
 
 public class SimpleAnnotatedMethod<T> extends AbstractAnnotatedItem<T, Method> implements AnnotatedMethod<T>
 {
    
+   private static final Type[] actualTypeArguements = new Type[0];
+   
    private Method method;
    
    public SimpleAnnotatedMethod(Method method)
@@ -17,12 +20,6 @@
    {
       return method;
    }
-   
-   @Override
-   public String toString()
-   {
-      return method + " " + getAnnotatedMethod().toString();
-   }
 
    public Method getDelegate()
    {
@@ -33,5 +30,10 @@
    {
       return (Class<T>) method.getReturnType();
    }
+   
+   public Type[] getActualTypeArguements()
+   {
+      return actualTypeArguements;
+   }
 
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedType.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedType.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedType.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -2,6 +2,8 @@
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -18,6 +20,7 @@
 {
    
    private Class<T> clazz;
+   private Type[] actualTypeArguements;
    private Set<AnnotatedField<?>> fields;
    private Map<Class<? extends Annotation>, Set<AnnotatedField<?>>> annotatedFields;
    private Map<Class<? extends Annotation>, Set<AnnotatedField<?>>> metaAnnotatedFields;
@@ -26,6 +29,15 @@
    {
       super(annotationMap);
       this.clazz = annotatedClass;
+      if (this.clazz.getGenericSuperclass() instanceof ParameterizedType)
+      {
+         ParameterizedType type = (ParameterizedType) this.clazz.getGenericSuperclass();
+         actualTypeArguements = type.getActualTypeArguments();
+      }
+      else
+      {
+         actualTypeArguements = new Type[0];
+      }
    }
    
    public SimpleAnnotatedType(Class<T> annotatedClass)
@@ -38,12 +50,6 @@
       return clazz;
    }
    
-   @Override
-   public String toString()
-   {
-      return clazz + " " + super.getAnnotationMap().toString();
-   }
-   
    public Class<T> getDelegate()
    {
       return clazz;
@@ -137,4 +143,9 @@
       return clazz;
    }
 
+   public Type[] getActualTypeArguements()
+   {
+      return actualTypeArguements;
+   }
+
 }
\ No newline at end of file

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractComponentModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractComponentModel.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractComponentModel.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -324,4 +324,9 @@
       return injectionPoints;
    }
 
+   public boolean isAssignableFrom(AnnotatedItem<?, ?> annotatedItem)
+   {
+      return this.getAnnotatedItem().isAssignableFrom(annotatedItem);
+   }
+   
 }
\ No newline at end of file

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/SimpleComponentModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/SimpleComponentModel.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/SimpleComponentModel.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -131,7 +131,7 @@
    @Override
    public String toString()
    {
-      return "SimpleComponentModel[" + getType().getName() + "]";
+      return "SimpleWebBean[" + getAnnotatedItem().toString() + "]";
    }
    
    @Override

Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/BeanMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/BeanMap.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/BeanMap.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -1,21 +0,0 @@
-package org.jboss.webbeans.util;
-
-import java.util.HashMap;
-
-import javax.webbeans.manager.Bean;
-
-public class BeanMap<V> extends MapWrapper<Bean<? extends V>, V>
-{
-
-   public BeanMap()
-   {
-      super(new HashMap<Bean<? extends V>, V>());
-   }
-   
-   @SuppressWarnings("unchecked")
-   public <T extends V> T get(Bean<? extends T> key)
-   {
-      return (T) super.get(key);
-   }
-
-}

Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ListComparator.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ListComparator.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ListComparator.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -0,0 +1,23 @@
+package org.jboss.webbeans.util;
+
+import java.util.Comparator;
+import java.util.List;
+
+public class ListComparator<T> implements Comparator<T>
+{
+   
+   private List<T> list;
+   
+   public ListComparator(List<T> list)
+   {
+      this.list = list;
+   }
+
+   public int compare(T o1, T o2)
+   {
+      int p1 = list.indexOf(o1);
+      int p2 = list.indexOf(o2);
+      return p1 - p2;
+   }
+
+}


Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ListComparator.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -5,6 +5,8 @@
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -173,4 +175,16 @@
       }
       return annotationTypeList.size() == 0;
    }
+   
+   public static Type[] getActualTypeArguements(Class<?> clazz)
+   {
+      if (clazz.getGenericSuperclass() instanceof ParameterizedType)
+      {
+         return ((ParameterizedType) clazz.getGenericSuperclass()).getActualTypeArguments(); 
+      }
+      else
+      {
+         return new Type[0];
+      }
+   }
 }

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -5,6 +5,7 @@
 import java.util.HashMap;
 import java.util.List;
 
+import javax.webbeans.Production;
 import javax.webbeans.Standard;
 
 import org.jboss.webbeans.ManagerImpl;
@@ -20,24 +21,21 @@
 import org.jboss.webbeans.test.annotations.RequestScopedAnimalStereotype;
 import org.jboss.webbeans.test.annotations.RiverFishStereotype;
 import org.jboss.webbeans.test.mock.MockManagerImpl;
-import org.jboss.webbeans.test.util.EmptyAnnotatedType;
 import org.testng.annotations.BeforeMethod;
 
 public class AbstractTest
 {
    
    protected ManagerImpl manager;
+
    
-   @Deprecated
-   protected AnnotatedType<?> emptyAnnotatedItem;
-   
    @BeforeMethod
    public void before()
    {
-      emptyAnnotatedItem = new EmptyAnnotatedType<Object>(new HashMap<Class<? extends Annotation>, Annotation>());
       
       List<Class<? extends Annotation>> enabledDeploymentTypes = new ArrayList<Class<? extends Annotation>>();
       enabledDeploymentTypes.add(Standard.class);
+      enabledDeploymentTypes.add(Production.class);
       enabledDeploymentTypes.add(AnotherDeploymentType.class);
       enabledDeploymentTypes.add(HornedAnimalDeploymentType.class);
       manager = new MockManagerImpl(enabledDeploymentTypes);

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ContextTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ContextTest.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ContextTest.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -11,7 +11,6 @@
 import org.jboss.webbeans.model.SimpleComponentModel;
 import org.jboss.webbeans.test.components.Tuna;
 import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.ExpectedExceptions;
 import org.testng.annotations.Test;
 
 /**

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InjectableTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InjectableTest.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InjectableTest.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -5,6 +5,7 @@
 
 import javax.webbeans.AnnotationLiteral;
 import javax.webbeans.Current;
+import javax.webbeans.TypeLiteral;
 import javax.webbeans.manager.Bean;
 
 import org.jboss.webbeans.BeanImpl;
@@ -13,14 +14,17 @@
 import org.jboss.webbeans.injectable.InjectableField;
 import org.jboss.webbeans.introspector.SimpleAnnotatedType;
 import org.jboss.webbeans.model.SimpleComponentModel;
-import org.jboss.webbeans.test.annotations.Chunky;
 import org.jboss.webbeans.test.annotations.Whitefish;
+import org.jboss.webbeans.test.bindings.ChunkyAnnotationLiteral;
 import org.jboss.webbeans.test.components.Animal;
 import org.jboss.webbeans.test.components.Cod;
+import org.jboss.webbeans.test.components.Farmer;
 import org.jboss.webbeans.test.components.FishFarm;
 import org.jboss.webbeans.test.components.Haddock;
+import org.jboss.webbeans.test.components.Plaice;
 import org.jboss.webbeans.test.components.Salmon;
 import org.jboss.webbeans.test.components.ScottishFish;
+import org.jboss.webbeans.test.components.ScottishFishFarmer;
 import org.jboss.webbeans.test.components.SeaBass;
 import org.jboss.webbeans.test.components.Sole;
 import org.jboss.webbeans.test.components.Tuna;
@@ -48,7 +52,7 @@
       Bean<Tuna> tunaBean = new BeanImpl<Tuna>(new SimpleComponentModel<Tuna>(new SimpleAnnotatedType<Tuna>(Tuna.class), getEmptyAnnotatedItem(Tuna.class), super.manager), manager);
       Set<Bean<?>> beans = new HashSet<Bean<?>>();
       beans.add(tunaBean);
-      Set<Bean<?>> possibleTargets = tunaField.getPossibleBeans(beans);
+      Set<Bean<?>> possibleTargets = tunaField.getMatchingBeans(beans);
       assert possibleTargets.size() == 1;
       assert possibleTargets.contains(tunaBean);
    }
@@ -56,7 +60,7 @@
    @Test
    public void testOneBindingType() throws Exception
    {
-      InjectableField<ScottishFish> scottishFishField = new InjectableField<ScottishFish>(FishFarm.class.getDeclaredField("scottishFish"));
+      InjectableField<ScottishFish> whiteScottishFishField = new InjectableField<ScottishFish>(FishFarm.class.getDeclaredField("whiteScottishFish"));
       Bean<Cod> codBean = new BeanImpl<Cod>(new SimpleComponentModel<Cod>(new SimpleAnnotatedType<Cod>(Cod.class), getEmptyAnnotatedItem(Cod.class), super.manager), manager);
       Bean<Salmon> salmonBean = new BeanImpl<Salmon>(new SimpleComponentModel<Salmon>(new SimpleAnnotatedType<Salmon>(Salmon.class), getEmptyAnnotatedItem(Salmon.class), super.manager), manager);
       Bean<Sole> soleBean = new BeanImpl<Sole>(new SimpleComponentModel<Sole>(new SimpleAnnotatedType<Sole>(Sole.class), getEmptyAnnotatedItem(Sole.class), super.manager), manager);
@@ -64,7 +68,7 @@
       beans.add(codBean);
       beans.add(salmonBean);
       beans.add(soleBean);
-      Set<Bean<?>> possibleTargets = scottishFishField.getPossibleBeans(beans);
+      Set<Bean<?>> possibleTargets = whiteScottishFishField.getMatchingBeans(beans);
       assert possibleTargets.size() == 2;
       assert possibleTargets.contains(codBean);
       assert possibleTargets.contains(soleBean);
@@ -73,7 +77,7 @@
    @Test
    public void testABindingType() throws Exception
    {
-      InjectableField<Animal> whiteChunkyFishField = new InjectableField<Animal>(FishFarm.class.getDeclaredField("whiteChunkyFish"));
+      InjectableField<Animal> whiteChunkyFishField = new InjectableField<Animal>(FishFarm.class.getDeclaredField("realChunkyWhiteFish"));
       Bean<Cod> codBean = new BeanImpl<Cod>(new SimpleComponentModel<Cod>(new SimpleAnnotatedType<Cod>(Cod.class), getEmptyAnnotatedItem(Cod.class), super.manager), manager);
       Bean<Salmon> salmonBean = new BeanImpl<Salmon>(new SimpleComponentModel<Salmon>(new SimpleAnnotatedType<Salmon>(Salmon.class), getEmptyAnnotatedItem(Salmon.class), super.manager), manager);
       Bean<Sole> soleBean = new BeanImpl<Sole>(new SimpleComponentModel<Sole>(new SimpleAnnotatedType<Sole>(Sole.class), getEmptyAnnotatedItem(Sole.class), super.manager), manager);
@@ -81,7 +85,7 @@
       beans.add(codBean);
       beans.add(salmonBean);
       beans.add(soleBean);
-      Set<Bean<?>> possibleTargets = whiteChunkyFishField.getPossibleBeans(beans);
+      Set<Bean<?>> possibleTargets = whiteChunkyFishField.getMatchingBeans(beans);
       assert possibleTargets.size() == 1;
       assert possibleTargets.contains(codBean);
    }
@@ -95,7 +99,7 @@
       Set<Bean<?>> beans = new HashSet<Bean<?>>();
       beans.add(seaBassBean);
       beans.add(haddockBean);
-      Set<Bean<?>> possibleTargets = animalField.getPossibleBeans(beans);
+      Set<Bean<?>> possibleTargets = animalField.getMatchingBeans(beans);
       assert possibleTargets.size() == 2;
       assert possibleTargets.contains(seaBassBean);
       assert possibleTargets.contains(haddockBean);
@@ -104,9 +108,9 @@
    @Test
    public void testResolveByType() throws Exception
    {
-      InjectableField<Animal> whiteChunkyFishField = new InjectableField<Animal>(FishFarm.class.getDeclaredField("whiteChunkyFish"));
+      InjectableField<Animal> realChunkyWhiteFishField = new InjectableField<Animal>(FishFarm.class.getDeclaredField("realChunkyWhiteFish"));
       InjectableField<Animal> animalField = new InjectableField<Animal>(FishFarm.class.getDeclaredField("animal"));
-      InjectableField<ScottishFish> scottishFishField = new InjectableField<ScottishFish>(FishFarm.class.getDeclaredField("scottishFish"));
+      InjectableField<ScottishFish> scottishFishField = new InjectableField<ScottishFish>(FishFarm.class.getDeclaredField("whiteScottishFish"));
       InjectableField<Tuna> tunaField = new InjectableField<Tuna>(FishFarm.class.getDeclaredField("tuna"));
       
       Bean<Tuna> tunaBean = new BeanImpl<Tuna>(new SimpleComponentModel<Tuna>(new SimpleAnnotatedType<Tuna>(Tuna.class), getEmptyAnnotatedItem(Tuna.class), super.manager), manager);
@@ -124,30 +128,83 @@
       manager.addBean(seaBassBean);
       
       ResolutionManager resolutionManager = manager.getResolutionManager();
-      resolutionManager.addInjectionPoint(whiteChunkyFishField);
+      resolutionManager.addInjectionPoint(realChunkyWhiteFishField);
       resolutionManager.addInjectionPoint(animalField);
       resolutionManager.addInjectionPoint(scottishFishField);
       resolutionManager.addInjectionPoint(tunaField);
       
-      resolutionManager.registerInjectionPoints();
-      
-      System.out.println("injection points registered");
-      
       assert manager.resolveByType(Tuna.class, new CurrentAnnotationLiteral()).size() == 1;
       assert manager.resolveByType(Tuna.class, new CurrentAnnotationLiteral()).contains(tunaBean);
       
+      assert manager.resolveByType(Tuna.class).size() == 1;
+      assert manager.resolveByType(Tuna.class).contains(tunaBean);
+      
       assert manager.resolveByType(Animal.class, new CurrentAnnotationLiteral()).size() == 3;
       assert manager.resolveByType(Animal.class, new CurrentAnnotationLiteral()).contains(salmonBean);
       assert manager.resolveByType(Animal.class, new CurrentAnnotationLiteral()).contains(seaBassBean);
       assert manager.resolveByType(Animal.class, new CurrentAnnotationLiteral()).contains(haddockBean);
       
-      assert manager.resolveByType(Animal.class, new AnnotationLiteral<Chunky>() {}, new AnnotationLiteral<Whitefish>() {}).size() == 1;
-      assert manager.resolveByType(Animal.class, new AnnotationLiteral<Chunky>() {}, new AnnotationLiteral<Whitefish>() {}).contains(codBean);
+      assert manager.resolveByType(Animal.class, new ChunkyAnnotationLiteral() {
+
+         public boolean realChunky()
+         {
+            return true;
+         }
+         
+      }, new AnnotationLiteral<Whitefish>() {}).size() == 1;
+      assert manager.resolveByType(Animal.class, new ChunkyAnnotationLiteral() {
+
+         public boolean realChunky()
+         {
+            return true;
+         }
+         
+      }, new AnnotationLiteral<Whitefish>() {}).contains(codBean);
       
       assert manager.resolveByType(ScottishFish.class, new AnnotationLiteral<Whitefish>() {}).size() == 2;
       assert manager.resolveByType(ScottishFish.class, new AnnotationLiteral<Whitefish>() {}).contains(codBean);
       assert manager.resolveByType(ScottishFish.class, new AnnotationLiteral<Whitefish>() {}).contains(soleBean);
       
    }
+   
+   @Test
+   public void testResolveByTypeWithTypeParameter() throws Exception
+   {
+      InjectableField<Farmer<ScottishFish>> scottishFishFarmerField = new InjectableField<Farmer<ScottishFish>>(FishFarm.class.getDeclaredField("scottishFishFarmer"));
       
+      Bean<ScottishFishFarmer> scottishFishFarmerBean = new BeanImpl<ScottishFishFarmer>(new SimpleComponentModel<ScottishFishFarmer>(new SimpleAnnotatedType<ScottishFishFarmer>(ScottishFishFarmer.class), getEmptyAnnotatedItem(ScottishFishFarmer.class), super.manager), manager);
+      Bean<Farmer> farmerBean = new BeanImpl<Farmer>(new SimpleComponentModel<Farmer>(new SimpleAnnotatedType<Farmer>(Farmer.class), getEmptyAnnotatedItem(Farmer.class), super.manager), manager);
+      
+      manager.addBean(scottishFishFarmerBean);
+      manager.addBean(farmerBean);
+      
+      ResolutionManager resolutionManager = manager.getResolutionManager();
+      resolutionManager.addInjectionPoint(scottishFishFarmerField);
+      
+      assert manager.resolveByType(new TypeLiteral<Farmer<ScottishFish>>(){}).size() == 1;
+      assert manager.resolveByType(new TypeLiteral<Farmer<ScottishFish>>(){}).contains(scottishFishFarmerBean);
+   }
+   
+   @Test
+   public void testOnlyHighestEnabledPreecedenceWebBeansResolved() throws Exception
+   {
+      InjectableField<Animal> whiteFishField = new InjectableField<Animal>(FishFarm.class.getDeclaredField("whiteFish"));
+      
+      Bean<Cod> codBean = new BeanImpl<Cod>(new SimpleComponentModel<Cod>(new SimpleAnnotatedType<Cod>(Cod.class), getEmptyAnnotatedItem(Cod.class), super.manager), manager);
+      Bean<Sole> soleBean = new BeanImpl<Sole>(new SimpleComponentModel<Sole>(new SimpleAnnotatedType<Sole>(Sole.class), getEmptyAnnotatedItem(Sole.class), super.manager), manager);
+      Bean<Plaice> plaiceBean = new BeanImpl<Plaice>(new SimpleComponentModel<Plaice>(new SimpleAnnotatedType<Plaice>(Plaice.class), getEmptyAnnotatedItem(Plaice.class), super.manager), manager);
+      
+      
+      manager.addBean(plaiceBean);
+      manager.addBean(codBean);
+      manager.addBean(soleBean);
+      
+      ResolutionManager resolutionManager = manager.getResolutionManager();
+      resolutionManager.addInjectionPoint(whiteFishField);
+
+      assert manager.resolveByType(Animal.class, new AnnotationLiteral<Whitefish>() {}).size() == 1;
+      assert manager.resolveByType(Animal.class, new AnnotationLiteral<Whitefish>() {}).contains(plaiceBean);
+      
+   }
+      
 }

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NameBasedResolutionTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NameBasedResolutionTest.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NameBasedResolutionTest.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -0,0 +1,51 @@
+package org.jboss.webbeans.test;
+
+import javax.webbeans.manager.Bean;
+
+import org.jboss.webbeans.BeanImpl;
+import org.jboss.webbeans.introspector.SimpleAnnotatedType;
+import org.jboss.webbeans.model.SimpleComponentModel;
+import org.jboss.webbeans.test.components.Cod;
+import org.jboss.webbeans.test.components.Haddock;
+import org.jboss.webbeans.test.components.Plaice;
+import org.jboss.webbeans.test.components.Salmon;
+import org.jboss.webbeans.test.components.SeaBass;
+import org.jboss.webbeans.test.components.Sole;
+import org.jboss.webbeans.test.components.Tuna;
+import org.testng.annotations.Test;
+
+public class NameBasedResolutionTest extends AbstractTest
+{
+
+   @Test
+   public void testNamedBasedResolution()
+   {
+      Bean<Tuna> tunaBean = new BeanImpl<Tuna>(new SimpleComponentModel<Tuna>(new SimpleAnnotatedType<Tuna>(Tuna.class), getEmptyAnnotatedItem(Tuna.class), super.manager), manager);
+      Bean<Cod> codBean = new BeanImpl<Cod>(new SimpleComponentModel<Cod>(new SimpleAnnotatedType<Cod>(Cod.class), getEmptyAnnotatedItem(Cod.class), super.manager), manager);
+      Bean<Salmon> salmonBean = new BeanImpl<Salmon>(new SimpleComponentModel<Salmon>(new SimpleAnnotatedType<Salmon>(Salmon.class), getEmptyAnnotatedItem(Salmon.class), super.manager), manager);
+      Bean<Sole> soleBean = new BeanImpl<Sole>(new SimpleComponentModel<Sole>(new SimpleAnnotatedType<Sole>(Sole.class), getEmptyAnnotatedItem(Sole.class), super.manager), manager);
+      Bean<SeaBass> seaBassBean = new BeanImpl<SeaBass>(new SimpleComponentModel<SeaBass>(new SimpleAnnotatedType<SeaBass>(SeaBass.class), getEmptyAnnotatedItem(SeaBass.class), super.manager), manager);
+      Bean<Haddock> haddockBean = new BeanImpl<Haddock>(new SimpleComponentModel<Haddock>(new SimpleAnnotatedType<Haddock>(Haddock.class), getEmptyAnnotatedItem(Haddock.class), super.manager), manager);
+      Bean<Plaice> plaiceBean = new BeanImpl<Plaice>(new SimpleComponentModel<Plaice>(new SimpleAnnotatedType<Plaice>(Plaice.class), getEmptyAnnotatedItem(Plaice.class), super.manager), manager);
+      
+      manager.addBean(tunaBean);
+      manager.addBean(codBean);
+      manager.addBean(salmonBean);
+      manager.addBean(soleBean);
+      manager.addBean(haddockBean);
+      manager.addBean(seaBassBean);
+      
+      assert manager.resolveByName("salmon").size() == 1;
+      assert manager.resolveByName("salmon").contains(salmonBean);
+      
+      assert manager.resolveByName("whitefish").size() == 2;
+      assert manager.resolveByName("whitefish").contains(codBean);
+      assert manager.resolveByName("whitefish").contains(soleBean);
+      
+      manager.addBean(plaiceBean);
+      
+      assert manager.resolveByName("whitefish").size() == 1; 
+      assert manager.resolveByName("whitefish").contains(plaiceBean);
+   }
+   
+}


Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NameBasedResolutionTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Chunky.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Chunky.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Chunky.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -18,5 +18,7 @@
 @BindingType
 public @interface Chunky
 {
+   
+   boolean realChunky();
 
 }

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/ChunkyAnnotationLiteral.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/ChunkyAnnotationLiteral.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/ChunkyAnnotationLiteral.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -0,0 +1,10 @@
+package org.jboss.webbeans.test.bindings;
+
+import javax.webbeans.AnnotationLiteral;
+
+import org.jboss.webbeans.test.annotations.Chunky;
+
+public abstract class ChunkyAnnotationLiteral extends AnnotationLiteral<Chunky> implements Chunky
+{
+
+}


Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/ChunkyAnnotationLiteral.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Cod.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Cod.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Cod.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -1,5 +1,6 @@
 package org.jboss.webbeans.test.components;
 
+import javax.webbeans.Named;
 import javax.webbeans.Production;
 
 import org.jboss.webbeans.test.annotations.Chunky;
@@ -7,7 +8,8 @@
 
 @Production
 @Whitefish
- at Chunky
+ at Chunky(realChunky=true)
+ at Named("whitefish")
 public class Cod implements ScottishFish
 {
 

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/FishFarm.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/FishFarm.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/FishFarm.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -20,11 +20,18 @@
    
    @SuppressWarnings("unused")
    @Whitefish
-   private ScottishFish scottishFish;
+   private ScottishFish whiteScottishFish;
    
-   @Whitefish @Chunky
-   private Animal whiteChunkyFish;
+   @SuppressWarnings("unused")
+   @Whitefish
+   private Animal whiteFish;
    
+   @SuppressWarnings("unused")
+   @Whitefish @Chunky(realChunky=true)
+   private Animal realChunkyWhiteFish;
+   
+   @SuppressWarnings("unused")
+   @Current
    private Farmer<ScottishFish> scottishFishFarmer;
    
 }

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Plaice.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Plaice.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Plaice.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -0,0 +1,14 @@
+package org.jboss.webbeans.test.components;
+
+import javax.webbeans.Named;
+
+import org.jboss.webbeans.test.annotations.AnotherDeploymentType;
+import org.jboss.webbeans.test.annotations.Whitefish;
+
+ at AnotherDeploymentType
+ at Whitefish
+ at Named("whitefish")
+public class Plaice implements Animal
+{
+
+}


Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Plaice.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Salmon.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Salmon.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Salmon.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -1,10 +1,10 @@
 package org.jboss.webbeans.test.components;
 
+import javax.webbeans.Named;
 import javax.webbeans.Production;
 
-import org.jboss.webbeans.test.annotations.Whitefish;
-
 @Production
+ at Named
 public class Salmon implements ScottishFish
 {
 

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/ScottishFishFarmer.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/ScottishFishFarmer.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/ScottishFishFarmer.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -0,0 +1,9 @@
+package org.jboss.webbeans.test.components;
+
+import javax.webbeans.Production;
+
+ at Production
+public class ScottishFishFarmer extends Farmer<ScottishFish>
+{
+
+}


Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/ScottishFishFarmer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Sole.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Sole.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Sole.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -1,11 +1,13 @@
 package org.jboss.webbeans.test.components;
 
+import javax.webbeans.Named;
 import javax.webbeans.Production;
 
 import org.jboss.webbeans.test.annotations.Whitefish;
 
 @Production
 @Whitefish
+ at Named("whitefish")
 public class Sole implements ScottishFish
 {
 

Deleted: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/util/EmptyAnnotatedType.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/util/EmptyAnnotatedType.java	2008-10-24 15:13:35 UTC (rev 143)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/util/EmptyAnnotatedType.java	2008-10-25 00:13:08 UTC (rev 144)
@@ -1,38 +0,0 @@
-package org.jboss.webbeans.test.util;
-
-import java.lang.annotation.Annotation;
-import java.util.Map;
-import java.util.Set;
-
-import org.jboss.webbeans.introspector.AnnotatedField;
-import org.jboss.webbeans.introspector.SimpleAnnotatedType;
-
-/**
- * An empty annotated type
- * 
- * TODO Update testsuite not to need this hack
- * 
- * @author pmuir
- *
- */
-public class EmptyAnnotatedType<T> extends SimpleAnnotatedType<T>
-{
-   
-   public EmptyAnnotatedType(Map<Class<? extends Annotation>, Annotation> annotationMap)
-   {
-      super(null, annotationMap);
-   }
-
-   public Set<AnnotatedField<?>> getFields()
-   {
-      return null;
-   }
-   
-   @Override
-   public Set<AnnotatedField<?>> getMetaAnnotatedFields(
-         Class<? extends Annotation> metaAnnotationType)
-   {
-      return null;
-   }
-
-}
\ No newline at end of file




More information about the weld-commits mailing list