openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r1384630 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: component/ decorator/ portable/creation/ proxy/ proxy/asm/ proxy/javassist/
Date Fri, 14 Sep 2012 03:05:15 GMT
Author: dblevins
Date: Fri Sep 14 03:05:14 2012
New Revision: 1384630

URL: http://svn.apache.org/viewvc?rev=1384630&view=rev
Log:
OWB-701: Removing Javassist
Refactored all Javassist dependencies into the new proxy.javassist package.
Start of ASM implementation (a work in progress).

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/Factory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/asm/
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/asm/AsmFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/asm/AsmProxyFactory.java
      - copied, changed from r1384168, openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AsmProxyFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/javassist/JavassistFactory.java
Removed:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AsmProxyFactory.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/AbstractDecoratorMethodHandler.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/MethodHandler.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java?rev=1384630&r1=1384629&r2=1384630&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java
Fri Sep 14 03:05:14 2012
@@ -136,9 +136,10 @@ public abstract class AbstractInjectionT
         boolean isDependentProxy = false;
         if(getScope() == Dependent.class && !(this instanceof EnterpriseBeanMarker))
         {
-            T result = (T) getWebBeansContext().getJavassistProxyFactory().createDependentScopedBeanProxy(this,
instance, creationalContext);
+            final JavassistProxyFactory proxyFactory = getWebBeansContext().getJavassistProxyFactory();
+            T result = (T) proxyFactory.createDependentScopedBeanProxy(this, instance, creationalContext);
             //Means that Dependent Bean has interceptor/decorator
-            if(JavassistProxyFactory.isProxyInstance(result))
+            if(proxyFactory.isProxyInstance(result))
             {
                 //This is a dependent scoped bean instance,
                 //Therefore we inject dependencies of this instance

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/AbstractDecoratorMethodHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/AbstractDecoratorMethodHandler.java?rev=1384630&r1=1384629&r2=1384630&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/AbstractDecoratorMethodHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/AbstractDecoratorMethodHandler.java
Fri Sep 14 03:05:14 2012
@@ -24,6 +24,8 @@ import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.lang.reflect.Method;
 
+import javax.naming.OperationNotSupportedException;
+
 import org.apache.webbeans.proxy.MethodHandler;
 
 public class AbstractDecoratorMethodHandler implements MethodHandler, Serializable
@@ -36,6 +38,12 @@ public class AbstractDecoratorMethodHand
         new Exception().fillInStackTrace().printStackTrace();
     }
 
+    public Object invoke(Object proxy, Method method, Object[] args)
+        throws Throwable
+    {
+        throw new OperationNotSupportedException();
+    }
+
     public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws
Throwable
     {
         //Don't attempt to call it if the method doesn't exist

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java?rev=1384630&r1=1384629&r2=1384630&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java
Fri Sep 14 03:05:14 2012
@@ -83,7 +83,8 @@ public class InjectionTargetProducer<T> 
                 //injection will be occured on Proxy instances that are 
                 //not correct. Injection must be on actual dependent
                 //instance,so not necessary to inject on proxy
-                if(bean.getScope() == Dependent.class && JavassistProxyFactory.isProxyInstance(instance))
+                final JavassistProxyFactory proxyFactory = this.bean.getWebBeansContext().getJavassistProxyFactory();
+                if(bean.getScope() == Dependent.class && proxyFactory.isProxyInstance(instance))
                 {
                     return;
                 }

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/Factory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/Factory.java?rev=1384630&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/Factory.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/Factory.java
Fri Sep 14 03:05:14 2012
@@ -0,0 +1,38 @@
+/*
+ * 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.proxy;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface Factory
+{
+    Class<?> getProxyClass(Class<?> superClass, Class<?>[] interfaces);
+
+    boolean isProxyInstance(Object o);
+
+    Object createProxy(MethodHandler handler, Class<?>[] interfaces)
+        throws InstantiationException, IllegalAccessException;
+
+     Object createProxy(Class<?> proxyClass)
+        throws InstantiationException, IllegalAccessException;
+
+
+    void setHandler(Object proxy, MethodHandler handler);
+}

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java?rev=1384630&r1=1384629&r2=1384630&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java
Fri Sep 14 03:05:14 2012
@@ -21,11 +21,7 @@ package org.apache.webbeans.proxy;
 import java.io.Serializable;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
 import java.lang.reflect.Type;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -38,10 +34,6 @@ import javax.enterprise.context.spi.Crea
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.Decorator;
 
-import javassist.util.proxy.MethodFilter;
-import javassist.util.proxy.ProxyFactory;
-import javassist.util.proxy.ProxyFactory.ClassLoaderProvider;
-import javassist.util.proxy.ProxyObject;
 import org.apache.webbeans.component.InjectionTargetBean;
 import org.apache.webbeans.component.OwbBean;
 import org.apache.webbeans.component.ResourceBean;
@@ -55,7 +47,7 @@ import org.apache.webbeans.intercept.Int
 import org.apache.webbeans.intercept.InterceptorHandler;
 import org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler;
 import org.apache.webbeans.intercept.webbeans.WebBeansInterceptor;
-import org.apache.webbeans.proxy.javassist.OpenWebBeansClassLoaderProvider;
+import org.apache.webbeans.proxy.javassist.JavassistFactory;
 import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.WebBeansUtil;
 
@@ -73,6 +65,7 @@ public final class JavassistProxyFactory
     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<?>>>();
+    private Factory factory = new JavassistFactory();
 
     /**
      * This map contains all configured special Scope->InterceptorHandler mappings.
@@ -81,21 +74,9 @@ public final class JavassistProxyFactory
     private Map<String, Class<? extends InterceptorHandler>> interceptorHandlerClasses
=
             new ConcurrentHashMap<String, Class<? extends InterceptorHandler>>();
 
-    public static Class<?> doPrivilegedCreateClass(ProxyFactory factory)
-    {
-        if (System.getSecurityManager() == null)
-        {
-            return factory.createClass();
-        }
-        else
-        {
-            return (Class<?>) AccessController.doPrivileged(new PrivilegedActionForProxyFactory(factory));
-        }
-    }
-
     public void setHandler(Object proxy, MethodHandler handler)
     {
-        ((ProxyObject)proxy).setHandler(handler);
+        factory.setHandler(proxy, handler);
     }
 
 
@@ -120,13 +101,12 @@ public final class JavassistProxyFactory
      */
     public Class<?> getEjbBeanProxyClass(OwbBean<?> bean, Class<?> iface)
     {
-        Class<?> proxyClass = null;
         ConcurrentMap<Class<?>, Class<?>> typeToProxyClassMap = ejbProxyClasses.get(bean);
         if (typeToProxyClassMap != null)
         {
-            proxyClass = typeToProxyClassMap.get(iface);
+            return typeToProxyClassMap.get(iface);
         }
-        return proxyClass;
+        return null;
     }
     
     public Object createDecoratorDelegate(OwbBean<?> bean, DelegateHandler newDelegateHandler)
@@ -136,106 +116,38 @@ public final class JavassistProxyFactory
         Class<?> proxyClass = this.getInterceptorProxyClasses().get(bean);
         if (proxyClass == null)
         {
-            ProxyFactory delegateFactory = this.createProxyFactory(bean);
-            proxyClass = this.getProxyClass(delegateFactory);
+            proxyClass = createProxyClass(bean);
             this.getInterceptorProxyClasses().put(bean, proxyClass);
         }
 
-        final Object delegate = proxyClass.newInstance();
+        final Object delegate = createProxy(proxyClass);
         setHandler(delegate, newDelegateHandler);
         return delegate;
     }
 
     public Class<?> getResourceBeanProxyClass(ResourceBean<?, ?> resourceBean)
     {
-        Class<?> proxyClass = null;
         try
         {
-            proxyClass = resourceBeanProxyClasses.get(resourceBean);
+            Class<?> proxyClass = resourceBeanProxyClasses.get(resourceBean);
             if (proxyClass == null)
             {
-                ProxyFactory fact = createProxyFactory(resourceBean);
-                proxyClass = getProxyClass(fact);
+                proxyClass = createProxyClass(resourceBean);
 
                 Class<?> oldClazz = resourceBeanProxyClasses.putIfAbsent(resourceBean,
proxyClass);
                 if (oldClazz != null)
                 {
                     return oldClazz;
                 }                
-            }                
+            }
+            return proxyClass;
         }
         catch (Exception e)
         {
             WebBeansUtil.throwRuntimeExceptions(e);
         }
 
-        return proxyClass;
-    }    
-
-    /**
-     * Defines the proxy for the given bean and iface using callers factory. Due
-     * to races with the concurrentmap, this might sometimes create additional
-     * javassist-defined classes that are not used by the caller and not stored
-     * in the map. Synchronizing the entire method, and getEjbBeanProxyClass, on
-     * ejbProxyClasses is an alternative.
-     * 
-     * @param bean the contextual representing the EJB
-     * @param iface the injected business local interface
-     * @param factory
-     * @return
-     */
-    public Class<?> defineEjbBeanProxyClass(OwbBean<?> bean, Class<?> iface,
ProxyFactory factory)
-    {
-        Class<?> proxyClass = null;
-
-        ConcurrentMap<Class<?>, Class<?>> typeToProxyClassMap = ejbProxyClasses.get(bean);
-        if (typeToProxyClassMap == null)
-        {
-            typeToProxyClassMap = new ConcurrentHashMap<Class<?>, Class<?>>();
-            ConcurrentMap<Class<?>, Class<?>> existingMap = ejbProxyClasses.putIfAbsent(bean,
typeToProxyClassMap);
-            
-            // use the map that beat us, because our new one definitely had no classes in
it.
-            typeToProxyClassMap = (existingMap != null) ? existingMap : typeToProxyClassMap;

-        }
-
-        proxyClass = typeToProxyClassMap.get(iface);
-
-        if (proxyClass == null)
-        {
-            proxyClass = doPrivilegedCreateClass(factory);
-            typeToProxyClassMap.putIfAbsent(iface, proxyClass);
-            // don't care if we were beaten in updating the iface->proxyclass map
-        }
-
-        return proxyClass;
-    }
-    
-    public  Class<?> createAbstractDecoratorProxyClass(OwbBean<?> bean)
-    {
-        //Will only get called once while defining the bean, so no need to cache
-        Class<?> clazz = null;
-        try
-        {
-            ProxyFactory fact = createProxyFactory(bean);
-            
-            clazz = doPrivilegedCreateClass(fact);
-        }
-        catch(Exception e)
-        {
-            WebBeansUtil.throwRuntimeExceptions(e);
-        }
-        return clazz;
-        
-    }
-
-    public Object createProxy(MethodHandler handler, Class<?>[] interfaces)
-        throws InstantiationException, IllegalAccessException
-    {
-        ProxyFactory pf = new ProxyFactory();
-        pf.setInterfaces(interfaces);
-        pf.setHandler(handler);
-
-        return getProxyClass(pf).newInstance();
+        return null;
     }
 
 
@@ -247,62 +159,18 @@ public final class JavassistProxyFactory
             Class<?> proxyClass = normalScopedBeanProxyClasses.get(bean);
             if (proxyClass == null)
             {
-                ProxyFactory fact = createProxyFactory(bean);
-
-                proxyClass = getProxyClass(fact);
+                proxyClass = createProxyClass(bean);
                 normalScopedBeanProxyClasses.putIfAbsent(bean, proxyClass);
             }
-            
-            result = proxyClass.newInstance();
+
+
+            result = createProxy(proxyClass);
             
             if (!(bean instanceof WebBeansDecorator<?>) && !(bean instanceof
WebBeansInterceptor<?>))
             {
                 InterceptorHandler interceptorHandler = createInterceptorHandler(bean, creationalContext);
 
-                if (!true)
-                {
-                    final Set<Type> types = bean.getTypes();
-                    final Set<Class<?>> interfaceList = new HashSet<Class<?>>();
-                    Class<?> superClass = null;
-                    for (Type generic : types)
-                    {
-                        Class<?> type = ClassUtil.getClazz(generic);
-
-                        if (type.isInterface())
-                        {
-                            interfaceList.add(type);
-                        }
-
-                        else if ((superClass == null) || (superClass.isAssignableFrom(type)
&& type != Object.class))
-                        {
-                            superClass = type;
-                        }
-
-                    }
-                    if (!interfaceList.contains(Serializable.class))
-                    {
-                        interfaceList.add(Serializable.class);
-                    }
-
-                    Class<?>[] interfaceArray = new Class<?>[interfaceList.size()];
-                    interfaceArray = interfaceList.toArray(interfaceArray);
-
-                    if (superClass == null || superClass.equals(Object.class))
-                    {
-                        return Proxy.newProxyInstance(WebBeansUtil.getCurrentClassLoader(),
interfaceArray,
-                                                      interceptorHandler);
-                    }
-                    else
-                    {
-                        return AsmProxyFactory.newProxyInstance(WebBeansUtil.getCurrentClassLoader(),
-                                                                interceptorHandler, superClass,
interfaceArray);
-                    }
-
-                }
-                else
-                {
-                    setHandler(result, interceptorHandler);
-                }
+                setHandler(result, interceptorHandler);
             }
         }
         catch (Exception e)
@@ -313,9 +181,14 @@ public final class JavassistProxyFactory
         return result;
     }
 
+    private Object createProxy(Class<?> proxyClass)
+        throws InstantiationException, IllegalAccessException
+    {
+        return proxyClass.newInstance();
+    }
+
     private InterceptorHandler createInterceptorHandler(OwbBean<?> bean, CreationalContext<?>
creationalContext)
     {
-        InterceptorHandler interceptorHandler = null;
         String scopeClassName = bean.getScope().getName();
         Class<? extends InterceptorHandler> interceptorHandlerClass = null;
         if (!interceptorHandlerClasses.containsKey(scopeClassName))
@@ -352,14 +225,14 @@ public final class JavassistProxyFactory
         if (interceptorHandlerClass.equals(NormalScopedBeanInterceptorHandler.class))
         {
             // this is faster that way...
-            interceptorHandler = new NormalScopedBeanInterceptorHandler(bean, creationalContext);
+            return new NormalScopedBeanInterceptorHandler(bean, creationalContext);
         }
         else
         {
             try
             {
                 Constructor ct = interceptorHandlerClass.getConstructor(OwbBean.class, CreationalContext.class);
-                interceptorHandler = (InterceptorHandler) ct.newInstance(bean, creationalContext);
+                return (InterceptorHandler) ct.newInstance(bean, creationalContext);
             }
             catch (NoSuchMethodException e)
             {
@@ -390,7 +263,6 @@ public final class JavassistProxyFactory
                                                          e);
             }
         }
-        return interceptorHandler;
     }
 
     public Object createBuildInBeanProxy(OwbBean<?> bean) 
@@ -401,11 +273,10 @@ public final class JavassistProxyFactory
             Class<?> proxyClass = buildInBeanProxyClasses.get(bean);
             if (proxyClass == null)
             {
-                ProxyFactory fact = createProxyFactory(bean);
-                proxyClass = getProxyClass(fact);
+                proxyClass = createProxyClass(bean);
                 buildInBeanProxyClasses.putIfAbsent(bean, proxyClass);
             }
-            result = proxyClass.newInstance();
+            result = createProxy(proxyClass);
         }
         catch (Exception e)
         {
@@ -417,8 +288,7 @@ public final class JavassistProxyFactory
     
     public  Object createDependentScopedBeanProxy(OwbBean<?> bean, Object actualInstance,
CreationalContext<?> creastionalContext)
     {
-        Object result = null;
-        
+
         List<InterceptorData> interceptors =  null;
         List<Decorator<?>> decorators = null;
         InjectionTargetBean<?> injectionTargetBean = null;
@@ -481,70 +351,83 @@ public final class JavassistProxyFactory
             Class<?> proxyClass = dependentScopedBeanProxyClasses.get(bean);
             if (proxyClass == null)
             {
-                ProxyFactory fact = createProxyFactory(bean);
-                proxyClass = getProxyClass(fact);
+                proxyClass = createProxyClass(bean);
                 dependentScopedBeanProxyClasses.putIfAbsent(bean, proxyClass);
             }
-            
-            result = proxyClass.newInstance();
+
+            Object result = createProxy(proxyClass);
             if (!(bean instanceof WebBeansDecorator<?>) && !(bean instanceof
WebBeansInterceptor<?>))
             {
                 setHandler(result, new DependentScopedBeanInterceptorHandler(bean, actualInstance,
creastionalContext));
             }
 
+            return result;
         }
         catch (Exception e)
         {
             WebBeansUtil.throwRuntimeExceptions(e);
         }
 
-        return result;
+        return null;
+    }
+
+    private Class<?> createProxyClass(OwbBean<?> bean)
+    {
+        final ProxyInfo info = getProxyInfo(bean);
+        return factory.getProxyClass(info.getSuperClass(), info.getInterfaces());
     }
 
+    public Class<?> createAbstractDecoratorProxyClass(OwbBean<?> bean)
+    {
+        return createProxyClass(bean);
+    }
 
-    public  Class<?> getProxyClass(ProxyFactory factory)
+    public boolean isProxyInstance(Object o)
     {
-        ClassLoaderProvider classLoaderProvider = ProxyFactory.classLoaderProvider;
-        Class<?> clazz = null;
-        try
+        return factory.isProxyInstance(o);
+    }
+
+    public Object createProxy(MethodHandler handler, Class<?>[] interfaces)
+        throws IllegalAccessException, InstantiationException
+    {
+        return factory.createProxy(handler, interfaces);
+    }
+
+    private static class ProxyInfo
+    {
+        private final Class<?> superClass;
+        private final Class<?>[] interfaces;
+
+        private ProxyInfo(Class<?> superClass, Class<?>[] interfaces)
         {
-            clazz = doPrivilegedCreateClass(factory);
+            this.superClass = superClass;
+            this.interfaces = interfaces;
         }
-        catch(RuntimeException e)
-        {
-            if(classLoaderProvider instanceof OpenWebBeansClassLoaderProvider)
-            {
-                ((OpenWebBeansClassLoaderProvider)classLoaderProvider).useCurrentClassLoader();
-            }
 
-            //try again with updated class loader
-            clazz = doPrivilegedCreateClass(factory);
+        public Class<?> getSuperClass()
+        {
+            return superClass;
         }
-        finally
+
+        public Class<?>[] getInterfaces()
         {
-            if(classLoaderProvider instanceof OpenWebBeansClassLoaderProvider)
-            {
-                ((OpenWebBeansClassLoaderProvider)classLoaderProvider).reset();
-            }
+            return interfaces;
         }
-        
-        return clazz; 
     }
-    
-    public  ProxyFactory createProxyFactory(Bean<?> bean) throws Exception
+
+    private static ProxyInfo getProxyInfo(Bean<?> bean)
     {
-        Set<Type> types = bean.getTypes();
-        Set<Class<?>> interfaceList = new HashSet<Class<?>>();
+        final Set<Class<?>> interfaceList = new HashSet<Class<?>>();
         Class<?> superClass = null;
-        for (Type generic : types)
+        for (Type generic : bean.getTypes())
         {
             Class<?> type = ClassUtil.getClazz(generic);
-            
+
             if (type.isInterface())
             {
                 interfaceList.add(type);
             }
-            
+
             else if ((superClass == null) || (superClass.isAssignableFrom(type) &&
type != Object.class))
             {
                 superClass = type;
@@ -559,50 +442,6 @@ public final class JavassistProxyFactory
         Class<?>[] interfaceArray = new Class<?>[interfaceList.size()];
         interfaceArray = interfaceList.toArray(interfaceArray);
 
-        ProxyFactory fact = new ProxyFactory();        
-        fact.setInterfaces(interfaceArray);
-        fact.setSuperclass(superClass);
-        fact.setFilter(FinalizeMethodFilter.INSTANCE);
-
-        return fact;
-        
-    }
-
-    /**
-     * @param o the object to check
-     * @return <code>true</code> if the given object is a proxy
-     */
-    public static boolean isProxyInstance(Object o)
-    {
-        return o instanceof ProxyObject;
-    }
-
-    private static class FinalizeMethodFilter implements MethodFilter
-    {
-        private static final String FINALIZE = "finalize".intern();
-
-        public static final FinalizeMethodFilter INSTANCE = new FinalizeMethodFilter();
-
-        public boolean isHandled(final Method method)
-        {
-            return !(method.getName() == FINALIZE
-                        && method.getParameterTypes().length == 0
-                        && method.getReturnType() == Void.TYPE);
-        }
-    }
-
-    protected static class PrivilegedActionForProxyFactory implements PrivilegedAction<Object>
-    {
-        private ProxyFactory factory;
-
-        protected PrivilegedActionForProxyFactory(ProxyFactory factory)
-        {
-            this.factory = factory;
-        }
-
-        public Object run()
-        {
-            return factory.createClass();
-        }
+        return new ProxyInfo(superClass, interfaceArray);
     }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/MethodHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/MethodHandler.java?rev=1384630&r1=1384629&r2=1384630&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/MethodHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/MethodHandler.java
Fri Sep 14 03:05:14 2012
@@ -18,9 +18,11 @@
  */
 package org.apache.webbeans.proxy;
 
+import java.lang.reflect.InvocationHandler;
+
 /**
  * @version $Rev$ $Date$
  */
-public interface MethodHandler extends javassist.util.proxy.MethodHandler
+public interface MethodHandler extends javassist.util.proxy.MethodHandler, InvocationHandler
 {
 }

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/asm/AsmFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/asm/AsmFactory.java?rev=1384630&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/asm/AsmFactory.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/asm/AsmFactory.java
Fri Sep 14 03:05:14 2012
@@ -0,0 +1,78 @@
+/*
+ * 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.proxy.asm;
+
+import java.lang.reflect.Proxy;
+
+import org.apache.webbeans.proxy.Factory;
+import org.apache.webbeans.proxy.MethodHandler;
+import org.apache.webbeans.util.WebBeansUtil;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AsmFactory implements Factory
+{
+
+    public Object createProxy(MethodHandler handler, Class<?> superClass, Class<?>[]
interfaceArray)
+    {
+        if (useJdkProxy(superClass))
+        {
+            return Proxy.newProxyInstance(WebBeansUtil.getCurrentClassLoader(), interfaceArray,
handler);
+        }
+        else
+        {
+            return AsmProxyFactory.newProxyInstance(WebBeansUtil.getCurrentClassLoader(),
handler, superClass,
+                                                    interfaceArray);
+        }
+
+    }
+
+    public Class<?> getProxyClass(Class<?> superClass, Class<?>[] interfaces)
+    {
+        return null;
+    }
+
+    public boolean isProxyInstance(Object o)
+    {
+        return false;
+    }
+
+    public Object createProxy(MethodHandler handler, Class<?>[] interfaces)
+        throws InstantiationException, IllegalAccessException
+    {
+        return null;
+    }
+
+    public Object createProxy(Class<?> proxyClass)
+        throws InstantiationException, IllegalAccessException
+    {
+        return null;
+    }
+
+    public void setHandler(Object proxy, MethodHandler handler)
+    {
+    }
+
+    private boolean useJdkProxy(Class<?> superClass)
+    {
+        return superClass == null || superClass.equals(Object.class);
+    }
+
+}

Copied: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/asm/AsmProxyFactory.java
(from r1384168, openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AsmProxyFactory.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/asm/AsmProxyFactory.java?p2=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/asm/AsmProxyFactory.java&p1=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AsmProxyFactory.java&r1=1384168&r2=1384630&rev=1384630&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AsmProxyFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/asm/AsmProxyFactory.java
Fri Sep 14 03:05:14 2012
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.webbeans.proxy;
+package org.apache.webbeans.proxy.asm;
 
 import java.io.ByteArrayOutputStream;
 import java.io.PrintStream;
@@ -39,6 +39,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.webbeans.proxy.ProxyGenerationException;
 import org.objectweb.asm.ClassWriter;
 import org.objectweb.asm.Label;
 import org.objectweb.asm.MethodVisitor;

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/javassist/JavassistFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/javassist/JavassistFactory.java?rev=1384630&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/javassist/JavassistFactory.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/javassist/JavassistFactory.java
Fri Sep 14 03:05:14 2012
@@ -0,0 +1,145 @@
+/*
+ * 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.proxy.javassist;
+
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import javassist.util.proxy.MethodFilter;
+import javassist.util.proxy.ProxyFactory;
+import javassist.util.proxy.ProxyObject;
+import org.apache.webbeans.proxy.Factory;
+import org.apache.webbeans.proxy.MethodHandler;
+
+/**
+* @version $Rev$ $Date$
+*/
+public class JavassistFactory
+    implements Factory
+{
+    public Class<?> getProxyClass(Class<?> superClass, Class<?>[] interfaces)
+    {
+        ProxyFactory fact = new ProxyFactory();
+        fact.setInterfaces(interfaces);
+        fact.setSuperclass(superClass);
+        fact.setFilter(FinalizeMethodFilter.INSTANCE);
+
+        return getProxyClass(fact);
+    }
+
+    private static Class<?> getProxyClass(ProxyFactory factory)
+    {
+        ProxyFactory.ClassLoaderProvider classLoaderProvider = ProxyFactory.classLoaderProvider;
+        try
+        {
+           return doPrivilegedCreateClass(factory);
+        }
+        catch(RuntimeException e)
+        {
+            if(classLoaderProvider instanceof OpenWebBeansClassLoaderProvider)
+            {
+                ((OpenWebBeansClassLoaderProvider)classLoaderProvider).useCurrentClassLoader();
+            }
+
+            //try again with updated class loader
+            return doPrivilegedCreateClass(factory);
+        }
+        finally
+        {
+            if(classLoaderProvider instanceof OpenWebBeansClassLoaderProvider)
+            {
+                ((OpenWebBeansClassLoaderProvider)classLoaderProvider).reset();
+            }
+        }
+    }
+
+    public Object createProxy(Class<?> proxyClass)
+        throws InstantiationException, IllegalAccessException
+    {
+        return proxyClass.newInstance();
+    }
+
+
+    private static Class<?> doPrivilegedCreateClass(ProxyFactory factory)
+    {
+        if (System.getSecurityManager() == null)
+        {
+            return factory.createClass();
+        }
+        else
+        {
+            return (Class<?>) AccessController.doPrivileged(new PrivilegedActionForProxyFactory(factory));
+        }
+    }
+
+    /**
+     * @param o the object to check
+     * @return <code>true</code> if the given object is a proxy
+     */
+    public boolean isProxyInstance(Object o)
+    {
+        return o instanceof ProxyObject;
+    }
+
+    public Object createProxy(MethodHandler handler, Class<?>[] interfaces)
+        throws InstantiationException, IllegalAccessException
+    {
+        ProxyFactory pf = new ProxyFactory();
+        pf.setInterfaces(interfaces);
+        pf.setHandler(handler);
+
+        return getProxyClass(pf).newInstance();
+    }
+
+    public void setHandler(Object proxy, MethodHandler handler)
+    {
+        ((ProxyObject)proxy).setHandler(handler);
+    }
+
+
+    protected static class PrivilegedActionForProxyFactory implements PrivilegedAction<Object>
+    {
+        private ProxyFactory factory;
+
+        protected PrivilegedActionForProxyFactory(ProxyFactory factory)
+        {
+            this.factory = factory;
+        }
+
+        public Object run()
+        {
+            return factory.createClass();
+        }
+    }
+
+    public static class FinalizeMethodFilter implements MethodFilter
+    {
+        private static final String FINALIZE = "finalize".intern();
+
+        public static final FinalizeMethodFilter INSTANCE = new FinalizeMethodFilter();
+
+        public boolean isHandled(final Method method)
+        {
+            return !(method.getName() == FINALIZE
+                        && method.getParameterTypes().length == 0
+                        && method.getReturnType() == Void.TYPE);
+        }
+    }
+}



Mime
View raw message