openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1433946 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/ main/java/org/apache/webbeans/component/creation/ main/java/org/apache/webbeans/intercept/ test/java/org/apache/webbeans/newtests/interceptors/fac...
Date Wed, 16 Jan 2013 14:14:43 GMT
Author: struberg
Date: Wed Jan 16 14:14:43 2013
New Revision: 1433946

URL: http://svn.apache.org/viewvc?rev=1433946&view=rev
Log:
OWB-344 apply interception info in validate phase

doing this during Bean construction is too early as not
all Interceptor<?> might yet be known because they might
get scanned/created only later during class-scanning

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/StereotypeInterceptedClass.java
      - copied, changed from r1433842, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/ClassInterceptedClass.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ManagedBean.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/WebBeansInterceptorConfig.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/ManagedBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ManagedBean.java?rev=1433946&r1=1433945&r2=1433946&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ManagedBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ManagedBean.java
Wed Jan 16 14:14:43 2013
@@ -24,7 +24,6 @@ import java.lang.reflect.Constructor;
 import java.lang.reflect.Type;
 import java.util.Set;
 
-import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.Decorator;
 

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=1433946&r1=1433945&r2=1433946&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
Wed Jan 16 14:14:43 2013
@@ -19,13 +19,9 @@
 package org.apache.webbeans.component.creation;
 
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
 import javax.annotation.PostConstruct;
@@ -34,8 +30,6 @@ import javax.enterprise.inject.spi.Annot
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.InjectionTarget;
-import javax.enterprise.inject.spi.Interceptor;
 
 import org.apache.webbeans.component.ManagedBean;
 import org.apache.webbeans.component.WebBeansType;
@@ -45,10 +39,7 @@ import org.apache.webbeans.decorator.Dec
 import org.apache.webbeans.decorator.WebBeansDecoratorConfig;
 import org.apache.webbeans.exception.inject.DeploymentException;
 import org.apache.webbeans.inject.impl.InjectionPointFactory;
-import org.apache.webbeans.intercept.InterceptorResolutionService;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
-import org.apache.webbeans.portable.InjectionTargetImpl;
-import org.apache.webbeans.proxy.InterceptorDecoratorProxyFactory;
 import org.apache.webbeans.portable.AbstractDecoratorInjectionTarget;
 import org.apache.webbeans.util.WebBeansUtil;
 
@@ -143,65 +134,6 @@ public class ManagedBeanBuilder<T, M ext
         return webBeansContext.getInterceptorUtil().getLifecycleMethods(getAnnotated(), PreDestroy.class,
false);
     }
 
-    @Override
-    protected InjectionTarget<T> buildInjectionTarget(Set<Type> types, Set<Annotation>
qualifiers, AnnotatedType<T> annotatedType, Set<InjectionPoint> points, WebBeansContext
webBeansContext, List<AnnotatedMethod<?>> postConstructMethods, List<AnnotatedMethod<?>>
preDestroyMethods)
-    {
-        InjectionTargetImpl<T> injectionTarget =  (InjectionTargetImpl<T>) super.buildInjectionTarget(types,
qualifiers, annotatedType, points, webBeansContext, postConstructMethods, preDestroyMethods);
   //To change body of overridden methods use File | Settings | File Templates.
-        InterceptorResolutionService.BeanInterceptorInfo interceptorInfo = webBeansContext.getInterceptorResolutionService().calculateInterceptorInfo(types,
qualifiers, annotatedType);
-
-        Map<Method, List<Interceptor<?>>> methodInterceptors = new HashMap<Method,
List<Interceptor<?>>>();
-        List<Method> nonBusinessMethods = new ArrayList<Method>();
-        for (Map.Entry<Method, InterceptorResolutionService.BusinessMethodInterceptorInfo>
miEntry : interceptorInfo.getBusinessMethodsInfo().entrySet())
-        {
-            Method interceptedMethod = miEntry.getKey();
-            InterceptorResolutionService.BusinessMethodInterceptorInfo mii = miEntry.getValue();
-            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.getCdiInterceptors())
-                {
-                    activeInterceptors.add(i);
-                }
-            }
-            if (activeInterceptors.size() > 0)
-            {
-                methodInterceptors.put(interceptedMethod, activeInterceptors);
-            }
-
-            // empty InterceptionType -> AROUND_INVOKE
-            if (!mii.getInterceptionTypes().isEmpty())
-            {
-                nonBusinessMethods.add(interceptedMethod);
-            }
-        }
-
-        if (methodInterceptors.size() > 0)
-        {
-            // we only need to create a proxy class for intercepted or decorated Beans
-            InterceptorDecoratorProxyFactory pf = webBeansContext.getInterceptorDecoratorProxyFactory();
-
-            // we take a fresh URLClassLoader to not blur the test classpath with synthetic
classes.
-            ClassLoader classLoader = this.getClass().getClassLoader();
-
-            Method[] businessMethods = methodInterceptors.keySet().toArray(new Method[methodInterceptors.size()]);
-            Method[] nonInterceptedMethods = interceptorInfo.getNonInterceptedMethods().toArray(new
Method[interceptorInfo.getNonInterceptedMethods().size()]);
-
-            Class<? extends T> proxyClass = pf.createProxyClass(classLoader, getBeanType(),
businessMethods, nonInterceptedMethods);
-
-            injectionTarget.setInterceptorInfo(interceptorInfo, proxyClass, methodInterceptors);
-        }
-
-        return injectionTarget;
-    }
-
     /**
      * @deprecated replaced via the various {@link InterceptorBeanBuilder}s
      */

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java?rev=1433946&r1=1433945&r2=1433946&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
Wed Jan 16 14:14:43 2013
@@ -21,12 +21,15 @@ package org.apache.webbeans.intercept;
 import org.apache.webbeans.annotation.AnnotationManager;
 import org.apache.webbeans.component.InjectionTargetBean;
 import org.apache.webbeans.component.EnterpriseBeanMarker;
+import org.apache.webbeans.component.InterceptedMarker;
 import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.intercept.webbeans.WebBeansInterceptorBeanPleaseRemove;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
 import org.apache.webbeans.plugins.OpenWebBeansEjbLCAPlugin;
+import org.apache.webbeans.portable.InjectionTargetImpl;
+import org.apache.webbeans.proxy.InterceptorDecoratorProxyFactory;
 import org.apache.webbeans.spi.BDABeansXmlScanner;
 import org.apache.webbeans.spi.ScannerService;
 import org.apache.webbeans.spi.plugins.OpenWebBeansEjbPlugin;
@@ -46,13 +49,18 @@ import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import static org.apache.webbeans.intercept.InterceptorResolutionService.BeanInterceptorInfo;
+
+
 /**
  * Configures the Web Beans related interceptors.
  *
@@ -60,7 +68,7 @@ import java.util.logging.Logger;
  * @version $Rev$ $Date$
  * @see org.apache.webbeans.intercept.webbeans.WebBeansInterceptorBeanPleaseRemove
  *
- * @deprecated this class can most probably get removed. All important logic is contained
in {@link InterceptorResolutionService}
+ * TODO most of the stuff in this class can most probably get removed. All important logic
is contained in {@link InterceptorResolutionService}
  */
 public final class WebBeansInterceptorConfig
 {
@@ -77,15 +85,83 @@ public final class WebBeansInterceptorCo
     /**
      * Configure bean instance interceptor stack.
      * @param bean bean instance
-     * @deprecated old InterceptorData based config
      */
     public void defineBeanInterceptorStack(InjectionTargetBean<?> bean)
     {
-        if (WebBeansContext.TODO_USING_NEW_INTERCEPTORS)
+        if (!WebBeansContext.TODO_USING_NEW_INTERCEPTORS)
         {
-            return; //X TODO
+            defineBeanInterceptorStackRemove(bean);
+            return;
+        }
+
+        if (bean instanceof InterceptedMarker)
+        {
+            InjectionTargetImpl<?> injectionTarget = (InjectionTargetImpl<?>)
bean.getInjectionTarget();
+            BeanInterceptorInfo interceptorInfo = webBeansContext.getInterceptorResolutionService().
+                    calculateInterceptorInfo(bean.getTypes(), bean.getQualifiers(), bean.getAnnotatedType());
+
+            Map<Method, List<Interceptor<?>>> methodInterceptors = new
HashMap<Method, List<Interceptor<?>>>();
+            List<Method> nonBusinessMethods = new ArrayList<Method>();
+            for (Map.Entry<Method, InterceptorResolutionService.BusinessMethodInterceptorInfo>
miEntry : interceptorInfo.getBusinessMethodsInfo().entrySet())
+            {
+                Method interceptedMethod = miEntry.getKey();
+                InterceptorResolutionService.BusinessMethodInterceptorInfo mii = miEntry.getValue();
+                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.getCdiInterceptors())
+                    {
+                        activeInterceptors.add(i);
+                    }
+                }
+                if (activeInterceptors.size() > 0)
+                {
+                    methodInterceptors.put(interceptedMethod, activeInterceptors);
+                }
+
+                // empty InterceptionType -> AROUND_INVOKE
+                if (!mii.getInterceptionTypes().isEmpty())
+                {
+                    nonBusinessMethods.add(interceptedMethod);
+                }
+            }
+
+            if (methodInterceptors.size() > 0)
+            {
+                // we only need to create a proxy class for intercepted or decorated Beans
+                InterceptorDecoratorProxyFactory pf = webBeansContext.getInterceptorDecoratorProxyFactory();
+
+                // we take a fresh URLClassLoader to not blur the test classpath with synthetic
classes.
+                ClassLoader classLoader = this.getClass().getClassLoader();
+
+                Method[] businessMethods = methodInterceptors.keySet().toArray(new Method[methodInterceptors.size()]);
+                Method[] nonInterceptedMethods = interceptorInfo.getNonInterceptedMethods().toArray(new
Method[interceptorInfo.getNonInterceptedMethods().size()]);
+
+                Class proxyClass = pf.createProxyClass(classLoader, bean.getReturnType(),
businessMethods, nonInterceptedMethods);
+
+                injectionTarget.setInterceptorInfo(interceptorInfo, proxyClass, methodInterceptors);
+            }
+
         }
 
+    }
+
+    /**
+     * Configure bean instance interceptor stack.
+     * @param bean bean instance
+     * @deprecated old InterceptorData based config
+     */
+    public void defineBeanInterceptorStackRemove(InjectionTargetBean<?> bean)
+    {
+
         Asserts.assertNotNull(bean, "bean parameter can no be null");
         if (!bean.getInterceptorStack().isEmpty())
         {
@@ -192,7 +268,7 @@ public final class WebBeansInterceptorCo
 
     /**
      * Configures the given class for applicable interceptors.
-     *
+     * @deprecated old interceptor stuff
      */
     public void configure(InjectionTargetBean<?> component, List<InterceptorData>
stack)
     {

Copied: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/StereotypeInterceptedClass.java
(from r1433842, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/ClassInterceptedClass.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/StereotypeInterceptedClass.java?p2=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/StereotypeInterceptedClass.java&p1=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/ClassInterceptedClass.java&r1=1433842&r2=1433946&rev=1433946&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/ClassInterceptedClass.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/factory/beans/StereotypeInterceptedClass.java
Wed Jan 16 14:14:43 2013
@@ -18,51 +18,25 @@
  */
 package org.apache.webbeans.newtests.interceptors.factory.beans;
 
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-
-import org.apache.webbeans.test.component.intercept.webbeans.bindings.Transactional;
+import org.apache.webbeans.test.component.intercept.webbeans.bindings.Secure;
 
 /**
- * A simple class which is class-level intercepted
+ * A simple class which is class-level intercepted by a Stereotype.
  */
-@Transactional
-public class ClassInterceptedClass
+public class StereotypeInterceptedClass
 {
-    private boolean defaultCtInvoked = false;
 
     private int meaningOfLife;
-    private float f;
-    private char c;
 
-    public ClassInterceptedClass()
-    {
-        defaultCtInvoked = true;
-    }
-
-    @PostConstruct
-    public void postConstruct()
-    {
-        System.out.println("postConstruct invoked");
-    }
-
-    @PreDestroy
-    private void preDestroy()
-    {
-        System.out.println("preDestroy invoked");
-    }
 
     public void init()
     {
-        f = 2.4f;
-        c = 'c';
         meaningOfLife = 42;
     }
 
+    @Secure
     public int getMeaningOfLife() throws NumberFormatException
     {
-        System.out.println("answering the question about life, the universe and everything!");
-        System.out.println("and being in " + this.getClass());
         return meaningOfLife;
     }
 
@@ -71,24 +45,10 @@ public class ClassInterceptedClass
         this.meaningOfLife = meaningOfLife;
     }
 
-    public float getFloat()
-    {
-        return f;
-    }
-
-    public ClassInterceptedClass getSelf()
+    public StereotypeInterceptedClass getSelf()
     {
         return this;
     }
 
-    public char getChar()
-    {
-        return c;
-    }
-
-    public String doThaBlowup() throws NumberFormatException
-    {
-        throw new NumberFormatException("should fit");
-    }
 
 }

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=1433946&r1=1433945&r2=1433946&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
Wed Jan 16 14:14:43 2013
@@ -33,6 +33,7 @@ import org.apache.webbeans.newtests.inte
 import org.apache.webbeans.newtests.interceptors.factory.beans.ClassMultiInterceptedClass;
 import org.apache.webbeans.newtests.interceptors.factory.beans.DecoratedClass;
 import org.apache.webbeans.newtests.interceptors.factory.beans.MethodInterceptedClass;
+import org.apache.webbeans.newtests.interceptors.factory.beans.StereotypeInterceptedClass;
 import org.apache.webbeans.test.annotation.binding.Binding1;
 import org.apache.webbeans.test.component.decorator.clean.ServiceDecorator;
 import org.apache.webbeans.test.component.intercept.webbeans.ActionInterceptor;
@@ -102,6 +103,32 @@ public class InterceptorResolutionServic
     }
 
     @Test
+    public void testStereotypeInterceptorBinding() throws Exception
+    {
+        Collection<String> beanXmls = new ArrayList<String>();
+        beanXmls.add(getXmlPath(this.getClass().getPackage().getName(), this.getClass().getSimpleName()));
+
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(StereotypeInterceptedClass.class);
+        beanClasses.add(Transactional.class);
+        beanClasses.add(TransactionalInterceptor.class);
+
+        startContainer(beanClasses, beanXmls);
+
+        InterceptorResolutionService ir = new InterceptorResolutionService(getWebBeansContext());
+        AnnotatedType<StereotypeInterceptedClass> annotatedType = getBeanManager().createAnnotatedType(StereotypeInterceptedClass.class);
+        Bean<StereotypeInterceptedClass> bean = (Bean<StereotypeInterceptedClass>)
getBeanManager().resolve(getBeanManager().getBeans(StereotypeInterceptedClass.class));
+
+        BeanInterceptorInfo interceptorInfo = ir.calculateInterceptorInfo(bean.getTypes(),
bean.getQualifiers(), annotatedType);
+        Assert.assertNotNull(interceptorInfo);
+
+        Assert.assertNotNull(interceptorInfo.getInterceptors());
+        Assert.assertEquals(1, interceptorInfo.getInterceptors().size());
+
+        shutDownContainer();
+    }
+
+    @Test
     public void testClassLevelMultipleInterceptor() throws Exception
     {
         Collection<String> beanXmls = new ArrayList<String>();



Mime
View raw message