[jboss-cvs] JBossAS SVN: r75171 - trunk/spring-int/src/main/org/jboss/spring/io.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Jun 28 17:37:12 EDT 2008


Author: alesj
Date: 2008-06-28 17:37:12 -0400 (Sat, 28 Jun 2008)
New Revision: 75171

Modified:
   trunk/spring-int/src/main/org/jboss/spring/io/VFSResource.java
   trunk/spring-int/src/main/org/jboss/spring/io/VFSResourcePatternResolver.java
Log:
Fixing pattern resolver - no effect on any AS5 code.

Modified: trunk/spring-int/src/main/org/jboss/spring/io/VFSResource.java
===================================================================
--- trunk/spring-int/src/main/org/jboss/spring/io/VFSResource.java	2008-06-28 21:29:09 UTC (rev 75170)
+++ trunk/spring-int/src/main/org/jboss/spring/io/VFSResource.java	2008-06-28 21:37:12 UTC (rev 75171)
@@ -127,4 +127,9 @@
    {
       return file.openStream();
    }
+
+   public String toString()
+   {
+      return getDescription();
+   }
 }

Modified: trunk/spring-int/src/main/org/jboss/spring/io/VFSResourcePatternResolver.java
===================================================================
--- trunk/spring-int/src/main/org/jboss/spring/io/VFSResourcePatternResolver.java	2008-06-28 21:29:09 UTC (rev 75170)
+++ trunk/spring-int/src/main/org/jboss/spring/io/VFSResourcePatternResolver.java	2008-06-28 21:37:12 UTC (rev 75171)
@@ -23,9 +23,11 @@
 
 import java.io.IOException;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.List;
-import java.util.ArrayList;
+import java.util.Enumeration;
 
+import org.jboss.logging.Logger;
 import org.jboss.virtual.VFS;
 import org.jboss.virtual.VirtualFile;
 import org.jboss.virtual.VirtualFileVisitor;
@@ -40,6 +42,8 @@
  */
 public class VFSResourcePatternResolver extends PathMatchingResourcePatternResolver
 {
+   private Logger log = Logger.getLogger(VFSResourcePatternResolver.class);
+
    public VFSResourcePatternResolver()
    {
       super(new VFSResourceLoader());
@@ -50,17 +54,54 @@
       super(new VFSResourceLoader(classLoader));
    }
 
-   public Resource[] getResources(String locationPattern) throws IOException
+   protected Resource[] findPathMatchingResources(String locationPattern) throws IOException
    {
+      locationPattern = locationPattern.substring(CLASSPATH_ALL_URL_PREFIX.length());
       String rootDirPath = determineRootDir(locationPattern);
       String subPattern = locationPattern.substring(rootDirPath.length());
-      URL rootURL = new URL(rootDirPath);
+      if (rootDirPath.startsWith("/"))
+         rootDirPath = rootDirPath.substring(1);
+
+      List<Resource> resources = new ArrayList<Resource>();
+      Enumeration<URL> urls = getClassLoader().getResources(rootDirPath);
+      while(urls.hasMoreElements())
+         resources.addAll(getVFSResources(urls.nextElement(), subPattern));
+
+      return resources.toArray(new Resource[resources.size()]);
+   }
+
+   /**
+    * Get VFS resources.
+    *
+    * @param rootURL the root URL
+    * @param subPattern the sub pattern
+    * @return vfs resources list
+    * @throws IOException for any error
+    */
+   protected List<Resource> getVFSResources(URL rootURL, String subPattern) throws IOException
+   {
+      log.debug("Scanning url: " + rootURL + ", sub-pattern: " + subPattern);
       VirtualFile root = VFS.getRoot(rootURL);
       PatternVirtualFileVisitor visitor = new PatternVirtualFileVisitor(subPattern);
       root.visit(visitor);
-      return visitor.getResources().toArray(new Resource[visitor.size()]);
+      if (log.isTraceEnabled())
+         log.trace("Found resources: " + visitor);
+      return visitor.getResources();
    }
 
+   protected Resource convertClassLoaderURL(URL url)
+   {
+      try
+      {
+         VirtualFile file = VFS.getRoot(url);
+         return new VFSResource(file);
+      }
+      catch (IOException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
    /**
     * Get visitor attributes.
     * Allows for override, if necessary.
@@ -102,5 +143,13 @@
       {
          return resources.size();
       }
+
+      public String toString()
+      {
+         StringBuffer buffer = new StringBuffer();
+         buffer.append("sub-pattern: ").append(subPattern);
+         buffer.append(", resources: ").append(resources);
+         return buffer.toString();
+      }
    }
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list