openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1467877 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: context/creational/CreationalContextImpl.java inject/instance/InstanceImpl.java intercept/NormalScopedBeanInterceptorHandler.java
Date Mon, 15 Apr 2013 07:19:11 GMT
Author: arne
Date: Mon Apr 15 07:19:11 2013
New Revision: 1467877

URL: http://svn.apache.org/r1467877
Log:
OWB-830: Implemented Instance#destroy

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java?rev=1467877&r1=1467876&r2=1467877&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
Mon Apr 15 07:19:11 2013
@@ -23,6 +23,7 @@ import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Stack;
 
@@ -135,7 +136,7 @@ public class CreationalContextImpl<T> im
     {
         //No-action
     }
-        
+     
     /**
      * Adds given dependent instance to the map.
      * 
@@ -181,6 +182,29 @@ public class CreationalContextImpl<T> im
         }
     }
 
+    public <X> void destroyDependent(X instance)
+    {
+        if (dependentObjects == null)
+        {
+            return;
+        }
+        synchronized (this)
+        {
+            for (Iterator<DependentCreationalContext<?>> i = dependentObjects.iterator();
i.hasNext();)
+            {
+                DependentCreationalContext<?> dependentContext = i.next();
+                if (dependentContext.getInstance() == instance)
+                {
+                    Contextual<X> dependentContextual = (Contextual<X>)dependentContext.getContextual();
+                    CreationalContext<X> creationalContext = (CreationalContext<X>)this;
+                    dependentContextual.destroy(instance, creationalContext);
+                    i.remove();
+                    break;
+                }
+            }
+        }
+    }
+
     @SuppressWarnings("unchecked")
     public void removeAllDependents()
     {

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=1467877&r1=1467876&r2=1467877&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
Mon Apr 15 07:19:11 2013
@@ -33,11 +33,14 @@ import javax.enterprise.inject.Instance;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.util.TypeLiteral;
+import javax.inject.Provider;
 
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.container.InjectionResolver;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
+import org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler;
+import org.apache.webbeans.proxy.OwbNormalScopeProxy;
 import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.InjectionExceptionUtil;
 import org.apache.webbeans.util.OwbCustomObjectInputStream;
@@ -66,7 +69,7 @@ public class InstanceImpl<T> implements 
     private WebBeansContext webBeansContext;
 
     private CreationalContextImpl<?> parentCreationalContext;
-
+    
     /**
      * Creates new instance.
      * 
@@ -279,6 +282,23 @@ public class InstanceImpl<T> implements 
         
         return instances.iterator();
     }
+
+    public void destroy(T instance)
+    {
+        if (instance instanceof OwbNormalScopeProxy)
+        {
+            OwbNormalScopeProxy proxy = (OwbNormalScopeProxy) instance;
+            Provider<T> provider = webBeansContext.getNormalScopeProxyFactory().getInstanceProvider(proxy);
+            NormalScopedBeanInterceptorHandler handler = (NormalScopedBeanInterceptorHandler)provider;
+            Bean<T> bean = (Bean<T>)handler.getBean();
+            CreationalContext<T> creationalContext = (CreationalContext<T>)parentCreationalContext;
+            bean.destroy(instance, creationalContext);
+        }
+        else
+        {
+            parentCreationalContext.destroyDependent(instance);
+        }
+    }
     
     private void writeObject(java.io.ObjectOutputStream op) throws IOException
     {
@@ -299,7 +319,6 @@ public class InstanceImpl<T> implements 
         injectionPoint = (InjectionPoint) inputStream.readObject();
     }
     
-
     public String toString()
     {
         StringBuilder builder = new StringBuilder();
@@ -323,5 +342,4 @@ public class InstanceImpl<T> implements 
 
         return builder.toString();
     }
-    
 }

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=1467877&r1=1467876&r2=1467877&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
Mon Apr 15 07:19:11 2013
@@ -70,6 +70,11 @@ public class NormalScopedBeanInterceptor
         return getContextualInstance();
     }
 
+    public Bean<?> getBean()
+    {
+        return bean;
+    }
+    
     protected BeanManager getBeanManager()
     {
         return beanManager;



Mime
View raw message