[jboss-cvs] JBossAS SVN: r66670 - trunk/server/src/main/org/jboss/deployment.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Nov 2 02:44:38 EDT 2007


Author: scott.stark at jboss.org
Date: 2007-11-02 02:44:38 -0400 (Fri, 02 Nov 2007)
New Revision: 66670

Modified:
   trunk/server/src/main/org/jboss/deployment/ReferenceMetaDataResolverDeployer.java
Log:
Fix the relative link resolution

Modified: trunk/server/src/main/org/jboss/deployment/ReferenceMetaDataResolverDeployer.java
===================================================================
--- trunk/server/src/main/org/jboss/deployment/ReferenceMetaDataResolverDeployer.java	2007-11-02 01:42:18 UTC (rev 66669)
+++ trunk/server/src/main/org/jboss/deployment/ReferenceMetaDataResolverDeployer.java	2007-11-02 06:44:38 UTC (rev 66670)
@@ -21,19 +21,15 @@
  */
 package org.jboss.deployment;
 
-import java.net.MalformedURLException;
-import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
-import java.util.StringTokenizer;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.deployer.DeploymentStages;
 import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer;
-import org.jboss.deployers.structure.spi.DeploymentContext;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
 import org.jboss.logging.Logger;
@@ -50,7 +46,6 @@
 import org.jboss.metadata.javaee.spec.Environment;
 import org.jboss.metadata.javaee.spec.MessageDestinationMetaData;
 import org.jboss.metadata.web.jboss.JBossWebMetaData;
-import org.jboss.util.Strings;
 
 /**
  * A deployer which resolves references for parsing deployers
@@ -286,69 +281,22 @@
 
    private static String resolveRelativeLink(DeploymentUnit unit, String link, boolean isLocal)
    {
+      DeploymentUnit top = unit.getTopLevel();
       String path = link.substring(0, link.indexOf('#'));
       String ejbName = link.substring(link.indexOf('#') + 1);
-      String us = unit.getName();
 
-      // Remove the trailing slash for unpacked deployments
-      if (us.charAt(us.length() - 1) == '/')
-         us = us.substring(0, us.length() - 1);
-
-      String ourPath = us.substring(0, us.lastIndexOf('/'));
-
+      
       if (log.isTraceEnabled())
       {
          log.trace("Resolving relative link: " + link);
-         log.trace("Looking for: '" + link + "', we're located at: '" + ourPath + "'");
       }
-
-      for (StringTokenizer st = new StringTokenizer(path, "/"); st.hasMoreTokens();)
-      {
-         String s = st.nextToken();
-         if (s.equals(".."))
-         {
-            ourPath = ourPath.substring(0, ourPath.lastIndexOf('/'));
-         }
-         else
-         {
-            ourPath += "/" + s;
-         }
-      }
-
-      URL target = null;
-
-      try
-      {
-         target = Strings.toURL(ourPath);
-      }
-      catch (MalformedURLException mue)
-      {
-         log.warn("Can't construct URL for: " + ourPath);
-         return null;
-      }
-
-      DeploymentUnit targetUnit = null;
-      try
-      {
-         targetUnit = findTargetUnit(unit, target);
-      }
-      catch (Exception e)
-      {
-         log.warn("Got Exception when looking for DeploymentUnit: " + e);
-         return null;
-      }
-
+      DeploymentUnit targetUnit = findLinkPath(top, path);
       if (targetUnit == null)
       {
-         log.warn("Can't locate DeploymentUnit for target: " + target);
+         log.warn("Can't locate DeploymentUnit for target: " + path);
          return null;
       }
 
-      if (log.isTraceEnabled())
-      {
-         log.trace("Found appropriate DeploymentUnit: " + targetUnit);
-      }
-
       String linkTarget = null;
       if (targetUnit.getAttachment(JBossMetaData.class) != null)
       {
@@ -372,11 +320,6 @@
       return linkTarget;
    }
 
-   private static DeploymentUnit findTargetUnit(DeploymentUnit unit, URL target)
-   {
-      return null;
-   }
-
    private static String resolveAbsoluteLink(DeploymentUnit unit, String link, boolean isLocal)
    {
       if (log.isTraceEnabled())
@@ -476,7 +419,7 @@
 
       if (link.indexOf('#') != -1)
          // link is specified in the form path/file.jar#Bean
-         return resolveRelativeMessageDestination(server, di, link);
+         return resolveRelativeMessageDestination(di, link);
       else
       {
          // link contains a Bean Name, scan the DeploymentUnit tree
@@ -485,58 +428,20 @@
       }
    }
 
-   private static MessageDestinationMetaData resolveRelativeMessageDestination(MainDeployerStructure server, DeploymentUnit unit, String link)
+   private static MessageDestinationMetaData resolveRelativeMessageDestination(DeploymentUnit unit, String link)
    {
       String path = link.substring(0, link.indexOf('#'));
       String destinationName = link.substring(link.indexOf('#') + 1);
-      String us = unit.getName();
 
-      // Remove the trailing slash for unpacked deployments
-      if (us.charAt(us.length() - 1) == '/')
-         us = us.substring(0, us.length() - 1);
-
-      String ourPath = us.substring(0, us.lastIndexOf('/'));
-
       if (log.isTraceEnabled())
       {
          log.trace("Resolving relative message-destination-link: " + link);
-         log.trace("Looking for: '" + link + "', we're located at: '" + ourPath + "'");
       }
-
-      for (StringTokenizer st = new StringTokenizer(path, "/"); st.hasMoreTokens();)
-      {
-         String s = st.nextToken();
-         if (s.equals(".."))
-            ourPath = ourPath.substring(0, ourPath.lastIndexOf('/'));
-         else ourPath += "/" + s;
-      }
-
-      URL target = null;
-      try
-      {
-         target = Strings.toURL(ourPath);
-      }
-      catch (MalformedURLException mue)
-      {
-         log.warn("Can't construct URL for: " + ourPath);
-         return null;
-      }
-
-      DeploymentUnit targetUnit = null;
-      try
-      {
-         DeploymentContext ctx = server.getDeploymentContext(target.toString());
-         targetUnit = ctx.getDeploymentUnit();
-      }
-      catch (Exception e)
-      {
-         log.warn("Got Exception when looking for DeploymentUnit: " + e);
-         return null;
-      }
-
+      DeploymentUnit top = unit.getTopLevel();
+      DeploymentUnit targetUnit = findLinkPath(top, path);
       if (targetUnit == null)
       {
-         log.warn("Can't locate DeploymentUnit for target: " + target);
+         log.warn("Can't locate DeploymentUnit for target: " + path);
          return null;
       }
 
@@ -593,6 +498,34 @@
       return null;
    }
 
+   private static DeploymentUnit findLinkPath(DeploymentUnit top, String path)
+   {
+      List<DeploymentUnit> children = top.getChildren();
+      DeploymentUnit targetUnit = null;
+      if(children != null)
+      {
+         for(DeploymentUnit child : children)
+         {
+            String childPath = child.getRelativePath();
+            if(childPath.endsWith(path))
+            {
+               targetUnit = child;
+            }
+         }
+      }
+   
+      if (targetUnit == null)
+      {
+         return null;
+      }
+   
+      if (log.isTraceEnabled())
+      {
+         log.trace("Found appropriate DeploymentUnit: " + targetUnit);
+      }
+      return targetUnit;
+   }
+
    private void dump(DeploymentUnit unit)
    {
       DeploymentUnit top = unit.getTopLevel();




More information about the jboss-cvs-commits mailing list