[webbeans-commits] Webbeans SVN: r2796 - in ri/trunk: impl/src/main/java/org/jboss/webbeans/bootstrap and 7 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Tue Jun 9 10:27:57 EDT 2009


Author: pete.muir at jboss.org
Date: 2009-06-09 10:27:57 -0400 (Tue, 09 Jun 2009)
New Revision: 2796

Added:
   ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/context/StringHolder.java
   ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/Target.java
Modified:
   ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/context/ContextLifecycle.java
   ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/ServiceRegistry.java
   ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingServiceRegistry.java
   ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/SimpleServiceRegistry.java
   ri/trunk/tests/src/main/java/org/jboss/webbeans/test/AbstractWebBeansTest.java
   ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/context/ParameterizedTypeScopedTest.java
   ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedProducerTest.java
   ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/lookup/LookupInstanceTest.java
Log:
More clean up

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java	2009-06-09 01:29:25 UTC (rev 2795)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java	2009-06-09 14:27:57 UTC (rev 2796)
@@ -51,7 +51,6 @@
 import javax.enterprise.inject.AmbiguousResolutionException;
 import javax.enterprise.inject.BindingType;
 import javax.enterprise.inject.Stereotype;
-import javax.enterprise.inject.TypeLiteral;
 import javax.enterprise.inject.UnproxyableResolutionException;
 import javax.enterprise.inject.UnsatisfiedResolutionException;
 import javax.enterprise.inject.deployment.Production;
@@ -782,45 +781,14 @@
     * @param bindings The binding types to match
     * @return An instance of the bean
     * 
-    * @see javax.enterprise.inject.spi.BeanManager#getInstanceByType(java.lang.Class,
-    *      java.lang.annotation.Annotation[])
     */
    @Deprecated
    public <T> T getInstanceByType(Class<T> type, Annotation... bindings)
    {
-      return getInstanceByType(ResolvableAnnotatedClass.of(type, bindings), bindings);
+      AnnotatedItem<T, ?> element = ResolvableAnnotatedClass.of(type, bindings);
+      return (T) getReference(getBean(element, bindings), type);
    }
 
-   /**
-    * Returns an instance by type literal and binding types
-    * 
-    * @param type The type to match
-    * @param bindings The binding types to match
-    * @return An instance of the bean
-    * 
-    * @see javax.enterprise.inject.spi.BeanManager#getInstanceByType(javax.enterprise.inject.TypeLiteral,
-    *      java.lang.annotation.Annotation[])
-    */
-   @Deprecated
-   public <T> T getInstanceByType(TypeLiteral<T> type, Annotation... bindings)
-   {
-      return getInstanceByType(ResolvableAnnotatedClass.of(type, bindings), bindings);
-   }
-
-   /**
-    * Resolve an instance, verify that the resolved bean can be instantiated,
-    * and return
-    * 
-    * @param element The annotated item to match
-    * @param bindings The binding types to match
-    * @return An instance of the bean
-    */
-   @Deprecated
-   public <T> T getInstanceByType(AnnotatedItem<T, ?> element, Annotation... bindings)
-   {
-      return (T) getReference(getBean(element, bindings), element.getType());
-   }
-
    public <T> Bean<T> getBean(AnnotatedItem<T, ?> element, Annotation... bindings)
    {
       Set<Bean<?>> beans = getBeans(element, bindings);

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java	2009-06-09 01:29:25 UTC (rev 2795)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java	2009-06-09 14:27:57 UTC (rev 2796)
@@ -213,9 +213,8 @@
          log.debug("Web Beans initialized. Validating beans.");
          manager.getResolver().resolveInjectionPoints();
          new BeanValidator(manager).validate();
-         manager.fireEvent(new AfterDeploymentValidationImpl());
          manager.getResolver().resolveInjectionPoints();
-         
+         manager.fireEvent(new AfterDeploymentValidationImpl());
          endDeploy(requestBeanStore);
       }
    }

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/context/ContextLifecycle.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/context/ContextLifecycle.java	2009-06-09 01:29:25 UTC (rev 2795)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/context/ContextLifecycle.java	2009-06-09 14:27:57 UTC (rev 2796)
@@ -22,6 +22,9 @@
  */
 package org.jboss.webbeans.context;
 
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Instance;
+
 import org.jboss.webbeans.CurrentManager;
 import org.jboss.webbeans.bootstrap.api.Lifecycle;
 import org.jboss.webbeans.context.api.BeanStore;
@@ -41,6 +44,8 @@
 {
 
    private static LogProvider log = Logging.getLogProvider(ContextLifecycle.class);
+   
+   @Any private Instance<ConversationManager> conversationManager;
 
    public void restoreSession(String id, BeanStore sessionBeanStore)
    {

Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/ServiceRegistry.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/ServiceRegistry.java	2009-06-09 01:29:25 UTC (rev 2795)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/ServiceRegistry.java	2009-06-09 14:27:57 UTC (rev 2796)
@@ -6,7 +6,7 @@
  * @author Pete Muir
  *
  */
-public interface ServiceRegistry
+public interface ServiceRegistry extends Iterable<Service>
 {
    
    /**

Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingServiceRegistry.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingServiceRegistry.java	2009-06-09 01:29:25 UTC (rev 2795)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingServiceRegistry.java	2009-06-09 14:27:57 UTC (rev 2796)
@@ -1,5 +1,7 @@
 package org.jboss.webbeans.bootstrap.api.helpers;
 
+import java.util.Iterator;
+
 import org.jboss.webbeans.bootstrap.api.Service;
 import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
 
@@ -23,4 +25,9 @@
       return delegate().get(type);
    }
    
+   public Iterator<Service> iterator()
+   {
+      return delegate().iterator();
+   }
+   
 }

Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/SimpleServiceRegistry.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/SimpleServiceRegistry.java	2009-06-09 01:29:25 UTC (rev 2795)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/SimpleServiceRegistry.java	2009-06-09 14:27:57 UTC (rev 2796)
@@ -17,7 +17,9 @@
 package org.jboss.webbeans.bootstrap.api.helpers;
 
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import org.jboss.webbeans.bootstrap.api.Service;
 import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
@@ -79,4 +81,40 @@
       return services.equals(obj);
    }
    
+   public Iterator<Service> iterator()
+   {
+      return new ValueIterator<Class<? extends Service>, Service>()
+      {
+
+         @Override
+         protected Iterator<Entry<Class<? extends Service>, Service>> delegate()
+         {
+            return services.entrySet().iterator();
+         }
+         
+      };
+   }
+   
+   private static abstract class ValueIterator<K, V> implements Iterator<V>
+   {
+      
+      protected abstract Iterator<Entry<K, V>> delegate();
+
+      public boolean hasNext()
+      {
+         return delegate().hasNext();
+      }
+
+      public V next()
+      {
+         return delegate().next().getValue();
+      }
+
+      public void remove()
+      {
+         delegate().remove();
+      }
+      
+   }
+   
 }

Modified: ri/trunk/tests/src/main/java/org/jboss/webbeans/test/AbstractWebBeansTest.java
===================================================================
--- ri/trunk/tests/src/main/java/org/jboss/webbeans/test/AbstractWebBeansTest.java	2009-06-09 01:29:25 UTC (rev 2795)
+++ ri/trunk/tests/src/main/java/org/jboss/webbeans/test/AbstractWebBeansTest.java	2009-06-09 14:27:57 UTC (rev 2796)
@@ -165,9 +165,20 @@
       {
          throw new RuntimeException("No beans resolved to " + beanType + " with bindings " + Arrays.asList(bindings));
       }
-      @SuppressWarnings("deprecated")
+      @SuppressWarnings("unchecked")
       Bean<T> bean = (Bean<T>) beans.iterator().next();
       return bean;
    }
    
+   @SuppressWarnings("unchecked")
+   public <T> T createContextualInstance(Class<T> beanType, Annotation... bindings)
+   {
+      return (T) createContextualInstance((Type) beanType, bindings);
+   }
+   
+   public Object createContextualInstance(Type beanType, Annotation... bindings)
+   {
+      return getCurrentManager().getReference(getBean(beanType, bindings), beanType);
+   }
+   
 }

Modified: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/context/ParameterizedTypeScopedTest.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/context/ParameterizedTypeScopedTest.java	2009-06-09 01:29:25 UTC (rev 2795)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/context/ParameterizedTypeScopedTest.java	2009-06-09 14:27:57 UTC (rev 2796)
@@ -2,8 +2,6 @@
 
 import java.util.List;
 
-import javax.enterprise.inject.TypeLiteral;
-
 import org.jboss.testharness.impl.packaging.Artifact;
 import org.jboss.webbeans.test.AbstractWebBeansTest;
 import org.testng.annotations.Test;
@@ -15,10 +13,7 @@
    @Test
    public void testStringList()
    {
-      List<String> str = getCurrentManager().getInstanceByType(new TypeLiteral<List<String>>()
-      {
-      });
-
+      List<String> str = createContextualInstance(StringHolder.class).getStrings();
       assert str.size() == 2;
    }
 }

Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/context/StringHolder.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/context/StringHolder.java	                        (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/context/StringHolder.java	2009-06-09 14:27:57 UTC (rev 2796)
@@ -0,0 +1,19 @@
+package org.jboss.webbeans.test.unit.context;
+
+import java.util.List;
+
+import javax.enterprise.inject.Current;
+
+
+public class StringHolder
+{
+
+   @Current 
+   private List<String> strings;
+   
+   public List<String> getStrings()
+   {
+      return strings;
+   }
+   
+}


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

Modified: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedProducerTest.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedProducerTest.java	2009-06-09 01:29:25 UTC (rev 2795)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/ParameterizedProducerTest.java	2009-06-09 14:27:57 UTC (rev 2796)
@@ -3,8 +3,6 @@
 import java.util.Collection;
 import java.util.List;
 
-import javax.enterprise.inject.TypeLiteral;
-
 import org.jboss.testharness.impl.packaging.Artifact;
 import org.jboss.webbeans.test.AbstractWebBeansTest;
 import org.testng.annotations.Test;
@@ -16,9 +14,8 @@
    @Test
    public void testParameterizedListInjection()
    {
-      assert getCurrentManager().getInstanceByType(new TypeLiteral<List<String>>()
-      {
-      }).size() == 2;
+      List<String> strings = createContextualInstance(Target.class).getStringList();
+      assert strings.size() == 2;
 
       ParameterizedListInjection item = getCurrentManager().getInstanceByType(ParameterizedListInjection.class);
       assert item.getFieldInjection().size() == 2;
@@ -30,9 +27,8 @@
    @Test
    public void testParameterizedCollectionInjection()
    {
-      assert getCurrentManager().getInstanceByType(new TypeLiteral<Collection<String>>()
-      {
-      }).size() == 2;
+      Collection<String> strings = createContextualInstance(Target.class).getStrings();
+      assert strings.size() == 2;
 
       ParameterizedCollectionInjection item = getCurrentManager().getInstanceByType(ParameterizedCollectionInjection.class);
       assert item.getFieldInjection().size() == 2;
@@ -56,7 +52,8 @@
    @Test
    public void testIntegerCollectionInjection()
    {
-      assert getCurrentManager().getInstanceByType(new TypeLiteral<Collection<Integer>>(){}).size() == 4;
+      Collection<Integer> integers = createContextualInstance(Target.class).getIntegers();
+      assert integers.size() == 4;
 
       IntegerCollectionInjection item = getCurrentManager().getInstanceByType(IntegerCollectionInjection.class);
       assert item.getFieldInjection().size() == 4;

Added: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/Target.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/Target.java	                        (rev 0)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/Target.java	2009-06-09 14:27:57 UTC (rev 2796)
@@ -0,0 +1,32 @@
+package org.jboss.webbeans.test.unit.implementation.producer.field;
+
+import java.util.Collection;
+import java.util.List;
+
+import javax.enterprise.inject.Current;
+
+public class Target
+{
+   
+   @Current private Collection<String> strings;
+   
+   @Current private Collection<Integer> integers;
+   
+   @Current private List<String> stringList;
+   
+   public Collection<String> getStrings()
+   {
+      return strings;
+   }
+   
+   public Collection<Integer> getIntegers()
+   {
+      return integers;
+   }
+   
+   public List<String> getStringList()
+   {
+      return stringList;
+   }
+
+}


Property changes on: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/producer/field/Target.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/lookup/LookupInstanceTest.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/lookup/LookupInstanceTest.java	2009-06-09 01:29:25 UTC (rev 2795)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/lookup/LookupInstanceTest.java	2009-06-09 14:27:57 UTC (rev 2796)
@@ -18,7 +18,7 @@
    @Test
    public void testLookupInstance() throws Exception
    {
-      assert getCurrentManager().getInstanceByType(new TypeLiteral<Instance<List<?>>>(){}, new ObtainsLiteral()) == null; 
+      assert createContextualInstance(new TypeLiteral<Instance<List<?>>>(){}.getRawType(), new ObtainsLiteral()) == null; 
    }
    
 }




More information about the weld-commits mailing list