openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1432509 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/ main/java/org/apache/webbeans/component/creation/ test/java/org/apache/webbeans/newtests/interceptors/resolution/ test/java/org/apache/webbeans/ne...
Date Sat, 12 Jan 2013 20:43:54 GMT
Author: struberg
Date: Sat Jan 12 20:43:54 2013
New Revision: 1432509

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

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/SelfInterceptorBeanBuilder.java
      - copied, changed from r1432492, openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/EjbInterceptorBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/SelfInterceptorBeanBuilderTest.java
      - copied, changed from r1432492, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/EjbInterceptorBeanBuilderTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/SelfInterceptedClass.java
Modified:
    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
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/SelfInterceptorBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/EjbInterceptorBeanBuilderTest.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=1432509&r1=1432508&r2=1432509&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
Sat Jan 12 20:43:54 2013
@@ -18,16 +18,12 @@
  */
 package org.apache.webbeans.component;
 
-import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.AnnotatedType;
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
 import java.util.Set;
 
 import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.context.creational.CreationalContextImpl;
-import org.apache.webbeans.inject.InjectableConstructor;
-import org.apache.webbeans.portable.InjectionTargetImpl;
+
 
 /**
  * <p>{@link javax.enterprise.inject.spi.Interceptor}
@@ -52,21 +48,6 @@ public class CdiInterceptorBean<T> exten
     private Set<Annotation> interceptorBindings;
 
 
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected T createComponentInstance(CreationalContext<T> creationalContext)
-    {
-        Constructor<T> con = getConstructor();
-        InjectionTargetImpl<T> injectionTarget = new InjectionTargetImpl<T>(getAnnotatedType(),
getInjectionPoints(), getWebBeansContext());
-        InjectableConstructor<T> ic = new InjectableConstructor<T>(con, injectionTarget,
(CreationalContextImpl<T>) creationalContext);
-
-        T instance = ic.doInjection();
-
-        return instance;
-    }
-
 
     public void setInterceptorBindings(Set<Annotation> interceptorBindings)
     {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InterceptorBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InterceptorBean.java?rev=1432509&r1=1432508&r2=1432509&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InterceptorBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InterceptorBean.java
Sat Jan 12 20:43:54 2013
@@ -19,6 +19,7 @@
 package org.apache.webbeans.component;
 
 import javax.enterprise.context.Dependent;
+import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.InterceptionType;
 import javax.enterprise.inject.spi.Interceptor;
@@ -31,7 +32,10 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.exception.WebBeansException;
+import org.apache.webbeans.inject.InjectableConstructor;
+import org.apache.webbeans.portable.InjectionTargetImpl;
 import org.apache.webbeans.util.ExceptionUtil;
 
 /**
@@ -107,6 +111,19 @@ public abstract class InterceptorBean<T>
         super(webBeansContext, WebBeansType.INTERCEPTOR, annotatedType.getJavaClass(), annotatedType);
     }
 
+    @Override
+    protected T createComponentInstance(CreationalContext<T> creationalContext)
+    {
+        Constructor<T> con = getConstructor();
+        InjectionTargetImpl<T> injectionTarget = new InjectionTargetImpl<T>(getAnnotatedType(),
getInjectionPoints(), getWebBeansContext());
+        InjectableConstructor<T> ic = new InjectableConstructor<T>(con, injectionTarget,
(CreationalContextImpl<T>) creationalContext);
+
+        T instance = ic.doInjection();
+
+        return instance;
+    }
+
+
     /**
      * Get constructor.
      *

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/SelfInterceptorBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/SelfInterceptorBean.java?rev=1432509&r1=1432508&r2=1432509&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/SelfInterceptorBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/SelfInterceptorBean.java
Sat Jan 12 20:43:54 2013
@@ -18,6 +18,7 @@
  */
 package org.apache.webbeans.component;
 
+import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.Interceptor;
 import java.lang.annotation.Annotation;
@@ -25,6 +26,7 @@ import java.util.Collections;
 import java.util.Set;
 
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.exception.WebBeansException;
 
 /**
  * <p>Implicit self-interceptor Bean implementation.
@@ -54,4 +56,9 @@ public class SelfInterceptorBean<T> exte
         return Collections.emptySet();
     }
 
+    public T create(CreationalContext<T> context)
+    {
+        throw new WebBeansException("You must not create an Interceptor instance of a self-intercepted
bean!");
+    }
+
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java?rev=1432509&r1=1432508&r2=1432509&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/CdiInterceptorBeanBuilder.java
Sat Jan 12 20:43:54 2013
@@ -19,17 +19,13 @@
 package org.apache.webbeans.component.creation;
 
 
-import javax.enterprise.inject.spi.AnnotatedConstructor;
 import javax.enterprise.inject.spi.AnnotatedType;
-import javax.enterprise.inject.spi.InjectionPoint;
 
 import java.lang.annotation.Annotation;
-import java.util.List;
 
 import org.apache.webbeans.component.CdiInterceptorBean;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
-import org.apache.webbeans.inject.impl.InjectionPointFactory;
 import org.apache.webbeans.util.ArrayUtil;
 
 /**
@@ -37,7 +33,6 @@ import org.apache.webbeans.util.ArrayUti
  */
 public class CdiInterceptorBeanBuilder<T> extends InterceptorBeanBuilder<T>
 {
-    private AnnotatedConstructor<T> constructor;
 
     public CdiInterceptorBeanBuilder(WebBeansContext webBeansContext, AnnotatedType<T>
annotatedType)
     {
@@ -69,30 +64,6 @@ public class CdiInterceptorBeanBuilder<T
         getBean().setInterceptorBindings(ArrayUtil.asSet(bindings));
     }
 
-    public void defineConstructor()
-    {
-        constructor = getBeanConstructor();
-        addConstructorInjectionPointMetaData();
-    }
-
-
-    protected void addConstructorInjectionPointMetaData()
-    {
-        if (constructor == null)
-        {
-            return;
-        }
-        CdiInterceptorBean<T> bean = getBean();
-        InjectionPointFactory injectionPointFactory = webBeansContext.getInjectionPointFactory();
-        List<InjectionPoint> injectionPoints = injectionPointFactory.getConstructorInjectionPointData(bean,
constructor);
-        for (InjectionPoint injectionPoint : injectionPoints)
-        {
-            addImplicitComponentForInjectionPoint(injectionPoint);
-            bean.addInjectionPoint(injectionPoint);
-        }
-        bean.setConstructor(constructor.getJavaMember());
-    }
-
     public CdiInterceptorBean<T> getBean()
     {
         return (CdiInterceptorBean<T>)super.getBean();

Copied: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/SelfInterceptorBeanBuilder.java
(from r1432492, openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/EjbInterceptorBeanBuilder.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/SelfInterceptorBeanBuilder.java?p2=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/SelfInterceptorBeanBuilder.java&p1=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/EjbInterceptorBeanBuilder.java&r1=1432492&r2=1432509&rev=1432509&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/EjbInterceptorBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/SelfInterceptorBeanBuilder.java
Sat Jan 12 20:43:54 2013
@@ -21,25 +21,24 @@ package org.apache.webbeans.component.cr
 
 import javax.enterprise.inject.spi.AnnotatedType;
 
-import org.apache.webbeans.component.EjbInterceptorBean;
+import org.apache.webbeans.component.SelfInterceptorBean;
 import org.apache.webbeans.config.WebBeansContext;
 
 /**
  * Bean builder for {@link org.apache.webbeans.component.InterceptorBean}s.
  */
-public class EjbInterceptorBeanBuilder<T> extends InterceptorBeanBuilder<T>
+public class SelfInterceptorBeanBuilder<T> extends InterceptorBeanBuilder<T>
 {
 
-    public EjbInterceptorBeanBuilder(WebBeansContext webBeansContext, AnnotatedType<T>
annotatedType)
+    public SelfInterceptorBeanBuilder(WebBeansContext webBeansContext, AnnotatedType<T>
annotatedType)
     {
-        super(new EjbInterceptorBean<T>(webBeansContext, annotatedType));
+        super(new SelfInterceptorBean<T>(webBeansContext, annotatedType));
     }
 
-    public void defineEjbInterceptorRules()
+    public void defineSelfInterceptorRules()
     {
         checkInterceptorConditions();
         defineInterceptorRules();
-
     }
 
     public boolean isInterceptorEnabled()
@@ -48,8 +47,8 @@ public class EjbInterceptorBeanBuilder<T
     }
 
 
-    public EjbInterceptorBean<T> getBean()
+    public SelfInterceptorBean<T> getBean()
     {
-        return (EjbInterceptorBean<T>)super.getBean();
+        return (SelfInterceptorBean<T>)super.getBean();
     }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/EjbInterceptorBeanBuilderTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/EjbInterceptorBeanBuilderTest.java?rev=1432509&r1=1432508&r2=1432509&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/EjbInterceptorBeanBuilderTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/EjbInterceptorBeanBuilderTest.java
Sat Jan 12 20:43:54 2013
@@ -18,6 +18,7 @@
  */
 package org.apache.webbeans.newtests.interceptors.resolution;
 
+import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.AnnotatedType;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -56,6 +57,10 @@ public class EjbInterceptorBeanBuilderTe
         InterceptorBean<EjbInterceptor> bean = ibb.getBean();
         Assert.assertNotNull(bean);
 
+        CreationalContext<EjbInterceptor> cc = getBeanManager().createCreationalContext(bean);
+
+        EjbInterceptor ebi = bean.create(cc);
+        Assert.assertNotNull(ebi);
 
         shutDownContainer();
     }

Copied: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/SelfInterceptorBeanBuilderTest.java
(from r1432492, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/EjbInterceptorBeanBuilderTest.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/SelfInterceptorBeanBuilderTest.java?p2=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/SelfInterceptorBeanBuilderTest.java&p1=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/EjbInterceptorBeanBuilderTest.java&r1=1432492&r2=1432509&rev=1432509&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/EjbInterceptorBeanBuilderTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/SelfInterceptorBeanBuilderTest.java
Sat Jan 12 20:43:54 2013
@@ -23,37 +23,32 @@ import java.util.ArrayList;
 import java.util.Collection;
 
 import org.apache.webbeans.component.InterceptorBean;
-import org.apache.webbeans.component.creation.EjbInterceptorBeanBuilder;
+import org.apache.webbeans.component.creation.SelfInterceptorBeanBuilder;
 import org.apache.webbeans.newtests.AbstractUnitTest;
-
-import org.apache.webbeans.newtests.interceptors.ejb.EjbInterceptor;
-import org.apache.webbeans.newtests.interceptors.ejb.ManagedBeanWithEjbInterceptor;
-import org.apache.webbeans.newtests.interceptors.resolution.beans.UtilitySampleBean;
+import org.apache.webbeans.newtests.interceptors.resolution.interceptors.SelfInterceptedClass;
 import org.junit.Assert;
 import org.junit.Test;
 
 /**
  * Test for building EJB-style interceptor beans
  */
-public class EjbInterceptorBeanBuilderTest extends AbstractUnitTest
+public class SelfInterceptorBeanBuilderTest extends AbstractUnitTest
 {
 
     @Test
     public void testEjbInterceptorBeanCreation()
     {
         Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
-        beanClasses.add(UtilitySampleBean.class);
-        beanClasses.add(EjbInterceptor.class);
-        beanClasses.add(ManagedBeanWithEjbInterceptor.class);
+        beanClasses.add(SelfInterceptedClass.class);
 
         startContainer(beanClasses, null);
 
-        AnnotatedType<EjbInterceptor> annotatedType = getBeanManager().createAnnotatedType(EjbInterceptor.class);
+        AnnotatedType<SelfInterceptedClass> annotatedType = getBeanManager().createAnnotatedType(SelfInterceptedClass.class);
 
-        EjbInterceptorBeanBuilder<EjbInterceptor> ibb
-                = new EjbInterceptorBeanBuilder<EjbInterceptor>(getWebBeansContext(),
annotatedType);
-        ibb.defineEjbInterceptorRules();
-        InterceptorBean<EjbInterceptor> bean = ibb.getBean();
+        SelfInterceptorBeanBuilder<SelfInterceptedClass> ibb
+                = new SelfInterceptorBeanBuilder<SelfInterceptedClass>(getWebBeansContext(),
annotatedType);
+        ibb.defineSelfInterceptorRules();
+        InterceptorBean<SelfInterceptedClass> bean = ibb.getBean();
         Assert.assertNotNull(bean);
 
 

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/SelfInterceptedClass.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/SelfInterceptedClass.java?rev=1432509&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/SelfInterceptedClass.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/SelfInterceptedClass.java
Sat Jan 12 20:43:54 2013
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.newtests.interceptors.resolution.interceptors;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+/**
+ * Sample bean which has an AroundInvoke interceptor on itself.
+ */
+public class SelfInterceptedClass
+{
+    public static int interceptionCount = 0;
+
+    private int meaningOfLife = 0;
+
+    public void someBusinessMethod()
+    {
+        meaningOfLife = 42;
+    }
+
+    public int getMeaningOfLife()
+    {
+        return meaningOfLife;
+    }
+
+    @AroundInvoke
+    private Object interceptMe(InvocationContext ic) throws Exception
+    {
+        interceptionCount++;
+        return ic.proceed();
+    }
+}
+



Mime
View raw message