This change to ResourceBean doesn't compile.  It appears to be a partial
backport.  I attempted to quickly resolve it by bringing in the
ResourceProxyHandler from trunk but hit another set of failures.

In the meantime I have reverted it.

Sincerely,

Joe

On Thu, Oct 28, 2010 at 4:44 AM, <gerdo...@apache.org> wrote:

> Author: gerdogdu
> Date: Thu Oct 28 08:44:01 2010
> New Revision: 1028219
>
> URL: http://svn.apache.org/viewvc?rev=1028219&view=rev
> Log:
> [OWB-486] ResourceBean tries to proxy final classes before testing them for
> being final, thanks to David Jencks, Also includes sync. problem that Ying
> has provided
>
> 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=1028219&r1=1028218&r2=1028219&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 Oct 28 08:44:01 2010
> @@ -21,8 +21,6 @@ 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;
> @@ -35,8 +33,6 @@ 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,
> @@ -55,37 +51,38 @@ 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);
> -            this.actualResourceReference =
> resourceService.getResourceReference(this.resourceReference);
> +            instance =
> resourceService.getResourceReference(this.resourceReference);
>
> -            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()))
> +            if (instance != null &&
> Modifier.isFinal(instance.getClass().getModifiers()))
>             {
> -                return this.actualResourceReference;
> +                return instance;
>             }
>
> +            instance = (X)
> JavassistProxyFactory.getInstance().getResourceBeanProxyClass(this).newInstance();
> +            ((ProxyObject) instance).setHandler(new
> ResourceProxyHandler(this,instance));
> +        }
> +        catch (Exception e)
> +        {
>             throw new WebBeansException(e);
>         }
> -
> +
>         return instance;
>     }
>
> -    @Override
> -    protected void destroyInstance(X instance, CreationalContext<X>
> creationalContext)
> +    /**
> +     * 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()
>     {
> -        this.actualResourceReference = null;
> +        ResourceInjectionService resourceService =
> ServiceLoader.getService(ResourceInjectionService.class);
> +        X instance =
> resourceService.getResourceReference(this.resourceReference);
> +        return instance;
>     }
> -
> -
> +
>     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=1028219&r1=1028218&r2=1028219&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 Oct 28 08:44:01 2010
> @@ -40,6 +40,7 @@ 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;
> @@ -61,7 +62,8 @@ 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<OwbBean<?>, Class<?>> interceptorProxyClasses =
> new ConcurrentHashMap<OwbBean<?>, Class<?>>();
> +    private ConcurrentMap<ResourceBean<?, ?>, Class<?>>
> resourceBeanProxyClasses = new ConcurrentHashMap<ResourceBean<?,?>,
> Class<?>>();
>     // second level map is indexed on local interface
>     private ConcurrentMap<OwbBean<?>, ConcurrentMap<Class<?>, Class<?>>>
> ejbProxyClasses = new ConcurrentHashMap<OwbBean<?>, ConcurrentMap<Class<?>,
> Class<?>>>();
>
> @@ -100,6 +102,32 @@ 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
>
>
>

Reply via email to