[jboss-cvs] JBossAS SVN: r82434 - in projects/ejb3/trunk: mc-int and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Dec 19 00:36:53 EST 2008


Author: ALRubinger
Date: 2008-12-19 00:36:53 -0500 (Fri, 19 Dec 2008)
New Revision: 82434

Added:
   projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/deployers/spi/Ejb3DeployerUtils.java
Modified:
   projects/ejb3/trunk/mc-int/pom.xml
   projects/ejb3/trunk/mc-int/src/main/java/org/jboss/ejb3/mcint/metadata/plugins/AbstractEjbReferenceValueMetadata.java
Log:
[EJBTHREE-1645] Centralize logic to get all EJB3 DeploymentUnits from MainDeployer

Added: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/deployers/spi/Ejb3DeployerUtils.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/deployers/spi/Ejb3DeployerUtils.java	                        (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/deployers/spi/Ejb3DeployerUtils.java	2008-12-19 05:36:53 UTC (rev 82434)
@@ -0,0 +1,104 @@
+/*
+ * 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.ejb3.common.deployers.spi;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
+import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+
+/**
+ * Ejb3DeployerUtils
+ * 
+ * A Set of Utilities to assist w/ EJB3 tasks related
+ * to VDF
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class Ejb3DeployerUtils
+{
+   // ------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------||
+   // ------------------------------------------------------------------------------||
+
+   /**
+    * MC Bind Name of the Main Deployer
+    */
+   private static final String MC_BEAN_NAME_MAIN_DEPLOYER = "MainDeployer";
+
+   // ------------------------------------------------------------------------------||
+   // Constructor ------------------------------------------------------------------||
+   // ------------------------------------------------------------------------------||
+
+   /**
+    * Internal Constructor, to prevent instanciation
+    */
+   private Ejb3DeployerUtils()
+   {
+      // Leave intact and private
+   }
+
+   // ------------------------------------------------------------------------------||
+   // Utility Methods --------------------------------------------------------------||
+   // ------------------------------------------------------------------------------||
+
+   /**
+    * Obtains all EJB3 Deployment Units registered w/ the Main Deployer
+    */
+   public static Set<DeploymentUnit> getAllEjb3DeploymentUnitsInMainDeployer()
+   {
+      // Initialize
+      Set<DeploymentUnit> deploymentUnits = new HashSet<DeploymentUnit>();
+
+      // Get at the MainDeployer
+      Object mainDeployer = Ejb3RegistrarLocator.locateRegistrar().lookup(MC_BEAN_NAME_MAIN_DEPLOYER);
+      assert mainDeployer instanceof DeployerClient && mainDeployer instanceof MainDeployerStructure : "Obtained Main Deployer is not of expected type";
+      DeployerClient dc = (DeployerClient) mainDeployer;
+      MainDeployerStructure mds = (MainDeployerStructure) mainDeployer;
+
+      // Loop through each Deployment
+      for (Deployment d : dc.getTopLevel())
+      {
+         // Get the associated DU
+         DeploymentUnit du = mds.getDeploymentUnit(d.getName());
+
+         // Ensure it's an EJB3 DU (by looking for the processed metadata)
+         if (du.getAttachment(AttachmentNames.PROCESSED_METADATA, JBossMetaData.class) == null)
+         {
+            continue;
+         }
+
+         // Add to the set
+         deploymentUnits.add(du);
+      }
+
+      // Return
+      return deploymentUnits;
+   }
+
+}

Modified: projects/ejb3/trunk/mc-int/pom.xml
===================================================================
--- projects/ejb3/trunk/mc-int/pom.xml	2008-12-19 04:03:33 UTC (rev 82433)
+++ projects/ejb3/trunk/mc-int/pom.xml	2008-12-19 05:36:53 UTC (rev 82434)
@@ -70,7 +70,7 @@
     <dependency>
       <groupId>org.jboss.ejb3</groupId>
       <artifactId>jboss-ejb3-common</artifactId>
-      <version>1.0.0-Beta4</version>
+      <version>1.0.0-SNAPSHOT</version>
     </dependency>
 
     <!-- EJB3 Test -->

Modified: projects/ejb3/trunk/mc-int/src/main/java/org/jboss/ejb3/mcint/metadata/plugins/AbstractEjbReferenceValueMetadata.java
===================================================================
--- projects/ejb3/trunk/mc-int/src/main/java/org/jboss/ejb3/mcint/metadata/plugins/AbstractEjbReferenceValueMetadata.java	2008-12-19 04:03:33 UTC (rev 82433)
+++ projects/ejb3/trunk/mc-int/src/main/java/org/jboss/ejb3/mcint/metadata/plugins/AbstractEjbReferenceValueMetadata.java	2008-12-19 05:36:53 UTC (rev 82434)
@@ -21,16 +21,15 @@
  */
 package org.jboss.ejb3.mcint.metadata.plugins;
 
+import java.util.Collection;
+
 import javax.naming.Context;
 import javax.naming.NamingException;
 
 import org.jboss.beans.metadata.plugins.AbstractDependencyValueMetaData;
-import org.jboss.deployers.client.spi.DeployerClient;
-import org.jboss.deployers.client.spi.Deployment;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
 import org.jboss.ejb3.common.deployers.spi.AttachmentNames;
-import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
+import org.jboss.ejb3.common.deployers.spi.Ejb3DeployerUtils;
 import org.jboss.ejb3.common.resolvers.spi.EjbReference;
 import org.jboss.ejb3.common.resolvers.spi.EjbReferenceResolver;
 import org.jboss.ejb3.common.resolvers.spi.UnresolvableReferenceException;
@@ -56,8 +55,6 @@
 
    private static final long serialVersionUID = 1L;
 
-   private static final String MC_BEAN_NAME_MAIN_DEPLOYER = "MainDeployer";
-
    private static final String DEPENDS_JNDI_PREFIX = "jndi:";
 
    // --------------------------------------------------------------------------------||
@@ -133,31 +130,28 @@
        * Look through all EJB3 DeploymentUnits
        */
 
-      // Get at the MainDeployer
-      Object mainDeployer = Ejb3RegistrarLocator.locateRegistrar().lookup(MC_BEAN_NAME_MAIN_DEPLOYER);
-      assert mainDeployer instanceof DeployerClient && mainDeployer instanceof MainDeployerStructure : "Obtained Main Deployer is not of expected type";
-      DeployerClient dc = (DeployerClient) mainDeployer;
-      MainDeployerStructure mds = (MainDeployerStructure) mainDeployer;
+      // Get all EJB3 DUs
+      Collection<DeploymentUnit> dus = Ejb3DeployerUtils.getAllEjb3DeploymentUnitsInMainDeployer();
 
-      // Loop through each Deployment
-      for (Deployment d : dc.getTopLevel())
+      // Loop through each DeploymentUnit
+      if (dus != null)
       {
-         // Get the associated DU
-         DeploymentUnit du = mds.getDeploymentUnit(d.getName());
-
-         // Ensure it's an EJB3 DU (by looking for the processed metadata)
-         if (du.getAttachment(AttachmentNames.PROCESSED_METADATA, JBossMetaData.class) == null)
+         for (DeploymentUnit du : dus)
          {
-            continue;
-         }
+            // Ensure it's an EJB3 DU (by looking for the processed metadata)
+            if (du.getAttachment(AttachmentNames.PROCESSED_METADATA, JBossMetaData.class) == null)
+            {
+               continue;
+            }
 
-         // Try to resolve
-         jndiName = resolver.resolveEjb(du, reference);
+            // Try to resolve
+            jndiName = resolver.resolveEjb(du, reference);
 
-         // If we've resolved here, we're done
-         if (jndiName != null)
-         {
-            break;
+            // If we've resolved here, we're done
+            if (jndiName != null)
+            {
+               break;
+            }
          }
       }
 




More information about the jboss-cvs-commits mailing list