[jboss-cvs] JBossAS SVN: r62964 - in trunk/ejb3/src/main/org/jboss/ejb3: enc and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu May 10 06:55:51 EDT 2007


Author: wolfc
Date: 2007-05-10 06:55:51 -0400 (Thu, 10 May 2007)
New Revision: 62964

Added:
   trunk/ejb3/src/main/org/jboss/ejb3/enc/MessageDestinationResolver.java
Modified:
   trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java
   trunk/ejb3/src/main/org/jboss/ejb3/metamodel/AssemblyDescriptor.java
Log:
EJBTHREE-957: refactor message resolving

Modified: trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java	2007-05-10 09:58:08 UTC (rev 62963)
+++ trunk/ejb3/src/main/org/jboss/ejb3/Ejb3Deployment.java	2007-05-10 10:55:51 UTC (rev 62964)
@@ -27,6 +27,7 @@
 import java.io.InputStream;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -49,9 +50,9 @@
 import org.hibernate.ejb.packaging.PersistenceMetadata;
 import org.jboss.ejb3.enc.EjbModuleEjbResolver;
 import org.jboss.ejb3.enc.EjbModulePersistenceUnitResolver;
+import org.jboss.ejb3.enc.MessageDestinationResolver;
 import org.jboss.ejb3.entity.PersistenceUnitDeployment;
 import org.jboss.ejb3.entity.PersistenceXmlLoader;
-import org.jboss.ejb3.metamodel.AssemblyDescriptor;
 import org.jboss.ejb3.metamodel.EjbJarDD;
 import org.jboss.ejb3.metamodel.EjbJarDDObjectFactory;
 import org.jboss.ejb3.metamodel.JBossDDObjectFactory;
@@ -96,6 +97,7 @@
    protected DeploymentScope deploymentScope;
    protected EjbModuleEjbResolver ejbRefResolver;
    protected EjbModulePersistenceUnitResolver persistenceUnitResolver;
+   protected MessageDestinationResolver messageDestinationResolver;
 
    //The JACC PolicyConfiguration
    PolicyConfiguration pc;
@@ -114,6 +116,25 @@
       }
       ejbRefResolver = new EjbModuleEjbResolver(deploymentScope, unit.getShortName(), ejbContainers, this);
       persistenceUnitResolver = new EjbModulePersistenceUnitResolver(persistenceUnitDeployments, deploymentScope, ejbContainers);
+      Collection<MessageDestination> destinations = null;
+      EjbJarDD dd;
+      // FIXME: Why isn't dd stored somewhere?
+      try
+      {
+         dd = EjbJarDDObjectFactory.parse(getDeploymentUnit().getEjbJarXml());
+         dd = JBossDDObjectFactory.parse(getDeploymentUnit().getJbossXml(), dd);
+      }
+      catch(IOException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch(JBossXBException e)
+      {
+         throw new RuntimeException(e);
+      }
+      if(dd != null && dd.getAssemblyDescriptor() != null)
+         destinations = dd.getAssemblyDescriptor().getMessageDestinations();
+      messageDestinationResolver = new MessageDestinationResolver(deploymentScope, destinations);
    }
 
    public DeploymentScope getEar()
@@ -580,58 +601,70 @@
       }
    }
    
-   private String getMessageDestination(String name)
+//   /**
+//    * Get the jndi name of a message destination.
+//    * 
+//    * @param name   the name of the message destination
+//    * @return       the jndi name
+//    */
+//   private String getMessageDestination(String name)
+//   {
+//      EjbJarDD dd;
+//      // FIXME: Why isn't dd stored somewhere?
+//      try
+//      {
+//         dd = EjbJarDDObjectFactory.parse(getDeploymentUnit().getEjbJarXml());
+//         dd = JBossDDObjectFactory.parse(getDeploymentUnit().getJbossXml(), dd);
+//      }
+//      catch(IOException e)
+//      {
+//         throw new RuntimeException(e);
+//      }
+//      catch(JBossXBException e)
+//      {
+//         throw new RuntimeException(e);
+//      }
+//
+//      AssemblyDescriptor ad = dd.getAssemblyDescriptor();
+//      if(ad == null)
+//         throw new IllegalStateException("No assembly descriptor found in '" + getName() + "'");
+//      MessageDestination md = ad.findMessageDestination(name);
+//      if(md == null)
+//         throw new IllegalStateException("No message destination '" + name + "' found in '" + getName() + "'");
+//      String jndiName = md.getJndiName();
+//      if(jndiName == null)
+//         throw new IllegalStateException("No jndi name specified for message destination '" + name + "' in '" + getName() + "'");
+//      return jndiName;
+//   }
+   
+   public String resolveMessageDestination(String link)
    {
-      EjbJarDD dd;
-      // FIXME: Why isn't dd stored somewhere?
-      try
-      {
-         dd = EjbJarDDObjectFactory.parse(getDeploymentUnit().getEjbJarXml());
-         dd = JBossDDObjectFactory.parse(getDeploymentUnit().getJbossXml(), dd);
-      }
-      catch(IOException e)
-      {
-         throw new RuntimeException(e);
-      }
-      catch(JBossXBException e)
-      {
-         throw new RuntimeException(e);
-      }
-
-      AssemblyDescriptor ad = dd.getAssemblyDescriptor();
-      if(ad == null)
-         throw new IllegalStateException("No assembly descriptor found in '" + getName() + "'");
-      MessageDestination md = ad.findMessageDestination(name);
-      if(md == null)
-         throw new IllegalStateException("No message destination '" + name + "' found in '" + getName() + "'");
-      String jndiName = md.getJndiName();
-      if(jndiName == null)
-         throw new IllegalStateException("No jndi name specified for message destination '" + name + "' in '" + getName() + "'");
-      return jndiName;
+//      // FIXME: this is a copy of DeploymentEjbResolver
+//      int hashIndex = link.indexOf('#');
+//      if (hashIndex != -1)
+//      {
+//         if (deploymentScope == null)
+//         {
+//            log.warn("ejb link '" + link + "' is relative, but no deployment scope found");
+//            return null;
+//         }
+//         String relativePath = link.substring(0, hashIndex);
+//         Ejb3Deployment dep = deploymentScope.findRelativeDeployment(relativePath);
+//         if (dep == null)
+//         {
+//            log.warn("can't find a deployment for path '" + relativePath + "' of ejb link '" + link + "'");
+//            return null;
+//         }
+//         String name = link.substring(hashIndex + 1);
+//         return dep.getMessageDestination(name);
+//      }
+//      return getMessageDestination(link);
+      return messageDestinationResolver.resolveMessageDestination(link);
    }
    
-   public String resolveMessageDestination(String link)
+   public MessageDestinationResolver getMessageDestinationResolver()
    {
-      // FIXME: this is a copy of DeploymentEjbResolver
-      int hashIndex = link.indexOf('#');
-      if (hashIndex != -1)
-      {
-         if (deploymentScope == null)
-         {
-            log.warn("ejb link '" + link + "' is relative, but no deployment scope found");
-            return null;
-         }
-         String relativePath = link.substring(0, hashIndex);
-         Ejb3Deployment dep = deploymentScope.findRelativeDeployment(relativePath);
-         if (dep == null)
-         {
-            log.warn("can't find a deployment for path '" + relativePath + "' of ejb link '" + link + "'");
-            return null;
-         }
-         String name = link.substring(hashIndex + 1);
-         return dep.getMessageDestination(name);
-      }
-      return getMessageDestination(link);
+      return messageDestinationResolver;
    }
    
    public String getName()

Added: trunk/ejb3/src/main/org/jboss/ejb3/enc/MessageDestinationResolver.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/enc/MessageDestinationResolver.java	                        (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/enc/MessageDestinationResolver.java	2007-05-10 10:55:51 UTC (rev 62964)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.enc;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.ejb3.DeploymentScope;
+import org.jboss.ejb3.Ejb3Deployment;
+import org.jboss.ejb3.metamodel.MessageDestination;
+import org.jboss.logging.Logger;
+
+/**
+ * Find a message destination link within any module of
+ * this JavaEE application deployment.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MessageDestinationResolver
+{
+   private static final Logger log = Logger.getLogger(MessageDestinationResolver.class);
+   
+   private DeploymentScope deploymentScope;
+   private Map<String, MessageDestination> messageDestinations = new HashMap<String, MessageDestination>();
+
+   public MessageDestinationResolver(DeploymentScope deploymentScope, Collection<MessageDestination> destinations)
+   {
+      this.deploymentScope = deploymentScope;
+      if(destinations != null)
+      {
+         for(MessageDestination dest : destinations)
+         {
+            messageDestinations.put(dest.getMessageDestinationName(), dest);
+         }
+      }
+   }
+   
+   private String getMessageDestinationJNDIName(String name)
+   {
+      MessageDestination dest = messageDestinations.get(name);
+      if(dest != null)
+         return dest.getJndiName();
+      return null;
+   }
+   
+   /**
+    * Resolve the message destination link name and return the
+    * matching jndi name.
+    * 
+    * @param link   name of the message destination
+    * @return       jndi name
+    */
+   public String resolveMessageDestination(String link)
+   {
+      int hashIndex = link.indexOf('#');
+      if (hashIndex != -1)
+      {
+         if (deploymentScope == null)
+         {
+            log.warn("Message destination link '" + link + "' is relative, but no deployment scope found");
+            return null;
+         }
+         String relativePath = link.substring(0, hashIndex);
+         Ejb3Deployment dep = deploymentScope.findRelativeDeployment(relativePath);
+         if (dep == null)
+         {
+            log.warn("Can't find a deployment for path '" + relativePath + "' of message destination link '" + link + "'");
+            return null;
+         }
+         String name = link.substring(hashIndex + 1);
+         return dep.resolveMessageDestination(name);
+      }
+      String jndiName = getMessageDestinationJNDIName(link);
+      if(jndiName != null)
+         return jndiName;
+      for(Ejb3Deployment dep : deploymentScope.getEjbDeployments())
+      {
+         jndiName = dep.getMessageDestinationResolver().getMessageDestinationJNDIName(link);
+         if(jndiName != null)
+            return jndiName;
+      }
+      log.warn("Can't find a message destination for link '" + link + "' anywhere");
+      return null;
+   }
+}

Modified: trunk/ejb3/src/main/org/jboss/ejb3/metamodel/AssemblyDescriptor.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/metamodel/AssemblyDescriptor.java	2007-05-10 09:58:08 UTC (rev 62963)
+++ trunk/ejb3/src/main/org/jboss/ejb3/metamodel/AssemblyDescriptor.java	2007-05-10 10:55:51 UTC (rev 62964)
@@ -65,7 +65,7 @@
 
    private List injects = new ArrayList();
    
-   public Collection getMessageDestinations()
+   public Collection<MessageDestination> getMessageDestinations()
    {
       return messageDestinations.values();
    }




More information about the jboss-cvs-commits mailing list