[webbeans-commits] Webbeans SVN: r3860 - in ri/trunk/impl/src/main/java/org/jboss/webbeans: bean and 1 other directory.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Mon Oct 5 19:00:55 EDT 2009


Author: marius.bogoevici
Date: 2009-10-05 19:00:55 -0400 (Mon, 05 Oct 2009)
New Revision: 3860

Modified:
   ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ManagedBean.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SessionBean.java
Log:
Expanding interceptor metadata discovery to SessionBeans.

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java	2009-10-05 18:25:00 UTC (rev 3859)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java	2009-10-05 23:00:55 UTC (rev 3860)
@@ -264,7 +264,7 @@
    /**
     * Interception model
     */
-   private transient final InterceptorRegistry<Class<?>, Interceptor> managedBeanBoundInterceptorsRegistry = new InterceptorRegistry<Class<?>, Interceptor>();
+   private transient final InterceptorRegistry<Class<?>, Interceptor> boundInterceptorsRegistry = new InterceptorRegistry<Class<?>, Interceptor>();
 
    /**
     * Create a new, root, manager
@@ -1413,8 +1413,8 @@
       this.currentInjectionPoint.remove();
    }
 
-   public InterceptorRegistry<Class<?>, Interceptor> getManagedBeanInterceptorRegistry()
+   public InterceptorRegistry<Class<?>, Interceptor> getBoundInterceptorsRegistry()
    {
-      return managedBeanBoundInterceptorsRegistry;
+      return boundInterceptorsRegistry;
    }
 }

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java	2009-10-05 18:25:00 UTC (rev 3859)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java	2009-10-05 23:00:55 UTC (rev 3860)
@@ -25,17 +25,18 @@
 import java.util.List;
 import java.util.Set;
 
-import javassist.util.proxy.ProxyFactory;
-import javassist.util.proxy.ProxyObject;
-
 import javax.enterprise.context.Dependent;
 import javax.enterprise.context.NormalScope;
 import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.Decorator;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.InjectionTarget;
+import javax.enterprise.inject.spi.InterceptionType;
+import javax.enterprise.inject.spi.Interceptor;
 import javax.inject.Scope;
 
+import org.jboss.interceptor.model.InterceptionModelBuilder;
 import org.jboss.webbeans.BeanManagerImpl;
 import org.jboss.webbeans.DefinitionException;
 import org.jboss.webbeans.bean.proxy.DecoratorProxyMethodHandler;
@@ -47,10 +48,14 @@
 import org.jboss.webbeans.introspector.WBMethod;
 import org.jboss.webbeans.log.LogProvider;
 import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.metadata.cache.MetaAnnotationStore;
 import org.jboss.webbeans.util.Beans;
 import org.jboss.webbeans.util.Proxies;
 import org.jboss.webbeans.util.Strings;
 
+import javassist.util.proxy.ProxyFactory;
+import javassist.util.proxy.ProxyObject;
+
 /**
  * An abstract bean representation common for class-based beans
  * 
@@ -116,6 +121,8 @@
       initDecorators();
       checkType();
       initProxyClassForDecoratedBean();
+      if (isInterceptionCandidate())
+            initInterceptors();
    }
    
    protected void checkType()
@@ -409,6 +416,54 @@
    {
       return preDestroy;
    }
-   
 
+    protected abstract boolean isInterceptionCandidate();
+
+   /**
+    * Extracts the complete set of interception bindings from a given set of annotations.
+    *
+    * @param manager
+    * @param annotations
+    * @return
+    */
+   protected static Set<Annotation> flattenInterceptorBindings(BeanManagerImpl manager, Set<Annotation> annotations)
+   {
+      Set<Annotation> foundInterceptionBindingTypes = new HashSet<Annotation>();
+      for (Annotation annotation: annotations)
+      {
+         if (manager.isInterceptorBindingType(annotation.annotationType()))
+         {
+            foundInterceptionBindingTypes.add(annotation);
+            foundInterceptionBindingTypes.addAll(manager.getServices().get(MetaAnnotationStore.class).getInterceptorBindingModel(annotation.annotationType()).getInheritedInterceptionBindingTypes());
+         }
+      }
+      return foundInterceptionBindingTypes;
+   }
+
+   protected void initInterceptors()
+   {
+      if (manager.getBoundInterceptorsRegistry().getInterceptionModel(getType()) == null)
+      {
+         InterceptionModelBuilder<Class<?>, Interceptor> builder = InterceptionModelBuilder.newBuilderFor(getType(), (Class) Interceptor.class);
+
+         Set<Annotation> classBindingAnnotations = flattenInterceptorBindings(manager, getAnnotatedItem().getAnnotations());
+         for (Class<? extends Annotation> annotation : getStereotypes())
+         {
+            classBindingAnnotations.addAll(flattenInterceptorBindings(manager, manager.getStereotypeDefinition(annotation)));
+         }
+
+         builder.interceptPostConstruct().with(manager.resolveInterceptors(InterceptionType.POST_CONSTRUCT, classBindingAnnotations.toArray(new Annotation[0])).toArray(new Interceptor<?>[]{}));
+         builder.interceptPreDestroy().with(manager.resolveInterceptors(InterceptionType.PRE_DESTROY, classBindingAnnotations.toArray(new Annotation[0])).toArray(new Interceptor<?>[]{}));
+
+         List<WBMethod<?, ?>> businessMethods = Beans.getInterceptableBusinessMethods(getAnnotatedItem());
+         for (WBMethod<?, ?> method : businessMethods)
+         {
+            List<Annotation> methodBindingAnnotations = new ArrayList<Annotation>(classBindingAnnotations);
+            methodBindingAnnotations.addAll(flattenInterceptorBindings(manager, method.getAnnotations()));
+            List<Interceptor<?>> methodBoundInterceptors = manager.resolveInterceptors(InterceptionType.AROUND_INVOKE, methodBindingAnnotations.toArray(new Annotation[]{}));
+            builder.interceptAroundInvoke(((AnnotatedMethod) method).getJavaMember()).with(methodBoundInterceptors.toArray(new Interceptor[]{}));
+         }
+         manager.getBoundInterceptorsRegistry().registerInterceptionModel(getType(), builder.build());
+      }
+   }
 }

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ManagedBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ManagedBean.java	2009-10-05 18:25:00 UTC (rev 3859)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ManagedBean.java	2009-10-05 23:00:55 UTC (rev 3860)
@@ -16,21 +16,15 @@
  */
 package org.jboss.webbeans.bean;
 
+import java.util.Set;
+
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.event.Observes;
 import javax.enterprise.inject.Disposes;
 import javax.enterprise.inject.spi.Decorator;
 import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.InterceptionType;
 import javax.enterprise.inject.spi.Interceptor;
-import javax.enterprise.inject.spi.AnnotatedMethod;
-import java.lang.annotation.Annotation;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.HashSet;
 
-import org.jboss.interceptor.model.InterceptionModelBuilder;
 import org.jboss.interceptor.proxy.DirectClassInterceptionHandler;
 import org.jboss.interceptor.proxy.InterceptionHandler;
 import org.jboss.interceptor.proxy.InterceptionHandlerFactory;
@@ -210,8 +204,6 @@
          initPostConstruct();
          initPreDestroy();
          initEEInjectionPoints();
-         if (isInterceptionCandidate())
-            initInterceptors();
       }
    }
 
@@ -223,31 +215,7 @@
       this.resourceInjectionPoints = Beans.getResourceInjectionPoints(this, getAnnotatedItem(), manager);
    }
 
-   private void initInterceptors()
-   {
-      InterceptionModelBuilder<Class<?>, Interceptor> builder = InterceptionModelBuilder.newBuilderFor(getType(), (Class) Interceptor.class);
 
-      Set<Annotation> classBindingAnnotations = flattenInterceptorBindings(manager, annotatedItem.getAnnotations());
-       for (Class<? extends Annotation> annotation: getStereotypes())
-      {
-          classBindingAnnotations.addAll(flattenInterceptorBindings(manager, manager.getStereotypeDefinition(annotation)));
-      }
-
-      builder.interceptPostConstruct().with(manager.resolveInterceptors(InterceptionType.POST_CONSTRUCT, classBindingAnnotations.toArray(new Annotation[0])).toArray(new Interceptor<?>[]{}));
-      builder.interceptPreDestroy().with(manager.resolveInterceptors(InterceptionType.PRE_DESTROY, classBindingAnnotations.toArray(new Annotation[0])).toArray(new Interceptor<?>[]{}));
-
-      List<WBMethod<?, ?>> businessMethods = Beans.getInterceptableBusinessMethods(getAnnotatedItem());
-      for (WBMethod<?, ?> method : businessMethods)
-      {
-         List<Annotation> methodBindingAnnotations = new ArrayList<Annotation>(classBindingAnnotations);
-         methodBindingAnnotations.addAll(flattenInterceptorBindings(manager, method.getAnnotations()));
-         List<Interceptor<?>> methodBoundInterceptors = manager.resolveInterceptors(InterceptionType.AROUND_INVOKE, methodBindingAnnotations.toArray(new Annotation[]{}));
-         builder.interceptAroundInvoke(((AnnotatedMethod)method).getJavaMember()).with(methodBoundInterceptors.toArray(new Interceptor[]{}));
-      }
-      manager.getManagedBeanInterceptorRegistry().registerInterceptionModel(getType(), builder.build());
-   }
-
-
    /**
     * Validates the type
     */
@@ -405,17 +373,17 @@
       return specializedBean;
    }
 
-   private boolean isInterceptionCandidate()
+   protected boolean isInterceptionCandidate()
    {
       return !Beans.isInterceptor(getAnnotatedItem()) && !Beans.isDecorator(getAnnotatedItem());
    }
 
    private boolean hasInterceptors()
    {
-      return manager.getManagedBeanInterceptorRegistry().getInterceptionModel(getType()).getAllInterceptors().size() > 0;
+      return manager.getBoundInterceptorsRegistry().getInterceptionModel(getType()).getAllInterceptors().size() > 0;
    }
 
-   private T applyInterceptors(T instance, final CreationalContext<T> creationalContext)
+   protected T applyInterceptors(T instance, final CreationalContext<T> creationalContext)
    {
       try
       {
@@ -427,7 +395,7 @@
                return new DirectClassInterceptionHandler<Interceptor>(instance, interceptor.getBeanClass());
             }
          };
-         instance = new InterceptorProxyCreatorImpl<Interceptor>(manager.getManagedBeanInterceptorRegistry(), factory).createProxyFromInstance(instance, getType());
+         instance = new InterceptorProxyCreatorImpl<Interceptor>(manager.getBoundInterceptorsRegistry(), factory).createProxyFromInstance(instance, getType());
 
       } catch (Exception e)
       {
@@ -436,24 +404,4 @@
       return instance;
    }
 
-   /**
-    * Extracts the complete set of interception bindings from a given set of annotations.
-    * 
-    * @param manager
-    * @param annotations
-    * @return
-    */
-   protected static Set<Annotation> flattenInterceptorBindings(BeanManagerImpl manager, Set<Annotation> annotations)
-   {
-      Set<Annotation> foundInterceptionBindingTypes = new HashSet<Annotation>();
-      for (Annotation annotation: annotations)
-      {
-         if (manager.isInterceptorBindingType(annotation.annotationType()))
-         {
-            foundInterceptionBindingTypes.add(annotation);
-            foundInterceptionBindingTypes.addAll(manager.getServices().get(MetaAnnotationStore.class).getInterceptorBindingModel(annotation.annotationType()).getInheritedInterceptionBindingTypes());
-         }
-      }
-      return foundInterceptionBindingTypes;
-   }
 }

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SessionBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SessionBean.java	2009-10-05 18:25:00 UTC (rev 3859)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SessionBean.java	2009-10-05 23:00:55 UTC (rev 3860)
@@ -389,6 +389,11 @@
    {
       return Collections.emptySet();
    }
+
+   protected boolean isInterceptionCandidate()
+   {
+      return true;
+   }
    
 }
 




More information about the weld-commits mailing list