openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1433454 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/creation/ main/java/org/apache/webbeans/intercept/ main/java/org/apache/webbeans/proxy/ test/java/org/apache/webbeans/newtests/interceptors/factory...
Date Tue, 15 Jan 2013 15:28:42 GMT
Author: struberg
Date: Tue Jan 15 15:28:42 2013
New Revision: 1433454

URL: http://svn.apache.org/viewvc?rev=1433454&view=rev
Log:
OWB-344 extract common functions and improve InterceptorResolution

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ManagedBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorUtil.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/NormalScopeProxyFactory.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/NormalScopeProxyFactoryTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorProxyChainTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorResolutionServiceTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java?rev=1433454&r1=1433453&r2=1433454&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
Tue Jan 15 15:28:42 2013
@@ -25,7 +25,6 @@ import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.Type;
-import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -119,27 +118,12 @@ public abstract class AbstractBeanBuilde
     }
 
     /**
-     * @return the Type hierarchy in the order superclass first. Object.class is <b>not</b>
included!
-     */
-    protected List<Class> getReverseClassHierarchy()
-    {
-        List<Class> hierarchy = new ArrayList<Class>();
-        Class clazz = getBeanType();
-        while (clazz != Object.class)
-        {
-            hierarchy.add(0, clazz);
-            clazz = clazz.getSuperclass();
-        }
-
-        return hierarchy;
-    }
-
-    /**
      * Check if the given annotatedMethod overrides some previously defined AnnotatedMethods
      * from a superclass and remove them if non-private.
      *
      *
-     * @param alreadyDefinedMethods the methods already calculated from the superclasses.
See {@link #getReverseClassHierarchy()}
+     * @param alreadyDefinedMethods the methods already calculated from the superclasses.
See
+     * {@link org.apache.webbeans.intercept.InterceptorUtil#getReverseClassHierarchy(Class)}
      * @param annotatedMethod the AnnotatedMethod to check for.
      * @return <code>true</code> if a method was overridden and got removed,
<code>false</code> otherwise.
      */

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java?rev=1433454&r1=1433453&r2=1433454&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/InterceptorBeanBuilder.java
Tue Jan 15 15:28:42 2013
@@ -151,7 +151,7 @@ public abstract class InterceptorBeanBui
      */
     protected void defineInterceptorMethods()
     {
-        List<Class> classHierarchy = getReverseClassHierarchy();
+        List<Class> classHierarchy = webBeansContext.getInterceptorUtil().getReverseClassHierarchy(getAnnotated().getJavaClass());
 
         AnnotatedMethod aroundInvokeMethod = null;
         List<AnnotatedMethod> postConstructMethods = new ArrayList<AnnotatedMethod>();

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ManagedBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ManagedBeanBuilder.java?rev=1433454&r1=1433453&r2=1433454&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ManagedBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ManagedBeanBuilder.java
Tue Jan 15 15:28:42 2013
@@ -21,7 +21,6 @@ package org.apache.webbeans.component.cr
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.Type;
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
 
@@ -125,58 +124,13 @@ public class ManagedBeanBuilder<T, M ext
     @Override
     protected List<AnnotatedMethod<?>> getPostConstructMethods()
     {
-        List<AnnotatedMethod<?>> postConstructMethods = new ArrayList<AnnotatedMethod<?>>();
-
-        AnnotatedType<T> annotatedType = getAnnotated();
-        List<Class> classes = getReverseClassHierarchy();
-        for (Class clazz : classes)
-        {
-            for (AnnotatedMethod annotatedMethod : annotatedType.getMethods())
-            {
-                if (annotatedMethod.getDeclaringType().getJavaClass() != clazz)
-                {
-                    continue;
-                }
-
-                if (annotatedMethod.isAnnotationPresent(PostConstruct.class))
-                {
-                    //X TODO check criterias!
-
-                    postConstructMethods.add(annotatedMethod);
-                }
-            }
-        }
-
-        return postConstructMethods;
+        return webBeansContext.getInterceptorUtil().getLifecycleMethods(getAnnotated(), PostConstruct.class,
true);
     }
 
     @Override
     protected List<AnnotatedMethod<?>> getPreDestroyMethods()
     {
-        List<AnnotatedMethod<?>> preDestroyMethods = new ArrayList<AnnotatedMethod<?>>();
-
-        AnnotatedType<T> annotatedType = getAnnotated();
-        List<Class> classes = getReverseClassHierarchy();
-        for (Class clazz : classes)
-        {
-            for (AnnotatedMethod annotatedMethod : annotatedType.getMethods())
-            {
-                if (annotatedMethod.getDeclaringType().getJavaClass() != clazz)
-                {
-                    continue;
-                }
-
-                if (annotatedMethod.isAnnotationPresent(PreDestroy.class))
-                {
-                    //X TODO check criterias!
-
-                    // reverse invocation order for PreDestroy methods!
-                    preDestroyMethods.add(0, annotatedMethod);
-                }
-            }
-        }
-
-        return preDestroyMethods;
+        return webBeansContext.getInterceptorUtil().getLifecycleMethods(getAnnotated(), PreDestroy.class,
false);
     }
 
     /**
@@ -230,7 +184,7 @@ public class ManagedBeanBuilder<T, M ext
 
     /**
      * Define decorator bean.
-     * @param processInjectionTargetEvent
+     * @param annotatedType
      */
     public ManagedBean<T> defineDecorator(AnnotatedType<T> annotatedType)
     {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java?rev=1433454&r1=1433453&r2=1433454&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
Tue Jan 15 15:28:42 2013
@@ -113,15 +113,16 @@ public class InterceptorResolutionServic
         }
 
         Set<Interceptor<?>> allUsedCdiInterceptors = new HashSet<Interceptor<?>>();
-        Map<Method, MethodInterceptorInfo> businessMethodInterceptorInfos = new HashMap<Method,
MethodInterceptorInfo>();
+        Map<Method, BusinessMethodInterceptorInfo> businessMethodInterceptorInfos =
new HashMap<Method, BusinessMethodInterceptorInfo>();
 
         List<Method> nonInterceptedMethods = new ArrayList<Method>();
 
         // iterate over all methods and build up the interceptor/decorator stack
         for (AnnotatedMethod annotatedMethod : interceptableAnnotatedMethods)
         {
-            InterceptionType interceptionType = calculateInterceptionType(annotatedMethod);
-            MethodInterceptorInfo methodInterceptorInfo = new MethodInterceptorInfo(interceptionType);
+            // this probably needs some more fine tuning if a method is both lifecycle and
used as business invocation.
+            Set<InterceptionType> interceptionTypes = collectInterceptionTypes(annotatedMethod);
+            BusinessMethodInterceptorInfo methodInterceptorInfo = new BusinessMethodInterceptorInfo(interceptionTypes);
 
             calculateEjbMethodInterceptors(methodInterceptorInfo, allUsedEjbInterceptors,
classLevelEjbInterceptors, annotatedMethod);
 
@@ -154,7 +155,7 @@ public class InterceptorResolutionServic
         }
     }
 
-    private void calculateEjbMethodInterceptors(MethodInterceptorInfo methodInterceptorInfo,
Set<Interceptor<?>> allUsedEjbInterceptors,
+    private void calculateEjbMethodInterceptors(BusinessMethodInterceptorInfo methodInterceptorInfo,
Set<Interceptor<?>> allUsedEjbInterceptors,
                                                 List<Interceptor<?>> classLevelEjbInterceptors,
AnnotatedMethod annotatedMethod)
     {
         List<Interceptor<?>> methodInterceptors = new ArrayList<Interceptor<?>>();
@@ -181,7 +182,7 @@ public class InterceptorResolutionServic
     }
 
 
-    private void calculateCdiMethodDecorators(MethodInterceptorInfo methodInterceptorInfo,
List<Decorator<?>> decorators, AnnotatedMethod annotatedMethod)
+    private void calculateCdiMethodDecorators(BusinessMethodInterceptorInfo methodInterceptorInfo,
List<Decorator<?>> decorators, AnnotatedMethod annotatedMethod)
     {
         if (decorators == null || decorators.isEmpty())
         {
@@ -256,7 +257,7 @@ public class InterceptorResolutionServic
 
     }
 
-    private void calculateCdiMethodInterceptors(MethodInterceptorInfo methodInterceptorInfo,
+    private void calculateCdiMethodInterceptors(BusinessMethodInterceptorInfo methodInterceptorInfo,
                                                 Set<Interceptor<?>> allUsedCdiInterceptors,
                                                 AnnotatedMethod annotatedMethod,
                                                 Set<Annotation> classInterceptorBindings)
@@ -274,9 +275,12 @@ public class InterceptorResolutionServic
             return;
         }
 
+        InterceptionType interceptionType = methodInterceptorInfo.getInterceptionTypes().isEmpty()
+                                                ? InterceptionType.AROUND_INVOKE
+                                                : methodInterceptorInfo.getInterceptionTypes().iterator().next();
//X TODO dirty hack for now...
+
         List<Interceptor<?>> methodInterceptors
-                = webBeansContext.getBeanManagerImpl().resolveInterceptors(methodInterceptorInfo.getInterceptionType(),
-                                                                           AnnotationUtil.asArray(cummulatedInterceptorBindings));
+                = webBeansContext.getBeanManagerImpl().resolveInterceptors(interceptionType,
AnnotationUtil.asArray(cummulatedInterceptorBindings));
 
         methodInterceptorInfo.setCdiInterceptors(methodInterceptors);
 
@@ -287,34 +291,36 @@ public class InterceptorResolutionServic
     /**
      * Determine the {@link InterceptionType} of the given AnnotatedMethod
      * of an intercepted method.
+     * An empty list means that this is an AroundInvoke method
      */
-    private InterceptionType calculateInterceptionType(AnnotatedMethod interceptableAnnotatedMethod)
+    private Set<InterceptionType> collectInterceptionTypes(AnnotatedMethod interceptableAnnotatedMethod)
     {
+        Set<InterceptionType> interceptionTypes = new HashSet<InterceptionType>();
         for (Annotation annotation : interceptableAnnotatedMethod.getAnnotations())
         {
             if (annotation.equals(PostConstruct.class))
             {
-                return InterceptionType.POST_CONSTRUCT;
+                interceptionTypes.add(InterceptionType.POST_CONSTRUCT);
             }
             if (annotation.equals(PreDestroy.class))
             {
-                return InterceptionType.PRE_DESTROY;
+                interceptionTypes.add(InterceptionType.PRE_DESTROY);
             }
             if (null != ejbPlugin && annotation.equals(prePassivateClass))
             {
-                return InterceptionType.PRE_PASSIVATE;
+                interceptionTypes.add(InterceptionType.PRE_PASSIVATE);
             }
             if (null != ejbPlugin && annotation.equals(postActivateClass))
             {
-                return InterceptionType.POST_ACTIVATE;
+                interceptionTypes.add(InterceptionType.POST_ACTIVATE);
             }
             if (null != ejbPlugin && annotation.equals(aroundTimeoutClass))
             {
-                return InterceptionType.AROUND_TIMEOUT;
+                interceptionTypes.add(InterceptionType.AROUND_TIMEOUT);
             }
         }
 
-        return InterceptionType.AROUND_INVOKE;
+        return interceptionTypes;
     }
 
     /**
@@ -356,7 +362,7 @@ public class InterceptorResolutionServic
     {
         public BeanInterceptorInfo(List<Decorator<?>> decorators,
                                    Set<Interceptor<?>> interceptors,
-                                   Map<Method, MethodInterceptorInfo> businessMethodsInfo,
+                                   Map<Method, BusinessMethodInterceptorInfo> businessMethodsInfo,
                                    List<Method> nonInterceptedMethods)
         {
             this.decorators = decorators;
@@ -381,7 +387,7 @@ public class InterceptorResolutionServic
          * For each business method which is either decorated or intercepted we keep an entry.
          * If there is no entry then the method has neither a decorator nor an interceptor.
          */
-        private Map<Method, MethodInterceptorInfo> businessMethodsInfo = new HashMap<Method,
MethodInterceptorInfo>();
+        private Map<Method, BusinessMethodInterceptorInfo> businessMethodsInfo = new
HashMap<Method, BusinessMethodInterceptorInfo>();
 
         /**
          * all non-intercepted methods
@@ -398,7 +404,7 @@ public class InterceptorResolutionServic
             return interceptors;
         }
 
-        public Map<Method, MethodInterceptorInfo> getBusinessMethodsInfo()
+        public Map<Method, BusinessMethodInterceptorInfo> getBusinessMethodsInfo()
         {
             return businessMethodsInfo;
         }
@@ -412,26 +418,25 @@ public class InterceptorResolutionServic
     /**
      * We track per method which Interceptors to invoke
      */
-    public static class MethodInterceptorInfo
+    public static class BusinessMethodInterceptorInfo
     {
-        private InterceptionType interceptionType;
         private Interceptor<?>[] ejbInterceptors = null;
         private Interceptor<?>[] cdiInterceptors = null;
         private Decorator<?>[]   methodDecorators = null;
 
-        public MethodInterceptorInfo(InterceptionType interceptionType)
+        /**
+         * lifecycle methods can serve multiple intercepton types :/
+         */
+        private Set<InterceptionType> interceptionTypes;
+
+        public BusinessMethodInterceptorInfo(Set<InterceptionType> interceptionTypes)
         {
-            this.interceptionType = interceptionType;
+            this.interceptionTypes = interceptionTypes;
         }
 
-        /**
-         * This is needed for later invoking the correct
-         * interceptor method on the Interceptors.
-         * (e.g. &#064;AroundInvoke vs &#064;PostConstruct interceptors)
-         */
-        public InterceptionType getInterceptionType()
+        public Set<InterceptionType> getInterceptionTypes()
         {
-            return interceptionType;
+            return interceptionTypes;
         }
 
         /**
@@ -508,4 +513,5 @@ public class InterceptorResolutionServic
             return cdiInterceptors == null && ejbInterceptors == null &&
methodDecorators == null;
         }
     }
+
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorUtil.java?rev=1433454&r1=1433453&r2=1433454&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorUtil.java
Tue Jan 15 15:28:42 2013
@@ -68,7 +68,7 @@ public final class InterceptorUtil
     /**
      * all the bit flags of private static and final modifiers
      */
-    private final int MODIFIER_STATIC_FINAL_PRIVATE = Modifier.STATIC | Modifier.FINAL |
Modifier.PRIVATE;
+    public final int MODIFIER_STATIC_FINAL_PRIVATE = Modifier.STATIC | Modifier.FINAL | Modifier.PRIVATE;
 
     private final WebBeansContext webBeansContext;
 
@@ -89,6 +89,53 @@ public final class InterceptorUtil
     }
 
     /**
+     * @return the Type hierarchy in the order superclass first. Object.class is <b>not</b>
included!
+     */
+    public List<Class> getReverseClassHierarchy(Class clazz)
+    {
+        List<Class> hierarchy = new ArrayList<Class>();
+        while (clazz != Object.class)
+        {
+            hierarchy.add(0, clazz);
+            clazz = clazz.getSuperclass();
+        }
+
+        return hierarchy;
+    }
+
+
+    public List<AnnotatedMethod<?>> getLifecycleMethods(AnnotatedType<?>
annotatedType, Class<? extends Annotation> annotation, boolean parentFirst)
+    {
+        List<AnnotatedMethod<?>> lifecycleMethods = new ArrayList<AnnotatedMethod<?>>();
+
+        List<Class> classes = getReverseClassHierarchy(annotatedType.getJavaClass());
+        for (Class clazz : classes)
+        {
+            for (AnnotatedMethod annotatedMethod : annotatedType.getMethods())
+            {
+                if (annotatedMethod.getDeclaringType().getJavaClass() != clazz)
+                {
+                    continue;
+                }
+
+                if (annotatedMethod.isAnnotationPresent(annotation))
+                {
+                    if (parentFirst)
+                    {
+                        lifecycleMethods.add(annotatedMethod);
+                    }
+                    else
+                    {
+                        lifecycleMethods.add(0, annotatedMethod);
+                    }
+                }
+            }
+        }
+
+        return lifecycleMethods;
+    }
+
+    /**
      * Check if the given method is a 'business method'
      * in the sense of the Interceptor specification
      * @param annotatedMethod
@@ -105,25 +152,6 @@ public final class InterceptorUtil
             return false;
         }
 
-        Set<Annotation> anns = annotatedMethod.getAnnotations();
-
-        // filter out all container 'special' methods
-        for (Annotation ann : anns)
-        {
-            Class <? extends Annotation> annCls = ann.annotationType();
-            if (annCls.equals(Inject.class)        ||
-                    annCls.equals(PreDestroy.class)    ||
-                    annCls.equals(PostConstruct.class) ||
-                    annCls.equals(AroundInvoke.class)  ||
-                    annCls.equals(AroundTimeout.class) ||    // JSR-299 7.2
-                    ((ejbPlugin != null)              &&
-                            (annCls.equals(prePassivateClass)   ||  // JSR-299 7.2
-                                    annCls.equals(postActivateClass))))    // JSR-299 7.2
-            {
-                return false;
-            }
-        }
-
         return true;
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java?rev=1433454&r1=1433453&r2=1433454&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
Tue Jan 15 15:28:42 2013
@@ -22,6 +22,7 @@ import java.lang.reflect.InvocationTarge
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 
+import org.apache.webbeans.exception.WebBeansException;
 import org.objectweb.asm.ClassWriter;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
@@ -32,6 +33,8 @@ import org.objectweb.asm.Type;
  */
 public abstract class AbstractProxyFactory
 {
+    public final static int MAX_CLASSLOAD_TRIES = 10000;
+
     /**
      * The name of the field which stores the passivationID of the Bean this proxy serves.
      * This is needed in case the proxy gets de-serialized back into a JVM
@@ -75,6 +78,32 @@ public abstract class AbstractProxyFacto
 
 
     /**
+     * Detect a free classname based on the given one
+     * @param proxyClassName
+     * @return
+     */
+    protected String getUnusedProxyClassName(ClassLoader classLoader, String proxyClassName)
+    {
+        for (int i = 0; i < MAX_CLASSLOAD_TRIES; i++)
+        {
+            try
+            {
+                String finalName = proxyClassName + i;
+                classLoader.loadClass(finalName);
+            }
+            catch (ClassNotFoundException cnfe)
+            {
+                // this is exactly what we need!
+                return proxyClassName;
+            }
+            // otherwise we continue ;)
+        }
+
+        throw new WebBeansException("Unable to detect a free proxy class name based on: "
+ proxyClassName);
+    }
+
+
+    /**
      * @param classLoader to use for creating the class in
      * @param classToProxy the class for which a subclass will get generated
      * @param interceptedMethods the list of intercepted or decorated business methods.

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java?rev=1433454&r1=1433453&r2=1433454&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java
Tue Jan 15 15:28:42 2013
@@ -137,12 +137,14 @@ public class InterceptorDecoratorProxyFa
      * @param nonInterceptedMethods all methods which are <b>not</b> intercepted
nor decorated and shall get delegated directly
      * @param <T>
      * @return the proxy class
+     * //X TODO for serialisation reasons this probably needs the Bean it serves.
      */
     public synchronized <T> Class<T> createProxyClass(ClassLoader classLoader,
Class<T> classToProxy,
                                                       Method[] interceptedMethods, Method[]
nonInterceptedMethods)
             throws ProxyGenerationException
     {
-        String proxyClassName = classToProxy.getName() + "$OwbInterceptProxy";
+        String proxyClassName = getUnusedProxyClassName(classLoader, classToProxy.getName()
+ "$OwbInterceptProxy");
+
 
         Class<T> clazz = createProxyClass(classLoader, proxyClassName, classToProxy,
interceptedMethods, nonInterceptedMethods);
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/NormalScopeProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/NormalScopeProxyFactory.java?rev=1433454&r1=1433453&r2=1433454&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/NormalScopeProxyFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/NormalScopeProxyFactory.java
Tue Jan 15 15:28:42 2013
@@ -23,7 +23,9 @@ import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.util.List;
 
+import org.apache.webbeans.util.ClassUtil;
 import org.objectweb.asm.ClassWriter;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
@@ -49,16 +51,17 @@ public class NormalScopeProxyFactory ext
     /**
      * @param classLoader to use for creating the class in
      * @param classToProxy the class for which a subclass will get generated
-     * @param nonInterceptedMethods all methods which are <b>not</b> intercepted
nor decorated and shall get delegated directly
      * @param <T>
      * @return the proxy class
+     * //X TODO for serialisation reasons this probably needs the Bean it serves.
      */
-    public synchronized <T> Class<T> createProxyClass(ClassLoader classLoader,
Class<T> classToProxy,
-                                                      Method[] nonInterceptedMethods)
+    public synchronized <T> Class<T> createProxyClass(ClassLoader classLoader,
Class<T> classToProxy)
             throws ProxyGenerationException
     {
-        String proxyClassName = classToProxy.getName() + "$OwbNormalScopeProxy";
+        String proxyClassName = getUnusedProxyClassName(classLoader, classToProxy.getName()
+ "$OwbNormalScopeProxy");
 
+        List<Method> methods = ClassUtil.getNonPrivateMethods(classToProxy);
+        Method[] nonInterceptedMethods = methods.toArray(new Method[methods.size()]);
         Class<T> clazz = createProxyClass(classLoader, proxyClassName, classToProxy,
null, nonInterceptedMethods);
 
         return clazz;

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/NormalScopeProxyFactoryTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/NormalScopeProxyFactoryTest.java?rev=1433454&r1=1433453&r2=1433454&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/NormalScopeProxyFactoryTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/NormalScopeProxyFactoryTest.java
Tue Jan 15 15:28:42 2013
@@ -50,7 +50,7 @@ public class NormalScopeProxyFactoryTest
         Method[] nonInterceptedMethods = methods.toArray(new Method[methods.size()]);;
         //X Method[] nonInterceptedMethods = new Method[]{methods.get(0)};
 
-        Class<ClassInterceptedClass> proxyClass = pf.createProxyClass(classLoader,
ClassInterceptedClass.class, nonInterceptedMethods);
+        Class<ClassInterceptedClass> proxyClass = pf.createProxyClass(classLoader,
ClassInterceptedClass.class);
         Assert.assertNotNull(proxyClass);
 
         ClassInterceptedClass internalInstance = new ClassInterceptedClass();

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorProxyChainTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorProxyChainTest.java?rev=1433454&r1=1433453&r2=1433454&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorProxyChainTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorProxyChainTest.java
Tue Jan 15 15:28:42 2013
@@ -3,7 +3,6 @@ package org.apache.webbeans.newtests.int
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.InterceptionType;
 import javax.enterprise.inject.spi.Interceptor;
 import javax.inject.Provider;
 import java.lang.reflect.Method;
@@ -27,7 +26,6 @@ import org.apache.webbeans.test.componen
 import org.apache.webbeans.test.component.intercept.webbeans.bindings.Action;
 import org.apache.webbeans.test.component.intercept.webbeans.bindings.Secure;
 import org.apache.webbeans.test.component.intercept.webbeans.bindings.Transactional;
-import org.apache.webbeans.util.ClassUtil;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -75,33 +73,32 @@ public class InterceptorProxyChainTest e
 
         Map<Method, List<Interceptor<?>>> methodInterceptors = new HashMap<Method,
List<Interceptor<?>>>();
         List<Method> nonBusinessMethods = new ArrayList<Method>();
-        for (Map.Entry<Method, InterceptorResolutionService.MethodInterceptorInfo>
miEntry : interceptorInfo.getBusinessMethodsInfo().entrySet())
+        for (Map.Entry<Method, InterceptorResolutionService.BusinessMethodInterceptorInfo>
miEntry : interceptorInfo.getBusinessMethodsInfo().entrySet())
         {
             Method interceptedMethod = miEntry.getKey();
-            InterceptorResolutionService.MethodInterceptorInfo mii = miEntry.getValue();
-            if (InterceptionType.AROUND_INVOKE.equals(mii.getInterceptionType()))
+            InterceptorResolutionService.BusinessMethodInterceptorInfo mii = miEntry.getValue();
+            List<Interceptor<?>> activeInterceptors = new ArrayList<Interceptor<?>>();
+
+            if (mii.getEjbInterceptors() != null)
             {
-                List<Interceptor<?>> activeInterceptors = new ArrayList<Interceptor<?>>();
-                if (mii.getEjbInterceptors() != null)
-                {
-                    for (Interceptor<?> i : mii.getEjbInterceptors())
-                    {
-                        activeInterceptors.add(i);
-                    }
-                }
-                if (mii.getCdiInterceptors() != null)
+                for (Interceptor<?> i : mii.getEjbInterceptors())
                 {
-                    for (Interceptor<?> i : mii.getCdiInterceptors())
-                    {
-                        activeInterceptors.add(i);
-                    }
+                    activeInterceptors.add(i);
                 }
-                if (activeInterceptors.size() > 0)
+            }
+            if (mii.getCdiInterceptors() != null)
+            {
+                for (Interceptor<?> i : mii.getCdiInterceptors())
                 {
-                    methodInterceptors.put(interceptedMethod, activeInterceptors);
+                    activeInterceptors.add(i);
                 }
             }
-            else
+            if (activeInterceptors.size() > 0)
+            {
+                methodInterceptors.put(interceptedMethod, activeInterceptors);
+            }
+
+            if (!mii.getInterceptionTypes().isEmpty())
             {
                 nonBusinessMethods.add(interceptedMethod);
             }
@@ -135,7 +132,7 @@ public class InterceptorProxyChainTest e
         //X this is for creating the NormalScoping Proxy which is now separate
         proxyInstance = createNormalScopingProxy(classLoader, ClassMultiInterceptedClass.class,
proxyInstance);
 
-        performBenchmarkOn(proxyInstance);
+        //X performBenchmarkOn(proxyInstance);
 
         shutDownContainer();
     }
@@ -144,11 +141,7 @@ public class InterceptorProxyChainTest e
     {
         NormalScopeProxyFactory pf = new NormalScopeProxyFactory();
 
-        List<Method> methods = ClassUtil.getNonPrivateMethods(clazz);
-
-        Method[] nonInterceptedMethods = methods.toArray(new Method[methods.size()]);
-
-        Class<T> proxyClass = pf.createProxyClass(classLoader, clazz, nonInterceptedMethods);
+        Class<T> proxyClass = pf.createProxyClass(classLoader, clazz);
         Assert.assertNotNull(proxyClass);
 
         return pf.createProxyInstance(proxyClass, new TestRequestScopedInstanceProvider(instance));

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorResolutionServiceTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorResolutionServiceTest.java?rev=1433454&r1=1433453&r2=1433454&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorResolutionServiceTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorResolutionServiceTest.java
Tue Jan 15 15:28:42 2013
@@ -81,11 +81,11 @@ public class InterceptorResolutionServic
 
         Assert.assertNull(interceptorInfo.getDecorators());
 
-        Map<Method, InterceptorResolutionService.MethodInterceptorInfo> methodInterceptorInfos
= interceptorInfo.getBusinessMethodsInfo();
+        Map<Method, InterceptorResolutionService.BusinessMethodInterceptorInfo> methodInterceptorInfos
= interceptorInfo.getBusinessMethodsInfo();
         Assert.assertNotNull(methodInterceptorInfos);
-        Assert.assertEquals(7, methodInterceptorInfos.size());
+        Assert.assertEquals(8, methodInterceptorInfos.size());
 
-        for (InterceptorResolutionService.MethodInterceptorInfo mi : methodInterceptorInfos.values())
+        for (InterceptorResolutionService.BusinessMethodInterceptorInfo mi : methodInterceptorInfos.values())
         {
             Assert.assertEquals(1, mi.getCdiInterceptors().length);
         }
@@ -122,11 +122,11 @@ public class InterceptorResolutionServic
 
         Assert.assertNull(interceptorInfo.getDecorators());
 
-        Map<Method, InterceptorResolutionService.MethodInterceptorInfo> methodInterceptorInfos
= interceptorInfo.getBusinessMethodsInfo();
+        Map<Method, InterceptorResolutionService.BusinessMethodInterceptorInfo> methodInterceptorInfos
= interceptorInfo.getBusinessMethodsInfo();
         Assert.assertNotNull(methodInterceptorInfos);
-        Assert.assertEquals(6, methodInterceptorInfos.size());
+        Assert.assertEquals(7, methodInterceptorInfos.size());
 
-        for (InterceptorResolutionService.MethodInterceptorInfo mi : methodInterceptorInfos.values())
+        for (InterceptorResolutionService.BusinessMethodInterceptorInfo mi : methodInterceptorInfos.values())
         {
             Assert.assertEquals(3, mi.getCdiInterceptors().length);
         }
@@ -161,11 +161,11 @@ public class InterceptorResolutionServic
 
         Assert.assertNull(interceptorInfo.getDecorators());
 
-        Map<Method, InterceptorResolutionService.MethodInterceptorInfo> methodInterceptorInfos
= interceptorInfo.getBusinessMethodsInfo();
+        Map<Method, InterceptorResolutionService.BusinessMethodInterceptorInfo> methodInterceptorInfos
= interceptorInfo.getBusinessMethodsInfo();
         Assert.assertNotNull(methodInterceptorInfos);
         Assert.assertEquals(2, methodInterceptorInfos.size());
 
-        for (Map.Entry<Method, InterceptorResolutionService.MethodInterceptorInfo>
mi : methodInterceptorInfos.entrySet())
+        for (Map.Entry<Method, InterceptorResolutionService.BusinessMethodInterceptorInfo>
mi : methodInterceptorInfos.entrySet())
         {
             if (mi.getKey().getName().equals("getMeaningOfLife"))
             {
@@ -231,9 +231,9 @@ public class InterceptorResolutionServic
         BeanInterceptorInfo interceptorInfo = ir.calculateInterceptorInfo(bean, annotatedType);
         Assert.assertNotNull(interceptorInfo);
         Assert.assertNotNull(interceptorInfo.getBusinessMethodsInfo());
-        Assert.assertEquals(1, interceptorInfo.getBusinessMethodsInfo().size());
+        Assert.assertEquals(2, interceptorInfo.getBusinessMethodsInfo().size());
 
-        for (Map.Entry<Method, InterceptorResolutionService.MethodInterceptorInfo>
mi : interceptorInfo.getBusinessMethodsInfo().entrySet())
+        for (Map.Entry<Method, InterceptorResolutionService.BusinessMethodInterceptorInfo>
mi : interceptorInfo.getBusinessMethodsInfo().entrySet())
         {
             Assert.assertNotNull(mi.getValue().getEjbInterceptors());
             Assert.assertEquals(1, mi.getValue().getEjbInterceptors().length);



Mime
View raw message