openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r936384 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/context/ main/java/org/apache/webbeans/context/creational/ main/java/org/apache/webbeans/intercept/ test/java/org/apache/webbeans/newtests/interceptors/inheri...
Date Wed, 21 Apr 2010 16:14:58 GMT
Author: gerdogdu
Date: Wed Apr 21 16:14:57 2010
New Revision: 936384

URL: http://svn.apache.org/viewvc?rev=936384&view=rev
Log:
[OWB-351,OWB-359] Removing creational context from InterceptorHandler.

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/BeanInstanceBag.java
  (with props)
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ApplicationContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ConversationContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/RequestContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/SessionContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/SingletonContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/WebBeansContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanIntereptorHandler.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorDataImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/inheritance/InheritedInterceptorTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java?rev=936384&r1=936383&r2=936384&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java
Wed Apr 21 16:14:57 2010
@@ -18,7 +18,6 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
 import javax.enterprise.context.ApplicationScoped;
@@ -31,6 +30,7 @@ import javax.enterprise.context.spi.Cont
 import javax.enterprise.context.spi.Contextual;
 import javax.enterprise.context.spi.CreationalContext;
 
+import org.apache.webbeans.context.creational.BeanInstanceBag;
 import org.apache.webbeans.context.type.ContextTypes;
 import org.apache.webbeans.util.Asserts;
 
@@ -53,16 +53,11 @@ public abstract class AbstractContext im
     protected ContextTypes type;
 
     /**Context contextual instances*/
-    protected Map<Contextual<?>, Object> componentInstanceMap = null;
+    protected Map<Contextual<?>, BeanInstanceBag<?>> componentInstanceMap
= null;
 
     /**Contextual Scope Type*/
     protected Class<? extends Annotation> scopeType;
     
-    /**Contextual to CreationalContext Map*/
-    protected final ConcurrentMap<Contextual<?>, CreationalContext<?>>
creationalContextMap = 
-        new ConcurrentHashMap<Contextual<?>, CreationalContext<?>>();
-       
-
     /**
      * Creates a new context instance
      */
@@ -70,7 +65,33 @@ public abstract class AbstractContext im
     {
 
     }
+    
 
+    public <T> void initContextualBag(Contextual<T> contextual, CreationalContext<T>
creationalContext)
+    {
+        createContextualBag(contextual, creationalContext);
+    }
+
+    @SuppressWarnings("unchecked")
+    private <T> void createContextualBag(Contextual<T> contextual, CreationalContext<T>
creationalContext)
+    {
+        BeanInstanceBag<T> bag = new BeanInstanceBag<T>(creationalContext);
+        
+        if(this.componentInstanceMap instanceof ConcurrentMap)
+        {
+            T exist = (T) ((ConcurrentMap) this.componentInstanceMap).putIfAbsent(contextual,
bag);
+            //no instance
+            if(exist == null)
+            {
+                this.componentInstanceMap.put(contextual, bag);
+            }
+        }
+        else
+        {
+            this.componentInstanceMap.put(contextual , bag);
+        }                
+    }
+    
     /**
      * Creates a new context with given scope type.
      * 
@@ -132,6 +153,8 @@ public abstract class AbstractContext im
         }
 
     }
+    
+    
 
     /**
      * {@inheritDoc}
@@ -141,28 +164,41 @@ public abstract class AbstractContext im
     {
         checkActive();
         
-        return (T) componentInstanceMap.get(component);
+        if(componentInstanceMap.get(component) != null)
+        {
+            return (T) componentInstanceMap.get(component).getBeanInstance();    
+        }
+        
+        return null;
     }
 
     /**
      * {@inheritDoc}
      */
-    public <T> T get(Contextual<T> component, CreationalContext<T> creationalContext)
+    public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext)
     {
         checkActive();
         
-        return getInstance(component, creationalContext);
+        return getInstance(contextual, creationalContext);
     }
 
     /**
      * {@inheritDoc} 
      */
     @SuppressWarnings("unchecked")
-    protected <T> T getInstance(Contextual<T> component, CreationalContext<T>
creationalContext)
+    protected <T> T getInstance(Contextual<T> contextual, CreationalContext<T>
creationalContext)
     {
-        T instance = (T)componentInstanceMap.get(component);
-
+        T instance = null;
         
+        //Look for bag
+        BeanInstanceBag<T> bag = (BeanInstanceBag<T>)componentInstanceMap.get(contextual);
       
+        if(bag == null)
+        {
+            createContextualBag(contextual, creationalContext);
+        }
+        
+        //Look for instance
+        instance = (T)componentInstanceMap.get(contextual).getBeanInstance();        
         if (instance != null)
         {
             return instance;
@@ -180,27 +216,14 @@ public abstract class AbstractContext im
                 //No instance
                 if(instance == null)
                 {
-                    instance = component.create(creationalContext);    
+                    instance = contextual.create(creationalContext);    
                 }
                 
-
+                //If succesfull creation
                 if (instance != null)
                 {
-                    if(this.componentInstanceMap instanceof ConcurrentMap)
-                    {
-                        T exist = (T) ((ConcurrentMap) this.componentInstanceMap).putIfAbsent(component,
instance);
-                        //no instance
-                        if(exist == null)
-                        {
-                            this.componentInstanceMap.put(component, instance);
-                        }
-                    }
-                    else
-                    {
-                        this.componentInstanceMap.put(component, instance);
-                    }
-                                           
-                    this.creationalContextMap.putIfAbsent(component, creationalContext);
+                    bag = (BeanInstanceBag<T>)this.componentInstanceMap.get(contextual);
+                    bag.setBeanInstance(instance);
                 }
                 
             }            
@@ -216,9 +239,9 @@ public abstract class AbstractContext im
     public <T> CreationalContext<T> getCreationalContext(Contextual<T>
contextual)
     {
         Asserts.assertNotNull(contextual);
-        if(this.creationalContextMap.containsKey(contextual))
+        if(this.componentInstanceMap.containsKey(contextual))
         {
-            return (CreationalContext<T>)this.creationalContextMap.get(contextual);
+            return (CreationalContext<T>)this.componentInstanceMap.get(contextual).getBeanCreationalContext();
         }
         
         return null;
@@ -243,27 +266,24 @@ public abstract class AbstractContext im
     @SuppressWarnings("unchecked")
     public void destroy()
     {
-        Set<Entry<Contextual<?>, Object>> entrySet = componentInstanceMap.entrySet();
-        Iterator<Entry<Contextual<?>, Object>> it = entrySet.iterator();
+        Set<Entry<Contextual<?>, BeanInstanceBag<?>>> entrySet =
componentInstanceMap.entrySet();
+        Iterator<Entry<Contextual<?>, BeanInstanceBag<?>>> it = entrySet.iterator();
 
-        Contextual<?> component = null;
+        Contextual<?> contextual = null;
         while (it.hasNext())
         {
-            component = it.next().getKey();
+            contextual = it.next().getKey();
             
-            Object instance = componentInstanceMap.get(component);
+            BeanInstanceBag<?> instance = componentInstanceMap.get(contextual);
             //Get creational context
-            CreationalContext<Object> cc = (CreationalContext<Object>)this.creationalContextMap.get(component);
+            CreationalContext<Object> cc = (CreationalContext<Object>)instance.getBeanCreationalContext();
 
             //Destroy instance
-            destroyInstance((Contextual<Object>) component, instance, cc);
+            destroyInstance((Contextual<Object>) contextual, instance.getBeanInstance(),
cc);
         }
         
-        //Clear cache
-        this.componentInstanceMap.clear();
-        //Clear creational context map
-        this.creationalContextMap.clear();
-        
+        //Clear context map
+        this.componentInstanceMap.clear();        
     }
 
     /**
@@ -300,7 +320,7 @@ public abstract class AbstractContext im
     /**
      * {@inheritDoc}
      */
-    public Map<Contextual<?>, Object> getComponentInstanceMap()
+    public Map<Contextual<?>, BeanInstanceBag<?>> getComponentInstanceMap()
     {
         return componentInstanceMap;
     }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ApplicationContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ApplicationContext.java?rev=936384&r1=936383&r2=936384&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ApplicationContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ApplicationContext.java
Wed Apr 21 16:14:57 2010
@@ -17,6 +17,7 @@ import java.util.concurrent.ConcurrentHa
 
 import javax.enterprise.context.spi.Contextual;
 
+import org.apache.webbeans.context.creational.BeanInstanceBag;
 import org.apache.webbeans.context.type.ContextTypes;
 
 /**
@@ -33,7 +34,7 @@ public class ApplicationContext extends 
     @Override
     public void setComponentInstanceMap()
     {
-        this.componentInstanceMap = new ConcurrentHashMap<Contextual<?>, Object>();
+        this.componentInstanceMap = new ConcurrentHashMap<Contextual<?>, BeanInstanceBag<?>>();
 
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ConversationContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ConversationContext.java?rev=936384&r1=936383&r2=936384&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ConversationContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/ConversationContext.java
Wed Apr 21 16:14:57 2010
@@ -17,6 +17,7 @@ import java.util.concurrent.ConcurrentHa
 
 import javax.enterprise.context.spi.Contextual;
 
+import org.apache.webbeans.context.creational.BeanInstanceBag;
 import org.apache.webbeans.context.type.ContextTypes;
 
 /**
@@ -35,7 +36,7 @@ public class ConversationContext extends
     @Override
     public void setComponentInstanceMap()
     {
-        this.componentInstanceMap = new ConcurrentHashMap<Contextual<?>, Object>();
+        this.componentInstanceMap = new ConcurrentHashMap<Contextual<?>, BeanInstanceBag<?>>();
     }
 
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/RequestContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/RequestContext.java?rev=936384&r1=936383&r2=936384&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/RequestContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/RequestContext.java
Wed Apr 21 16:14:57 2010
@@ -17,6 +17,7 @@ import java.util.concurrent.ConcurrentHa
 
 import javax.enterprise.context.spi.Contextual;
 
+import org.apache.webbeans.context.creational.BeanInstanceBag;
 import org.apache.webbeans.context.type.ContextTypes;
 
 /**
@@ -38,7 +39,7 @@ public class RequestContext extends Abst
     @Override
     public void setComponentInstanceMap()
     {
-        this.componentInstanceMap = new ConcurrentHashMap<Contextual<?>, Object>();
+        this.componentInstanceMap = new ConcurrentHashMap<Contextual<?>, BeanInstanceBag<?>>();
 
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/SessionContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/SessionContext.java?rev=936384&r1=936383&r2=936384&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/SessionContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/SessionContext.java
Wed Apr 21 16:14:57 2010
@@ -18,6 +18,7 @@ import java.util.concurrent.ConcurrentHa
 
 import javax.enterprise.context.spi.Contextual;
 
+import org.apache.webbeans.context.creational.BeanInstanceBag;
 import org.apache.webbeans.context.type.ContextTypes;
 
 /**
@@ -35,7 +36,7 @@ public class SessionContext extends Abst
     @Override
     public void setComponentInstanceMap()
     {
-        this.componentInstanceMap = new ConcurrentHashMap<Contextual<?>, Object>();
+        this.componentInstanceMap = new ConcurrentHashMap<Contextual<?>, BeanInstanceBag<?>>();
 
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/SingletonContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/SingletonContext.java?rev=936384&r1=936383&r2=936384&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/SingletonContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/SingletonContext.java
Wed Apr 21 16:14:57 2010
@@ -17,6 +17,7 @@ import java.util.concurrent.ConcurrentHa
 
 import javax.enterprise.context.spi.Contextual;
 
+import org.apache.webbeans.context.creational.BeanInstanceBag;
 import org.apache.webbeans.context.type.ContextTypes;
 
 /**
@@ -33,6 +34,6 @@ public class SingletonContext extends Ab
     @Override
     public void setComponentInstanceMap()
     {
-        this.componentInstanceMap = new ConcurrentHashMap<Contextual<?>, Object>();
+        this.componentInstanceMap = new ConcurrentHashMap<Contextual<?>, BeanInstanceBag<?>>();
     }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/WebBeansContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/WebBeansContext.java?rev=936384&r1=936383&r2=936384&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/WebBeansContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/WebBeansContext.java
Wed Apr 21 16:14:57 2010
@@ -16,7 +16,9 @@ package org.apache.webbeans.context;
 import java.util.Map;
 
 import javax.enterprise.context.spi.Contextual;
+import javax.enterprise.context.spi.CreationalContext;
 
+import org.apache.webbeans.context.creational.BeanInstanceBag;
 import org.apache.webbeans.context.type.ContextTypes;
 
 
@@ -26,7 +28,20 @@ import org.apache.webbeans.context.type.
  * @version $Rev$ $Date$
  */
 public interface WebBeansContext extends javax.enterprise.context.spi.Context
-{        
+{   
+    /**
+     * Initializes this contextual bag with
+     * given creational context.
+     * <p>
+     * Given creational context is used fot creating the
+     * bean instance.
+     * </p>
+     * @param <T> type
+     * @param contextual contextual bean
+     * @param creationalContext creational context
+     */
+    public <T> void initContextualBag(Contextual<T> contextual, CreationalContext<T>
creationalContext);
+    
     /**
      * Destroys the context.
      */
@@ -44,5 +59,13 @@ public interface WebBeansContext extends
      * 
      * @return instance map
      */
-    public Map<Contextual<?>, Object> getComponentInstanceMap();
+    public Map<Contextual<?>, BeanInstanceBag<?>> getComponentInstanceMap();
+    
+    /**
+     * Gets creational context of the given bean.
+     * @param <T> type
+     * @param contextual contextual bean
+     * @return creational context of the given bean
+     */
+    public <T> CreationalContext<T> getCreationalContext(Contextual<T>
contextual);
 }
\ No newline at end of file

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/BeanInstanceBag.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/BeanInstanceBag.java?rev=936384&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/BeanInstanceBag.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/BeanInstanceBag.java
Wed Apr 21 16:14:57 2010
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.context.creational;
+
+import javax.enterprise.context.spi.CreationalContext;
+
+public class BeanInstanceBag<T>
+{
+    private final CreationalContext<T> beanCreationalContext;
+    
+    private volatile T beanInstance;
+    
+    public BeanInstanceBag(CreationalContext<T> beanCreationalContext)
+    {
+        this.beanCreationalContext = beanCreationalContext;
+    }
+
+    /**
+     * @return the beanCreationalContext
+     */
+    public CreationalContext<T> getBeanCreationalContext()
+    {
+        return beanCreationalContext;
+    }
+    
+    
+
+    /**
+     * @param beanInstance the beanInstance to set
+     */
+    public void setBeanInstance(T beanInstance)
+    {
+        this.beanInstance = beanInstance;
+    }
+
+    /**
+     * @return the beanInstance
+     */
+    public T getBeanInstance()
+    {
+        return beanInstance;
+    }
+
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/BeanInstanceBag.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanIntereptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanIntereptorHandler.java?rev=936384&r1=936383&r2=936384&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanIntereptorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanIntereptorHandler.java
Wed Apr 21 16:14:57 2010
@@ -56,7 +56,7 @@ public class ApplicationScopedBeanIntere
     {
         if (cachedInstance == null) 
         {
-            cachedInstance = super.getContextualInstance(bean);
+            cachedInstance = super.getContextualInstance();
         }
         
         return cachedInstance;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorDataImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorDataImpl.java?rev=936384&r1=936383&r2=936384&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorDataImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorDataImpl.java
Wed Apr 21 16:14:57 2010
@@ -305,6 +305,10 @@ public class InterceptorDataImpl impleme
                 return this.decoratorInterceptor; 
             }
             
+            if(ownerCreationalContext == null)
+            {
+                System.out.println("Null");
+            }
             interceptor = ownerCreationalContext.getDependentInterceptor(ownerInstance,this.webBeansInterceptor);
             //There is no define interceptor, define and add it into dependent
             if(interceptor == null)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java?rev=936384&r1=936383&r2=936384&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
Wed Apr 21 16:14:57 2010
@@ -147,9 +147,6 @@ public abstract class InterceptorHandler
     /**Intercepted methods*/
     protected transient Map<Method, List<InterceptorData>> interceptedMethodMap
= new WeakHashMap<Method, List<InterceptorData>>();
     
-    /**Delegate handler*/
-    protected transient DelegateHandler delegateHandler;
-
     /**
      * Creates a new handler.
      * @param bean proxied bean
@@ -188,7 +185,7 @@ public abstract class InterceptorHandler
             else if (bean instanceof InjectionTargetBean<?>)
             {
                 InjectionTargetBean<?> injectionTarget = (InjectionTargetBean<?>)
this.bean;
-
+                DelegateHandler delegateHandler = null;
                 //Check method is business method
                 if (InterceptorUtil.isWebBeansBusinessMethod(method))
                 {
@@ -203,13 +200,13 @@ public abstract class InterceptorHandler
                             JavassistProxyFactory.getInterceptorProxyClasses().put(bean,
proxyClass);
                         }
                         Object delegate = proxyClass.newInstance();
-                        this.delegateHandler = new DelegateHandler(this.bean);
-                        ((ProxyObject)delegate).setHandler(this.delegateHandler);
+                        delegateHandler = new DelegateHandler(this.bean);
+                        ((ProxyObject)delegate).setHandler(delegateHandler);
 
                         // Gets component decorator stack
                         decorators = WebBeansDecoratorConfig.getDecoratorStack(injectionTarget,
instance, delegate, ownerCreationalContext);                        
                         //Sets decorator stack of delegate
-                        this.delegateHandler.setDecorators(decorators);
+                        delegateHandler.setDecorators(decorators);
                         
                     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java?rev=936384&r1=936383&r2=936384&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java
Wed Apr 21 16:14:57 2010
@@ -18,7 +18,6 @@
  */
 package org.apache.webbeans.intercept;
 
-import java.lang.ref.WeakReference;
 import java.lang.reflect.Method;
 import java.util.List;
 
@@ -43,9 +42,6 @@ public class NormalScopedBeanInterceptor
     /**Serial id*/
     private static final long serialVersionUID = 1L;
     
-    /**Creational context*/
-    private transient WeakReference<CreationalContext<?>> creationalContext =
null;
-
     /**
      * Creates a new bean instance
      * @param bean bean 
@@ -53,8 +49,20 @@ public class NormalScopedBeanInterceptor
      */
     public NormalScopedBeanInterceptorHandler(OwbBean<?> bean, CreationalContext<?>
creationalContext)
     {
-        super(bean);
-        this.creationalContext = new WeakReference<CreationalContext<?>>(creationalContext);
+        super(bean);    
+        
+        //Initiate bean for saving creational context instance
+        initiateBeanBag((OwbBean<Object>)bean, (CreationalContext<Object>)creationalContext);
+    }
+    
+    private void initiateBeanBag(OwbBean<Object> bean, CreationalContext<Object>
creationalContext)
+    {
+        Context webbeansContext = getBeanManager().getContext(bean.getScope());
+        if (webbeansContext instanceof AbstractContext)
+        {
+            AbstractContext owbContext = (AbstractContext)webbeansContext;
+            owbContext.initContextualBag(bean, creationalContext);
+        }
     }
     
     /**
@@ -64,10 +72,10 @@ public class NormalScopedBeanInterceptor
     public Object invoke(Object instance, Method method, Method proceed, Object[] arguments)
throws Exception
     {
         //Get instance from context
-        Object webbeansInstance = getContextualInstance((OwbBean<Object>) this.bean);
+        Object webbeansInstance = getContextualInstance();
         
         //Call super
-        return super.invoke(webbeansInstance, method, proceed, arguments, (CreationalContextImpl<?>)
this.creationalContext.get());
+        return super.invoke(webbeansInstance, method, proceed, arguments, (CreationalContextImpl<?>)
getContextualCreationalContext());
     }
         
     /**
@@ -75,9 +83,9 @@ public class NormalScopedBeanInterceptor
      */
     protected Object callAroundInvokes(Method proceed, Object[] arguments, List<InterceptorData>
stack) throws Exception
     {
-        InvocationContextImpl impl = new InvocationContextImpl(this.bean, getContextualInstance((OwbBean<Object>)
this.bean),
+        InvocationContextImpl impl = new InvocationContextImpl(this.bean, getContextualInstance(),
                                                                proceed, arguments, stack,
InterceptorType.AROUND_INVOKE);
-        impl.setCreationalContext(creationalContext.get());
+        impl.setCreationalContext(getContextualCreationalContext());
 
         return impl.proceed();
 
@@ -89,38 +97,53 @@ public class NormalScopedBeanInterceptor
      * @param bean bean instance
      * @return the underlying contextual instance, either cached or resolved from the context

      */
-    protected Object getContextualInstance(OwbBean<Object> bean)
+    protected Object getContextualInstance()
     {
         Object webbeansInstance = null;
-        
+
         //Context of the bean
-        Context webbeansContext = getBeanManager().getContext(bean.getScope());
+        Context webbeansContext = getBeanManager().getContext(this.bean.getScope());
         
         //Already saved in context?
-        webbeansInstance=webbeansContext.get(bean);
+        webbeansInstance=webbeansContext.get(this.bean);
         if (webbeansInstance != null)
         {
             // voila, we are finished if we found an existing contextual instance
             return webbeansInstance;
         }
+        else
+        {
+            // finally, we create a new contextual instance
+            webbeansInstance = webbeansContext.get((Contextual<Object>)this.bean, getContextualCreationalContext());
  
+        }
+                
+        return webbeansInstance;
+    }
+    
+    protected CreationalContext<Object> getContextualCreationalContext()
+    {
+        CreationalContext<Object> creationalContext = null;
         
+        OwbBean<Object> contextual = (OwbBean<Object>)this.bean;
+        //Context of the bean
+        Context webbeansContext = getBeanManager().getContext(bean.getScope());
         if (webbeansContext instanceof AbstractContext)
         {
-            CreationalContext<?> cc = ((AbstractContext)webbeansContext).getCreationalContext(bean);
-            if (cc != null)
+            AbstractContext owbContext = (AbstractContext)webbeansContext;
+            creationalContext = owbContext.getCreationalContext(contextual);
+
+            //No creational context means that no BeanInstanceBag
+            //Actually this can be occurs like scenarions
+            //@SessionScoped bean injected into @ApplicationScopedBean
+            //And session is destroyed and restarted but proxy still
+            //contained in @ApplicationScopedBean
+            if(creationalContext == null)
             {
-                creationalContext = new WeakReference<CreationalContext<?>>(cc);
-            }
-        }
-        if ((creationalContext == null) || creationalContext.get() == null)
-        {
-            // if there was no CreationalContext set from external, we create a new one
-            creationalContext = new WeakReference<CreationalContext<?>>(CreationalContextFactory.getInstance().getCreationalContext(bean));
+                creationalContext = CreationalContextFactory.getInstance().getCreationalContext(contextual);
+                owbContext.initContextualBag((OwbBean<Object>)this.bean, creationalContext);
+            }            
         }
-        
-        // finally, we create a new contextual instance
-        webbeansInstance = webbeansContext.get((Contextual<Object>)this.bean, (CreationalContext<Object>)
creationalContext.get());
-        
-        return webbeansInstance;
+                
+        return creationalContext;
     }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/inheritance/InheritedInterceptorTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/inheritance/InheritedInterceptorTest.java?rev=936384&r1=936383&r2=936384&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/inheritance/InheritedInterceptorTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/inheritance/InheritedInterceptorTest.java
Wed Apr 21 16:14:57 2010
@@ -19,6 +19,7 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Set;
 
+import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.Bean;
 
 import junit.framework.Assert;
@@ -71,6 +72,34 @@ public class InheritedInterceptorTest ex
     public void tearDown() { 
         shutDownContainer();
     }
+    
+    @Test
+    public void testNormalScopeNoNewInstance()
+    {
+        do_testNormalScopeNoNewInstance();
+    }
+    
+    @Test
+    public void testLoopNormalScopeNoNewInstance()
+    {
+        for (int i = 0; i<100; i++) 
+        {
+            do_testNormalScopeNoNewInstance();
+        }
+    }
+     
+    public void do_testNormalScopeNoNewInstance() 
+    { 
+        for (Bean<?> bean : beans)
+        {
+            CreationalContext<?> cc = getBeanManager().createCreationalContext(null);
+
+            DeckType d1 = (DeckType) getBeanManager().getReference(bean, DeckType.class,
cc);
+            d1.shuffle();
+            // Can't reproduce in TC with this call
+            // cc.release();
+        }
+    }    
    
     @Test
     public void testStereotype()



Mime
View raw message