[webbeans-commits] Webbeans SVN: r3845 - in ri/trunk/impl: src/main/java/org/jboss/webbeans and 7 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Mon Oct 5 03:58:32 EDT 2009


Author: marius.bogoevici
Date: 2009-10-05 03:58:32 -0400 (Mon, 05 Oct 2009)
New Revision: 3845

Added:
   ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/InterceptorImpl.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/cache/InterceptorBindingModel.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/InterceptorResolvable.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeInterceptorResolver.java
Modified:
   ri/trunk/impl/pom.xml
   ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ManagedBean.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AbstractBeanDeployer.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/WBAnnotated.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/cache/MetaAnnotationStore.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/ResolvableFactory.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeBeanResolver.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeDisposerResolver.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeObserverResolver.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeResolver.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Beans.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/BeansXmlParser.java
Log:
Implementation of Interceptors based on @InterceptionBinding.

Modified: ri/trunk/impl/pom.xml
===================================================================
--- ri/trunk/impl/pom.xml	2009-10-05 07:23:57 UTC (rev 3844)
+++ ri/trunk/impl/pom.xml	2009-10-05 07:58:32 UTC (rev 3845)
@@ -114,7 +114,16 @@
          <artifactId>jsf-api</artifactId>
          <optional>true</optional>
       </dependency>
-      
+
+       <dependency>
+           <groupId>org.jboss.interceptors</groupId>
+           <artifactId>interceptors</artifactId>
+       </dependency>
+
+       <dependency>
+           <groupId>junit</groupId>
+           <artifactId>junit</artifactId>
+       </dependency>
    </dependencies>
 
    <build>

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 07:23:57 UTC (rev 3844)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java	2009-10-05 07:58:32 UTC (rev 3845)
@@ -60,6 +60,7 @@
 
 import org.jboss.webbeans.bean.DecoratorImpl;
 import org.jboss.webbeans.bean.SessionBean;
+import org.jboss.webbeans.bean.InterceptorImpl;
 import org.jboss.webbeans.bean.proxy.ClientProxyProvider;
 import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
 import org.jboss.webbeans.context.CreationalContextImpl;
@@ -77,17 +78,12 @@
 import org.jboss.webbeans.manager.api.WebBeansManager;
 import org.jboss.webbeans.metadata.cache.MetaAnnotationStore;
 import org.jboss.webbeans.metadata.cache.ScopeModel;
-import org.jboss.webbeans.resolution.NameBasedResolver;
-import org.jboss.webbeans.resolution.ResolvableFactory;
-import org.jboss.webbeans.resolution.ResolvableWBClass;
-import org.jboss.webbeans.resolution.TypeSafeBeanResolver;
-import org.jboss.webbeans.resolution.TypeSafeDecoratorResolver;
-import org.jboss.webbeans.resolution.TypeSafeObserverResolver;
-import org.jboss.webbeans.resolution.TypeSafeResolver;
+import org.jboss.webbeans.resolution.*;
 import org.jboss.webbeans.resources.ClassTransformer;
 import org.jboss.webbeans.util.Beans;
 import org.jboss.webbeans.util.Proxies;
 import org.jboss.webbeans.util.Reflections;
+import org.jboss.interceptor.registry.InterceptorRegistry;
 
 import com.google.common.base.Function;
 import com.google.common.base.Supplier;
@@ -103,11 +99,12 @@
  * Interceptors etc. as well as providing resolution
  * 
  * @author Pete Muir
- * 
+ * @author Marius Bogoevici
  */
 public class BeanManagerImpl implements WebBeansManager, Serializable
 {
-   
+
+
    private static class CurrentActivity
    {
 	
@@ -214,8 +211,9 @@
     * archives
     */
    private transient final TypeSafeBeanResolver<Bean<?>> beanResolver;
-   private transient final TypeSafeResolver<DecoratorImpl<?>> decoratorResolver;
-   private transient final TypeSafeResolver<ObserverMethod<?,?>> observerResolver;
+   private transient final TypeSafeResolver<? extends Resolvable, DecoratorImpl<?>> decoratorResolver;
+   private transient final TypeSafeResolver<? extends Resolvable, InterceptorImpl<?>> interceptorResolver;
+   private transient final TypeSafeResolver<? extends Resolvable, ObserverMethod<?,?>> observerResolver;
    private transient final NameBasedResolver nameBasedResolver;
    private transient final ELResolver webbeansELResolver;
    private transient Namespace rootNamespace;
@@ -231,6 +229,7 @@
     */
    private transient final List<Bean<?>> beans;
    private transient final List<DecoratorImpl<?>> decorators;
+   private transient final List<InterceptorImpl<?>> interceptors;
    private transient final List<String> namespaces;
    private transient final List<ObserverMethod<?,?>> observers;
    
@@ -256,6 +255,11 @@
    private transient final ThreadLocal<Stack<InjectionPoint>> currentInjectionPoint;
 
    /**
+    * Interception model
+    */
+   private transient final InterceptorRegistry<Class<?>, Interceptor> managedBeanBoundInterceptorsRegistry = new InterceptorRegistry<Class<?>, Interceptor>();
+
+   /**
     * Create a new, root, manager
     * 
     * @param serviceRegistry
@@ -277,6 +281,7 @@
             serviceRegistry, 
             new CopyOnWriteArrayList<Bean<?>>(),
             new CopyOnWriteArrayList<DecoratorImpl<?>>(),
+            new CopyOnWriteArrayList<InterceptorImpl<?>>(),
             new CopyOnWriteArrayList<ObserverMethod<?,?>>(),
             new CopyOnWriteArrayList<String>(),
             new ConcurrentHashMap<EjbDescriptor<?>, SessionBean<?>>(),
@@ -288,6 +293,7 @@
             new ArrayList<Class<?>>(),
             new ArrayList<Class<? extends Annotation>>(),
             new ArrayList<Class<?>>(),
+            new ArrayList<Class<?>>(), 
             id,
             new AtomicInteger());
    }
@@ -304,6 +310,7 @@
             services, 
             new CopyOnWriteArrayList<Bean<?>>(),
             new CopyOnWriteArrayList<DecoratorImpl<?>>(),
+            new CopyOnWriteArrayList<InterceptorImpl<?>>(),
             new CopyOnWriteArrayList<ObserverMethod<?,?>>(),
             new CopyOnWriteArrayList<String>(),
             rootManager.getEnterpriseBeans(),
@@ -315,6 +322,7 @@
             new ArrayList<Class<?>>(),
             new ArrayList<Class<? extends Annotation>>(),
             new ArrayList<Class<?>>(),
+            new ArrayList<Class<?>>(),
             id,
             new AtomicInteger());
    }
@@ -338,7 +346,8 @@
       return new BeanManagerImpl(
             parentManager.getServices(), 
             beans, 
-            parentManager.getDecorators(), 
+            parentManager.getDecorators(),
+            parentManager.getInterceptors(),
             registeredObservers, 
             namespaces, 
             parentManager.getEnterpriseBeans(), 
@@ -350,6 +359,7 @@
             parentManager.getEnabledPolicyClasses(),
             parentManager.getEnabledPolicyStereotypes(),
             parentManager.getEnabledDecoratorClasses(),
+            parentManager.getEnabledInterceptorClasses(),
             new StringBuilder().append(parentManager.getChildIds().incrementAndGet()).toString(),
             parentManager.getChildIds());
    }
@@ -363,7 +373,8 @@
    private BeanManagerImpl(
          ServiceRegistry serviceRegistry, 
          List<Bean<?>> beans, 
-         List<DecoratorImpl<?>> decorators, 
+         List<DecoratorImpl<?>> decorators,
+         List<InterceptorImpl<?>> interceptors,
          List<ObserverMethod<?,?>> observers, 
          List<String> namespaces,
          Map<EjbDescriptor<?>, SessionBean<?>> enterpriseBeans, 
@@ -374,13 +385,15 @@
          Map<Contextual<?>, Contextual<?>> specializedBeans, 
          Collection<Class<?>> enabledPolicyClasses,
          Collection<Class<? extends Annotation>> enabledPolicyStereotypes,
-         List<Class<?>> enabledDecoratorClasses, 
+         List<Class<?>> enabledDecoratorClasses,
+         List<Class<?>> enabledInterceptorClasses,
          String id,
          AtomicInteger childIds)
    {
       this.services = serviceRegistry;
       this.beans = beans;
       this.decorators = decorators;
+      this.interceptors = interceptors;
       this.enterpriseBeans = enterpriseBeans;
       this.passivationCapableBeans = riBeans;
       this.clientProxyProvider = clientProxyProvider;
@@ -391,6 +404,7 @@
       this.enabledPolicyClasses = enabledPolicyClasses;
       this.enabledPolicyStereotypes = enabledPolicyStereotypes;
       setEnabledDecoratorClasses(enabledDecoratorClasses);
+      setEnabledInterceptorClasses(enabledInterceptorClasses);
       this.namespaces = namespaces;
       this.id = id;
       this.childIds = new AtomicInteger();
@@ -403,6 +417,7 @@
       // TODO Currently we build the accessible bean list on the fly, we need to set it in stone once bootstrap is finished...
       this.beanResolver = new TypeSafeBeanResolver<Bean<?>>(this, createDynamicAccessibleIterable(Transform.BEAN));
       this.decoratorResolver = new TypeSafeDecoratorResolver(this, createDynamicAccessibleIterable(Transform.DECORATOR_BEAN));
+      this.interceptorResolver = new TypeSafeInterceptorResolver(this, createDynamicAccessibleIterable(Transform.INTERCEPTOR_BEAN));
       this.observerResolver = new TypeSafeObserverResolver(this, createDynamicAccessibleIterable(Transform.EVENT_OBSERVER));
       this.nameBasedResolver = new NameBasedResolver(this, createDynamicAccessibleIterable(Transform.BEAN));
       this.webbeansELResolver = new WebBeansELResolver(this);
@@ -486,6 +501,16 @@
          }
          
       };
+
+      public static Transform<InterceptorImpl<?>> INTERCEPTOR_BEAN = new Transform<InterceptorImpl<?>>()
+      {
+
+         public Iterable<InterceptorImpl<?>> transform(BeanManagerImpl beanManager)
+         {
+            return beanManager.getInterceptors();
+         }
+
+      };
       
       public static Transform<ObserverMethod<?,?>> EVENT_OBSERVER = new Transform<ObserverMethod<?,?>>()
       {
@@ -519,6 +544,7 @@
    
    protected Set<BeanManagerImpl> getAccessibleManagers()
    {
+
       return accessibleManagers;
    }
 
@@ -559,6 +585,14 @@
       return resolveObserverMethods(event.getClass(), bindings);
    }
 
+   public void addInterceptor(InterceptorImpl<?> bean)
+   {
+      interceptors.add(bean);
+      //TODO decide if interceptor is passivationCapable
+      interceptorResolver.clear();
+   }
+
+
    @SuppressWarnings("unchecked")
    private <T> Set<ObserverMethod<?, T>> resolveObserverMethods(Type eventType, Annotation... bindings)
    {
@@ -776,6 +810,11 @@
    {
       return Collections.unmodifiableList(decorators);
    }
+
+    public List<InterceptorImpl<?>> getInterceptors()
+   {
+      return Collections.unmodifiableList(interceptors);
+   }
    
    public Iterable<Bean<?>> getAccessibleBeans()
    {
@@ -1058,7 +1097,7 @@
     */
    public List<Interceptor<?>> resolveInterceptors(InterceptionType type, Annotation... interceptorBindings)
    {
-      throw new UnsupportedOperationException();
+      return new ArrayList<Interceptor<?>>(interceptorResolver.resolve(ResolvableFactory.of(type,interceptorBindings)));
    }
 
    /**
@@ -1281,7 +1320,14 @@
 
    public Set<Annotation> getInterceptorBindingTypeDefinition(Class<? extends Annotation> bindingType)
    {
-      throw new UnsupportedOperationException("Not yet implemented");
+      if (getServices().get(MetaAnnotationStore.class).getInterceptorBindingModel(bindingType).isValid())
+      {
+         return getServices().get(MetaAnnotationStore.class).getInterceptorBindingModel(bindingType).getInheritedInterceptionBindingTypes();
+      }
+      else
+      {
+         throw new IllegalArgumentException("Not a interception binding :" + bindingType);
+      }
    }
 
    public Bean<?> getPassivationCapableBean(String id)
@@ -1308,7 +1354,7 @@
 
    public boolean isInterceptorBindingType(Class<? extends Annotation> annotationType)
    {
-      throw new UnsupportedOperationException("Not yet implemented");
+      return getServices().get(MetaAnnotationStore.class).getInterceptorBindingModel(annotationType).isValid();
    }
 
    public boolean isNormalScope(Class<? extends Annotation> annotationType)
@@ -1385,4 +1431,8 @@
       services.cleanup();
    }
 
+   public InterceptorRegistry<Class<?>, Interceptor> getManagedBeanInterceptorRegistry()
+   {
+      return managedBeanBoundInterceptorsRegistry;
+   }
 }

Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/InterceptorImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/InterceptorImpl.java	                        (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/InterceptorImpl.java	2009-10-05 07:58:32 UTC (rev 3845)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed 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.jboss.webbeans.bean;
+
+import org.jboss.interceptor.model.InterceptorClassMetadata;
+import org.jboss.interceptor.registry.InterceptorClassMetadataRegistry;
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.introspector.WBClass;
+import org.jboss.webbeans.metadata.cache.MetaAnnotationStore;
+
+import javax.enterprise.inject.spi.InterceptionType;
+import javax.enterprise.inject.spi.Interceptor;
+import javax.interceptor.InvocationContext;
+import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author Marius Bogoevici
+ */
+public class InterceptorImpl<T> extends ManagedBean<T> implements Interceptor<T>
+{
+   private final InterceptorClassMetadata interceptorClassMetadata;
+
+   private final Set<Annotation> interceptorBindingTypes;
+
+   protected InterceptorImpl(WBClass<T> type, BeanManagerImpl manager)
+   {
+      super(type, new StringBuilder().append(Interceptor.class.getSimpleName()).append(BEAN_ID_SEPARATOR).append(type.getName()).toString(), manager);
+      this.interceptorClassMetadata = InterceptorClassMetadataRegistry.getRegistry().getInterceptorClassMetadata(type.getJavaClass());
+      this.interceptorBindingTypes = new HashSet<Annotation>();
+      for (Annotation annotation: getAnnotatedItem().getAnnotations())
+      {
+         if (manager.isInterceptorBindingType(annotation.annotationType()))
+         {
+            interceptorBindingTypes.add(annotation);
+            interceptorBindingTypes.addAll(getManager().getServices().get(MetaAnnotationStore.class).getInterceptorBindingModel(annotation.annotationType()).getInheritedInterceptionBindingTypes());
+         }
+      }
+      
+   }
+
+   public static <T> InterceptorImpl<T> of(WBClass<T> type, BeanManagerImpl manager)
+   {
+      return new InterceptorImpl(type, manager);
+   }
+
+   public Set<Annotation> getInterceptorBindingTypes()
+   {
+      return interceptorBindingTypes;
+   }
+
+   public Object intercept(InterceptionType type, T instance, InvocationContext ctx)
+   {
+      try
+      {
+         return ctx.proceed();
+      } catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   public boolean intercepts(InterceptionType type)
+   {
+      return interceptorClassMetadata.getInterceptorMethods(org.jboss.interceptor.model.InterceptionType.valueOf(type.name())).size() > 0;
+   }
+
+   @Override
+   public void postConstruct(T instance)
+   {
+      // do nothing on PostConstruct
+   }
+
+   @Override
+   public void preDestroy(T instance)
+   {
+      // do nothing on PreDestroy
+   }
+}

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 07:23:57 UTC (rev 3844)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ManagedBean.java	2009-10-05 07:58:32 UTC (rev 3845)
@@ -16,16 +16,28 @@
  */
 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 org.jboss.interceptor.model.InterceptionModelBuilder;
+import org.jboss.interceptor.proxy.DirectClassInterceptionHandler;
+import org.jboss.interceptor.proxy.InterceptionHandler;
+import org.jboss.interceptor.proxy.InterceptionHandlerFactory;
+import org.jboss.interceptor.proxy.InterceptorProxyCreatorImpl;
+import org.jboss.interceptor.util.InterceptionUtils;
 import org.jboss.webbeans.BeanManagerImpl;
 import org.jboss.webbeans.DefinitionException;
+import org.jboss.webbeans.DeploymentException;
 import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
 import org.jboss.webbeans.injection.ConstructorInjectionPoint;
 import org.jboss.webbeans.injection.InjectionContextImpl;
@@ -43,9 +55,9 @@
 
 /**
  * Represents a simple bean
- * 
+ *
  * @author Pete Muir
- * 
+ * @author Marius Bogoevici
  * @param <T> The type (class) of the bean
  */
 public class ManagedBean<T> extends AbstractClassBean<T>
@@ -62,11 +74,10 @@
 
    private ManagedBean<?> specializedBean;
 
-   
 
    /**
     * Creates a simple, annotation defined Web Bean
-    * 
+    *
     * @param <T> The type
     * @param clazz The class
     * @param manager the current manager
@@ -79,7 +90,7 @@
 
    /**
     * Constructor
-    * 
+    *
     * @param type The type of the bean
     * @param manager The Web Beans manager
     */
@@ -93,7 +104,7 @@
 
    /**
     * Creates an instance of the bean
-    * 
+    *
     * @return The instance
     */
    public T create(CreationalContext<T> creationalContext)
@@ -105,14 +116,21 @@
       }
       T instance = produce(creationalContext);
       inject(instance, creationalContext);
-      postConstruct(instance);
       if (hasDecorators())
       {
          instance = applyDecorators(instance, creationalContext, originalInjectionPoint);
       }
+      if (isInterceptionCandidate() && hasInterceptors())
+      {
+         instance = applyInterceptors(instance, creationalContext);
+         InterceptionUtils.executePostConstruct(instance);
+      } else
+      {
+         postConstruct(instance);
+      }
       return instance;
    }
-   
+
    public T produce(CreationalContext<T> ctx)
    {
       T instance = constructor.newInstance(manager, ctx);
@@ -124,7 +142,7 @@
       }
       return instance;
    }
-   
+
    public void inject(final T instance, final CreationalContext<T> ctx)
    {
       new InjectionContextImpl<T>(getManager(), this, instance)
@@ -135,9 +153,9 @@
             Beans.injectEEFields(instance, getManager(), ejbInjectionPoints, persistenceContextInjectionPoints, persistenceUnitInjectionPoints, resourceInjectionPoints);
             Beans.injectFieldsAndInitializers(instance, ctx, getManager(), getInjectableFields(), getInitializerMethods());
          }
-         
+
       }.run();
-      
+
    }
 
    protected InjectionPoint attachCorrectInjectionPoint()
@@ -148,8 +166,7 @@
          DecoratorImpl<?> decoratorBean = (DecoratorImpl<?>) decorator;
          InjectionPoint outerDelegateInjectionPoint = decoratorBean.getDelegateInjectionPoint();
          return getManager().replaceOrPushCurrentInjectionPoint(outerDelegateInjectionPoint);
-      }
-      else
+      } else
       {
          throw new IllegalStateException("Cannot operate on user defined decorator");
       }
@@ -157,14 +174,19 @@
 
    /**
     * Destroys an instance of the bean
-    * 
+    *
     * @param instance The instance
     */
    public void destroy(T instance, CreationalContext<T> creationalContext)
    {
       try
       {
-         preDestroy(instance);
+         if (!isInterceptionCandidate() || !hasInterceptors())
+            preDestroy(instance);
+         else
+         {
+            InterceptionUtils.executePredestroy(instance);
+         }
          creationalContext.release();
       }
       catch (Exception e)
@@ -187,6 +209,8 @@
          initPostConstruct();
          initPreDestroy();
          initEEInjectionPoints();
+         if (isInterceptionCandidate())
+            initInterceptors();
       }
    }
 
@@ -198,6 +222,42 @@
       this.resourceInjectionPoints = Beans.getResourceInjectionPoints(this, getAnnotatedItem(), manager);
    }
 
+   private void initInterceptors()
+   {
+      InterceptionModelBuilder<Class<?>, Interceptor> builder = InterceptionModelBuilder.newBuilderFor(getType(), (Class) Interceptor.class);
+
+      List<Annotation> classBindingAnnotations = new ArrayList<Annotation>();
+
+      for (Annotation annotation : getType().getAnnotations())
+      {
+         if (manager.isInterceptorBindingType(annotation.annotationType()))
+         {
+            classBindingAnnotations.add(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);
+         for (Annotation annotation : method.getAnnotations())
+         {
+            if (manager.isInterceptorBindingType(annotation.annotationType()))
+            {
+               methodBindingAnnotations.add(annotation);
+               methodBindingAnnotations.addAll(manager.getServices().get(MetaAnnotationStore.class).getInterceptorBindingModel(annotation.annotationType()).getInheritedInterceptionBindingTypes());
+            }
+         }
+         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
     */
@@ -230,7 +290,7 @@
                DecoratorImpl<?> decoratorBean = (DecoratorImpl<?>) decorator;
                for (WBMethod<?, ?> decoratorMethod : decoratorBean.getAnnotatedItem().getWBMethods())
                {
-                  WBMethod<?, ?> method = getAnnotatedItem().getWBMethod(decoratorMethod.getSignature());  
+                  WBMethod<?, ?> method = getAnnotatedItem().getWBMethod(decoratorMethod.getSignature());
                   if (method != null && !method.isStatic() && !method.isPrivate() && method.isFinal())
                   {
                      throw new DefinitionException("Decorated bean method " + method + " (decorated by "+ decoratorMethod + ") cannot be declarted final");
@@ -260,7 +320,7 @@
          }
       }
    }
-   
+
    protected void checkConstructor()
    {
       if (!constructor.getAnnotatedWBParameters(Disposes.class).isEmpty())
@@ -294,8 +354,7 @@
       if (!(specializedBean instanceof ManagedBean))
       {
          throw new DefinitionException(toString() + " doesn't have a simple bean as a superclass " + specializedBean);
-      }
-      else
+      } else
       {
          this.specializedBean = (ManagedBean<?>) specializedBean;
       }
@@ -314,7 +373,7 @@
 
    /**
     * Returns the constructor
-    * 
+    *
     * @return The constructor
     */
    public WBConstructor<T> getConstructor()
@@ -324,7 +383,7 @@
 
    /**
     * Gets a string representation
-    * 
+    *
     * @return The string representation
     */
    @Override
@@ -332,7 +391,7 @@
    {
       return getDescription("simple bean");
    }
-   
+
    protected String getDescription(String beanType)
    {
       StringBuilder buffer = new StringBuilder();
@@ -356,4 +415,35 @@
       return specializedBean;
    }
 
+   private boolean isInterceptionCandidate()
+   {
+      return !Beans.isInterceptor(getAnnotatedItem()) && !Beans.isDecorator(getAnnotatedItem());
+   }
+
+   private boolean hasInterceptors()
+   {
+      return manager.getManagedBeanInterceptorRegistry().getInterceptionModel(getType()).getAllInterceptors().size() > 0;
+   }
+
+   private T applyInterceptors(T instance, final CreationalContext<T> creationalContext)
+   {
+      try
+      {
+         InterceptionHandlerFactory<Interceptor> factory = new InterceptionHandlerFactory<Interceptor>()
+         {
+            public InterceptionHandler createFor(final Interceptor interceptor)
+            {
+               final Object instance = getManager().getReference(interceptor, creationalContext);
+               return new DirectClassInterceptionHandler<Interceptor>(instance, interceptor.getBeanClass());
+            }
+         };
+         instance = new InterceptorProxyCreatorImpl<Interceptor>(manager.getManagedBeanInterceptorRegistry(), factory).createProxyFromInstance(instance, getType());
+
+      } catch (Exception e)
+      {
+         throw new DeploymentException(e);
+      }
+      return instance;
+   }
+
 }

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AbstractBeanDeployer.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AbstractBeanDeployer.java	2009-10-05 07:23:57 UTC (rev 3844)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AbstractBeanDeployer.java	2009-10-05 07:58:32 UTC (rev 3845)
@@ -16,9 +16,9 @@
  */
 package org.jboss.webbeans.bootstrap;
 
+import java.util.Set;
 import java.lang.reflect.Member;
 import java.lang.reflect.Type;
-import java.util.Set;
 
 import javax.enterprise.event.Observes;
 import javax.enterprise.inject.Disposes;
@@ -40,6 +40,7 @@
 import org.jboss.webbeans.bean.ProducerMethod;
 import org.jboss.webbeans.bean.RIBean;
 import org.jboss.webbeans.bean.SessionBean;
+import org.jboss.webbeans.bean.InterceptorImpl;
 import org.jboss.webbeans.bean.ee.EEResourceProducerField;
 import org.jboss.webbeans.bean.ee.PersistenceContextProducerField;
 import org.jboss.webbeans.bootstrap.events.ProcessObserverMethodImpl;
@@ -90,6 +91,12 @@
          manager.addDecorator(bean);
          log.debug("Bean: " + bean);
       }
+      for (InterceptorImpl<?> bean: getEnvironment().getInterceptors())
+      {
+         bean.initialize(getEnvironment());
+         manager.addInterceptor(bean);
+         log.debug("Interceptor: " + bean);
+      }
       for (RIBean<?> bean : beans)
       {
          bean.initialize(getEnvironment());
@@ -237,6 +244,12 @@
       DecoratorImpl<T> bean = DecoratorImpl.of(annotatedClass, manager);
       getEnvironment().addBean(bean);
    }
+
+   protected <T> void createInterceptor(WBClass<T> annotatedClass)
+   {
+      InterceptorImpl<T> bean = InterceptorImpl.of(annotatedClass, manager);
+      getEnvironment().addBean(bean);
+   }
    
    protected <T> void createEnterpriseBean(InternalEjbDescriptor<T> ejbDescriptor)
    {

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java	2009-10-05 07:23:57 UTC (rev 3844)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java	2009-10-05 07:58:32 UTC (rev 3845)
@@ -109,7 +109,7 @@
          }
          else if (managedBeanOrDecorator && clazz.isAnnotationPresent(Interceptor.class))
          {
-            //createInterceptor(clazz);
+            createInterceptor(clazz);
          }
          else if (managedBeanOrDecorator && !clazz.isAbstract())
          {

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java	2009-10-05 07:23:57 UTC (rev 3844)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java	2009-10-05 07:58:32 UTC (rev 3845)
@@ -34,6 +34,7 @@
 import org.jboss.webbeans.bean.ProducerField;
 import org.jboss.webbeans.bean.ProducerMethod;
 import org.jboss.webbeans.bean.RIBean;
+import org.jboss.webbeans.bean.InterceptorImpl;
 import org.jboss.webbeans.bean.builtin.AbstractBuiltInBean;
 import org.jboss.webbeans.bean.builtin.ExtensionBean;
 import org.jboss.webbeans.ejb.EjbDescriptors;
@@ -53,6 +54,7 @@
    private final List<DisposalMethod<?, ?>> allDisposalBeans;
    private final Set<DisposalMethod<?, ?>> resolvedDisposalBeans;
    private final Set<DecoratorImpl<?>> decorators;
+   private final Set<InterceptorImpl<?>> interceptors;
    private final EjbDescriptors ejbDescriptors;
    private final TypeSafeDisposerResolver disposalMethodResolver;
 
@@ -64,6 +66,7 @@
       this.resolvedDisposalBeans = new HashSet<DisposalMethod<?, ?>>();
       this.beans = new HashSet<RIBean<?>>();
       this.decorators = new HashSet<DecoratorImpl<?>>();
+      this.interceptors = new HashSet<InterceptorImpl<?>>();
       this.observers = new HashSet<ObserverMethodImpl<?, ?>>();
       this.ejbDescriptors = ejbDescriptors;
       this.disposalMethodResolver = new TypeSafeDisposerResolver(manager, allDisposalBeans);
@@ -131,6 +134,11 @@
    {
       decorators.add(bean);
    }
+
+   public void addBean(InterceptorImpl<?> bean)
+   {
+      interceptors.add(bean);
+   }
    
    public void addBean(DisposalMethod<?, ?> bean)
    {
@@ -152,6 +160,11 @@
       return Collections.unmodifiableSet(decorators);
    }
 
+   public Set<InterceptorImpl<?>> getInterceptors()
+   {
+      return Collections.unmodifiableSet(interceptors);
+   }
+
    public Set<ObserverMethodImpl<?, ?>> getObservers()
    {
       return Collections.unmodifiableSet(observers);

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/WBAnnotated.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/WBAnnotated.java	2009-10-05 07:23:57 UTC (rev 3844)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/WBAnnotated.java	2009-10-05 07:58:32 UTC (rev 3845)
@@ -27,6 +27,7 @@
 import javax.enterprise.inject.stereotype.Stereotype;
 import javax.inject.Qualifier;
 import javax.inject.Scope;
+import javax.interceptor.InterceptorBinding;
 
 /**
  * AnnotatedItem provides a uniform access to the annotations on an annotated
@@ -40,7 +41,7 @@
 
    // The set of meta-annotations to map
    @SuppressWarnings("unchecked")
-   public static final Set<Class<? extends Annotation>> MAPPED_METAANNOTATIONS = new HashSet<Class<? extends Annotation>>(Arrays.asList(Qualifier.class, Stereotype.class, Scope.class, NormalScope.class));
+   public static final Set<Class<? extends Annotation>> MAPPED_METAANNOTATIONS = new HashSet<Class<? extends Annotation>>(Arrays.asList(Qualifier.class, Stereotype.class, Scope.class, NormalScope.class, InterceptorBinding.class));
 
    /**
     * Gets all annotations which are annotated with the given meta annotation

Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/cache/InterceptorBindingModel.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/cache/InterceptorBindingModel.java	                        (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/cache/InterceptorBindingModel.java	2009-10-05 07:58:32 UTC (rev 3845)
@@ -0,0 +1,113 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed 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.jboss.webbeans.metadata.cache;
+
+import org.jboss.webbeans.resources.ClassTransformer;
+import org.jboss.webbeans.util.collections.Arrays2;
+import org.jboss.webbeans.log.Log;
+import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.introspector.WBMethod;
+
+import javax.interceptor.InterceptorBinding;
+import javax.enterprise.inject.Nonbinding;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Set;
+
+/**
+ * @author Marius Bogoevici
+ */
+public class InterceptorBindingModel<T extends Annotation> extends AnnotationModel<T>
+{
+   private static final Set<Class<? extends Annotation>> META_ANNOTATIONS = Arrays2.<Class<? extends Annotation>>asSet(InterceptorBinding.class);
+   private static final Log log = Logging.getLog(BindingTypeModel.class);
+   private Set<WBMethod<?,?>> nonBindingTypes;
+   private Set<Annotation> inheritedInterceptionBindingTypes;
+   private Set<Annotation> metaAnnotations;
+
+   public InterceptorBindingModel(Class<T> type, ClassTransformer transformer)
+   {
+      super(type, transformer);
+      initNonBindingTypes();
+      initInterceptionBindingTypes();
+      this.metaAnnotations = getAnnotatedAnnotation().getAnnotations();
+   }
+
+   protected Set<Class<? extends Annotation>> getMetaAnnotationTypes()
+   {
+      return META_ANNOTATIONS;
+   }
+
+   public Set<Annotation> getMetaAnnotations()
+   {
+      return metaAnnotations;
+   }
+
+   protected void initNonBindingTypes()
+   {
+      nonBindingTypes = getAnnotatedAnnotation().getAnnotatedMembers(Nonbinding.class);
+   }
+
+   protected void initInterceptionBindingTypes()
+   {
+      inheritedInterceptionBindingTypes = getAnnotatedAnnotation().getMetaAnnotations(InterceptorBinding.class);
+   }
+
+   public Set<Annotation> getInheritedInterceptionBindingTypes()
+   {
+      return inheritedInterceptionBindingTypes;
+   }
+
+   public boolean isEqual(Annotation instance, Annotation other)
+   {
+      if (instance.annotationType().equals(getRawType()) && other.annotationType().equals(getRawType()))
+      {
+         for (WBMethod<?, ?> annotatedMethod : getAnnotatedAnnotation().getMembers())
+         {
+            if (!nonBindingTypes.contains(annotatedMethod))
+            {
+               try
+               {
+                  Object thisValue = annotatedMethod.invoke(instance);
+                  Object thatValue = annotatedMethod.invoke(other);
+                  if (!thisValue.equals(thatValue))
+                  {
+                     return false;
+                  }
+               }
+               catch (IllegalArgumentException e)
+               {
+                  throw new RuntimeException(e);
+               }
+               catch (IllegalAccessException e)
+               {
+                  throw new RuntimeException(e);
+               }
+               catch (InvocationTargetException e)
+               {
+                  throw new RuntimeException(e);
+               }
+
+            }
+         }
+         return true;
+      }
+      return false;
+   }
+
+}

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/cache/MetaAnnotationStore.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/cache/MetaAnnotationStore.java	2009-10-05 07:23:57 UTC (rev 3844)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/metadata/cache/MetaAnnotationStore.java	2009-10-05 07:58:32 UTC (rev 3845)
@@ -38,7 +38,9 @@
    private ConcurrentCache<Class<? extends Annotation>, ScopeModel<?>> scopes = new ConcurrentCache<Class<? extends Annotation>, ScopeModel<?>>();
    // The binding type models
    private ConcurrentCache<Class<? extends Annotation>, BindingTypeModel<?>> bindingTypes = new ConcurrentCache<Class<? extends Annotation>, BindingTypeModel<?>>();
-   
+   // the interceptor bindings
+   private ConcurrentCache<Class<? extends Annotation>, InterceptorBindingModel<?>> interceptorBindings = new ConcurrentCache<Class<? extends Annotation>, InterceptorBindingModel<?>>();
+
    private final ClassTransformer classTransformer;
 
    public MetaAnnotationStore(ClassTransformer classTransformer)
@@ -124,6 +126,7 @@
       buffer.append("Registered binding type models: " + bindingTypes.size() + "\n");
       buffer.append("Registered scope type models: " + scopes.size() + "\n");
       buffer.append("Registered stereotype models: " + stereotypes.size() + "\n");
+      buffer.append("Registered interceptor binding models: " + interceptorBindings.size() + "\n");
       return buffer.toString();
    }
    
@@ -134,4 +137,16 @@
       stereotypes.clear();
    }
 
+   public <T extends Annotation> InterceptorBindingModel getInterceptorBindingModel(final Class<T> interceptorBinding)
+   {
+      return interceptorBindings.putIfAbsent(interceptorBinding, new Callable<InterceptorBindingModel<T>>()
+      {
+
+         public InterceptorBindingModel<T> call() throws Exception
+         {
+            return new InterceptorBindingModel<T>(interceptorBinding, classTransformer);
+         }
+
+      });
+   }
 }

Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/InterceptorResolvable.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/InterceptorResolvable.java	                        (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/InterceptorResolvable.java	2009-10-05 07:58:32 UTC (rev 3845)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed 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.jboss.webbeans.resolution;
+
+import javax.enterprise.inject.spi.InterceptionType;
+
+/**
+ * @author Marius Bogoevici
+ */
+public interface InterceptorResolvable extends Resolvable
+{
+
+   InterceptionType getInterceptionType();
+
+}

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/ResolvableFactory.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/ResolvableFactory.java	2009-10-05 07:23:57 UTC (rev 3844)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/ResolvableFactory.java	2009-10-05 07:58:32 UTC (rev 3845)
@@ -23,12 +23,15 @@
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.Collections;
 
 import org.jboss.webbeans.bean.AbstractClassBean;
 import org.jboss.webbeans.introspector.WBAnnotated;
 import org.jboss.webbeans.literal.DefaultLiteral;
 import org.jboss.webbeans.util.Reflections;
 
+import javax.enterprise.inject.spi.InterceptionType;
+
 public class ResolvableFactory
 {
 
@@ -56,6 +59,11 @@
       return new ResolvableImpl(new HashSet<Annotation>(Arrays.asList(bindings)), typeClosure, declaringBean);
    }
 
+   public static Resolvable of(InterceptionType interceptionType, Annotation... bindings)
+   {
+      return new InterceptorResolvableImpl(new HashSet<Annotation>(Arrays.asList(bindings)), interceptionType );
+   }
+
    private ResolvableFactory() {}
 
    private static class ResolvableImpl implements Resolvable
@@ -126,4 +134,20 @@
 
    }
 
+   private static class InterceptorResolvableImpl extends ResolvableImpl implements InterceptorResolvable
+   {
+      private final InterceptionType interceptionType;
+
+      private InterceptorResolvableImpl(Set<Annotation> bindings, InterceptionType interceptionType)
+      {
+         super(bindings, Collections.singleton((Type)Object.class), null);
+         this.interceptionType = interceptionType;
+      }
+
+      public InterceptionType getInterceptionType()
+      {
+         return interceptionType;
+      }
+   }
+
 }

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeBeanResolver.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeBeanResolver.java	2009-10-05 07:23:57 UTC (rev 3844)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeBeanResolver.java	2009-10-05 07:58:32 UTC (rev 3845)
@@ -34,7 +34,7 @@
  * @author pmuir
  *
  */
-public class TypeSafeBeanResolver<T extends Bean<?>> extends TypeSafeResolver<T>
+public class TypeSafeBeanResolver<T extends Bean<?>> extends TypeSafeResolver<Resolvable, T>
 {
 
    public static final Set<ResolvableTransformer> TRANSFORMERS;

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeDisposerResolver.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeDisposerResolver.java	2009-10-05 07:23:57 UTC (rev 3844)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeDisposerResolver.java	2009-10-05 07:58:32 UTC (rev 3845)
@@ -28,7 +28,7 @@
  * @author pmuir
  *
  */
-public class TypeSafeDisposerResolver extends TypeSafeResolver<DisposalMethod<?, ?>>
+public class TypeSafeDisposerResolver extends TypeSafeResolver<Resolvable, DisposalMethod<?, ?>>
 {
 
    private final BeanManagerImpl manager;

Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeInterceptorResolver.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeInterceptorResolver.java	                        (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeInterceptorResolver.java	2009-10-05 07:58:32 UTC (rev 3845)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed 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.jboss.webbeans.resolution;
+
+import org.jboss.webbeans.bean.InterceptorImpl;
+import org.jboss.webbeans.bean.DecoratorImpl;
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.util.Reflections;
+import org.jboss.webbeans.util.Beans;
+
+import java.util.*;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+public class TypeSafeInterceptorResolver extends TypeSafeResolver<InterceptorResolvable,InterceptorImpl<?>>
+{
+   private BeanManagerImpl manager;
+
+
+   public TypeSafeInterceptorResolver(BeanManagerImpl manager, Iterable<InterceptorImpl<?>> interceptors)
+   {
+      super(interceptors);
+      this.manager = manager;
+   }
+
+   @Override
+   protected boolean matches(InterceptorResolvable resolvable, InterceptorImpl<?> bean)
+   {
+      return bean.intercepts(resolvable.getInterceptionType())
+            && bean.getInterceptorBindingTypes().size() > 0
+            && Beans.containsAllInterceptionBindings(bean.getInterceptorBindingTypes(), resolvable.getQualifiers(), getManager())
+            && getManager().getEnabledInterceptorClasses().contains(bean.getType());
+   }
+
+
+   @Override
+   protected Set<InterceptorImpl<?>> sortResult(Set<InterceptorImpl<?>> matchedInterceptors)
+   {
+      Set<InterceptorImpl<?>> sortedBeans = new TreeSet<InterceptorImpl<?>>(new Comparator<InterceptorImpl<?>>()
+      {
+
+         public int compare(InterceptorImpl<?> o1, InterceptorImpl<?> o2)
+         {
+            List<Class<?>> enabledInterceptors = getManager().getEnabledInterceptorClasses();
+            int p1 = enabledInterceptors.indexOf(((InterceptorImpl<?>) o1).getType());
+            int p2 = enabledInterceptors.indexOf(((InterceptorImpl<?>) o2).getType());
+            return p1 - p2;
+         }
+
+      });
+      sortedBeans.addAll(matchedInterceptors);
+      return sortedBeans;
+   }
+
+   protected Set<InterceptorImpl<?>> filterResult(Set<InterceptorImpl<?>> matched)
+   {
+      return matched;
+   }
+
+   protected Iterable<ResolvableTransformer> getTransformers()
+   {
+      return Collections.EMPTY_SET;
+   }
+
+   public BeanManagerImpl getManager()
+   {
+      return manager;
+   }
+}

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeObserverResolver.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeObserverResolver.java	2009-10-05 07:23:57 UTC (rev 3844)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeObserverResolver.java	2009-10-05 07:58:32 UTC (rev 3845)
@@ -29,7 +29,7 @@
  * @author pmuir
  *
  */
-public class TypeSafeObserverResolver extends TypeSafeResolver<ObserverMethod<?,?>>
+public class TypeSafeObserverResolver extends TypeSafeResolver<Resolvable, ObserverMethod<?,?>>
 {
 
    private final BeanManagerImpl manager;

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeResolver.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeResolver.java	2009-10-05 07:23:57 UTC (rev 3844)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeResolver.java	2009-10-05 07:58:32 UTC (rev 3845)
@@ -27,8 +27,9 @@
  * Implementation of type safe bean resolution
  * 
  * @author Pete Muir
+ * @author Marius Bogoevici
  */
-public abstract class TypeSafeResolver<T>
+public abstract class TypeSafeResolver<R extends Resolvable,T>
 {
    private static final long serialVersionUID = 1L;
    
@@ -140,7 +141,7 @@
       Set<T> result = new HashSet<T>();
       for (T bean : iterable)
       {
-         if (matches(resolvable, bean))
+         if (matches((R)resolvable.delegate(), bean))
          {
             result.add(bean);
          }
@@ -148,7 +149,7 @@
       return result;
    }
 
-   protected abstract boolean matches(Resolvable resolvable, T t);
+   protected abstract boolean matches(R resolvable, T t);
 
    /**
     * Gets a string representation

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Beans.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Beans.java	2009-10-05 07:23:57 UTC (rev 3844)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Beans.java	2009-10-05 07:58:32 UTC (rev 3845)
@@ -18,6 +18,8 @@
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
+import java.lang.reflect.Member;
+import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -30,6 +32,7 @@
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.decorator.Decorates;
+import javax.decorator.Decorator;
 import javax.enterprise.context.spi.Contextual;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.event.Observes;
@@ -37,7 +40,10 @@
 import javax.enterprise.inject.Disposes;
 import javax.enterprise.inject.Produces;
 import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.Interceptor;
+import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.inject.Inject;
+import javax.interceptor.AroundInvoke;
 
 import org.jboss.webbeans.BeanManagerImpl;
 import org.jboss.webbeans.DefinitionException;
@@ -53,17 +59,15 @@
 import org.jboss.webbeans.injection.spi.EjbInjectionServices;
 import org.jboss.webbeans.injection.spi.JpaInjectionServices;
 import org.jboss.webbeans.injection.spi.ResourceInjectionServices;
-import org.jboss.webbeans.introspector.MethodSignature;
-import org.jboss.webbeans.introspector.WBClass;
-import org.jboss.webbeans.introspector.WBConstructor;
-import org.jboss.webbeans.introspector.WBField;
-import org.jboss.webbeans.introspector.WBMethod;
-import org.jboss.webbeans.introspector.WBParameter;
+import org.jboss.webbeans.introspector.*;
 import org.jboss.webbeans.log.Log;
 import org.jboss.webbeans.log.Logging;
 import org.jboss.webbeans.metadata.cache.BindingTypeModel;
 import org.jboss.webbeans.metadata.cache.MetaAnnotationStore;
+import org.jboss.webbeans.metadata.cache.InterceptorBindingModel;
 import org.jboss.webbeans.persistence.PersistenceApiAbstraction;
+import org.jboss.interceptor.model.InterceptionType;
+import org.jboss.interceptor.model.InterceptionTypeRegistry;
 
 import com.google.common.base.Supplier;
 import com.google.common.collect.Multimap;
@@ -218,6 +222,35 @@
          return null;
       }
    }
+
+   public static List<WBMethod<?,?>> getInterceptableBusinessMethods(WBClass<?> type)
+   {
+      List<WBMethod<?, ?>> annotatedMethods = new ArrayList<WBMethod<?, ?>>();
+      for (WBMethod<?, ?> annotatedMethod : type.getWBMethods())
+      {
+         int modifiers = ((WBMember) annotatedMethod).getJavaMember().getModifiers();
+         boolean businessMethod = !annotatedMethod.isStatic()
+               && (Modifier.isPublic(modifiers)
+                  || Modifier.isProtected(modifiers))
+               && !annotatedMethod.isAnnotationPresent(Inject.class)
+               && !annotatedMethod.isAnnotationPresent(Produces.class)
+               && annotatedMethod.getAnnotatedWBParameters(Disposes.class).isEmpty()
+               && annotatedMethod.getAnnotatedWBParameters(Observes.class).isEmpty();
+
+         if (businessMethod)
+         {
+            for (InterceptionType interceptionType : InterceptionTypeRegistry.getSupportedInterceptionTypes())
+            {
+               businessMethod = !annotatedMethod.isAnnotationPresent(InterceptionTypeRegistry.getAnnotationClass(interceptionType));
+               if (!businessMethod)
+                  break;
+            }
+            if (businessMethod)
+               annotatedMethods.add(annotatedMethod);
+         }
+      }
+      return annotatedMethods;
+   }
    
 
    public static Set<WBInjectionPoint<?, ?>> getEjbInjectionPoints(Bean<?> declaringBean, WBClass<?> type, BeanManagerImpl manager)
@@ -425,6 +458,28 @@
       }
       return true;
    }
+
+   public static boolean containsAllInterceptionBindings(Set<Annotation> expectedBindings, Set<Annotation> existingBindings, BeanManagerImpl manager)
+   {
+      for (Annotation binding : expectedBindings)
+      {
+         InterceptorBindingModel<?> bindingType = manager.getServices().get(MetaAnnotationStore.class).getInterceptorBindingModel(binding.annotationType());
+         boolean matchFound = false;
+         // TODO Something wrong with annotation proxy hashcode in JDK/AnnotationLiteral hashcode, so always do a full check, don't use contains
+         for (Annotation otherBinding : existingBindings)
+         {
+            if (bindingType.isEqual(binding, otherBinding))
+            {
+               matchFound = true;
+            }
+         }
+         if (!matchFound)
+         {
+            return false;
+         }
+      }
+      return true;
+   }
    
 
    /**
@@ -655,5 +710,15 @@
          initializer.invoke(instance, manager, creationalContext, CreationException.class);
       }
    }
+
+   public static <T> boolean isInterceptor(WBClass<T> annotatedItem)
+   {
+      return annotatedItem.isAnnotationPresent(javax.interceptor.Interceptor.class);
+   }
+
+   public static <T> boolean isDecorator(WBClass<T> annotatedItem)
+   {
+      return annotatedItem.isAnnotationPresent(Decorator.class);
+   }
    
 }

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/BeansXmlParser.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/BeansXmlParser.java	2009-10-05 07:23:57 UTC (rev 3844)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/xml/BeansXmlParser.java	2009-10-05 07:58:32 UTC (rev 3845)
@@ -103,7 +103,7 @@
    
    public List<Class<?>> getEnabledInterceptorClasses()
    {
-      return Collections.emptyList();
+      return enabledInterceptorClasses;
    }
    
    public BeansXmlParser(ResourceLoader resourceLoader, Iterable<URL> beansXml)



More information about the weld-commits mailing list