tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: few generic handling for ejbs
Date Wed, 04 Mar 2015 21:03:50 GMT
Repository: tomee
Updated Branches:
  refs/heads/develop 073b05a62 -> a1ec5e3b0


few generic handling for ejbs


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/a1ec5e3b
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/a1ec5e3b
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/a1ec5e3b

Branch: refs/heads/develop
Commit: a1ec5e3b09099ff1dc0f938a94fa38df7142e58a
Parents: 073b05a
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Wed Mar 4 22:03:38 2015 +0100
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Wed Mar 4 22:03:38 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/openejb/cdi/CdiEjbBean.java | 87 ++++++++++----------
 .../java/org/apache/openejb/cdi/CdiPlugin.java  |  3 +-
 tck/cdi-embedded/pom.xml                        |  5 +-
 tck/cdi-embedded/src/test/resources/failing.xml |  2 +-
 4 files changed, 49 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/a1ec5e3b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java
index 34cd0b3..b11d079 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java
@@ -34,23 +34,8 @@ import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.ejb.common.component.BaseEjbBean;
 import org.apache.webbeans.intercept.InterceptorResolutionService;
 import org.apache.webbeans.portable.InjectionTargetImpl;
+import org.apache.webbeans.util.GenericsUtil;
 
-import javax.decorator.Decorator;
-import javax.ejb.NoSuchEJBException;
-import javax.ejb.Remove;
-import javax.enterprise.context.Dependent;
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.Typed;
-import javax.enterprise.inject.spi.AnnotatedMethod;
-import javax.enterprise.inject.spi.AnnotatedType;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanAttributes;
-import javax.enterprise.inject.spi.DefinitionException;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.InjectionTarget;
-import javax.enterprise.inject.spi.SessionBeanType;
-import javax.interceptor.Interceptor;
-import javax.transaction.UserTransaction;
 import java.io.Serializable;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
@@ -61,12 +46,29 @@ import java.rmi.NoSuchObjectException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Level;
+import javax.decorator.Decorator;
+import javax.ejb.NoSuchEJBException;
+import javax.ejb.Remove;
+import javax.enterprise.context.Dependent;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.Typed;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanAttributes;
+import javax.enterprise.inject.spi.DefinitionException;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.InjectionTarget;
+import javax.enterprise.inject.spi.SessionBeanType;
+import javax.interceptor.Interceptor;
+import javax.transaction.UserTransaction;
 
 public class CdiEjbBean<T> extends BaseEjbBean<T> implements InterceptedMarker,
DeploymentValidationService.BeanInterceptorInfoProvider {
     private final Map<Integer, Object> dependentSFSBToBeRemoved = new ConcurrentHashMap<Integer,
Object>();
@@ -86,15 +88,16 @@ public class CdiEjbBean<T> extends BaseEjbBean<T> implements
InterceptedMarker,
         EjbInjectionTargetImpl.class.cast(getInjectionTarget()).setCdiEjbBean(this);
     }
 
-    public CdiEjbBean(final BeanContext beanContext, final WebBeansContext webBeansContext,
final Class beanClass, final AnnotatedType<T> at,
+    public CdiEjbBean(final BeanContext bc, final WebBeansContext webBeansContext, final
Class beanClass, final AnnotatedType<T> at,
                       final InjectionTargetFactoryImpl<T> factory, final BeanAttributes<T>
attributes) {
-        super(webBeansContext, toSessionType(beanContext.getComponentType()), at, new EJBBeanAttributesImpl<T>(beanContext,
-                attributes, true), beanClass, factory);
-        this.beanContext = beanContext;
-        beanContext.set(Bean.class, this);
-        passivatingId = beanContext.getDeploymentID() + getReturnType().getName();
-
-        final boolean stateful = BeanType.STATEFUL.equals(beanContext.getComponentType());
+        super(webBeansContext, toSessionType(bc.getComponentType()), at,
+                new EJBBeanAttributesImpl<T>(bc, attributes),
+                beanClass, factory);
+        this.beanContext = bc;
+        bc.set(Bean.class, this);
+        passivatingId = bc.getDeploymentID() + getReturnType().getName();
+
+        final boolean stateful = BeanType.STATEFUL.equals(bc.getComponentType());
         final boolean isDependent = getScope().equals(Dependent.class);
         isDependentAndStateful = isDependent && stateful;
         if (webBeansContext.getBeanManagerImpl().isPassivatingScope(getScope()) &&
stateful) {
@@ -321,16 +324,11 @@ public class CdiEjbBean<T> extends BaseEjbBean<T> implements
InterceptedMarker,
         private final BeanContext beanContext;
         private final Set<Type> ejbTypes;
 
-        public EJBBeanAttributesImpl(final BeanContext bc, final BeanAttributes<T>
beanAttributes, final boolean withSerializable) {
+        public EJBBeanAttributesImpl(final BeanContext bc, final BeanAttributes<T>
beanAttributes) {
             super(beanAttributes, false);
             this.beanContext = bc;
             this.ejbTypes = new HashSet<Type>();
             initTypes();
-            if (withSerializable) {
-                if (!ejbTypes.contains(Serializable.class)) {
-                    ejbTypes.add(Serializable.class);
-                }
-            }
         }
 
         @Override
@@ -349,8 +347,19 @@ public class CdiEjbBean<T> extends BaseEjbBean<T> implements
InterceptedMarker,
 
             final List<Class> cl = beanContext.getBusinessLocalInterfaces();
             if (cl != null && !cl.isEmpty()) {
+                final Map<Class<?>, Type> apis = new HashMap<>(cl.size());
+                for (final Type t : beanContext.getManagedClass().getGenericInterfaces())
{
+                    if (ParameterizedType.class.isInstance(t)) {
+                        try {
+                            apis.put(Class.class.cast(ParameterizedType.class.cast(t).getRawType()),
t);
+                        } catch (final Throwable th) {
+                            // no-op
+                        }
+                    }
+                }
                 for (final Class<?> c : cl) {
-                    ejbTypes.addAll(parentInterfaces(c));
+                    final Type type = apis.get(c);
+                    ejbTypes.addAll(GenericsUtil.getTypeClosure(type != null ? type : c));
                 }
             }
 
@@ -364,22 +373,14 @@ public class CdiEjbBean<T> extends BaseEjbBean<T> implements
InterceptedMarker,
             ejbTypes.add(Object.class);
         }
 
-        private static Collection<Class<?>> parentInterfaces(final Class<?>
c) {
-            final Collection<Class<?>> set = new HashSet<>();
-            set.add(c);
-            for (final Class<?> parent : c.getInterfaces()) {
-                set.addAll(parentInterfaces(parent));
-            }
-            return set;
-        }
-
         private static void addApiTypes(final Collection<Type> clazzes, final Class<?>
beanClass) {
             final Typed typed = beanClass.getAnnotation(Typed.class);
             if (typed == null || typed.value().length == 0) {
-                Class<?> current = beanClass;
-                while (current != null && !Object.class.equals(current)) {
+                Type current = beanClass;
+                while (current != null && Object.class != current) {
                     clazzes.add(current);
-                    current = current.getSuperclass();
+                    // TODO: better loop
+                    current = Class.class.isInstance(current) ? Class.class.cast(current).getGenericSuperclass()
: null;
                 }
             } else {
                 Collections.addAll(clazzes, typed.value());

http://git-wip-us.apache.org/repos/asf/tomee/blob/a1ec5e3b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiPlugin.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiPlugin.java b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiPlugin.java
index f93645d..3c04eee 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiPlugin.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiPlugin.java
@@ -137,8 +137,7 @@ public class CdiPlugin extends AbstractOwbPlugin implements OpenWebBeansJavaEEPl
     public <T> BeanAttributes<T> createBeanAttributes(final AnnotatedType<T>
type) {
         return new CdiEjbBean.EJBBeanAttributesImpl(
                 findBeanContext(webBeansContext, type.getJavaClass()),
-                BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes(type).build(),
-                false);
+                BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes(type).build());
     }
 
     public void configureDeployments(final List<BeanContext> ejbDeployments) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/a1ec5e3b/tck/cdi-embedded/pom.xml
----------------------------------------------------------------------
diff --git a/tck/cdi-embedded/pom.xml b/tck/cdi-embedded/pom.xml
index 784bdf6..dc0361b 100644
--- a/tck/cdi-embedded/pom.xml
+++ b/tck/cdi-embedded/pom.xml
@@ -171,7 +171,7 @@
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
-        <version>2.17</version>
+        <version>2.18</version>
         <configuration>
           <reuseForks>true</reuseForks>
           <forkCount>1</forkCount>
@@ -182,7 +182,7 @@
             <suiteXmlFile>src/test/resources/passing.xml</suiteXmlFile>
           </suiteXmlFiles>
           <properties>
-            <property> <!-- broken cause @RequestScoped beans are parameter and
testng logs parameters -->
+            <property> <!-- broken cause @RequestScoped beans are parameters and
testng logs parameters -->
               <name>usedefaultlisteners</name>
               <value>false</value>
             </property>
@@ -203,6 +203,7 @@
             <openejb.cdi.producer.interception>false</openejb.cdi.producer.interception>
             <openejb.cdi.filter.classloader>false</openejb.cdi.filter.classloader>
 
+            <openejb.strict.interface.declaration>true</openejb.strict.interface.declaration>
             <openejb.http.mock-request>true</openejb.http.mock-request>
             <openejb.http.default-content-type>text/plain</openejb.http.default-content-type>
             <openejb.embedded.try-jsp>true</openejb.embedded.try-jsp>

http://git-wip-us.apache.org/repos/asf/tomee/blob/a1ec5e3b/tck/cdi-embedded/src/test/resources/failing.xml
----------------------------------------------------------------------
diff --git a/tck/cdi-embedded/src/test/resources/failing.xml b/tck/cdi-embedded/src/test/resources/failing.xml
index 2e50751..09755fc 100644
--- a/tck/cdi-embedded/src/test/resources/failing.xml
+++ b/tck/cdi-embedded/src/test/resources/failing.xml
@@ -31,7 +31,7 @@
     -Dopenejb.embedded.try-jsp=true
     -->
     <classes>
-      <class name="org.jboss.cdi.tck.tests.context.conversation.filter.ConversationFilterTest"
/>
+      <class name="org.jboss.cdi.tck.tests.definition.bean.types.enterprise.SessionBeanTypesTest"
/>
     </classes>
   </test>
 </suite>


Mime
View raw message