[jboss-cvs] JBossAS SVN: r108369 - in trunk/weld-int: deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Sep 28 17:21:42 EDT 2010


Author: marius.bogoevici
Date: 2010-09-28 17:21:41 -0400 (Tue, 28 Sep 2010)
New Revision: 108369

Added:
   trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/util/EjbDiscoveryUtils.java
Modified:
   trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/ArchiveInfoDeployer.java
   trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/Archive.java
   trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ArchiveFactory.java
   trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ArchiveInfo.java
   trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ArchiveLoader.java
   trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/LibraryDiscoveryService.java
Log:
JBAS-8472 - EjbDescriptors are filtered out, so that only they are made available only to the archives in which they are deployed, thus avoiding duplication of beans in hierarchical deployments.

Modified: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/ArchiveInfoDeployer.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/ArchiveInfoDeployer.java	2010-09-28 17:02:13 UTC (rev 108368)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/ArchiveInfoDeployer.java	2010-09-28 21:21:41 UTC (rev 108369)
@@ -29,6 +29,8 @@
 import org.jboss.util.NotImplementedException;
 import org.jboss.weld.integration.deployer.env.bda.ArchiveInfo;
 import org.jboss.weld.integration.deployer.ext.JBossWeldMetaData;
+import org.jboss.weld.integration.util.EjbDiscoveryUtils;
+import org.jboss.weld.integration.util.JBossEjb;
 
 /**
  * ArchiveInfo deployer.
@@ -53,7 +55,7 @@
       }
       if (classLoader instanceof RealClassLoader)
       {
-         unit.addAttachment(ArchiveInfo.class, new ArchiveInfo(classLoader));
+         unit.addAttachment(ArchiveInfo.class, new ArchiveInfo(classLoader, EjbDiscoveryUtils.getVisibleEJbNames(unit)));
       }
       else
          // FIXME

Modified: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/Archive.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/Archive.java	2010-09-28 17:02:13 UTC (rev 108368)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/Archive.java	2010-09-28 21:21:41 UTC (rev 108369)
@@ -108,7 +108,8 @@
       this.classLoader = archiveInfo.getClassLoader();
       this.classpath = archiveInfo.getClasspath();
       this.classpath.addArchive(this);
-      this.ejbs = ejbs;
+      // configure only the ejbs that are visible to this archive
+      this.ejbs = filterDescriptors(archiveInfo, ejbs);
       // update instances map
       synchronized (instances)
       {
@@ -116,6 +117,20 @@
       }
    }
 
+   private static Collection<EjbDescriptor<?>> filterDescriptors(ArchiveInfo archiveInfo, Collection<EjbDescriptor<?>> ejbs)
+   {
+      ArrayList<EjbDescriptor<?>> descriptors = new ArrayList<EjbDescriptor<?>>();
+      for (EjbDescriptor<?> ejbDescriptor: ejbs)
+      {
+         Collection<String> ejbNames = archiveInfo.getEjbNames();
+         if (ejbNames.contains(ejbDescriptor.getEjbName()))
+         {
+            descriptors.add(ejbDescriptor);
+         }
+      }
+      return descriptors;
+   }
+
    /**
     * Returns all classes contained in this archive.
     * 

Modified: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ArchiveFactory.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ArchiveFactory.java	2010-09-28 17:02:13 UTC (rev 108368)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ArchiveFactory.java	2010-09-28 21:21:41 UTC (rev 108369)
@@ -43,7 +43,6 @@
     * 
     * @param archiveInfo contains all information necessary for the initialization of the
     *                    archive
-    * @param ejbs        the list of EJB descriptors
     */
    public static Archive createArchive(ArchiveInfo archiveInfo, Collection<EjbDescriptor<?>> ejbs)
    {

Modified: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ArchiveInfo.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ArchiveInfo.java	2010-09-28 17:02:13 UTC (rev 108368)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ArchiveInfo.java	2010-09-28 21:21:41 UTC (rev 108369)
@@ -22,6 +22,7 @@
 package org.jboss.weld.integration.deployer.env.bda;
 
 import java.lang.ref.WeakReference;
+import java.util.Collection;
 import java.util.Map;
 import java.util.WeakHashMap;
 
@@ -43,7 +44,8 @@
 
    // keeps track of the instances that are currently under use by deployers
    private static final Map<ClassLoader, WeakReference<ArchiveInfo>> instances = new WeakHashMap<ClassLoader, WeakReference<ArchiveInfo>>();
-
+   private Collection<String> ejbNames;
+   
    // adapts an Archive to a Classpath
    private ArchiveToClasspath classpathAdapter;
    // the classpath
@@ -75,8 +77,9 @@
     * during deployment.
     * 
     * @param classLoader the classLoader that is loading the archive under deployment.
+    * @param ejbNames the names of the EJBs that are deployed in this archive
     */
-   public ArchiveInfo(ClassLoader classLoader)
+   public ArchiveInfo(ClassLoader classLoader, Collection<String> ejbNames)
    {
       // must wrap in WeakReference because value refers strongly to its own key
       // see WeakHashMap javadoc
@@ -84,6 +87,7 @@
       this.classLoader = classLoader;
       this.classpath = classpathFactory.create(classLoader);
       this.environment = new WeldDiscoveryEnvironment();
+      this.ejbNames = ejbNames;
    }
 
    /**
@@ -117,6 +121,14 @@
    }
 
    /**
+    * Gets the EJBs of this archive
+    */
+   public Collection<String> getEjbNames()
+   {
+      return ejbNames;
+   }
+
+   /**
     * Returns a classpath adapter, indicating that the archive under deployment will be
     * used as a classpath itself.
     * 

Modified: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ArchiveLoader.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ArchiveLoader.java	2010-09-28 17:02:13 UTC (rev 108368)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/ArchiveLoader.java	2010-09-28 21:21:41 UTC (rev 108369)
@@ -80,7 +80,7 @@
          Archive archive = Archive.getInstance(beanClassLoader);
          if (archive == null)
          {
-            ArchiveInfo archiveInfo = new ArchiveInfo(beanClassLoader);
+            ArchiveInfo archiveInfo = new ArchiveInfo(beanClassLoader, Collections.<java.lang.String>emptyList());
             Collection<EjbDescriptor<?>> ejbs = Collections.emptyList();
             archive = ArchiveFactory.createArchive(archiveInfo, ejbs);
             registerArchiveLoadedByDeployment(archive, deployment);

Modified: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/LibraryDiscoveryService.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/LibraryDiscoveryService.java	2010-09-28 17:02:13 UTC (rev 108368)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/bda/LibraryDiscoveryService.java	2010-09-28 21:21:41 UTC (rev 108369)
@@ -23,11 +23,7 @@
 package org.jboss.weld.integration.deployer.env.bda;
 
 import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.jboss.classloading.spi.dependency.Module;
@@ -105,7 +101,7 @@
                if (cl != null)
                {
                   // create an ArchiveInfo with the ClassLoader
-                  ArchiveInfo archiveInfo = new ArchiveInfo(cl);
+                  ArchiveInfo archiveInfo = new ArchiveInfo(cl, Collections.<String>emptyList());
                   // finally create the Archive
                   Archive archive = ArchiveFactory.createArchive(archiveInfo, new ArrayList<EjbDescriptor<?>>());
                   // ... and the corresponding BDA

Added: trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/util/EjbDiscoveryUtils.java
===================================================================
--- trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/util/EjbDiscoveryUtils.java	                        (rev 0)
+++ trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/util/EjbDiscoveryUtils.java	2010-09-28 21:21:41 UTC (rev 108369)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.util;
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.ejb3.common.deployers.spi.AttachmentNames;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.metadata.web.jboss.JBossWebMetaData;
+
+
+
+/**
+ * @author Marius Bogoevici
+ */
+public abstract class EjbDiscoveryUtils
+{
+   public static Collection<String> getVisibleEJbNames(DeploymentUnit du)
+   {
+      // Ensure it's an EJB3 DU (by looking for the processed metadata)
+      List<String> ejbNames = new ArrayList<String>();
+      if (du.getAttachment(AttachmentNames.PROCESSED_METADATA, JBossMetaData.class) != null && du.getAttachment(JBossMetaData.class).isEJB3x())
+      {
+         JBossMetaData jBossMetaData = du.getAttachment(JBossMetaData.class);
+         for (JBossEnterpriseBeanMetaData enterpriseBeanMetaData : jBossMetaData.getEnterpriseBeans())
+         {
+            ejbNames.add(enterpriseBeanMetaData.getEjbName());
+         }
+      }
+
+      List<DeploymentUnit> children = du.getChildren();
+      if (children != null && children.isEmpty() == false)
+      {
+         //scan children, but exclude wars
+         for (DeploymentUnit childDu : children)
+         {
+            if (childDu.getAttachment(JBossWebMetaData.class) == null)
+            {
+               ejbNames.addAll(getVisibleEJbNames(childDu));
+            }
+         }
+      }
+
+      return ejbNames;
+   }
+}



More information about the jboss-cvs-commits mailing list