You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2013/01/08 23:57:56 UTC

svn commit: r1430620 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component: CdiInterceptorBean.java EjbInterceptorBean.java InterceptorBean.java

Author: struberg
Date: Tue Jan  8 22:57:56 2013
New Revision: 1430620

URL: http://svn.apache.org/viewvc?rev=1430620&view=rev
Log:
OWB-344 introduce EjbInterceptorBean

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/EjbInterceptorBean.java
      - copied, changed from r1430567, openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InterceptorBean.java
      - copied, changed from r1430567, openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java?rev=1430620&r1=1430619&r2=1430620&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java Tue Jan  8 22:57:56 2013
@@ -18,31 +18,20 @@
  */
 package org.apache.webbeans.component;
 
-import javax.enterprise.context.Dependent;
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.InterceptionType;
 import javax.enterprise.inject.spi.Interceptor;
-import javax.interceptor.InvocationContext;
 import java.lang.annotation.Annotation;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.util.Set;
 
 import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.exception.WebBeansException;
-import org.apache.webbeans.intercept.InterceptorResolution;
-import org.apache.webbeans.util.Asserts;
-import org.apache.webbeans.util.ExceptionUtil;
 
 /**
  * <p>{@link Interceptor} Bean implementation for CDI-style Beans.
  * This is Interceptors which got defined using
  * &#064;{@link javax.interceptor.InterceptorBinding}.</p>
- *
- * <p>Any Interceptor is also an InjectionTarget as they can contain
- * &#064;Inject InjectionPoints.</p>
  */
-public class CdiInterceptorBean<T> extends AbstractInjectionTargetBean<T> implements Interceptor<T>
+public class CdiInterceptorBean<T> extends InterceptorBean<T> implements Interceptor<T>
 {
     /**
      *
@@ -57,138 +46,13 @@ public class CdiInterceptorBean<T> exten
                               Set<Annotation> interceptorBindings,
                               Set<InterceptionType> intercepts)
     {
-        super(WebBeansType.INTERCEPTOR, returnType, annotatedType, webBeansContext);
+        super(returnType, annotatedType, webBeansContext, intercepts);
         this.interceptorBindings = interceptorBindings;
-
-        Asserts.assertNotNull(intercepts, "Interceptor does not handle any InterceptionTypes!");
-        this.intercepts = intercepts;
-
     }
 
-    /**
-     * Contains all the information about single intercepted Methods;
-     */
-    private InterceptorResolution.BeanInterceptorInfo interceptorInfo;
-
 
     private Set<Annotation> interceptorBindings;
 
-    private Set<InterceptionType> intercepts;
-
-    /**
-     * The Method to be called for InterceptionType.AROUND_INVOKE.
-     * The method signature must be
-     * <pre>Object <METHOD>(InvocationContext) throws Exception</pre>
-     */
-    private Method aroundInvokeMethod;
-
-    /**
-     * The Method to be called for InterceptionType.AROUND_TIMEOUT.
-     * The method signature must be
-     * <pre>Object <METHOD>(InvocationContext) throws Exception</pre>
-     */
-    private Method aroundTimeoutMethod;
-
-    /**
-     * All &#064;PostConstruct interceptor method
-     * The method signature must be
-     * <pre>void <METHOD>(InvocationContext) throws Exception</pre>
-     */
-    private Method postConstructMethod;
-
-    /**
-     * All &#064;PreDestroy interceptor method
-     * The method signature must be
-     * <pre>void <METHOD>(InvocationContext) throws Exception</pre>
-     */
-    private Method preDestroyMethod;
-
-    /**
-     * All &#064;PrePassivate interceptor method
-     * The method signature must be
-     * <pre>void <METHOD>(InvocationContext) throws Exception</pre>
-     */
-    private Method prePassivateMethod;
-
-    /**
-     * All &#064;PostActivate interceptor method
-     * The method signature must be
-     * <pre>void <METHOD>(InvocationContext) throws Exception</pre>
-     */
-    private Method postActivateMethod;
-
-    public void setAroundInvokeMethod(Method aroundInvokeMethod)
-    {
-        this.aroundInvokeMethod = aroundInvokeMethod;
-    }
-
-    public void setAroundTimeoutMethod(Method aroundTimeoutMethod)
-    {
-        this.aroundTimeoutMethod = aroundTimeoutMethod;
-    }
-
-    public void setPostActivateMethod(Method postActivateMethod)
-    {
-        this.postActivateMethod = postActivateMethod;
-    }
-
-    public void setPostConstructMethod(Method postConstructMethod)
-    {
-        this.postConstructMethod = postConstructMethod;
-    }
-
-    public void setPreDestroyMethod(Method preDestroyMethod)
-    {
-        this.preDestroyMethod = preDestroyMethod;
-    }
-
-    public void setPrePassivateMethod(Method prePassivateMethod)
-    {
-        this.prePassivateMethod = prePassivateMethod;
-    }
-
-    /**
-     * Interceptors are by default &#064;Dependent scoped.
-     */
-    @Override
-    public Class<? extends Annotation> getScope()
-    {
-        return Dependent.class;
-    }
-
-    /**
-     * @param interceptionType
-     * @return the underlying interceptor method for the given InterceptionType or <code>null</code>
-     */
-    protected Method getInterceptorMethod(InterceptionType interceptionType)
-    {
-        if (InterceptionType.AROUND_INVOKE.equals(interceptionType))
-        {
-            return aroundInvokeMethod;
-        }
-        if (InterceptionType.POST_CONSTRUCT.equals(interceptionType))
-        {
-            return postConstructMethod;
-        }
-        if (InterceptionType.PRE_DESTROY.equals(interceptionType))
-        {
-            return preDestroyMethod;
-        }
-        if (InterceptionType.AROUND_TIMEOUT.equals(interceptionType))
-        {
-            return aroundTimeoutMethod;
-        }
-        if (InterceptionType.POST_ACTIVATE.equals(interceptionType))
-        {
-            return postActivateMethod;
-        }
-        if (InterceptionType.PRE_PASSIVATE.equals(interceptionType))
-        {
-            return prePassivateMethod;
-        }
-
-        throw new WebBeansException("InterceptionType not yet supported: " + interceptionType);
-    }
 
     @Override
     public Set<Annotation> getInterceptorBindings()
@@ -196,27 +60,5 @@ public class CdiInterceptorBean<T> exten
         return interceptorBindings;
     }
 
-    @Override
-    public boolean intercepts(InterceptionType interceptionType)
-    {
-        return intercepts.contains(interceptionType);
-    }
-
-    @Override
-    public Object intercept(InterceptionType interceptionType, T instance, InvocationContext invocationContext)
-    {
-        try
-        {
-            return getInterceptorMethod(interceptionType).invoke(instance, invocationContext);
-        }
-        catch (InvocationTargetException ite)
-        {
-            throw ExceptionUtil.throwAsRuntimeException(ite);
-        }
-        catch (IllegalAccessException iae)
-        {
-            throw ExceptionUtil.throwAsRuntimeException(iae);
-        }
-    }
 
 }

Copied: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/EjbInterceptorBean.java (from r1430567, openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/EjbInterceptorBean.java?p2=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/EjbInterceptorBean.java&p1=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java&r1=1430567&r2=1430620&rev=1430620&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/EjbInterceptorBean.java Tue Jan  8 22:57:56 2013
@@ -18,205 +18,44 @@
  */
 package org.apache.webbeans.component;
 
-import javax.enterprise.context.Dependent;
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.InterceptionType;
 import javax.enterprise.inject.spi.Interceptor;
-import javax.interceptor.InvocationContext;
 import java.lang.annotation.Annotation;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
+import java.util.Collections;
 import java.util.Set;
 
 import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.exception.WebBeansException;
-import org.apache.webbeans.intercept.InterceptorResolution;
-import org.apache.webbeans.util.Asserts;
-import org.apache.webbeans.util.ExceptionUtil;
 
 /**
- * <p>{@link Interceptor} Bean implementation for CDI-style Beans.
- * This is Interceptors which got defined using
- * &#064;{@link javax.interceptor.InterceptorBinding}.</p>
- *
- * <p>Any Interceptor is also an InjectionTarget as they can contain
- * &#064;Inject InjectionPoints.</p>
+ * <p>{@link javax.enterprise.inject.spi.Interceptor} Bean implementation for EJB-style Beans.
+ * This is Interceptors which got defined by being referenced via
+ * &#064;{@link javax.interceptor.Interceptors}.</p>
  */
-public class CdiInterceptorBean<T> extends AbstractInjectionTargetBean<T> implements Interceptor<T>
+public class EjbInterceptorBean<T> extends InterceptorBean<T> implements Interceptor<T>
 {
     /**
      *
-     * @param returnType the return Type of the Bean
+     * @param returnType the return Type of the Bean. This is also the class of the Interceptor
      * @param annotatedType AnnotatedType will be returned by some methods in the SPI
      * @param webBeansContext
-     * @param interceptorBindings the &#064;{@link javax.interceptor.InterceptorBinding} annotations handled by this Interceptor
      * @param intercepts the InterceptionTypes this Bean handles on the intercepted target
      */
-    public CdiInterceptorBean(Class<T> returnType, AnnotatedType<T> annotatedType,
+    public EjbInterceptorBean(Class<T> returnType, AnnotatedType<T> annotatedType,
                               WebBeansContext webBeansContext,
-                              Set<Annotation> interceptorBindings,
                               Set<InterceptionType> intercepts)
     {
-        super(WebBeansType.INTERCEPTOR, returnType, annotatedType, webBeansContext);
-        this.interceptorBindings = interceptorBindings;
-
-        Asserts.assertNotNull(intercepts, "Interceptor does not handle any InterceptionTypes!");
-        this.intercepts = intercepts;
-
+        super(returnType, annotatedType, webBeansContext, intercepts);
     }
 
     /**
-     * Contains all the information about single intercepted Methods;
-     */
-    private InterceptorResolution.BeanInterceptorInfo interceptorInfo;
-
-
-    private Set<Annotation> interceptorBindings;
-
-    private Set<InterceptionType> intercepts;
-
-    /**
-     * The Method to be called for InterceptionType.AROUND_INVOKE.
-     * The method signature must be
-     * <pre>Object <METHOD>(InvocationContext) throws Exception</pre>
+     * @return always an empty Set as this interceptor doesn't have any InterceptorBindings
      */
-    private Method aroundInvokeMethod;
-
-    /**
-     * The Method to be called for InterceptionType.AROUND_TIMEOUT.
-     * The method signature must be
-     * <pre>Object <METHOD>(InvocationContext) throws Exception</pre>
-     */
-    private Method aroundTimeoutMethod;
-
-    /**
-     * All &#064;PostConstruct interceptor method
-     * The method signature must be
-     * <pre>void <METHOD>(InvocationContext) throws Exception</pre>
-     */
-    private Method postConstructMethod;
-
-    /**
-     * All &#064;PreDestroy interceptor method
-     * The method signature must be
-     * <pre>void <METHOD>(InvocationContext) throws Exception</pre>
-     */
-    private Method preDestroyMethod;
-
-    /**
-     * All &#064;PrePassivate interceptor method
-     * The method signature must be
-     * <pre>void <METHOD>(InvocationContext) throws Exception</pre>
-     */
-    private Method prePassivateMethod;
-
-    /**
-     * All &#064;PostActivate interceptor method
-     * The method signature must be
-     * <pre>void <METHOD>(InvocationContext) throws Exception</pre>
-     */
-    private Method postActivateMethod;
-
-    public void setAroundInvokeMethod(Method aroundInvokeMethod)
-    {
-        this.aroundInvokeMethod = aroundInvokeMethod;
-    }
-
-    public void setAroundTimeoutMethod(Method aroundTimeoutMethod)
-    {
-        this.aroundTimeoutMethod = aroundTimeoutMethod;
-    }
-
-    public void setPostActivateMethod(Method postActivateMethod)
-    {
-        this.postActivateMethod = postActivateMethod;
-    }
-
-    public void setPostConstructMethod(Method postConstructMethod)
-    {
-        this.postConstructMethod = postConstructMethod;
-    }
-
-    public void setPreDestroyMethod(Method preDestroyMethod)
-    {
-        this.preDestroyMethod = preDestroyMethod;
-    }
-
-    public void setPrePassivateMethod(Method prePassivateMethod)
-    {
-        this.prePassivateMethod = prePassivateMethod;
-    }
-
-    /**
-     * Interceptors are by default &#064;Dependent scoped.
-     */
-    @Override
-    public Class<? extends Annotation> getScope()
-    {
-        return Dependent.class;
-    }
-
-    /**
-     * @param interceptionType
-     * @return the underlying interceptor method for the given InterceptionType or <code>null</code>
-     */
-    protected Method getInterceptorMethod(InterceptionType interceptionType)
-    {
-        if (InterceptionType.AROUND_INVOKE.equals(interceptionType))
-        {
-            return aroundInvokeMethod;
-        }
-        if (InterceptionType.POST_CONSTRUCT.equals(interceptionType))
-        {
-            return postConstructMethod;
-        }
-        if (InterceptionType.PRE_DESTROY.equals(interceptionType))
-        {
-            return preDestroyMethod;
-        }
-        if (InterceptionType.AROUND_TIMEOUT.equals(interceptionType))
-        {
-            return aroundTimeoutMethod;
-        }
-        if (InterceptionType.POST_ACTIVATE.equals(interceptionType))
-        {
-            return postActivateMethod;
-        }
-        if (InterceptionType.PRE_PASSIVATE.equals(interceptionType))
-        {
-            return prePassivateMethod;
-        }
-
-        throw new WebBeansException("InterceptionType not yet supported: " + interceptionType);
-    }
-
     @Override
     public Set<Annotation> getInterceptorBindings()
     {
-        return interceptorBindings;
+        return Collections.emptySet();
     }
 
-    @Override
-    public boolean intercepts(InterceptionType interceptionType)
-    {
-        return intercepts.contains(interceptionType);
-    }
-
-    @Override
-    public Object intercept(InterceptionType interceptionType, T instance, InvocationContext invocationContext)
-    {
-        try
-        {
-            return getInterceptorMethod(interceptionType).invoke(instance, invocationContext);
-        }
-        catch (InvocationTargetException ite)
-        {
-            throw ExceptionUtil.throwAsRuntimeException(ite);
-        }
-        catch (IllegalAccessException iae)
-        {
-            throw ExceptionUtil.throwAsRuntimeException(iae);
-        }
-    }
 
 }

Copied: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InterceptorBean.java (from r1430567, openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InterceptorBean.java?p2=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InterceptorBean.java&p1=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java&r1=1430567&r2=1430620&rev=1430620&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/CdiInterceptorBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InterceptorBean.java Tue Jan  8 22:57:56 2013
@@ -30,48 +30,35 @@ import java.util.Set;
 
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.exception.WebBeansException;
-import org.apache.webbeans.intercept.InterceptorResolution;
 import org.apache.webbeans.util.Asserts;
 import org.apache.webbeans.util.ExceptionUtil;
 
 /**
- * <p>{@link Interceptor} Bean implementation for CDI-style Beans.
- * This is Interceptors which got defined using
- * &#064;{@link javax.interceptor.InterceptorBinding}.</p>
+ * <p>Abstract {@link javax.enterprise.inject.spi.Interceptor} Bean implementation.
  *
  * <p>Any Interceptor is also an InjectionTarget as they can contain
  * &#064;Inject InjectionPoints.</p>
  */
-public class CdiInterceptorBean<T> extends AbstractInjectionTargetBean<T> implements Interceptor<T>
+public abstract class InterceptorBean<T> extends AbstractInjectionTargetBean<T> implements Interceptor<T>
 {
     /**
      *
      * @param returnType the return Type of the Bean
      * @param annotatedType AnnotatedType will be returned by some methods in the SPI
      * @param webBeansContext
-     * @param interceptorBindings the &#064;{@link javax.interceptor.InterceptorBinding} annotations handled by this Interceptor
      * @param intercepts the InterceptionTypes this Bean handles on the intercepted target
      */
-    public CdiInterceptorBean(Class<T> returnType, AnnotatedType<T> annotatedType,
-                              WebBeansContext webBeansContext,
-                              Set<Annotation> interceptorBindings,
-                              Set<InterceptionType> intercepts)
+    public InterceptorBean(Class<T> returnType, AnnotatedType<T> annotatedType,
+                           WebBeansContext webBeansContext,
+                           Set<InterceptionType> intercepts)
     {
         super(WebBeansType.INTERCEPTOR, returnType, annotatedType, webBeansContext);
-        this.interceptorBindings = interceptorBindings;
 
         Asserts.assertNotNull(intercepts, "Interceptor does not handle any InterceptionTypes!");
         this.intercepts = intercepts;
-
     }
 
-    /**
-     * Contains all the information about single intercepted Methods;
-     */
-    private InterceptorResolution.BeanInterceptorInfo interceptorInfo;
-
 
-    private Set<Annotation> interceptorBindings;
 
     private Set<InterceptionType> intercepts;
 
@@ -190,11 +177,6 @@ public class CdiInterceptorBean<T> exten
         throw new WebBeansException("InterceptionType not yet supported: " + interceptionType);
     }
 
-    @Override
-    public Set<Annotation> getInterceptorBindings()
-    {
-        return interceptorBindings;
-    }
 
     @Override
     public boolean intercepts(InterceptionType interceptionType)