[webbeans-commits] Webbeans SVN: r3791 - ri/trunk/impl/src/main/java/org/jboss/webbeans.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Mon Sep 28 10:19:21 EDT 2009


Author: cpopetz
Date: 2009-09-28 10:19:21 -0400 (Mon, 28 Sep 2009)
New Revision: 3791

Modified:
   ri/trunk/impl/src/main/java/org/jboss/webbeans/SimpleInjectionTarget.java
Log:
allow creation of InjectionTarget<T> where T is non-Producible by deferring exception until produce() is invoked


Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/SimpleInjectionTarget.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/SimpleInjectionTarget.java	2009-09-25 19:32:22 UTC (rev 3790)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/SimpleInjectionTarget.java	2009-09-28 14:19:21 UTC (rev 3791)
@@ -57,8 +57,18 @@
       this.beanManager = beanManager;
       this.type = type;
       this.injectionPoints = new HashSet<InjectionPoint>();
-      this.constructor = Beans.getBeanConstructor(null, type);
-      this.injectionPoints.addAll(Beans.getParameterInjectionPoints(null, constructor));
+      ConstructorInjectionPoint<T> constructor = null;
+      try
+      {
+         constructor = Beans.getBeanConstructor(null, type);
+         this.injectionPoints.addAll(Beans.getParameterInjectionPoints(null, constructor));
+      }
+      catch (Exception e)
+      {
+         // this means the bean of a type that cannot be produce()d, but that is non-fatal
+         // unless someone calls produce()
+      }
+      this.constructor = constructor;
       this.injectableFields = new HashSet<FieldInjectionPoint<?,?>>();
       this.injectableFields.addAll(Beans.getFieldInjectionPoints(null, type));
       this.injectionPoints.addAll(injectableFields);
@@ -75,6 +85,16 @@
 
    public T produce(CreationalContext<T> ctx)
    {
+      if (constructor == null)
+      {
+         // this means we couldn't find a constructor on instantiation, which
+         // means there isn't one that's spec-compliant
+         // try again so the correct DefinitionException is thrown
+         Beans.getBeanConstructor(null, type);
+         // should not be reached
+         throw new IllegalStateException(
+               "We were not previously able to find the bean constructor, but now are?");
+      }
       return constructor.newInstance(beanManager, ctx);
    }
    




More information about the weld-commits mailing list