[jboss-cvs] JBossAS SVN: r74303 - in projects/vfs/trunk/src/main/java/org/jboss/virtual: protocol and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jun 9 04:48:10 EDT 2008


Author: alesj
Date: 2008-06-09 04:48:10 -0400 (Mon, 09 Jun 2008)
New Revision: 74303

Added:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/AbstractZipHandler.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/zip/
   projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/zip/Handler.java
Modified:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfs/Handler.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfsfile/Handler.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfsmemory/Handler.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfszip/Handler.java
Log:
Make cache in VFS URL connection soft.
Add zip url handler.
Refactor handlers.

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java	2008-06-09 00:02:39 UTC (rev 74302)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/vfs/VirtualFileURLConnection.java	2008-06-09 08:48:10 UTC (rev 74303)
@@ -26,9 +26,9 @@
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.Map;
 
+import org.jboss.util.collection.SoftValueHashMap;
 import org.jboss.virtual.VFS;
 import org.jboss.virtual.VirtualFile;
 
@@ -36,11 +36,13 @@
  * Implements basic URLConnection for a VirtualFile
  *
  * @author <a href="bill at jboss.com">Bill Burke</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @version $Revision: 1.1 $
  */
 public class VirtualFileURLConnection extends URLConnection
 {
-   public static Map<URL, VFS> urlCache = Collections.synchronizedMap(new HashMap<URL, VFS>());
+   @SuppressWarnings("unchecked")
+   public static Map<URL, VFS> urlCache = Collections.<URL, VFS>synchronizedMap(new SoftValueHashMap());
 
    protected VirtualFile file;
    protected URL vfsurl;
@@ -68,7 +70,8 @@
       return getVirtualFile();
    }
 
-   public static VirtualFile resolveCachedVirtualFile(URL vfsurl, String relativePath) throws IOException
+   @SuppressWarnings("deprecation")
+   protected static VirtualFile resolveCachedVirtualFile(URL vfsurl, String relativePath) throws IOException
    {
       VFS vfs = urlCache.get(vfsurl);
       if (vfs == null)
@@ -90,17 +93,18 @@
       return vfs.findChild(relativePath);
    }
 
-   public static VirtualFile resolveVirtualFile(URL vfsurl, String relativePath) throws IOException
+   @SuppressWarnings("deprecation")
+   protected static VirtualFile resolveVirtualFile(URL vfsurl, String relativePath) throws IOException
    {
       VFS vfs = VFS.getVFS(vfsurl);
       return vfs.findChild(relativePath);
    }
 
-   public synchronized VirtualFile getVirtualFile() throws IOException
+   protected synchronized VirtualFile getVirtualFile() throws IOException
    {
       if (file == null)
       {
-         if (this.getUseCaches())
+         if (getUseCaches())
          {
             file = resolveCachedVirtualFile(vfsurl, relativePath);
          }

Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/AbstractZipHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/AbstractZipHandler.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/AbstractZipHandler.java	2008-06-09 08:48:10 UTC (rev 74303)
@@ -0,0 +1,57 @@
+/*
+* 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.virtual.protocol;
+
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+
+import org.jboss.virtual.plugins.context.zip.ZipEntryContextFactory;
+import org.jboss.virtual.plugins.vfs.VirtualFileURLConnection;
+import org.jboss.virtual.spi.VFSContext;
+import org.jboss.virtual.spi.VirtualFileHandler;
+
+/**
+ * VFS's zip URL handler.
+ *
+ * @author <a href="strukelj at parsek.net">Marko Strukelj</a>
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AbstractZipHandler extends URLStreamHandler
+{
+   protected URLConnection openConnection(URL url) throws IOException
+   {
+      VFSContext ctx = ZipEntryContextFactory.getInstance().getVFS(url);
+      if (ctx == null)
+         throw new IOException("No VFS context found for URL: " + url);
+
+      String rootPath = ctx.getRootURI().getPath();
+      String entryPath = url.getFile().substring(rootPath.length());
+
+      VirtualFileHandler child = ctx.getChild(ctx.getRoot(), entryPath);
+      if (child == null)
+         throw new IOException("No VFS file found for URL: " + url);
+
+      return new VirtualFileURLConnection(url, child.getVirtualFile());
+   }
+}

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfs/Handler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfs/Handler.java	2008-06-09 00:02:39 UTC (rev 74302)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfs/Handler.java	2008-06-09 08:48:10 UTC (rev 74303)
@@ -39,18 +39,17 @@
  */
 public class Handler extends URLStreamHandler
 {
-   protected URLConnection openConnection(URL u) throws IOException
+   protected URLConnection openConnection(URL url) throws IOException
    {
-      String host = u.getHost();
+      String host = url.getHost();
       AssembledDirectory directory = AssembledContextFactory.getInstance().find(host);
       if (directory == null)
-         throw new IOException("vfs does not exist: " + u.toString());
+         throw new IOException("vfs does not exist: " + url);
 
-      VirtualFile vf = directory.findChild(u.getPath());
+      VirtualFile vf = directory.getChild(url.getPath());
       if (vf == null)
-         throw new IOException("vfs does not exist: " + u.toString());
+         throw new IOException("vfs does not exist: " + url);
 
-      return new VirtualFileURLConnection(u, vf);
+      return new VirtualFileURLConnection(url, vf);
    }
-
 }

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfsfile/Handler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfsfile/Handler.java	2008-06-09 00:02:39 UTC (rev 74302)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfsfile/Handler.java	2008-06-09 08:48:10 UTC (rev 74303)
@@ -37,9 +37,9 @@
  */
 public class Handler extends URLStreamHandler
 {
-   protected URLConnection openConnection(URL u) throws IOException
+   protected URLConnection openConnection(URL url) throws IOException
    {
-      String file = u.toString().substring(8); // strip out vfsfile:
+      String file = url.toString().substring(8); // strip out vfsfile:
       URL vfsurl = null;
       String relative;
       File fp = new File(file);
@@ -67,8 +67,8 @@
       }
 
       if (vfsurl == null)
-         throw new IOException("vfsfile does not exist: " + u.toString());
+         throw new IOException("VFS file does not exist: " + url);
 
-      return new VirtualFileURLConnection(u, vfsurl, relative);
+      return new VirtualFileURLConnection(url, vfsurl, relative);
    }
 }

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfsmemory/Handler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfsmemory/Handler.java	2008-06-09 00:02:39 UTC (rev 74302)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfsmemory/Handler.java	2008-06-09 08:48:10 UTC (rev 74303)
@@ -40,17 +40,17 @@
  */
 public class Handler extends URLStreamHandler
 {
-   protected URLConnection openConnection(URL u) throws IOException
+   protected URLConnection openConnection(URL url) throws IOException
    {
-      String host = u.getHost();
+      String host = url.getHost();
       VFS vfs = MemoryFileFactory.find(host);
       if (vfs == null)
-         throw new IOException("vfs does not exist: " + u.toString());
+         throw new IOException("VFS does not exist: " + url);
 
-      VirtualFile vf = vfs.getChild(u.getPath());
+      VirtualFile vf = vfs.getChild(url.getPath());
       if (vf == null)
-         throw new IOException("vfs does not exist: " + u.toString());
+         throw new IOException("VFS does not exist: " + url);
 
-      return new VirtualFileURLConnection(u, vf);
+      return new VirtualFileURLConnection(url, vf);
    }
 }

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfszip/Handler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfszip/Handler.java	2008-06-09 00:02:39 UTC (rev 74302)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfszip/Handler.java	2008-06-09 08:48:10 UTC (rev 74303)
@@ -1,40 +1,13 @@
 package org.jboss.virtual.protocol.vfszip;
 
-import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.spi.VirtualFileHandler;
-import org.jboss.virtual.plugins.context.zip.ZipEntryContext;
-import org.jboss.virtual.plugins.context.zip.ZipEntryContextFactory;
-import org.jboss.virtual.plugins.vfs.VirtualFileURLConnection;
+import org.jboss.virtual.protocol.AbstractZipHandler;
 
-import java.io.IOException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.net.URLStreamHandler;
-
 /**
  * URLStreamHandler for VFS
  *
  * @author <a href="strukelj at parsek.net">Marko Strukelj</a>
  * @version $Revision: 1.0 $
  */
-
-public class Handler extends URLStreamHandler
+public class Handler extends AbstractZipHandler
 {
-   protected URLConnection openConnection(URL u) throws IOException
-   {
-      String url = u.toString();
-      ZipEntryContext ctx = (ZipEntryContext) ZipEntryContextFactory.getInstance().getVFS(u);
-      if (ctx == null)
-         throw new IOException("No VFS context found for URL: " + url);
-
-      String rootPath = ctx.getRootURI().getPath();
-      String entryPath = u.getFile().substring(rootPath.length());
-      
-      VirtualFileHandler child = ctx.getChild(ctx.getRoot(), entryPath);
-      VirtualFile vf = child == null ? null : child.getVirtualFile();
-      if (vf == null)
-         throw new IOException("No VFS file found for URL: " + url);
-
-      return new VirtualFileURLConnection(u, vf);
-   }
 }

Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/zip/Handler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/zip/Handler.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/zip/Handler.java	2008-06-09 08:48:10 UTC (rev 74303)
@@ -0,0 +1,46 @@
+/*
+* 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.virtual.protocol.zip;
+
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+
+import org.jboss.virtual.protocol.AbstractZipHandler;
+
+/**
+ * Zip url handler.
+ *
+ * In case someone is stripping vfs off
+ * and just ends with zip protocol.
+ * (like I did in EJB3) ;-)
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class Handler extends AbstractZipHandler
+{
+   protected URLConnection openConnection(URL url) throws IOException
+   {
+      url = new URL("vfs" + url.toExternalForm());
+      return super.openConnection(url);
+   }
+}




More information about the jboss-cvs-commits mailing list