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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Sep 1 09:04:13 EDT 2008


Author: wolfc
Date: 2008-09-01 09:04:13 -0400 (Mon, 01 Sep 2008)
New Revision: 77751

Added:
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/resolvers/
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/resolvers/DefaultMessageDestinationReferenceResolver.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/resolvers/MessageDestinationReferenceResolver.java
Removed:
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/enc/MessageDestinationResolver.java
Modified:
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3Deployment.java
Log:
EJBTHREE-1481: created MessageDestinationReferenceResolver

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3Deployment.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3Deployment.java	2008-09-01 12:54:26 UTC (rev 77750)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3Deployment.java	2008-09-01 13:04:13 UTC (rev 77751)
@@ -47,9 +47,7 @@
 import org.jboss.ejb3.cache.CacheFactoryRegistry;
 import org.jboss.ejb3.cache.persistence.PersistenceManagerFactoryRegistry;
 import org.jboss.ejb3.common.lang.ClassHelper;
-import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
 import org.jboss.ejb3.enc.EjbModulePersistenceUnitResolver;
-import org.jboss.ejb3.enc.MessageDestinationResolver;
 import org.jboss.ejb3.entity.PersistenceUnitDeployment;
 import org.jboss.ejb3.entity.SecondLevelCacheUtil;
 import org.jboss.ejb3.javaee.JavaEEApplication;
@@ -60,6 +58,7 @@
 import org.jboss.ejb3.pool.PoolFactoryRegistry;
 import org.jboss.ejb3.proxy.factory.ProxyFactoryHelper;
 import org.jboss.ejb3.proxy.factory.RemoteProxyFactoryRegistry;
+import org.jboss.ejb3.resolvers.MessageDestinationReferenceResolver;
 import org.jboss.injection.InjectionHandler;
 import org.jboss.jpa.resolvers.PersistenceUnitDependencyResolver;
 import org.jboss.logging.Logger;
@@ -128,7 +127,8 @@
 
    protected EjbModulePersistenceUnitResolver persistenceUnitResolver;
 
-   protected MessageDestinationResolver messageDestinationResolver;
+   private MessageDestinationReferenceResolver messageDestinationReferenceResolver;
+   
    protected CacheFactoryRegistry cacheFactoryRegistry;
    protected RemoteProxyFactoryRegistry remoteProxyFactoryRegistry;
    protected PersistenceManagerFactoryRegistry persistenceManagerFactoryRegistry;
@@ -163,7 +163,6 @@
       MessageDestinationsMetaData destinations = null;
       if (metaData != null && metaData.getAssemblyDescriptor() != null)
          destinations = metaData.getAssemblyDescriptor().getMessageDestinations();
-      messageDestinationResolver = new MessageDestinationResolver(deploymentScope, destinations);
    }
    
    /**
@@ -240,6 +239,13 @@
    {
       return persistenceManagerFactoryRegistry;
    }
+   
+   @Inject
+   public void setMessageDestinationReferenceResolver(MessageDestinationReferenceResolver resolver)
+   {
+      this.messageDestinationReferenceResolver = resolver;
+   }
+   
    public void setPersistenceManagerFactoryRegistry(PersistenceManagerFactoryRegistry registry)
    {
       this.persistenceManagerFactoryRegistry = registry;
@@ -823,65 +829,9 @@
       }
    }
 
-   //   /**
-   //    * 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)
    {
-      //      // 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);
+      return messageDestinationReferenceResolver.resolveMessageDestinationJndiName(deploymentUnit, link);
    }
 
    protected String resolvePersistenceUnitSupplier(String persistenceUnitName)
@@ -889,11 +839,6 @@
       return persistenceUnitDependencyResolver.resolvePersistenceUnitSupplier(deploymentUnit, persistenceUnitName);
    }
    
-   public MessageDestinationResolver getMessageDestinationResolver()
-   {
-      return messageDestinationResolver;
-   }
-
    /**
     * Do not call, for use in Ejb3Handler.
     * 

Deleted: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/enc/MessageDestinationResolver.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/enc/MessageDestinationResolver.java	2008-09-01 12:54:26 UTC (rev 77750)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/enc/MessageDestinationResolver.java	2008-09-01 13:04:13 UTC (rev 77751)
@@ -1,107 +0,0 @@
-/*
- * 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.HashMap;
-import java.util.Map;
-
-import org.jboss.ejb3.DeploymentScope;
-import org.jboss.ejb3.Ejb3Deployment;
-import org.jboss.logging.Logger;
-import org.jboss.metadata.javaee.spec.MessageDestinationMetaData;
-import org.jboss.metadata.javaee.spec.MessageDestinationsMetaData;
-
-/**
- * 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, MessageDestinationMetaData> messageDestinations = new HashMap<String, MessageDestinationMetaData>();
-   
-   public MessageDestinationResolver(DeploymentScope deploymentScope, MessageDestinationsMetaData mergedMessageDestinations)
-   {
-      this.deploymentScope = deploymentScope;
-      if (mergedMessageDestinations != null)
-      {
-         for (MessageDestinationMetaData dest : mergedMessageDestinations)
-         {
-            messageDestinations.put(dest.getMessageDestinationName(), dest);
-         }
-      }
-      // TODO Auto-generated constructor stub
-   }
-
-   private String getMessageDestinationJNDIName(String name)
-   {
-      MessageDestinationMetaData 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;
-   }
-}

Added: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/resolvers/DefaultMessageDestinationReferenceResolver.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/resolvers/DefaultMessageDestinationReferenceResolver.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/resolvers/DefaultMessageDestinationReferenceResolver.java	2008-09-01 13:04:13 UTC (rev 77751)
@@ -0,0 +1,150 @@
+/*
+ * 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.resolvers;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.metadata.client.jboss.JBossClientMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.metadata.javaee.spec.MessageDestinationMetaData;
+import org.jboss.metadata.javaee.spec.MessageDestinationsMetaData;
+import org.jboss.metadata.web.jboss.JBossWebMetaData;
+
+/**
+ * The default implementation of a MessageDestinationReferenceResolver.
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class DefaultMessageDestinationReferenceResolver implements MessageDestinationReferenceResolver
+{
+   private static String findMessageDestination(DeploymentUnit deploymentUnit, MessageDestinationsMetaData destinations, String name)
+   {
+      if(destinations == null)
+         return null;
+      MessageDestinationMetaData destination = destinations.get(name);
+      if(destination != null)
+      {
+         String jndiName = destination.getMappedName();
+         if(jndiName != null)
+            return jndiName;
+         else
+            throw new IllegalStateException("Message destination " + name + " in " + deploymentUnit + " does not define a mapped name");
+      }
+      return null;
+   }
+   
+   private static String findWithinApplication(DeploymentUnit unit, String name)
+   {
+      String jndiName = findWithinModule(unit, name);
+      if(jndiName != null)
+         return jndiName;
+      
+      for(DeploymentUnit child : unit.getChildren())
+      {
+         jndiName = findWithinApplication(child, name);
+         if(jndiName != null)
+            return jndiName;
+      }
+      return null;
+   }
+   
+   private static String findWithinModule(DeploymentUnit deploymentUnit, String name)
+   {
+      JBossMetaData ejbMetaData = deploymentUnit.getAttachment(JBossMetaData.class);
+      if(ejbMetaData != null)
+      {
+         MessageDestinationsMetaData destinations = ejbMetaData.getAssemblyDescriptor().getMessageDestinations();
+         String jndiName = findMessageDestination(deploymentUnit, destinations, name);
+         if(jndiName != null)
+            return jndiName;
+      }
+      
+      JBossWebMetaData webMetaData = deploymentUnit.getAttachment(JBossWebMetaData.class);
+      if(webMetaData != null)
+      {
+         MessageDestinationsMetaData destinations = webMetaData.getMessageDestinations();
+         String jndiName = findMessageDestination(deploymentUnit, destinations, name);
+         if(jndiName != null)
+            return jndiName;
+      }
+      
+      JBossClientMetaData clientMetaData = deploymentUnit.getAttachment(JBossClientMetaData.class);
+      if(clientMetaData != null)
+      {
+         MessageDestinationsMetaData destinations = clientMetaData.getMessageDestinations();
+         String jndiName = findMessageDestination(deploymentUnit, destinations, name);
+         if(jndiName != null)
+            return jndiName;
+      }
+      return null;
+   }
+   
+   // TODO: duplicate of DefaultPersistenceUnitDependencyResolver.getDeploymentUnit
+   private static DeploymentUnit getDeploymentUnit(DeploymentUnit current, String path)
+   {
+      if(path.startsWith("/"))
+         return getDeploymentUnit(current.getTopLevel(), path.substring(1));
+      if(path.startsWith("./"))
+         return getDeploymentUnit(current, path.substring(2));
+      if(path.startsWith("../"))
+         return getDeploymentUnit(current.getParent(), path.substring(3));
+      int i = path.indexOf('/');
+      String name;
+      if(i == -1)
+         name = path;
+      else
+         name = path.substring(0, i);
+      for(DeploymentUnit child : current.getChildren())
+      {
+         if(child.getSimpleName().equals(name))
+            return child;
+      }
+      throw new IllegalArgumentException("Can't find a deployment unit named " + name + " at " + current);
+   }
+   
+   public String resolveMessageDestinationJndiName(DeploymentUnit deploymentUnit, String link)
+   {
+      int i = (link == null ? -1 : link.indexOf('#'));
+      if(i != -1)
+      {
+         String path = link.substring(0, i);
+         link = link.substring(i + 1);
+         // Since we want to look relatively to the component jar, we should start in
+         // our parent.
+         deploymentUnit = getDeploymentUnit(deploymentUnit, "../" + path);
+         String jndiName = findWithinModule(deploymentUnit, link);
+         if(jndiName != null)
+            return jndiName;
+      }
+      else
+      {
+         String jndiName = findWithinModule(deploymentUnit, link);
+         if(jndiName != null)
+            return jndiName;
+         // TODO: can't find this in the spec, but apparently it's allowed.
+         jndiName = findWithinApplication(deploymentUnit.getTopLevel(), link);
+         if(jndiName != null)
+            return jndiName;
+      }
+      throw new IllegalArgumentException("Deployment unit " + deploymentUnit + " does not define a message destination " + link);
+   }
+}

Added: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/resolvers/MessageDestinationReferenceResolver.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/resolvers/MessageDestinationReferenceResolver.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/resolvers/MessageDestinationReferenceResolver.java	2008-09-01 13:04:13 UTC (rev 77751)
@@ -0,0 +1,42 @@
+/*
+ * 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.resolvers;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * Based on the available meta data resolve message destination references.
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface MessageDestinationReferenceResolver
+{
+   /**
+    * Get the JNDI name of the message destination specified by link.
+    * 
+    * @param deploymentUnit the deployment unit in which the reference is defined
+    * @param link           the name of the message destination
+    * @return the JNDI name of the message destination
+    */
+   String resolveMessageDestinationJndiName(DeploymentUnit deploymentUnit, String link);
+}




More information about the jboss-cvs-commits mailing list