[jboss-cvs] JBossAS SVN: r80736 - in projects/vfs/trunk/src: test/java/org/jboss/test/virtual/test and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Nov 10 06:13:13 EST 2008


Author: alesj
Date: 2008-11-10 06:13:13 -0500 (Mon, 10 Nov 2008)
New Revision: 80736

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/test/java/org/jboss/test/virtual/test/VFSUnitTestCase.java
Log:
[JBVFS-76]; enable/disable options for VFS

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/VFS.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/VFS.java	2008-11-10 09:05:31 UTC (rev 80735)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VFS.java	2008-11-10 11:13:13 UTC (rev 80736)
@@ -77,6 +77,19 @@
    }
 
    /**
+    * Get the vfs context.
+    *
+    * This is package protected method.
+    * Same as VirtualFile::getHandler. 
+    *
+    * @return the vfs context
+    */
+   VFSContext getContext()
+   {
+      return context;
+   }
+
+   /**
     * Get the virtual file system for a root uri
     * 
     * @param rootURI the root URI

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java	2008-11-10 09:05:31 UTC (rev 80735)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java	2008-11-10 11:13:13 UTC (rev 80736)
@@ -542,6 +542,21 @@
    }
 
    /**
+    * Get the options for this vfs.
+    *
+    * @param vfs the vfs
+    * @return options map
+    */
+   private static Map<String, String> getOptions(VFS vfs)
+   {
+      if (vfs == null)
+         throw new IllegalArgumentException("Null vfs");
+
+      VFSContext context = vfs.getContext();
+      return context.getOptions();
+   }
+
+   /**
     * Get the option.
     *
     * @param file the file
@@ -555,6 +570,19 @@
    }
 
    /**
+    * Get the option.
+    *
+    * @param vfs the vfs
+    * @param key the option key
+    * @return key's option
+    */
+   public static String getOption(VFS vfs, String key)
+   {
+      Map<String, String> options = getOptions(vfs);
+      return options != null ? options.get(key) : null;
+   }
+
+   /**
     * Enable option.
     *
     * @param file the file
@@ -585,6 +613,36 @@
    }
 
    /**
+    * Enable option.
+    *
+    * @param vfs the vfs
+    * @param optionName option name
+    */
+   protected static void enableOption(VFS vfs, String optionName)
+   {
+      Map<String, String> options = getOptions(vfs);
+      if (options == null)
+         throw new IllegalArgumentException("Cannot enable " + optionName + " on null options: " + vfs);
+
+      options.put(optionName, Boolean.TRUE.toString());
+   }
+
+   /**
+    * Disable option.
+    *
+    * @param vfs the vfs
+    * @param optionName option name
+    */
+   protected static void disableOption(VFS vfs, String optionName)
+   {
+      Map<String, String> options = getOptions(vfs);
+      if (options == null)
+         throw new IllegalArgumentException("Cannot disable " + optionName + " on null options: " + vfs);
+
+      options.remove(optionName);
+   }
+
+   /**
     * Enable copy for file param.
     *
     * @param file the file
@@ -605,8 +663,28 @@
    }
 
    /**
-    * Enable repaer for file param.
+    * Enable copy for vfs param.
     *
+    * @param vfs the vfs
+    */
+   public static void enableCopy(VFS vfs)
+   {
+      enableOption(vfs, USE_COPY_QUERY);
+   }
+
+   /**
+    * Disable copy for vfs param.
+    *
+    * @param vfs the vfs
+    */
+   public static void disableCopy(VFS vfs)
+   {
+      disableOption(vfs, USE_COPY_QUERY);
+   }
+
+   /**
+    * Enable reaper for file param.
+    *
     * @param file the file
     */
    public static void enableNoReaper(VirtualFile file)
@@ -625,6 +703,26 @@
    }
 
    /**
+    * Enable reaper for vfs param.
+    *
+    * @param vfs the vfs
+    */
+   public static void enableNoReaper(VFS vfs)
+   {
+      enableOption(vfs, NO_REAPER_QUERY);
+   }
+
+   /**
+    * Disable reaper for vfs param.
+    *
+    * @param vfs the vfs
+    */
+   public static void disableNoReaper(VFS vfs)
+   {
+      disableOption(vfs, NO_REAPER_QUERY);
+   }
+
+   /**
     * Enable case sensitive for file param.
     *
     * @param file the file
@@ -645,6 +743,26 @@
    }
 
    /**
+    * Enable case sensitive for vfs param.
+    *
+    * @param vfs the vfs
+    */
+   public static void enableCaseSensitive(VFS vfs)
+   {
+      enableOption(vfs, CASE_SENSITIVE_QUERY);
+   }
+
+   /**
+    * Disable case sensitive for vfs param.
+    *
+    * @param vfs the vfs
+    */
+   public static void disableCaseSensitive(VFS vfs)
+   {
+      disableOption(vfs, CASE_SENSITIVE_QUERY);
+   }
+
+   /**
     * Unpack the nested artifact under file param.
     *
     * @param file the file to unpack

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSUnitTestCase.java	2008-11-10 09:05:31 UTC (rev 80735)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSUnitTestCase.java	2008-11-10 11:13:13 UTC (rev 80736)
@@ -35,6 +35,7 @@
 import org.jboss.test.virtual.support.MockVirtualFileFilter;
 import org.jboss.virtual.VFS;
 import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VFSUtils;
 import org.jboss.virtual.plugins.vfs.helpers.FilterVirtualFileVisitor;
 
 /**
@@ -55,6 +56,24 @@
       return new TestSuite(VFSUnitTestCase.class);
    }
 
+   public void testVFSOptions() throws Exception
+   {
+      URL url = getResource("/vfs/test");
+      VFS vfs = VFS.getVFS(url);
+
+      // currently we don't test any vfs root's behavior
+
+      VFSUtils.enableCopy(vfs);
+      VFSUtils.disableCopy(vfs);
+
+      VFSUtils.enableNoReaper(vfs);
+      VFSUtils.disableNoReaper(vfs);
+
+      VFSUtils.enableCaseSensitive(vfs);
+      VFSUtils.disableCaseSensitive(vfs);
+   }
+
+
    public void testGetVFSURI() throws Exception
    {
       MockVFSContext context = registerSimpleVFSContext();




More information about the jboss-cvs-commits mailing list