[jboss-cvs] JBossAS SVN: r110718 - in trunk/weld-int: deployer/src/main/java/org/jboss/weld/integration/deployer/metadata and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Feb 19 14:04:27 EST 2011


Author: alesj
Date: 2011-02-19 14:04:27 -0500 (Sat, 19 Feb 2011)
New Revision: 110718

Added:
   trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/metadata/WeldLifecycleInterceptor.java
   trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/mock/
   trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/mock/MockServices.java
Modified:
   trunk/weld-int/assembly/src/main/assembly/resources/META-INF/weld-services-jboss-beans.xml
   trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/metadata/WeldEjbInterceptorMetadataDeployer.java
   trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/ejb/JBossEjbInjectionServices.java
   trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/ejb/JBossEjbServices.java
   trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/persistence/JBossJpaServices.java
   trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/util/AbstractJBossServices.java
   trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/util/JBossEjb.java
Log:
[WELD-848]; add lifecycle interceptor (best attempt to fix this issue), reduce resolver usage, mock Weld service support.


Modified: trunk/weld-int/assembly/src/main/assembly/resources/META-INF/weld-services-jboss-beans.xml
===================================================================
--- trunk/weld-int/assembly/src/main/assembly/resources/META-INF/weld-services-jboss-beans.xml	2011-02-18 16:42:07 UTC (rev 110717)
+++ trunk/weld-int/assembly/src/main/assembly/resources/META-INF/weld-services-jboss-beans.xml	2011-02-19 19:04:27 UTC (rev 110718)
@@ -10,13 +10,13 @@
 
    <!-- EJB Services: @EJB-style lookup -->
    <beanfactory name="JBossEjbServices" class="org.jboss.weld.integration.ejb.JBossEjbServices">
-      <property name="resolver"><inject bean="WeldJBossEjb" property="resolver"/></property>
+      <property name="resolver"><inject/></property>
       <property name="jbossEjb"><inject bean="WeldJBossEjb" /></property>
    </beanfactory>
    
    <!-- EJB Injection Services: @EJB-style injection -->
    <beanfactory name="JBossEjbInjectionServices" class="org.jboss.weld.integration.ejb.JBossEjbInjectionServices">
-      <property name="resolver"><inject bean="WeldJBossEjb" property="resolver"/></property>
+      <property name="resolver"><inject/></property>
       <property name="jbossEjb"><inject bean="WeldJBossEjb" /></property>
    </beanfactory>
   

Modified: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/metadata/WeldEjbInterceptorMetadataDeployer.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/metadata/WeldEjbInterceptorMetadataDeployer.java	2011-02-18 16:42:07 UTC (rev 110717)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/metadata/WeldEjbInterceptorMetadataDeployer.java	2011-02-19 19:04:27 UTC (rev 110718)
@@ -21,20 +21,13 @@
  */
 package org.jboss.weld.integration.deployer.metadata;
 
+import javax.interceptor.ExcludeClassInterceptors;
+import javax.interceptor.ExcludeDefaultInterceptors;
+
 import java.lang.reflect.AnnotatedElement;
 import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 
-import javax.interceptor.ExcludeClassInterceptors;
-import javax.interceptor.ExcludeDefaultInterceptors;
-
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.deployer.DeploymentStages;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
@@ -46,22 +39,12 @@
 import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
 import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeansMetaData;
 import org.jboss.metadata.ejb.jboss.JBossMetaData;
-import org.jboss.metadata.ejb.spec.AroundInvokeMetaData;
-import org.jboss.metadata.ejb.spec.AroundInvokesMetaData;
-import org.jboss.metadata.ejb.spec.EjbJar30MetaData;
-import org.jboss.metadata.ejb.spec.EjbJar3xMetaData;
-import org.jboss.metadata.ejb.spec.InterceptorBindingMetaData;
-import org.jboss.metadata.ejb.spec.InterceptorBindingsMetaData;
-import org.jboss.metadata.ejb.spec.InterceptorClassesMetaData;
-import org.jboss.metadata.ejb.spec.InterceptorMetaData;
-import org.jboss.metadata.ejb.spec.InterceptorOrderMetaData;
-import org.jboss.metadata.ejb.spec.InterceptorsMetaData;
-import org.jboss.metadata.ejb.spec.MethodParametersMetaData;
-import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
+import org.jboss.metadata.ejb.spec.*;
+import org.jboss.metadata.javaee.spec.LifecycleCallbackMetaData;
+import org.jboss.metadata.javaee.spec.LifecycleCallbacksMetaData;
 import org.jboss.scanning.annotations.spi.AnnotationIndex;
 import org.jboss.scanning.annotations.spi.Element;
 import org.jboss.vfs.VirtualFile;
-
 import org.jboss.weld.integration.ejb.SessionBeanInterceptor;
 import org.jboss.weld.integration.ejb.interceptor.Jsr299BindingsInterceptor;
 
@@ -75,7 +58,7 @@
 public class WeldEjbInterceptorMetadataDeployer extends WeldAwareMetadataDeployer<JBossMetaData>
 {
    private static final Class<SessionBeanInterceptor> INJECTION_INTERCEPTOR_CLASS = SessionBeanInterceptor.class;
-   private static final Class<org.jboss.weld.ejb.SessionBeanInterceptor> CONTEXT_INTERCEPTOR_CLASS = org.jboss.weld.ejb.SessionBeanInterceptor.class;
+   private static final Class<WeldLifecycleInterceptor> CONTEXT_INTERCEPTOR_CLASS = WeldLifecycleInterceptor.class;
    private static final Class<Jsr299BindingsInterceptor> BINDINGS_INTERCEPTOR_CLASS = Jsr299BindingsInterceptor.class;
 
    public static final String INJECTION_INTERCEPTOR_CLASS_NAME = INJECTION_INTERCEPTOR_CLASS.getName();
@@ -118,15 +101,39 @@
       aroundInvokeMetaData.setMethodName("aroundInvoke");
       contextIMD.getAroundInvokes().add(aroundInvokeMetaData);
 
+      // make sure we have a context when activating/passivating
+      addPostActivate(contextIMD, "lifecycleCallback");
+      addPrePassivate(contextIMD, "lifecycleCallback");
+
       // create interceptor metadata instance for JSR-299 specific bindings
       bindingsIMD = interceptorsMetaData.get(BINDINGS_INTERCEPTOR_CLASS_NAME);
 
       // create interceptor binding metadata instance
       injectionIBMD = createInterceptorBindingMetadata(INJECTION_INTERCEPTOR_CLASS_NAME);
       contextIBMD = createInterceptorBindingMetadata(CONTEXT_INTERCEPTOR_CLASS_NAME);
+   }
 
+   private static void addLifecycleCallback(LifecycleCallbacksMetaData lifecycleCallbacksMetaData, String methodName)
+   {
+      LifecycleCallbackMetaData lifecycleCallbackMetaData = new LifecycleCallbackMetaData();
+      lifecycleCallbackMetaData.setMethodName(methodName);
+      lifecycleCallbacksMetaData.add(lifecycleCallbackMetaData);
    }
 
+   private static void addPostActivate(InterceptorMetaData interceptorMetaData, String methodName)
+   {
+      if (interceptorMetaData.getPostActivates() == null)
+         interceptorMetaData.setPostActivates(new LifecycleCallbacksMetaData());
+      addLifecycleCallback(interceptorMetaData.getPostActivates(), methodName);
+   }
+
+   private static void addPrePassivate(InterceptorMetaData interceptorMetaData, String methodName)
+   {
+      if (interceptorMetaData.getPrePassivates() == null)
+         interceptorMetaData.setPrePassivates(new LifecycleCallbacksMetaData());
+      addLifecycleCallback(interceptorMetaData.getPrePassivates(), methodName);
+   }
+
    private InterceptorBindingMetaData createInterceptorBindingMetadata(String interceptorClassName)
    {
       InterceptorBindingMetaData ibmd = new InterceptorBindingMetaData();

Added: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/metadata/WeldLifecycleInterceptor.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/metadata/WeldLifecycleInterceptor.java	                        (rev 0)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/metadata/WeldLifecycleInterceptor.java	2011-02-19 19:04:27 UTC (rev 110718)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.weld.integration.deployer.metadata;
+
+import javax.interceptor.InvocationContext;
+
+import org.jboss.weld.ejb.SessionBeanInterceptor;
+
+/**
+ * Handle all Weld SFSB invocations, including lifecycle.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class WeldLifecycleInterceptor extends SessionBeanInterceptor
+{
+   private static final long serialVersionUID = 1L;
+
+   public void lifecycleCallback(InvocationContext invocation) throws Exception
+   {
+      aroundInvoke(invocation);
+   }
+}

Modified: trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/ejb/JBossEjbInjectionServices.java
===================================================================
--- trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/ejb/JBossEjbInjectionServices.java	2011-02-18 16:42:07 UTC (rev 110717)
+++ trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/ejb/JBossEjbInjectionServices.java	2011-02-19 19:04:27 UTC (rev 110718)
@@ -1,12 +1,12 @@
 package org.jboss.weld.integration.ejb;
 
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
 import javax.ejb.EJB;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.naming.NamingException;
 
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
 import org.jboss.ejb3.ejbref.resolver.spi.EjbReference;
 import org.jboss.ejb3.ejbref.resolver.spi.EjbReferenceResolver;
 import org.jboss.weld.injection.spi.EjbInjectionServices;
@@ -23,9 +23,8 @@
  */
 public class JBossEjbInjectionServices extends AbstractJBossServices implements EjbInjectionServices, DeploymentUnitAware
 {
+   private EjbReferenceResolver resolver;
 
-   protected EjbReferenceResolver resolver;
-
    public JBossEjbInjectionServices() throws NamingException
    {
       super();

Modified: trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/ejb/JBossEjbServices.java
===================================================================
--- trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/ejb/JBossEjbServices.java	2011-02-18 16:42:07 UTC (rev 110717)
+++ trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/ejb/JBossEjbServices.java	2011-02-19 19:04:27 UTC (rev 110718)
@@ -1,14 +1,13 @@
 package org.jboss.weld.integration.ejb;
 
+import javax.naming.NamingException;
+
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
-
-import javax.naming.NamingException;
-
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.ejb3.common.deployers.spi.AttachmentNames;
 import org.jboss.ejb3.ejbref.resolver.spi.EjbReferenceResolver;
@@ -34,8 +33,7 @@
  */
 public class JBossEjbServices extends AbstractJBossServices implements EjbServices, DeploymentUnitAware
 {
-
-   protected EjbReferenceResolver resolver;
+   private EjbReferenceResolver resolver;
    private final List<EjbDescriptor<?>> ejbs = new ArrayList<EjbDescriptor<?>>();
    private final List<String> ejbContainerNames = new ArrayList<String>();
    private Map<String, InterceptorBindings> interceptorBindings = new ConcurrentHashMap<String, InterceptorBindings>();

Added: trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/mock/MockServices.java
===================================================================
--- trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/mock/MockServices.java	                        (rev 0)
+++ trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/mock/MockServices.java	2011-02-19 19:04:27 UTC (rev 110718)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.weld.integration.mock;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.jboss.beans.metadata.spi.factory.BeanFactory;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.weld.integration.vdf.DeploymentUnitAware;
+
+/**
+ * Mock Weld services, in case we need to disable some real service.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class MockServices implements Serializable, BeanFactory, DeploymentUnitAware, InvocationHandler
+{
+   private static final long serialVersionUID = 1L;
+
+   private List<Class<?>> interfaces;
+   private volatile Object proxy;
+
+   public MockServices(Class<?>... interfaces)
+   {
+      if (interfaces == null || interfaces.length == 0)
+         throw new IllegalArgumentException("Null or empty interfaces");
+
+      this.interfaces = new ArrayList<Class<?>>();
+      this.interfaces.addAll(Arrays.asList(interfaces));
+      this.interfaces.add(Serializable.class);
+      this.interfaces.add(DeploymentUnitAware.class);
+   }
+
+   /**
+    * Create proxy, exposing all interfaces from ctor.
+    *
+    * @return proxy
+    */
+   public Object createBean()
+   {
+      if (proxy == null)
+      {
+         proxy = Proxy.newProxyInstance(
+               MockServices.class.getClassLoader(),
+               interfaces.toArray(new Class<?>[interfaces.size()]),
+               this);
+      }
+      return proxy;
+   }
+
+   public void setDeploymentUnit(DeploymentUnit unit)
+   {
+      // ignore
+   }
+
+   public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+   {
+      return null; // TODO -- mock return values as well?
+   }
+}

Modified: trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/persistence/JBossJpaServices.java
===================================================================
--- trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/persistence/JBossJpaServices.java	2011-02-18 16:42:07 UTC (rev 110717)
+++ trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/persistence/JBossJpaServices.java	2011-02-19 19:04:27 UTC (rev 110718)
@@ -1,9 +1,5 @@
 package org.jboss.weld.integration.persistence;
 
-import java.lang.reflect.Method;
-import java.util.Collection;
-import java.util.Collections;
-
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.naming.NamingException;
 import javax.persistence.EntityManager;
@@ -11,6 +7,10 @@
 import javax.persistence.PersistenceContext;
 import javax.persistence.PersistenceUnit;
 
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Collections;
+
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.ejb3.common.deployers.spi.AttachmentNames;
 import org.jboss.jpa.deployment.ManagedEntityManagerFactory;
@@ -23,9 +23,15 @@
 import org.jboss.weld.injection.spi.JpaInjectionServices;
 import org.jboss.weld.integration.util.AbstractJBossServices;
 
+/**
+ * JPA Weld Utitlies
+ *
+ * @author Pete Muir
+ * @author ales.justin at jboss.org
+ * @author JBoss EJB3 team
+ */
 public class JBossJpaServices extends AbstractJBossServices implements JpaInjectionServices
 {
-
    public JBossJpaServices() throws NamingException
    {
       super();
@@ -43,6 +49,7 @@
       return Collections.emptyList();
    }
 
+   @SuppressWarnings({"deprecation"})
    public EntityManager resolvePersistenceContext(InjectionPoint injectionPoint)
    {
       if (!injectionPoint.getAnnotated().isAnnotationPresent(PersistenceContext.class))
@@ -84,6 +91,7 @@
       }
    }
 
+   @SuppressWarnings({"deprecation"})
    private EntityManagerFactory resolvePersistenceUnit(String unitName)
    {
       PersistenceUnitDeployment deployment = lookupPersistenceUnitDeployment(unitName);
@@ -102,8 +110,7 @@
       {
          throw new IllegalStateException("No persistence unit available for " + unitName);
       }
-      PersistenceUnitDeployment deployment = jbossEjb.lookupPersistenceUnitDeployment(beanName);
-      return deployment;
+      return jbossEjb.lookupPersistenceUnitDeployment(beanName);
    }
 
    private static String getPersistenceUnitSupplier(DeploymentUnit deploymentUnit, PersistenceUnitDependencyResolver persistenceUnitDependencyResolver, String persistenceUnitName)
@@ -129,5 +136,4 @@
       }
       return null;
    }
-
 }

Modified: trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/util/AbstractJBossServices.java
===================================================================
--- trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/util/AbstractJBossServices.java	2011-02-18 16:42:07 UTC (rev 110717)
+++ trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/util/AbstractJBossServices.java	2011-02-19 19:04:27 UTC (rev 110718)
@@ -7,9 +7,14 @@
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.weld.bootstrap.api.Service;
 
+/**
+ * Abstract JBoss Weld services.
+ *
+ * @author Pete Muir
+ * @author ales.justin at jboss.org
+ */
 public class AbstractJBossServices implements Service
 {
-
    protected DeploymentUnit topLevelDeploymentUnit;
    protected JBossEjb jbossEjb;
    protected final Context context;
@@ -36,7 +41,5 @@
 
    public void cleanup()
    {
-
    }
-
 }
\ No newline at end of file

Modified: trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/util/JBossEjb.java
===================================================================
--- trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/util/JBossEjb.java	2011-02-18 16:42:07 UTC (rev 110717)
+++ trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/util/JBossEjb.java	2011-02-19 19:04:27 UTC (rev 110718)
@@ -2,7 +2,6 @@
 
 import org.jboss.beans.metadata.api.annotations.Inject;
 import org.jboss.dependency.spi.ControllerContext;
-import org.jboss.ejb3.ejbref.resolver.spi.EjbReferenceResolver;
 import org.jboss.jpa.deployment.PersistenceUnitDeployment;
 import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
 import org.jboss.kernel.spi.dependency.KernelController;
@@ -12,24 +11,11 @@
  *
  * @author Pete Muir
  * @author ales.justin at jboss.org
- *
  */
 public class JBossEjb
 {
    private KernelController controller;
-   private EjbReferenceResolver resolver;
 
-   @Inject
-   public void setResolver(EjbReferenceResolver resolver)
-   {
-      this.resolver = resolver;
-   }
-
-   public EjbReferenceResolver getResolver()
-   {
-      return resolver;
-   }
-
    @Inject(bean = KernelConstants.KERNEL_CONTROLLER_NAME)
    public void setController(KernelController controller)
    {
@@ -37,10 +23,10 @@
    }
 
    /**
-    * Get the EjbReferenceResolver from the MC controller.
+    * Get the PersistenceUnitDeployment from the MC controller.
     *
     * @param name the bean name
-    * @return the EjbReferenceResolver
+    * @return the PersistenceUnitDeployment
     */
    public PersistenceUnitDeployment lookupPersistenceUnitDeployment(String name)
    {



More information about the jboss-cvs-commits mailing list