[jboss-cvs] JBossAS SVN: r83684 - in projects/vfs/trunk/src: main/java/org/jboss/virtual/plugins and 7 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jan 30 09:37:24 EST 2009


Author: alesj
Date: 2009-01-30 09:37:24 -0500 (Fri, 30 Jan 2009)
New Revision: 83684

Added:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/TempContext.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/registry/
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/registry/DefaultVFSRegistry.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/registry/
   projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/registry/VFSContextFinder.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/registry/VFSRegistry.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/registry/VFSRegistryBuilder.java
Modified:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/VFS.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/AbstractVFSCache.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/IterableTimedVFSCache.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/IterableVFSCache.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/PathMatchingVFSCache.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/AbstractCopyMechanism.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContext.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTestCase.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java
Log:
Initial temp introduction - still much TODO.

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/VFS.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/VFS.java	2009-01-30 14:24:30 UTC (rev 83683)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VFS.java	2009-01-30 14:37:24 UTC (rev 83684)
@@ -32,8 +32,7 @@
 import org.jboss.virtual.spi.VFSContextFactory;
 import org.jboss.virtual.spi.VFSContextFactoryLocator;
 import org.jboss.virtual.spi.VirtualFileHandler;
-import org.jboss.virtual.spi.cache.VFSCache;
-import org.jboss.virtual.spi.cache.VFSCacheFactory;
+import org.jboss.virtual.spi.registry.VFSRegistry;
 
 /**
  * Virtual File System
@@ -126,12 +125,14 @@
       {
          VirtualFileHandler fileHandler = file.getHandler();
          VFSContext context = fileHandler.getVFSContext();
+         context.cleanupTempHandlers(fileHandler.getPathName());
+         
          VirtualFileHandler contextHandler = context.getRoot();
          // the file is the context root, hence possible cache candidate
          if (fileHandler.equals(contextHandler))
          {
-            VFSCache cache = VFSCacheFactory.getInstance();
-            cache.removeContext(context);
+            VFSRegistry registry = VFSRegistry.getInstance();
+            registry.removeContext(context);
          }
       }
       catch (Exception ignored)
@@ -153,7 +154,7 @@
       if (factory == null)
          throw new IOException("No context factory for " + rootURI);
       VFSContext context = factory.getVFS(rootURI);
-      VFSCacheFactory.getInstance().putContext(context);
+      VFSRegistry.getInstance().addContext(context);
       return context.getVFS();
    }
 
@@ -181,8 +182,8 @@
     */
    public static VirtualFile getRoot(URI rootURI) throws IOException
    {
-      VFSCache cache = VFSCacheFactory.getInstance();
-      VirtualFile file = cache.getFile(rootURI);
+      VFSRegistry registry = VFSRegistry.getInstance();
+      VirtualFile file = registry.getFile(rootURI);
       return (file != null) ? file : createNewRoot(rootURI);
    }
 
@@ -235,7 +236,7 @@
       if (factory == null)
          throw new IOException("No context factory for " + rootURL);
       VFSContext context = factory.getVFS(rootURL);
-      VFSCacheFactory.getInstance().putContext(context);
+      VFSRegistry.getInstance().addContext(context);
       return context.getVFS();
    }
 
@@ -263,8 +264,8 @@
     */
    public static VirtualFile getRoot(URL rootURL) throws IOException
    {
-      VFSCache cache = VFSCacheFactory.getInstance();
-      VirtualFile file = cache.getFile(rootURL);
+      VFSRegistry registry = VFSRegistry.getInstance();
+      VirtualFile file = registry.getFile(rootURL);
       return (file != null) ? file : createNewRoot(rootURL);
    }
 

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java	2009-01-30 14:24:30 UTC (rev 83683)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java	2009-01-30 14:37:24 UTC (rev 83684)
@@ -1062,4 +1062,58 @@
       VirtualFileHandler handler = file.getHandler();
       return handler.getRealURL();
    }
+
+   /**
+    * Get relative path.
+    *
+    * @param context the vfs context
+    * @param uri the uri
+    * @return uri's relative path to context's root
+    */
+   public static String getRelativePath(VFSContext context, URI uri)
+   {
+      String uriPath = stripProtocol(uri);
+      String contextKey = getKey(context);
+      return uriPath.substring(contextKey.length());
+   }
+
+   /**
+    * Strip protocol from url string.
+    *
+    * @param uri the uri
+    * @return uri's path string
+    */
+   protected static String stripProtocol(URI uri)
+   {
+      String path = uri.getPath();
+      if (path != null && path.length() > 0)
+      {
+         StringBuilder sb = new StringBuilder(path);
+
+         if (sb.charAt(0) != '/')
+            sb.insert(0, '/');
+         if (sb.charAt(sb.length() - 1) != '/')
+            sb.append('/');
+
+         path = sb.toString();
+      }
+      else
+      {
+         path = "/";
+      }
+
+      return path;
+   }
+
+   /**
+    * Get path key.
+    *
+    * @param context the vfs context
+    * @return contex's root path w/o protocol
+    */
+   protected static String getKey(VFSContext context)
+   {
+      URI uri = context.getRootURI();
+      return stripProtocol(uri);
+   }
 }

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/AbstractVFSCache.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/AbstractVFSCache.java	2009-01-30 14:24:30 UTC (rev 83683)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/AbstractVFSCache.java	2009-01-30 14:37:24 UTC (rev 83684)
@@ -33,6 +33,7 @@
 import org.jboss.virtual.VirtualFile;
 import org.jboss.virtual.spi.VFSContext;
 import org.jboss.virtual.spi.VirtualFileHandler;
+import org.jboss.virtual.spi.registry.VFSContextFinder;
 import org.jboss.virtual.spi.cache.CacheStatistics;
 import org.jboss.virtual.spi.cache.VFSCache;
 
@@ -41,7 +42,7 @@
  *
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
-public abstract class AbstractVFSCache implements VFSCache, CacheStatistics
+public abstract class AbstractVFSCache implements VFSCache, CacheStatistics, VFSContextFinder
 {
    protected Logger log = Logger.getLogger(getClass());
    
@@ -149,15 +150,6 @@
    protected abstract VFSContext getContext(String path);
 
    /**
-    * Find cached context.
-    * This method must take read lock.
-    *
-    * @param uri the uri to match
-    * @return found context or null
-    */
-   protected abstract VFSContext findContext(URI uri);
-
-   /**
     * Get path key.
     *
     * @param context the vfs context

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/IterableTimedVFSCache.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/IterableTimedVFSCache.java	2009-01-30 14:24:30 UTC (rev 83683)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/IterableTimedVFSCache.java	2009-01-30 14:37:24 UTC (rev 83684)
@@ -57,7 +57,7 @@
    }
 
    @SuppressWarnings("unchecked")
-   protected VFSContext findContext(URI uri)
+   public VFSContext findContext(URI uri)
    {
       String uriString = stripProtocol(uri);
       TimedCachePolicy tcp = getPolicy();

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/IterableVFSCache.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/IterableVFSCache.java	2009-01-30 14:24:30 UTC (rev 83683)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/IterableVFSCache.java	2009-01-30 14:37:24 UTC (rev 83684)
@@ -42,7 +42,7 @@
     */
    protected abstract Iterable<String> getKeys();
 
-   protected VFSContext findContext(URI uri)
+   public VFSContext findContext(URI uri)
    {
       String uriString = stripProtocol(uri);
       Iterable<String> keys = getKeys();

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/PathMatchingVFSCache.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/PathMatchingVFSCache.java	2009-01-30 14:24:30 UTC (rev 83683)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/cache/PathMatchingVFSCache.java	2009-01-30 14:37:24 UTC (rev 83684)
@@ -40,7 +40,7 @@
     * @param uri the uri to match
     * @return found context or null
     */
-   protected VFSContext findContext(URI uri)
+   public VFSContext findContext(URI uri)
    {
       String uriString = stripProtocol(uri);
       List<String> tokens = PathTokenizer.getTokens(uriString);

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java	2009-01-30 14:24:30 UTC (rev 83683)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java	2009-01-30 14:37:24 UTC (rev 83684)
@@ -26,8 +26,10 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.jboss.logging.Logger;
 import org.jboss.virtual.VFS;
@@ -65,6 +67,9 @@
    /** Root's peer within another context */
    private VirtualFileHandler rootPeer;
 
+   /** The temp handlers */
+   private Map<String, VirtualFileHandler> tempHandlers = new ConcurrentHashMap<String, VirtualFileHandler>();
+
    /** The exception handler */
    private ExceptionHandler exceptionHandler;
 
@@ -336,6 +341,46 @@
       }
    }
 
+   public void addTempHandler(String path, VirtualFileHandler handler)
+   {
+      tempHandlers.put(path, handler);
+   }
+
+   public VirtualFileHandler findTempHandler(URI uri) throws IOException
+   {
+      String relativePath = VFSUtils.getRelativePath(this, uri);
+      for (Map.Entry<String, VirtualFileHandler> entry : tempHandlers.entrySet())
+      {
+         if (relativePath.startsWith(entry.getKey()))
+         {
+            VirtualFileHandler handler = entry.getValue();
+            String path = relativePath.substring(handler.getPathName().length());
+            return handler.getChild(path);
+         }
+      }
+      return null;
+   }
+
+   public void cleanupTempHandlers(String path)
+   {
+      Iterator<Map.Entry<String, VirtualFileHandler>> iter = tempHandlers.entrySet().iterator();
+      while (iter.hasNext())
+      {
+         Map.Entry<String, VirtualFileHandler> entry = iter.next();
+         if (entry.getKey().startsWith(path))
+         {
+            try
+            {
+               entry.getValue().cleanup();
+            }
+            catch (Throwable ignored)
+            {
+            }
+            iter.remove();
+         }
+      }
+   }
+
    public ExceptionHandler getExceptionHandler()
    {
       return exceptionHandler;

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java	2009-01-30 14:24:30 UTC (rev 83683)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java	2009-01-30 14:37:24 UTC (rev 83684)
@@ -99,6 +99,9 @@
    /** The vfsPath */
    private transient String vfsPath;
 
+   /** The local vfsPath */
+   private transient String localVfsPath;
+
    /** The reference count */
    private transient AtomicInteger references = new AtomicInteger(0);
 
@@ -226,6 +229,19 @@
     */
    public String getLocalPathName()
    {
+      if (localVfsPath == null)
+         localVfsPath = readLocalPathName();
+
+      return localVfsPath;
+   }
+
+   /**
+    * Create local path name.
+    *
+    * @return the local path name
+    */
+   private String readLocalPathName()
+   {
       try
       {
          VirtualFileHandler handler = getLocalVFSContext().getRoot();

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/AbstractCopyMechanism.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/AbstractCopyMechanism.java	2009-01-30 14:24:30 UTC (rev 83683)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/AbstractCopyMechanism.java	2009-01-30 14:37:24 UTC (rev 83684)
@@ -132,11 +132,12 @@
       File guidDir = createTempDirectory(getTempDirectory(), GUID.asString());
       // unpack handler
       File copy = copy(guidDir, handler);
+
+      VFSContext oldVFSContext = handler.getVFSContext();
       // create new handler
-      FileSystemContext fileSystemContext = new FileSystemContext(copy);
+      FileSystemContext fileSystemContext = new TempContext(copy, oldVFSContext, handler.getPathName());
 
       // merge old options
-      VFSContext oldVFSContext = handler.getVFSContext();
       Map<String, String> newOptions = fileSystemContext.getOptions();
       if (newOptions != null) // shouldn't be null, but we check anyway
          newOptions.put(VFSUtils.IS_TEMP_FILE, Boolean.TRUE.toString());

Copied: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/TempContext.java (from rev 83550, projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/AbstractCopyMechanism.java)
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/TempContext.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/TempContext.java	2009-01-30 14:37:24 UTC (rev 83684)
@@ -0,0 +1,58 @@
+/*
+* 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.plugins.copy;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+
+import org.jboss.virtual.plugins.context.file.FileSystemContext;
+import org.jboss.virtual.spi.VFSContext;
+
+/**
+ * Temp context;
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TempContext extends FileSystemContext
+{
+   /** The old context */
+   private VFSContext oldContext;
+
+   /**The relative path */
+   private String relativePath;
+
+   public TempContext(File file, VFSContext oldContext, String relativePath) throws IOException, URISyntaxException
+   {
+      super(file);
+      this.oldContext = oldContext;
+      this.relativePath = relativePath;
+   }
+
+   @Override
+   public void cleanupTempHandlers(String path)
+   {
+      // this path should be ""?
+      super.cleanupTempHandlers(path);
+      oldContext.cleanupTempHandlers(relativePath + path);      
+   }
+}
\ No newline at end of file


Property changes on: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/copy/TempContext.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/registry/DefaultVFSRegistry.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/registry/DefaultVFSRegistry.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/registry/DefaultVFSRegistry.java	2009-01-30 14:37:24 UTC (rev 83684)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.plugins.registry;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.spi.VFSContext;
+import org.jboss.virtual.spi.VirtualFileHandler;
+import org.jboss.virtual.spi.cache.VFSCache;
+import org.jboss.virtual.spi.cache.VFSCacheFactory;
+import org.jboss.virtual.spi.registry.VFSContextFinder;
+import org.jboss.virtual.spi.registry.VFSRegistry;
+
+/**
+ * Default vfs registry.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class DefaultVFSRegistry extends VFSRegistry
+{
+   private VFSCache cache;
+   private VFSContextFinder finder;
+
+   protected VFSCache getCache()
+   {
+      if (cache == null)
+         cache = VFSCacheFactory.getInstance();
+
+      return cache;
+   }
+
+   protected VFSContextFinder getContextFinder()
+   {
+      if (finder == null)
+         finder = createContextFinder();
+
+      return finder;
+   }
+
+   protected VFSContextFinder createContextFinder()
+   {
+      VFSCache cache = getCache();
+      if (cache instanceof VFSContextFinder)
+      {
+         return VFSContextFinder.class.cast(cache);
+      }
+      else
+      {
+         return new DummyVFSContextFinder();
+      }
+   }
+
+   public void addContext(VFSContext context)
+   {
+      getCache().putContext(context);
+   }
+
+   public void removeContext(VFSContext context)
+   {
+      getCache().removeContext(context);
+   }
+
+   public VirtualFile getFile(URI uri) throws IOException
+   {
+      if (uri == null)
+         throw new IllegalArgumentException("Null uri");
+
+      VFSContext context = getContextFinder().findContext(uri);
+      if (context != null)
+      {
+         VirtualFileHandler handler = context.findTempHandler(uri);
+         if (handler != null)
+            return handler.getVirtualFile();
+      }
+      return getCache().getFile(uri);
+   }
+
+   public VirtualFile getFile(URL url) throws IOException
+   {
+      if (url == null)
+         throw new IllegalArgumentException("Null url");
+
+      try
+      {
+         return getFile(VFSUtils.toURI(url));
+      }
+      catch (URISyntaxException e)
+      {
+         IOException ioe = new IOException();
+         ioe.initCause(e);
+         throw ioe;
+      }
+   }
+
+   private static class DummyVFSContextFinder implements VFSContextFinder
+   {
+      public VFSContext findContext(URI uri)
+      {
+         return null;
+      }
+   }
+}

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContext.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContext.java	2009-01-30 14:24:30 UTC (rev 83683)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContext.java	2009-01-30 14:37:24 UTC (rev 83684)
@@ -127,4 +127,10 @@
     * @param exceptionHandler the exception handler.
     */
    void setExceptionHandler(ExceptionHandler exceptionHandler);
+
+   void addTempHandler(String path, VirtualFileHandler handler);
+
+   VirtualFileHandler findTempHandler(URI uri) throws IOException;
+
+   void cleanupTempHandlers(String path);
 }

Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/registry/VFSContextFinder.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/registry/VFSContextFinder.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/registry/VFSContextFinder.java	2009-01-30 14:37:24 UTC (rev 83684)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.spi.registry;
+
+import java.net.URI;
+
+import org.jboss.virtual.spi.VFSContext;
+
+/**
+ * VFS Context finder.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface VFSContextFinder
+{
+   /**
+    * Find the vfs context.
+    *
+    * @param uri the uri
+    * @return vfs context or null if not found
+    */
+   VFSContext findContext(URI uri);
+}

Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/registry/VFSRegistry.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/registry/VFSRegistry.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/registry/VFSRegistry.java	2009-01-30 14:37:24 UTC (rev 83684)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.spi.registry;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.spi.VFSContext;
+
+/**
+ * VFS registry.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class VFSRegistry
+{
+   public static VFSRegistry getInstance()
+   {
+      return VFSRegistryBuilder.getInstance();
+   }
+
+   public abstract void addContext(VFSContext context);
+
+   public abstract void removeContext(VFSContext context);
+
+   public abstract VirtualFile getFile(URI uri) throws IOException;
+
+   public abstract VirtualFile getFile(URL url) throws IOException;
+}

Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/registry/VFSRegistryBuilder.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/registry/VFSRegistryBuilder.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/registry/VFSRegistryBuilder.java	2009-01-30 14:37:24 UTC (rev 83684)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.spi.registry;
+
+import java.security.AccessController;
+
+import org.jboss.util.builder.AbstractBuilder;
+
+/**
+ * VFS registry.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public final class VFSRegistryBuilder
+{
+   /** The default vfs registry */
+   private static String DEFAULT_FACTORY = "org.jboss.virtual.plugins.registry.DefaultVFSRegistry";
+
+   /** The singleton */
+   private static VFSRegistry singleton;
+
+   /**
+    * Get the instance
+    *
+    * @return the instance
+    */
+   static synchronized VFSRegistry getInstance()
+   {
+      if (singleton == null)
+      {
+         AbstractBuilder<VFSRegistry> builder = new AbstractBuilder<VFSRegistry>(VFSRegistry.class, DEFAULT_FACTORY);
+         singleton = AccessController.doPrivileged(builder);
+      }
+      return singleton;
+   }
+}
\ No newline at end of file

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTestCase.java	2009-01-30 14:24:30 UTC (rev 83683)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/FileCleanupUnitTestCase.java	2009-01-30 14:37:24 UTC (rev 83684)
@@ -28,13 +28,15 @@
 import java.net.URL;
 
 import junit.framework.Test;
+import org.jboss.util.id.GUID;
 import org.jboss.virtual.VFS;
 import org.jboss.virtual.VFSUtils;
 import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.plugins.cache.LRUVFSCache;
 import org.jboss.virtual.plugins.copy.AbstractCopyMechanism;
-import org.jboss.virtual.plugins.cache.LRUVFSCache;
 import org.jboss.virtual.spi.cache.VFSCache;
 import org.jboss.virtual.spi.cache.VFSCacheFactory;
+import org.jboss.virtual.spi.registry.VFSRegistryBuilder;
 
 /**
  * Test file closing
@@ -72,10 +74,17 @@
       field.setAccessible(true);
       field.set(null, null);
 
+      // nullify the registry
+      clazz = VFSRegistryBuilder.class;
+      field = clazz.getDeclaredField("singleton");
+      field.setAccessible(true);
+      field.set(null, null);
+
       String tempDirKey = System.getProperty("vfs.temp.dir", "jboss.server.temp.dir");
-      String tempDirString = System.getProperty(tempDirKey, System.getProperty("java.io.tmpdir")) + "filecleanup";
+      String tempDirString = System.getProperty(tempDirKey, System.getProperty("java.io.tmpdir")) + GUID.asString();
 
       tempDir =  new File(tempDirString);
+      tempDir.deleteOnExit();      
       if (tempDir.exists())
       {
          deleteTempDir();
@@ -94,21 +103,15 @@
    {
       try
       {
+         deleteTempDir();
+
          VFSCacheFactory.getInstance().stop();
-      }
-      catch (Throwable ignored)
-      {
-      }
-      finally
-      {
          VFSCacheFactory.setInstance(null);
+
+         System.clearProperty("jboss.server.temp.dir");
       }
-
-      System.clearProperty("jboss.server.temp.dir");
-
-      try
+      catch (Throwable t)
       {
-         deleteTempDir();
       }
       finally
       {
@@ -155,7 +158,7 @@
    {
       VFSCache cache = VFSCacheFactory.getInstance();
       VirtualFile file = cache.getFile(uri);
-      assertNull(file);
+      assertNull("" + uri, file);
    }
 
    public void testNestedJarCleanup() throws Exception

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java	2009-01-30 14:24:30 UTC (rev 83683)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSCacheTest.java	2009-01-30 14:37:24 UTC (rev 83684)
@@ -80,8 +80,8 @@
             VirtualFile nested = root.findChild("/nested.jar/complex.jar/subfolder/subsubfolder/subsubchild");
             URL nestedURL = nested.toURL();
 
-            assertEquals(file, cache.getFile(fileURL));
-            assertEquals(nested, cache.getFile(nestedURL));
+            assertEquals(file, VFS.getRoot(fileURL));
+            assertEquals(nested, VFS.getRoot(nestedURL));
 
             VFSCacheFactory.setInstance(null);
             VFSCache wrapper = new WrapperVFSCache(cache);




More information about the jboss-cvs-commits mailing list