[weld-commits] Weld SVN: r5390 - core/trunk/impl/src/main/java/org/jboss/weld/bean.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Thu Jan 7 09:10:21 EST 2010


Author: pete.muir at jboss.org
Date: 2010-01-07 09:10:21 -0500 (Thu, 07 Jan 2010)
New Revision: 5390

Modified:
   core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
   core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java
   core/trunk/impl/src/main/java/org/jboss/weld/bean/SessionBean.java
Log:
WELD-329

Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java	2010-01-07 13:42:35 UTC (rev 5389)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java	2010-01-07 14:10:21 UTC (rev 5390)
@@ -22,6 +22,7 @@
 import static org.jboss.weld.logging.messages.BeanMessage.INVOCATION_ERROR;
 import static org.jboss.weld.logging.messages.BeanMessage.NON_CONTAINER_DECORATOR;
 import static org.jboss.weld.logging.messages.BeanMessage.ONLY_ONE_SCOPE_ALLOWED;
+import static org.jboss.weld.logging.messages.BeanMessage.PARAMETER_ANNOTATION_NOT_ALLOWED_ON_CONSTRUCTOR;
 import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_BEAN_ACCESS_FAILED;
 import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_FAILED;
 import static org.jboss.weld.logging.messages.BeanMessage.SPECIALIZING_BEAN_MUST_EXTEND_A_BEAN;
@@ -40,6 +41,8 @@
 import javax.enterprise.context.Dependent;
 import javax.enterprise.context.NormalScope;
 import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Disposes;
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.Decorator;
 import javax.enterprise.inject.spi.InjectionPoint;
@@ -63,6 +66,7 @@
 import org.jboss.weld.context.SerializableContextualImpl;
 import org.jboss.weld.context.SerializableContextualInstanceImpl;
 import org.jboss.weld.ejb.EJBApiAbstraction;
+import org.jboss.weld.injection.ConstructorInjectionPoint;
 import org.jboss.weld.injection.FieldInjectionPoint;
 import org.jboss.weld.injection.MethodInjectionPoint;
 import org.jboss.weld.introspector.WeldClass;
@@ -74,7 +78,6 @@
 import org.jboss.weld.util.Proxies;
 import org.jboss.weld.util.Strings;
 import org.jboss.weld.util.Proxies.TypeInfo;
-import org.jboss.weld.util.reflection.Reflections;
 import org.jboss.weld.util.reflection.SecureReflections;
 import org.slf4j.cal10n.LocLogger;
 
@@ -116,6 +119,8 @@
    // Injection target for the bean
    private InjectionTarget<T> injectionTarget;
 
+   private ConstructorInjectionPoint<T> constructor;
+
    /**
     * Constructor
     * 
@@ -168,6 +173,7 @@
       }
    }
 
+   @Override
    public void checkType()
    {
       
@@ -625,5 +631,37 @@
       }
    }
 
+   protected void checkConstructor()
+   {
+      if (!constructor.getAnnotatedWBParameters(Disposes.class).isEmpty())
+      {
+         throw new DefinitionException(PARAMETER_ANNOTATION_NOT_ALLOWED_ON_CONSTRUCTOR, "@Disposes", constructor);
+      }
+      if (!constructor.getAnnotatedWBParameters(Observes.class).isEmpty())
+      {
+         throw new DefinitionException(PARAMETER_ANNOTATION_NOT_ALLOWED_ON_CONSTRUCTOR, "@Observes", constructor);
+      }
+   }
 
+   /**
+    * Initializes the constructor
+    */
+   protected void initConstructor()
+   {
+      this.constructor = Beans.getBeanConstructor(this, getAnnotatedItem());
+      // TODO We loop unecessarily many times here, I want to probably introduce some callback mechanism. PLM.
+      addInjectionPoints(Beans.getParameterInjectionPoints(this, constructor));
+   }
+
+   /**
+    * Returns the constructor
+    *
+    * @return The constructor
+    */
+   public ConstructorInjectionPoint<T> getConstructor()
+   {
+      return constructor;
+   }
+
+
 }

Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java	2010-01-07 13:42:35 UTC (rev 5389)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java	2010-01-07 14:10:21 UTC (rev 5390)
@@ -24,7 +24,6 @@
 import static org.jboss.weld.logging.messages.BeanMessage.FINAL_BEAN_CLASS_WITH_DECORATORS_NOT_ALLOWED;
 import static org.jboss.weld.logging.messages.BeanMessage.FINAL_DECORATED_BEAN_METHOD_NOT_ALLOWED;
 import static org.jboss.weld.logging.messages.BeanMessage.NON_CONTAINER_DECORATOR;
-import static org.jboss.weld.logging.messages.BeanMessage.PARAMETER_ANNOTATION_NOT_ALLOWED_ON_CONSTRUCTOR;
 import static org.jboss.weld.logging.messages.BeanMessage.PASSIVATING_BEAN_NEEDS_SERIALIZABLE_IMPL;
 import static org.jboss.weld.logging.messages.BeanMessage.PUBLIC_FIELD_ON_NORMAL_SCOPED_BEAN_NOT_ALLOWED;
 import static org.jboss.weld.logging.messages.BeanMessage.SIMPLE_BEAN_AS_NON_STATIC_INNER_CLASS_NOT_ALLOWED;
@@ -36,8 +35,6 @@
 
 import javax.enterprise.context.Dependent;
 import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.Disposes;
 import javax.enterprise.inject.spi.Decorator;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.InjectionTarget;
@@ -56,7 +53,6 @@
 import org.jboss.weld.bean.interceptor.CdiInterceptorHandlerFactory;
 import org.jboss.weld.bean.interceptor.ClassInterceptionHandlerFactory;
 import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
-import org.jboss.weld.injection.ConstructorInjectionPoint;
 import org.jboss.weld.injection.InjectionContextImpl;
 import org.jboss.weld.injection.WeldInjectionPoint;
 import org.jboss.weld.introspector.WeldClass;
@@ -84,9 +80,6 @@
    private static final LocLogger log = loggerFactory().getLogger(BEAN);
    private static final XLogger xLog = loggerFactory().getXLogger(BEAN);
 
-   // The constructor
-   private ConstructorInjectionPoint<T> constructor;
-   
    // The Java EE style injection points
    private Set<WeldInjectionPoint<?, ?>> ejbInjectionPoints;
    private Set<WeldInjectionPoint<?, ?>> persistenceContextInjectionPoints;
@@ -273,7 +266,7 @@
 
    protected T createInstance(CreationalContext<T> ctx) 
    {
-      return constructor.newInstance(manager, ctx);
+      return getConstructor().newInstance(manager, ctx);
    }
 
    @Override
@@ -425,18 +418,6 @@
       }
    }
 
-   protected void checkConstructor()
-   {
-      if (!constructor.getAnnotatedWBParameters(Disposes.class).isEmpty())
-      {
-         throw new DefinitionException(PARAMETER_ANNOTATION_NOT_ALLOWED_ON_CONSTRUCTOR, "@Disposes", constructor);
-      }
-      if (!constructor.getAnnotatedWBParameters(Observes.class).isEmpty())
-      {
-         throw new DefinitionException(PARAMETER_ANNOTATION_NOT_ALLOWED_ON_CONSTRUCTOR, "@Observes", constructor);
-      }
-   }
-
    @Override
    protected void preSpecialize(BeanDeployerEnvironment environment)
    {
@@ -466,26 +447,6 @@
 
 
    /**
-    * Initializes the constructor
-    */
-   protected void initConstructor()
-   {
-      this.constructor = Beans.getBeanConstructor(this, getAnnotatedItem());
-      // TODO We loop unecessarily many times here, I want to probably introduce some callback mechanism. PLM.
-      addInjectionPoints(Beans.getParameterInjectionPoints(this, constructor));
-   }
-
-   /**
-    * Returns the constructor
-    *
-    * @return The constructor
-    */
-   public ConstructorInjectionPoint<T> getConstructor()
-   {
-      return constructor;
-   }
-
-   /**
     * Gets a string representation
     *
     * @return The string representation

Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/SessionBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/SessionBean.java	2010-01-07 13:42:35 UTC (rev 5389)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/SessionBean.java	2010-01-07 14:10:21 UTC (rev 5390)
@@ -125,6 +125,7 @@
       this.ejbDescriptor = ejbDescriptor;
       initTypes();
       initBindings();
+      initConstructor();
    }
 
    /**
@@ -135,6 +136,7 @@
    {
       if (!isInitialized())
       {
+         checkConstructor();
          super.initialize(environment);
          initProxyClass();
          checkEJBTypeAllowed();
@@ -180,29 +182,17 @@
 
             public T produce(CreationalContext<T> ctx)
             {
-               try
-               {
-                  T instance = SecureReflections.newInstance(proxyClass);
-                  ctx.push(instance);
-                  return Proxies.attachMethodHandler(instance, new EnterpriseBeanProxyMethodHandler<T>(SessionBean.this, ctx));
-               }
-               catch (InstantiationException e)
-               {
-                  throw new WeldException(PROXY_INSTANTIATION_FAILED, e, this);
-               }
-               catch (IllegalAccessException e)
-               {
-                  throw new WeldException(PROXY_INSTANTIATION_BEAN_ACCESS_FAILED, e, this);
-               }
-               catch (Exception e)
-               {
-                  throw new CreationException(EJB_NOT_FOUND, e, proxyClass);
-               }
+               return SessionBean.this.createInstance(ctx);
             }
             
          });
       }
    }
+   
+   protected T createInstance(CreationalContext<T> ctx) 
+   {
+      return getConstructor().newInstance(manager, ctx);
+   }
 
    @Override
    protected void initTypes()
@@ -299,12 +289,30 @@
     */
    public T create(final CreationalContext<T> creationalContext)
    {
-      T instance = getInjectionTarget().produce(creationalContext);
-      if (hasDecorators())
+      try
       {
-         instance = applyDecorators(instance, creationalContext, null);
+         T instance = SecureReflections.newInstance(proxyClass);
+         creationalContext.push(instance);
+         Proxies.attachMethodHandler(instance, new EnterpriseBeanProxyMethodHandler<T>(SessionBean.this, creationalContext));
+         if (hasDecorators())
+         {
+            instance = applyDecorators(instance, creationalContext, null);
+         }
+         return instance;
       }
-      return instance;
+      catch (InstantiationException e)
+      {
+         throw new WeldException(PROXY_INSTANTIATION_FAILED, e, this);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new WeldException(PROXY_INSTANTIATION_BEAN_ACCESS_FAILED, e, this);
+      }
+      catch (Exception e)
+      {
+         throw new CreationException(EJB_NOT_FOUND, e, proxyClass);
+      }
+      
    }
 
    public void destroy(T instance, CreationalContext<T> creationalContext)



More information about the weld-commits mailing list