Return-Path: X-Original-To: apmail-tomee-commits-archive@www.apache.org Delivered-To: apmail-tomee-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CE2631095C for ; Wed, 4 Mar 2015 21:03:50 +0000 (UTC) Received: (qmail 35096 invoked by uid 500); 4 Mar 2015 21:03:50 -0000 Delivered-To: apmail-tomee-commits-archive@tomee.apache.org Received: (qmail 35070 invoked by uid 500); 4 Mar 2015 21:03:50 -0000 Mailing-List: contact commits-help@tomee.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tomee.apache.org Delivered-To: mailing list commits@tomee.apache.org Received: (qmail 35061 invoked by uid 99); 4 Mar 2015 21:03:50 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Mar 2015 21:03:50 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 808BDE0F7F; Wed, 4 Mar 2015 21:03:50 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: rmannibucau@apache.org To: commits@tomee.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: tomee git commit: few generic handling for ejbs Date: Wed, 4 Mar 2015 21:03:50 +0000 (UTC) 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 Authored: Wed Mar 4 22:03:38 2015 +0100 Committer: Romain Manni-Bucau 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 extends BaseEjbBean implements InterceptedMarker, DeploymentValidationService.BeanInterceptorInfoProvider { private final Map dependentSFSBToBeRemoved = new ConcurrentHashMap(); @@ -86,15 +88,16 @@ public class CdiEjbBean extends BaseEjbBean implements InterceptedMarker, EjbInjectionTargetImpl.class.cast(getInjectionTarget()).setCdiEjbBean(this); } - public CdiEjbBean(final BeanContext beanContext, final WebBeansContext webBeansContext, final Class beanClass, final AnnotatedType at, + public CdiEjbBean(final BeanContext bc, final WebBeansContext webBeansContext, final Class beanClass, final AnnotatedType at, final InjectionTargetFactoryImpl factory, final BeanAttributes attributes) { - super(webBeansContext, toSessionType(beanContext.getComponentType()), at, new EJBBeanAttributesImpl(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(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 extends BaseEjbBean implements InterceptedMarker, private final BeanContext beanContext; private final Set ejbTypes; - public EJBBeanAttributesImpl(final BeanContext bc, final BeanAttributes beanAttributes, final boolean withSerializable) { + public EJBBeanAttributesImpl(final BeanContext bc, final BeanAttributes beanAttributes) { super(beanAttributes, false); this.beanContext = bc; this.ejbTypes = new HashSet(); initTypes(); - if (withSerializable) { - if (!ejbTypes.contains(Serializable.class)) { - ejbTypes.add(Serializable.class); - } - } } @Override @@ -349,8 +347,19 @@ public class CdiEjbBean extends BaseEjbBean implements InterceptedMarker, final List cl = beanContext.getBusinessLocalInterfaces(); if (cl != null && !cl.isEmpty()) { + final Map, 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 extends BaseEjbBean implements InterceptedMarker, ejbTypes.add(Object.class); } - private static Collection> parentInterfaces(final Class c) { - final Collection> set = new HashSet<>(); - set.add(c); - for (final Class parent : c.getInterfaces()) { - set.addAll(parentInterfaces(parent)); - } - return set; - } - private static void addApiTypes(final Collection 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 BeanAttributes createBeanAttributes(final AnnotatedType 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 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 @@ org.apache.maven.plugins maven-surefire-plugin - 2.17 + 2.18 true 1 @@ -182,7 +182,7 @@ src/test/resources/passing.xml - + usedefaultlisteners false @@ -203,6 +203,7 @@ false false + true true text/plain true 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 --> - +