You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ar...@apache.org on 2013/01/14 08:48:23 UTC

svn commit: r1432821 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: component/AbstractInjectionTargetBean.java component/AbstractOwbBean.java component/InjectionTargetBean.java portable/creation/InjectionTargetProducer.java

Author: arne
Date: Mon Jan 14 07:48:22 2013
New Revision: 1432821

URL: http://svn.apache.org/viewvc?rev=1432821&view=rev
Log:
OWB-755: Removed postConstruct

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java?rev=1432821&r1=1432820&r2=1432821&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java Mon Jan 14 07:48:22 2013
@@ -114,25 +114,6 @@ public abstract class AbstractInjectionT
      */
     protected T createInstance(CreationalContext<T> creationalContext)
     {
-        T instance;
-
-        //Default creation phases
-        instance = createDefaultInstance(creationalContext);
-
-        return instance;
-    }
-
-    /**
-     * Returns bean instance.
-     * 
-     * @param creationalContext creational context
-     * @return bean instance
-     */
-    @SuppressWarnings("unchecked")
-    protected T createDefaultInstance(CreationalContext<T> creationalContext)
-    {
-        beforeConstructor();
-        
         //Create actual bean instance
         T instance = createComponentInstance(creationalContext);
         //For dependent instance checks
@@ -199,53 +180,6 @@ public abstract class AbstractInjectionT
     }
 
     /**
-     * Called before constructor.
-     */
-    protected void beforeConstructor()
-    {
-
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void postConstruct(T instance, CreationalContext<T> cretionalContext)
-    {
-        postConstructDefault(instance, cretionalContext);
-    }
-
-    /**
-     * Default post construct.
-     * 
-     * @param instance bean instance
-     */
-    protected void postConstructDefault(T instance, CreationalContext<T> ownerCreationalContext)
-    {
-        if(getWebBeansType().equals(WebBeansType.MANAGED))
-        {
-            // Call Post Construct
-            if (WebBeansUtil.isContainsInterceptorMethod(getInterceptorStack(), InterceptionType.POST_CONSTRUCT))
-            {
-                InvocationContextImpl impl = new InvocationContextImpl(getWebBeansContext(), null, instance, null, null,
-                        getWebBeansContext().getInterceptorUtil().getInterceptorMethods(getInterceptorStack(),
-                                                                                        InterceptionType.POST_CONSTRUCT),
-                                                                                        InterceptionType.POST_CONSTRUCT);
-                impl.setCreationalContext(ownerCreationalContext);
-                try
-                {
-                    impl.proceed();
-                }
-
-                catch (Exception e)
-                {
-                    getLogger().log(Level.SEVERE, WebBeansLoggerFacade.constructMessage(OWBLogConst.ERROR_0008, "@PostConstruct."), e);
-                    throw new WebBeansException(e);
-                }
-            }            
-        }        
-    }
-
-    /**
      * {@inheritDoc}
      */
     public void preDestroy(T instance, CreationalContext<T> creationalContext)
@@ -400,7 +334,4 @@ public abstract class AbstractInjectionT
             }
         }
     }    
-    
-    
-    
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java?rev=1432821&r1=1432820&r2=1432821&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java Mon Jan 14 07:48:22 2013
@@ -35,6 +35,7 @@ import javax.enterprise.inject.CreationE
 import javax.enterprise.inject.Disposes;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.InjectionTarget;
+import javax.enterprise.inject.spi.InterceptionType;
 import javax.enterprise.inject.spi.Producer;
 
 import org.apache.webbeans.config.OWBLogConst;
@@ -42,8 +43,11 @@ import org.apache.webbeans.config.WebBea
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.exception.WebBeansException;
+import org.apache.webbeans.intercept.InvocationContextImpl;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
 import org.apache.webbeans.portable.InjectionTargetImpl;
+import org.apache.webbeans.util.WebBeansUtil;
 
 /**
  * Abstract implementation of the {@link OwbBean} contract. 
@@ -169,9 +173,9 @@ public abstract class AbstractOwbBean<T>
             }
             else
             {
-                instance = createInstance(creationalContext); 
                 if(this instanceof AbstractInjectionTargetBean)
                 {
+                    instance = createInstance(creationalContext); 
                     AbstractInjectionTargetBean<T> injectionTargetBean = (AbstractInjectionTargetBean<T>)this;
                     //Inject resources
                     injectionTargetBean.injectResources(instance, creationalContext);
@@ -179,7 +183,32 @@ public abstract class AbstractOwbBean<T>
                     new InjectionTargetImpl<T>(injectionTargetBean.getAnnotatedType(), getInjectionPoints(), webBeansContext).inject(instance, creationalContext); 
                     
                     //Post construct
-                    injectionTargetBean.postConstruct(instance, creationalContext);
+                    if(getWebBeansType().equals(WebBeansType.MANAGED))
+                    {
+                        // Call Post Construct
+                        if (WebBeansUtil.isContainsInterceptorMethod(injectionTargetBean.getInterceptorStack(), InterceptionType.POST_CONSTRUCT))
+                        {
+                            InvocationContextImpl impl = new InvocationContextImpl(getWebBeansContext(), null, instance, null, null,
+                                    getWebBeansContext().getInterceptorUtil().getInterceptorMethods(injectionTargetBean.getInterceptorStack(),
+                                                                                                    InterceptionType.POST_CONSTRUCT),
+                                                                                                    InterceptionType.POST_CONSTRUCT);
+                            impl.setCreationalContext(creationalContext);
+                            try
+                            {
+                                impl.proceed();
+                            }
+
+                            catch (Exception e)
+                            {
+                                getLogger().log(Level.SEVERE, WebBeansLoggerFacade.constructMessage(OWBLogConst.ERROR_0008, "@PostConstruct."), e);
+                                throw new WebBeansException(e);
+                            }
+                        }            
+                    }        
+                }
+                else
+                {
+                    instance = createInstance(creationalContext);     
                 }
             }                                    
         }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java?rev=1432821&r1=1432820&r2=1432821&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java Mon Jan 14 07:48:22 2013
@@ -57,13 +57,6 @@ public interface InjectionTargetBean<T> 
     public List<Decorator<?>> getDecoratorStack();
 
     /**
-     * Calls post constrcut method.
-     * 
-     * @param instance bean instance
-     */
-    public void postConstruct(T instance, CreationalContext<T> creationalContext);
-    
-    /**
      * Calls predestroy method.
      * 
      * @param instance bean instance

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java?rev=1432821&r1=1432820&r2=1432821&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java Mon Jan 14 07:48:22 2013
@@ -18,17 +18,27 @@
  */
 package org.apache.webbeans.portable.creation;
 
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
 import javax.enterprise.context.Dependent;
 import javax.enterprise.context.spi.Contextual;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.InjectionTarget;
+import javax.enterprise.inject.spi.InterceptionType;
 
 import org.apache.webbeans.component.EnterpriseBeanMarker;
 import org.apache.webbeans.component.InjectionTargetBean;
+import org.apache.webbeans.component.WebBeansType;
+import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
+import org.apache.webbeans.exception.WebBeansException;
 import org.apache.webbeans.inject.AbstractInjectable;
+import org.apache.webbeans.intercept.InvocationContextImpl;
+import org.apache.webbeans.logger.WebBeansLoggerFacade;
 import org.apache.webbeans.portable.InjectionTargetImpl;
 import org.apache.webbeans.proxy.ProxyFactory;
+import org.apache.webbeans.util.WebBeansUtil;
 
 /**
  * InjectionTargetProducer implementation.
@@ -40,6 +50,8 @@ import org.apache.webbeans.proxy.ProxyFa
 @SuppressWarnings("unchecked")
 public class InjectionTargetProducer<T> extends AbstractProducer<T> implements InjectionTarget<T>
 {
+    private Logger logger;
+
     /**
      * Creates a new injection target producer.
      * @param bean injection target bean
@@ -117,7 +129,28 @@ public class InjectionTargetProducer<T> 
         InjectionTargetBean<T> bean = getBean(InjectionTargetBean.class);    
         if(!(bean instanceof EnterpriseBeanMarker))
         {
-            bean.postConstruct(instance, creationalContext);
+            if(bean.getWebBeansType().equals(WebBeansType.MANAGED))
+            {
+                // Call Post Construct
+                if (WebBeansUtil.isContainsInterceptorMethod(bean.getInterceptorStack(), InterceptionType.POST_CONSTRUCT))
+                {
+                    InvocationContextImpl impl = new InvocationContextImpl(bean.getWebBeansContext(), null, instance, null, null,
+                            bean.getWebBeansContext().getInterceptorUtil().getInterceptorMethods(bean.getInterceptorStack(),
+                                                                                            InterceptionType.POST_CONSTRUCT),
+                                                                                            InterceptionType.POST_CONSTRUCT);
+                    impl.setCreationalContext(creationalContext);
+                    try
+                    {
+                        impl.proceed();
+                    }
+
+                    catch (Exception e)
+                    {
+                        getLogger().log(Level.SEVERE, WebBeansLoggerFacade.constructMessage(OWBLogConst.ERROR_0008, "@PostConstruct."), e);
+                        throw new WebBeansException(e);
+                    }
+                }            
+            }        
         }
     }
 
@@ -130,4 +163,15 @@ public class InjectionTargetProducer<T> 
         bean.destroyCreatedInstance(instance, creationalContext);
     }
 
+    /**
+     * The Logger should really only be used to log errors!
+     */
+    protected synchronized Logger getLogger()
+    {
+        if (logger == null)
+        {
+            logger = WebBeansLoggerFacade.getLogger(getClass());
+        }
+        return logger;
+    }
 }