[jboss-osgi-commits] JBoss-OSGI SVN: r102399 - projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Mon Mar 15 07:25:29 EDT 2010


Author: thomas.diesler at jboss.com
Date: 2010-03-15 07:25:28 -0400 (Mon, 15 Mar 2010)
New Revision: 102399

Modified:
   projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VFSAdaptor30.java
Log:
smplify mount handling

Modified: projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VFSAdaptor30.java
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VFSAdaptor30.java	2010-03-15 11:24:46 UTC (rev 102398)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VFSAdaptor30.java	2010-03-15 11:25:28 UTC (rev 102399)
@@ -51,7 +51,7 @@
       suffixes.add(".jar");
       suffixes.add(".war");
    }
-   
+
    public VirtualFile getRoot(URL url) throws IOException
    {
       try
@@ -68,49 +68,59 @@
    {
       if (other == null)
          return null;
-      
+
       if (other instanceof org.jboss.vfs.VirtualFile == false)
          throw new IllegalArgumentException("Not a org.jboss.vfs.VirtualFile: " + other);
-      
+
       org.jboss.vfs.VirtualFile nativeFile = (org.jboss.vfs.VirtualFile)other;
       VirtualFile abstractFile = registry.get(other);
       if (abstractFile != null)
          return abstractFile;
-      
+
       // Accept the file for mounting
       MountHandle mountHandle = null;
-      if (nativeFile.isFile())
+      if (acceptForMount((org.jboss.vfs.VirtualFile)other) == true)
       {
+         try
+         {
+            TempFileProvider tmp = TempFileProvider.create("osgimount-", null);
+            mountHandle = VFS.mountZip(nativeFile, nativeFile, tmp);
+         }
+         catch (IOException ex)
+         {
+            throw new IllegalStateException("Cannot mount native file: " + other, ex);
+         }
+      }
+
+      // Register the VirtualFile abstraction
+      abstractFile = new VirtualFileAdaptor30(nativeFile, mountHandle);
+      registry.put(nativeFile, abstractFile);
+      return abstractFile;
+   }
+
+   private boolean acceptForMount(org.jboss.vfs.VirtualFile nativeFile)
+   {
+      boolean accept = false;
+      if (nativeFile.isFile() == false)
+      {
          String rootName = nativeFile.getName();
          for (String suffix : suffixes)
          {
             if (rootName.endsWith(suffix))
             {
-               try
-               {
-                  TempFileProvider tmp = TempFileProvider.create("osgimount-", null);
-                  mountHandle = VFS.mountZip(nativeFile, nativeFile, tmp);
-                  break;
-               }
-               catch (IOException ex)
-               {
-                  throw new IllegalStateException("Cannot mount native file: " + other, ex);
-               }
+               accept = true;
+               break;
             }
          }
       }
-         
-      // Register the VirtualFile abstraction
-      abstractFile = new VirtualFileAdaptor30(nativeFile, mountHandle);
-      registry.put(nativeFile, abstractFile);
-      return abstractFile;
+      return accept;
    }
 
    public Object adapt(VirtualFile virtualFile)
    {
       if (virtualFile == null)
          return null;
-      
+
       VirtualFileAdaptor30 adaptor = (VirtualFileAdaptor30)virtualFile;
       return adaptor.getDelegate();
    }
@@ -118,7 +128,7 @@
    static void safeClose(VirtualFileAdaptor30 virtualFile)
    {
       registry.remove(virtualFile.getDelegate());
-      
+
       MountHandle mountHandle = virtualFile.getMountHandle();
       if (mountHandle != null)
          VFSUtils.safeClose(mountHandle);



More information about the jboss-osgi-commits mailing list