openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r1385029 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: config/WebBeansContext.java decorator/AbstractDecoratorMethodHandler.java proxy/JavassistProxyFactory.java proxy/asm/AsmProxyFactory.java
Date Sat, 15 Sep 2012 08:33:40 GMT
Author: dblevins
Date: Sat Sep 15 08:33:39 2012
New Revision: 1385029

URL: http://svn.apache.org/viewvc?rev=1385029&view=rev
Log:
OWB-701: Remove Javassist
Fully functional ASM implementation
Ability to set alternate "JavassistProxyFactory" implementations

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/AbstractDecoratorMethodHandler.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/asm/AsmProxyFactory.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java?rev=1385029&r1=1385028&r2=1385029&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
Sat Sep 15 08:33:39 2012
@@ -77,7 +77,7 @@ public class WebBeansContext
     private final ExtensionLoader extensionLoader = new ExtensionLoader(this);
     private final InterceptorsManager interceptorsManager = new InterceptorsManager(this);
     private final WebBeansInterceptorConfig webBeansInterceptorConfig = new WebBeansInterceptorConfig(this);
-    private final JavassistProxyFactory javassistProxyFactory = new JavassistProxyFactory();
+    private final JavassistProxyFactory javassistProxyFactory;
     private final OpenWebBeansConfiguration openWebBeansConfiguration;
     private final PluginLoader pluginLoader = new PluginLoader();
     private final SerializableBeanVault serializableBeanVault = new SerializableBeanVault();
@@ -135,6 +135,10 @@ public class WebBeansContext
         }
         loaderService = getService(LoaderService.class);
         securityService = getService(SecurityService.class);
+
+        javassistProxyFactory = serviceMap.containsKey(JavassistProxyFactory.class)
+            ? (JavassistProxyFactory) serviceMap.get(JavassistProxyFactory.class)
+            : new JavassistProxyFactory();
         OpenWebBeansClassLoaderProvider.initProxyFactoryClassLoaderProvider();
 
         // Allow the WebBeansContext itself to be looked up

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=1385029&r1=1385028&r2=1385029&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
Sat Sep 15 08:33:39 2012
@@ -39,7 +39,8 @@ public class AbstractDecoratorMethodHand
     public Object invoke(Object proxy, Method method, Object[] args)
         throws Throwable
     {
-        throw new NoSuchMethodException();
+        final Method proceed = proxy.getClass().getMethod("_$$" + method.getName(), method.getParameterTypes());
+        return proceed.invoke(proxy, args);
     }
 
     public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws
Throwable

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=1385029&r1=1385028&r2=1385029&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
Sat Sep 15 08:33:39 2012
@@ -53,20 +53,24 @@ import org.apache.webbeans.util.WebBeans
 
 public final class JavassistProxyFactory
 {
-    public JavassistProxyFactory()
-    {
-
-    }
-    
-    private ConcurrentMap<OwbBean<?>, Class<?>> buildInBeanProxyClasses
= new ConcurrentHashMap<OwbBean<?>, Class<?>>();    
+    private ConcurrentMap<OwbBean<?>, Class<?>> buildInBeanProxyClasses
= new ConcurrentHashMap<OwbBean<?>, Class<?>>();
     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<?>>();
     // 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();
-//    private Factory factory = new AsmFactory();
+    private Factory factory;
+
+    public JavassistProxyFactory()
+    {
+        this(new JavassistFactory());
+    }
+
+    public JavassistProxyFactory(Factory factory)
+    {
+        this.factory = factory;
+    }
 
     /**
      * This map contains all configured special Scope->InterceptorHandler mappings.

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/asm/AsmProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/asm/AsmProxyFactory.java?rev=1385029&r1=1385028&r2=1385029&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/asm/AsmProxyFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/asm/AsmProxyFactory.java
Sat Sep 15 08:33:39 2012
@@ -257,28 +257,8 @@ public class AsmProxyFactory
         cw.visitField(ACC_FINAL + ACC_PRIVATE, NON_BUSINESS_HANDLER_NAME, "Ljava/lang/reflect/InvocationHandler;",
null,
                       null).visitEnd();
 
-        for (Constructor<?> constructor : classToProxy.getDeclaredConstructors())
-        {
-
-            final String descriptor = Type.getConstructorDescriptor(constructor);
-            final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", descriptor,
null, null);
-            mv.visitCode();
-            mv.visitVarInsn(ALOAD, 0);
-
-            int offset = 1;
-            for (Class<?> aClass : constructor.getParameterTypes())
-            {
-                final Type type = Type.getType(aClass);
-                mv.visitVarInsn(type.getOpcode(ILOAD), offset);
-                offset += type.getSize();
-            }
-
-            mv.visitMethodInsn(INVOKESPECIAL, classFileName, "<init>", descriptor);
-            mv.visitInsn(RETURN);
-            mv.visitMaxs(-1, -1);
-            mv.visitEnd();
+        propagateConstructors(classToProxy, cw, classFileName);
 
-        }
         final Map<String, List<Method>> methodMap = new HashMap<String, List<Method>>();
 
         getNonPrivateMethods(classToProxy, methodMap);
@@ -296,6 +276,8 @@ public class AsmProxyFactory
             {
                 final String name = method.getName();
 
+                addDirectAccessMethod(classToProxy, cw, method, name);
+
                 if (Modifier.isPublic(method.getModifiers()) ||
                     (method.getParameterTypes().length == 0 && ("finalize".equals(name)
|| "clone".equals(name))))
                 {
@@ -314,6 +296,73 @@ public class AsmProxyFactory
         return cw.toByteArray();
     }
 
+    private static void propagateConstructors(Class<?> classToProxy, ClassWriter cw,
String classFileName)
+    {
+        for (Constructor<?> constructor : classToProxy.getDeclaredConstructors())
+        {
+
+            final String descriptor = Type.getConstructorDescriptor(constructor);
+            final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", descriptor,
null, null);
+            mv.visitCode();
+            mv.visitVarInsn(ALOAD, 0);
+
+            int offset = 1;
+            for (Class<?> aClass : constructor.getParameterTypes())
+            {
+                final Type type = Type.getType(aClass);
+                mv.visitVarInsn(type.getOpcode(ILOAD), offset);
+                offset += type.getSize();
+            }
+
+            mv.visitMethodInsn(INVOKESPECIAL, classFileName, "<init>", descriptor);
+            mv.visitInsn(RETURN);
+            mv.visitMaxs(-1, -1);
+            mv.visitEnd();
+
+        }
+    }
+
+    private static void addDirectAccessMethod(Class<?> classToProxy, ClassWriter cw,
Method method, String name)
+    {
+        try
+        {
+            final Method impl = classToProxy.getMethod(name, method.getParameterTypes());
+            if (!Modifier.isAbstract(impl.getModifiers()))
+            {
+                final String[] exceptions = new String[impl.getExceptionTypes().length];
+                for (int i = 0; i < exceptions.length; i++)
+                {
+                    exceptions[i] = Type.getType(impl.getExceptionTypes()[i]).getInternalName();
+                }
+
+                final String methodDescriptor = Type.getMethodDescriptor(impl);
+                final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "_$$" + name, methodDescriptor,
+                                                               null, exceptions);
+                mv.visitCode();
+                mv.visitVarInsn(ALOAD, 0);
+
+                int offset = 1;
+                for (Class<?> aClass : impl.getParameterTypes())
+                {
+                    final Type type = Type.getType(aClass);
+                    mv.visitVarInsn(type.getOpcode(ILOAD), offset);
+                    offset += type.getSize();
+                }
+
+                final Type declaringClass = Type.getType(impl.getDeclaringClass());
+                mv.visitMethodInsn(INVOKESPECIAL, declaringClass.getInternalName(), name,
methodDescriptor);
+
+                final Type returnType = Type.getType(method.getReturnType());
+                mv.visitInsn(returnType.getOpcode(IRETURN));
+                mv.visitMaxs(-1, -1);
+                mv.visitEnd();
+            }
+        }
+        catch (NoSuchMethodException e)
+        {
+        }
+    }
+
     private static void getNonPrivateMethods(Class<?> clazz, Map<String, List<Method>>
methodMap)
     {
         while (clazz != null)



Mime
View raw message