openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1591632 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: context/AbstractContext.java inject/instance/InstanceImpl.java
Date Thu, 01 May 2014 12:14:49 GMT
Author: arne
Date: Thu May  1 12:14:48 2014
New Revision: 1591632

URL: http://svn.apache.org/r1591632
Log:
OWB-951: Implemented AlterableContext

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.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=1591632&r1=1591631&r2=1591632&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
Thu May  1 12:14:48 2014
@@ -18,16 +18,20 @@
  */
 package org.apache.webbeans.context;
 
-import java.io.*;
+import java.io.IOException;
+import java.io.NotSerializableException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
 import java.lang.annotation.Annotation;
 import java.util.HashMap;
-import java.util.Iterator;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
-import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentMap;
 
 import javax.enterprise.context.ContextNotActiveException;
+import javax.enterprise.context.spi.AlterableContext;
 import javax.enterprise.context.spi.Context;
 import javax.enterprise.context.spi.Contextual;
 import javax.enterprise.context.spi.CreationalContext;
@@ -46,7 +50,7 @@ import org.apache.webbeans.context.creat
  * @see ApplicationContext
  * @see ConversationContext
  */
-public abstract class AbstractContext implements Context, Serializable
+public abstract class AbstractContext implements Context, AlterableContext, Serializable
 {
     private static final long serialVersionUID = 2357678967444477818L;
     /**Context status, active or not*/
@@ -58,10 +62,6 @@ public abstract class AbstractContext im
 
     /**Contextual Scope Type*/
     protected Class<? extends Annotation> scopeType;
-    
-
-
-
 
     @SuppressWarnings("unchecked")
     private <T> void createContextualBag(Contextual<T> contextual, CreationalContext<T>
creationalContext)
@@ -164,6 +164,21 @@ public abstract class AbstractContext im
         return  instance;
     }
 
+    @Override
+    public void destroy(Contextual<?> contextual) {
+        
+        BeanInstanceBag<?> instance = componentInstanceMap.get(contextual);
+        //Get creational context
+        CreationalContext<Object> cc = (CreationalContext<Object>)instance.getBeanCreationalContext();
+
+        //Destroy instance
+        final Object beanInstance = instance.getBeanInstance();
+        if (beanInstance != null)
+        {
+            destroyInstance((Contextual<Object>)contextual, beanInstance, cc);
+        }
+    }
+
     /**
      * Destroy the given web beans component instance.
      * 
@@ -171,40 +186,23 @@ public abstract class AbstractContext im
      * @param component web beans component
      * @param instance component instance
      */
-    private <T> void destroyInstance(Contextual<T> component, T instance,CreationalContext<T>
creationalContext)
+    private <T> void destroyInstance(Contextual<T> component, T instance, CreationalContext<T>
creationalContext)
     {
         //Destroy component
         component.destroy(instance,creationalContext);
+        componentInstanceMap.remove(component);
     }
     
     /**
      * {@inheritDoc}
      */
-    @SuppressWarnings("unchecked")
     public void destroy()
     {
-        Set<Entry<Contextual<?>, BeanInstanceBag<?>>> entrySet =
componentInstanceMap.entrySet();
-        Iterator<Entry<Contextual<?>, BeanInstanceBag<?>>> it = entrySet.iterator();
-
-        Contextual<?> contextual;
-        while (it.hasNext())
+        Set<Contextual<?>> keySet = new HashSet<Contextual<?>>(componentInstanceMap.keySet());
+        for (Contextual<?> contextual: keySet)
         {
-            contextual = it.next().getKey();
-            
-            BeanInstanceBag<?> instance = componentInstanceMap.get(contextual);
-            //Get creational context
-            CreationalContext<Object> cc = (CreationalContext<Object>)instance.getBeanCreationalContext();
-
-            //Destroy instance
-            final Object beanInstance = instance.getBeanInstance();
-            if (beanInstance != null)
-            {
-                destroyInstance((Contextual<Object>) contextual, beanInstance, cc);
-            }
+            destroy(contextual);
         }
-        
-        //Clear context map
-        componentInstanceMap.clear();
         setActive(false);
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java?rev=1591632&r1=1591631&r2=1591632&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java
Thu May  1 12:14:48 2014
@@ -30,6 +30,8 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
+import javax.enterprise.context.spi.AlterableContext;
+import javax.enterprise.context.spi.Context;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.Instance;
 import javax.enterprise.inject.spi.Bean;
@@ -288,7 +290,16 @@ public class InstanceImpl<T> implements 
             NormalScopedBeanInterceptorHandler handler = (NormalScopedBeanInterceptorHandler)provider;
             Bean<T> bean = (Bean<T>)handler.getBean();
             CreationalContext<T> creationalContext = (CreationalContext<T>)parentCreationalContext;
-            bean.destroy(instance, creationalContext);
+            Context currentContext = webBeansContext.getContextsService().getCurrentContext(bean.getScope());
+            if (currentContext instanceof AlterableContext)
+            {
+                AlterableContext alterableContext = (AlterableContext)currentContext;
+                alterableContext.destroy(bean);
+            }
+            else
+            {
+                bean.destroy(instance, creationalContext);
+            }
         }
         else
         {



Mime
View raw message