openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bergm...@apache.org
Subject svn commit: r1030782 - in /openwebbeans/branches/owb_1.0.x/webbeans-impl/src/main/java/org/apache/webbeans: component/ResourceBean.java proxy/JavassistProxyFactory.java
Date Thu, 04 Nov 2010 00:44:02 GMT
Author: bergmark
Date: Thu Nov  4 00:44:02 2010
New Revision: 1030782

URL: http://svn.apache.org/viewvc?rev=1030782&view=rev
Log:
Revert revision r1028219 build break in ResourceBean

Modified:
    openwebbeans/branches/owb_1.0.x/webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java
    openwebbeans/branches/owb_1.0.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java

Modified: openwebbeans/branches/owb_1.0.x/webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.0.x/webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java?rev=1030782&r1=1030781&r2=1030782&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.0.x/webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java
(original)
+++ openwebbeans/branches/owb_1.0.x/webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java
Thu Nov  4 00:44:02 2010
@@ -21,6 +21,8 @@ package org.apache.webbeans.component;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Modifier;
 
+import javassist.util.proxy.ProxyFactory;
+
 import javax.enterprise.context.spi.CreationalContext;
 
 import javassist.util.proxy.ProxyObject;
@@ -33,6 +35,8 @@ import org.apache.webbeans.spi.api.Resou
 
 public class ResourceBean<X, T extends Annotation> extends ProducerFieldBean<X>
 {
+    private X actualResourceReference = null;
+    
     private ResourceReference<X,T> resourceReference = null;
     
     public ResourceBean(Class<X> returnType, InjectionTargetBean<?> ownerBean,
@@ -51,38 +55,37 @@ public class ResourceBean<X, T extends A
         X instance = null;
         try
         {
+            //X TODO cache proxy class!
+            ProxyFactory proxyFactory = JavassistProxyFactory.getInstance().createProxyFactory(this);
+            
             ResourceInjectionService resourceService = ServiceLoader.getService(ResourceInjectionService.class);
-            instance = resourceService.getResourceReference(this.resourceReference);
+            this.actualResourceReference = resourceService.getResourceReference(this.resourceReference);
 
-            if (instance != null && Modifier.isFinal(instance.getClass().getModifiers()))
-            {
-                return instance;
-            }
-            
-            instance = (X) JavassistProxyFactory.getInstance().getResourceBeanProxyClass(this).newInstance();
-            ((ProxyObject) instance).setHandler(new ResourceProxyHandler(this,instance));
+            instance = (X)(JavassistProxyFactory.getInstance().getProxyClass(proxyFactory).newInstance());
+            ((ProxyObject)instance).setHandler(new ResourceProxyHandler(this.actualResourceReference));
         }
         catch (Exception e)
         {
+            //check type is final
+            //return actual resource
+            if(Modifier.isFinal(this.actualResourceReference.getClass().getModifiers()))
+            {
+                return this.actualResourceReference;
+            }
+            
             throw new WebBeansException(e);
         }
-
+        
         return instance;
     }
 
-    /**
-     * Called after deserialization to get a new instance for some type of resource bean
instance that are
-     * not serializable.
-     * 
-     * @return a new instance of this resource bean.
-     */
-    public X getActualInstance() 
+    @Override
+    protected void destroyInstance(X instance, CreationalContext<X> creationalContext)
     {
-        ResourceInjectionService resourceService = ServiceLoader.getService(ResourceInjectionService.class);
-        X instance = resourceService.getResourceReference(this.resourceReference);
-        return instance;
+        this.actualResourceReference = null;
     }
-    
+
+
     public boolean isPassivationCapable()
     {
         return true;

Modified: openwebbeans/branches/owb_1.0.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.0.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java?rev=1030782&r1=1030781&r2=1030782&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.0.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java
(original)
+++ openwebbeans/branches/owb_1.0.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java
Thu Nov  4 00:44:02 2010
@@ -40,7 +40,6 @@ import javax.enterprise.inject.spi.Decor
 import org.apache.webbeans.annotation.WebBeansAnnotation;
 import org.apache.webbeans.component.InjectionTargetBean;
 import org.apache.webbeans.component.OwbBean;
-import org.apache.webbeans.component.ResourceBean;
 import org.apache.webbeans.config.WebBeansFinder;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.decorator.WebBeansDecorator;
@@ -62,8 +61,7 @@ public final class JavassistProxyFactory
     
     private ConcurrentMap<OwbBean<?>, Class<?>> normalScopedBeanProxyClasses
= new ConcurrentHashMap<OwbBean<?>, Class<?>>();    
     private ConcurrentMap<OwbBean<?>, Class<?>> dependentScopedBeanProxyClasses
= new ConcurrentHashMap<OwbBean<?>, Class<?>>();    
-    private ConcurrentMap<OwbBean<?>, Class<?>> interceptorProxyClasses
= new ConcurrentHashMap<OwbBean<?>, Class<?>>();
-    private ConcurrentMap<ResourceBean<?, ?>, Class<?>> resourceBeanProxyClasses
= new ConcurrentHashMap<ResourceBean<?,?>, Class<?>>();
+    private ConcurrentMap<OwbBean<?>, Class<?>> interceptorProxyClasses
= new ConcurrentHashMap<OwbBean<?>, Class<?>>();    
     // second level map is indexed on local interface
     private ConcurrentMap<OwbBean<?>, ConcurrentMap<Class<?>, Class<?>>>
ejbProxyClasses = new ConcurrentHashMap<OwbBean<?>, ConcurrentMap<Class<?>,
Class<?>>>();    
     
@@ -102,32 +100,6 @@ public final class JavassistProxyFactory
         }
         return proxyClass;
     }
-    
-    public Class<?> getResourceBeanProxyClass(ResourceBean<?, ?> resourceBean)
-    {
-        Class<?> proxyClass = null;
-        try
-        {
-            proxyClass = this.resourceBeanProxyClasses.get(resourceBean);
-            if (proxyClass == null)
-            {
-                ProxyFactory fact = createProxyFactory(resourceBean);
-                proxyClass = getProxyClass(fact);
-
-                Class<?> oldClazz = this.resourceBeanProxyClasses.putIfAbsent(resourceBean,
proxyClass);
-                if (oldClazz != null)
-                {
-                    return oldClazz;
-                }                
-            }                
-        }
-        catch (Exception e)
-        {
-            WebBeansUtil.throwRuntimeExceptions(e);
-        }
-
-        return proxyClass;
-    }    
 
     /**
      * Defines the proxy for the given bean and iface using callers factory. Due



Mime
View raw message