[jboss-cvs] JBossAS SVN: r75156 - in trunk: spring-int/src/main/org/jboss/spring and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jun 27 07:09:04 EDT 2008


Author: alesj
Date: 2008-06-27 07:09:04 -0400 (Fri, 27 Jun 2008)
New Revision: 75156

Added:
   trunk/spring-int/src/main/org/jboss/spring/io/
   trunk/spring-int/src/main/org/jboss/spring/io/VFSResource.java
   trunk/spring-int/src/main/org/jboss/spring/io/VFSResourceLoader.java
   trunk/spring-int/src/main/org/jboss/spring/io/VFSResourcePatternResolver.java
Modified:
   trunk/component-matrix/pom.xml
Log:
Update spring to 2.5.
Implement spring io utils based on vfs.

Modified: trunk/component-matrix/pom.xml
===================================================================
--- trunk/component-matrix/pom.xml	2008-06-27 09:48:14 UTC (rev 75155)
+++ trunk/component-matrix/pom.xml	2008-06-27 11:09:04 UTC (rev 75156)
@@ -53,7 +53,7 @@
     <version.org.jboss.security>2.0.2.CR5</version.org.jboss.security>
     <version.oswego-concurrent.concurrent>1.3.4-jboss-update1</version.oswego-concurrent.concurrent>
     <version.suffix.org.jboss.javaee>.CR1</version.suffix.org.jboss.javaee>
-    <version.org.springframework>2.0</version.org.springframework>
+    <version.org.springframework>2.5</version.org.springframework>
     <version.sun-jaxws>2.1.1</version.sun-jaxws>
     <version.xdoclet>1.2.3</version.xdoclet>
   </properties>

Added: trunk/spring-int/src/main/org/jboss/spring/io/VFSResource.java
===================================================================
--- trunk/spring-int/src/main/org/jboss/spring/io/VFSResource.java	                        (rev 0)
+++ trunk/spring-int/src/main/org/jboss/spring/io/VFSResource.java	2008-06-27 11:09:04 UTC (rev 75156)
@@ -0,0 +1,130 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.spring.io;
+
+import java.net.URL;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.io.IOException;
+import java.io.File;
+import java.io.InputStream;
+
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VFSUtils;
+import org.springframework.core.io.Resource;
+
+/**
+ * VFS based Resource.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class VFSResource implements Resource
+{
+   private VirtualFile file;
+
+   public VFSResource(VirtualFile file)
+   {
+      if (file == null)
+         throw new IllegalArgumentException("Null file");
+      this.file = file;
+   }
+
+   public boolean exists()
+   {
+      try
+      {
+         return file.exists();
+      }
+      catch (IOException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   public boolean isOpen()
+   {
+      return false;
+   }
+
+   public URL getURL() throws IOException
+   {
+      try
+      {
+         return file.toURL();
+      }
+      catch (URISyntaxException e)
+      {
+         IOException ioe = new IOException(e.getMessage());
+         ioe.initCause(e);
+         throw ioe;
+      }
+   }
+
+   public URI getURI() throws IOException
+   {
+      try
+      {
+         return file.toURI();
+      }
+      catch (URISyntaxException e)
+      {
+         IOException ioe = new IOException(e.getMessage());
+         ioe.initCause(e);
+         throw ioe;
+      }
+   }
+
+   public File getFile() throws IOException
+   {
+      try
+      {
+         return new File(VFSUtils.getCompatibleURL(file).toURI());
+      }
+      catch (URISyntaxException e)
+      {
+         IOException ioe = new IOException(e.getMessage());
+         ioe.initCause(e);
+         throw ioe;
+      }
+   }
+
+   @SuppressWarnings("deprecation")
+   public Resource createRelative(String relativePath) throws IOException
+   {
+      return new VFSResource(file.findChild(relativePath));
+   }
+
+   public String getFilename()
+   {
+      return file.getName();
+   }
+
+   public String getDescription()
+   {
+      return file.toString();
+   }
+
+   public InputStream getInputStream() throws IOException
+   {
+      return file.openStream();
+   }
+}

Added: trunk/spring-int/src/main/org/jboss/spring/io/VFSResourceLoader.java
===================================================================
--- trunk/spring-int/src/main/org/jboss/spring/io/VFSResourceLoader.java	                        (rev 0)
+++ trunk/spring-int/src/main/org/jboss/spring/io/VFSResourceLoader.java	2008-06-27 11:09:04 UTC (rev 75156)
@@ -0,0 +1,72 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.spring.io;
+
+import java.net.URL;
+
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.DefaultResourceLoader;
+import org.springframework.core.io.Resource;
+import org.springframework.util.Assert;
+
+/**
+ * VFS based ResourceLoader.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class VFSResourceLoader extends DefaultResourceLoader
+{
+   public VFSResourceLoader()
+   {
+   }
+
+   public VFSResourceLoader(ClassLoader classLoader)
+   {
+      super(classLoader);
+   }
+
+   public Resource getResource(String location)
+   {
+      Assert.notNull(location, "Location must not be null");
+      if (location.startsWith(CLASSPATH_URL_PREFIX))
+      {
+         return new ClassPathResource(location.substring(CLASSPATH_URL_PREFIX.length()), getClassLoader());
+      }
+      else
+      {
+         try
+         {
+            // Try to parse the location as a URL...
+            URL url = new URL(location);
+            VirtualFile file = VFS.getRoot(url);
+            return new VFSResource(file);
+         }
+         catch (Exception ex)
+         {
+            // No URL -> resolve as resource path.
+            return getResourceByPath(location);
+         }
+      }
+   }
+}
\ No newline at end of file

Added: trunk/spring-int/src/main/org/jboss/spring/io/VFSResourcePatternResolver.java
===================================================================
--- trunk/spring-int/src/main/org/jboss/spring/io/VFSResourcePatternResolver.java	                        (rev 0)
+++ trunk/spring-int/src/main/org/jboss/spring/io/VFSResourcePatternResolver.java	2008-06-27 11:09:04 UTC (rev 75156)
@@ -0,0 +1,106 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.spring.io;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+import java.util.ArrayList;
+
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileVisitor;
+import org.jboss.virtual.VisitorAttributes;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+
+/**
+ * VFS based ResourcePatternResolver.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class VFSResourcePatternResolver extends PathMatchingResourcePatternResolver
+{
+   public VFSResourcePatternResolver()
+   {
+      super(new VFSResourceLoader());
+   }
+
+   public VFSResourcePatternResolver(ClassLoader classLoader)
+   {
+      super(new VFSResourceLoader(classLoader));
+   }
+
+   public Resource[] getResources(String locationPattern) throws IOException
+   {
+      String rootDirPath = determineRootDir(locationPattern);
+      String subPattern = locationPattern.substring(rootDirPath.length());
+      URL rootURL = new URL(rootDirPath);
+      VirtualFile root = VFS.getRoot(rootURL);
+      PatternVirtualFileVisitor visitor = new PatternVirtualFileVisitor(subPattern);
+      root.visit(visitor);
+      return visitor.getResources().toArray(new Resource[visitor.size()]);
+   }
+
+   /**
+    * Get visitor attributes.
+    * Allows for override, if necessary.
+    * 
+    * @return  visitor attributes
+    */
+   protected VisitorAttributes getVisitorAttributes()
+   {
+      return VisitorAttributes.RECURSE_LEAVES_ONLY;
+   }
+
+   private class PatternVirtualFileVisitor implements VirtualFileVisitor
+   {
+      private String subPattern;
+      private List<Resource> resources = new ArrayList<Resource>();
+
+      private PatternVirtualFileVisitor(String subPattern)
+      {
+         this.subPattern = subPattern;
+      }
+
+      public VisitorAttributes getAttributes()
+      {
+         return getVisitorAttributes();
+      }
+
+      public void visit(VirtualFile vf)
+      {
+         if (getPathMatcher().match(subPattern, vf.getPathName()))
+            resources.add(new VFSResource(vf));
+      }
+
+      public List<Resource> getResources()
+      {
+         return resources;
+      }
+
+      public int size()
+      {
+         return resources.size();
+      }
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list