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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Feb 15 07:06:55 EST 2009


Author: alesj
Date: 2009-02-15 07:06:53 -0500 (Sun, 15 Feb 2009)
New Revision: 84220

Added:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DefaultOptions.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/Options.java
Removed:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/Options.java
Modified:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.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/context/zip/ZipEntryContext.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContext.java
Log:
Make Options interface.

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java	2009-02-15 03:23:44 UTC (rev 84219)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VFSUtils.java	2009-02-15 12:06:53 UTC (rev 84220)
@@ -49,9 +49,9 @@
 import org.jboss.virtual.plugins.copy.UnjarCopyMechanism;
 import org.jboss.virtual.plugins.copy.UnpackCopyMechanism;
 import org.jboss.virtual.spi.LinkInfo;
-import org.jboss.virtual.spi.Options;
 import org.jboss.virtual.spi.VFSContext;
 import org.jboss.virtual.spi.VirtualFileHandler;
+import org.jboss.virtual.spi.Options;
 import org.jboss.virtual.spi.cache.VFSCacheFactory;
 
 /**
@@ -811,8 +811,8 @@
     */
    public static boolean isTemporaryFile(VirtualFile file)
    {
-      Boolean isTemp = getOption(file, IS_TEMP_FILE, Boolean.class);
-      return isTemp != null && isTemp;
+      Options options = getOptions(file);
+      return options.getBooleanOption(IS_TEMP_FILE);
    }
 
    /**

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-02-15 03:23:44 UTC (rev 84219)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java	2009-02-15 12:06:53 UTC (rev 84220)
@@ -66,7 +66,7 @@
    private final URI rootURI;
 
    /** Options associated with the root URL */
-   private Options options = new Options();
+   private Options options = createNewOptions();
 
    /** Root's peer within another context */
    private VirtualFileHandler rootPeer;
@@ -102,6 +102,16 @@
       this(rootURL.toURI());
    }
 
+   /**
+    * Create options.
+    *
+    * @return the new options
+    */
+   protected Options createNewOptions()
+   {
+      return new DefaultOptions();
+   }
+
    public VFS getVFS()
    {
       if (vfs == null)
@@ -129,25 +139,20 @@
       return options;
    }
 
-   public void mergeOptions(Options other)
+   protected void setOption(String name, Object option)
    {
-      options.merge(other);
-   }
-
-   public void setOption(String name, Object option)
-   {
       if (option == null)
          options.removeOption(name);
       else
          options.addOption(name, option);
    }
 
-   public Object getOption(String name)
+   protected Object getOption(String name)
    {
       return options.getOption(name);
    }
 
-   public <T> T getOption(Class<T> expectedType)
+   protected <T> T getOption(Class<T> expectedType)
    {
       if (expectedType == null)
          throw new IllegalArgumentException("Null expectedType");
@@ -155,7 +160,7 @@
       return getOption(expectedType.getName(), expectedType);
    }
 
-   public <T> T getOption(String name, Class<T> expectedType)
+   protected <T> T getOption(String name, Class<T> expectedType)
    {
       return options.getOption(name, expectedType);
    }

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-02-15 03:23:44 UTC (rev 84219)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java	2009-02-15 12:06:53 UTC (rev 84220)
@@ -42,6 +42,7 @@
 import org.jboss.virtual.spi.VFSContextFactory;
 import org.jboss.virtual.spi.VFSContextFactoryLocator;
 import org.jboss.virtual.spi.VirtualFileHandler;
+import org.jboss.virtual.spi.Options;
 
 /**
  * AbstractVirtualFileHandler.
@@ -286,7 +287,8 @@
                VFSContext context = getVFSContext();
                String path = getPathName();
 
-               VirtualFileHandler oldRoot = context.getOption(VirtualFileHandler.class);
+               Options options = context.getOptions();
+               VirtualFileHandler oldRoot = options.getOption(VirtualFileHandler.class);
                if (oldRoot == null)
                {
                   StringBuffer buf = new StringBuffer();
@@ -565,8 +567,8 @@
     */
    protected boolean isTemporary()
    {
-      Boolean isTemp = getVFSContext().getOption(VFSUtils.IS_TEMP_FILE, Boolean.class);
-      return isTemp != null && isTemp;
+      Options options = getVFSContext().getOptions();
+      return options.getBooleanOption(VFSUtils.IS_TEMP_FILE);
    }
 
    public void close()

Copied: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DefaultOptions.java (from rev 84203, projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/Options.java)
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DefaultOptions.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DefaultOptions.java	2009-02-15 12:06:53 UTC (rev 84220)
@@ -0,0 +1,183 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, 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.context;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.Future;
+
+import org.jboss.virtual.spi.Options;
+
+/**
+ * Options impl.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class DefaultOptions implements Options
+{
+   /** The options */
+   private transient Map<String, Object> options;
+
+   public int size()
+   {
+      return options == null ? 0 : options.size();
+   }
+
+   public void merge(Options other)
+   {
+      if (other == null)
+         throw new IllegalArgumentException("Null other options");
+
+      if (other.size() == 0)
+         return;
+
+      // get all from other
+      Map<String, Object> map = other.getOptions(Object.class);
+
+      synchronized (this)
+      {
+         if (options == null)
+            options = new HashMap<String, Object>();
+
+         options.putAll(map);
+      }
+   }
+
+   public <T> Map<String, T> getOptions(Class<T> exactType)
+   {
+      if (exactType == null)
+         throw new IllegalArgumentException("Null exact type");
+
+      Map<String, T> result = new HashMap<String,T>();
+      if (options != null && options.isEmpty() == false)
+      {
+         for (Map.Entry<String, Object> entry : options.entrySet())
+         {
+            Object value = entry.getValue();
+            if (exactType.isInstance(value))
+            {
+               result.put(entry.getKey(), exactType.cast(value));
+            }
+         }
+      }
+      return result;
+   }
+
+   public void addOption(String name, Object option)
+   {
+      if (name == null)
+         throw new IllegalArgumentException("Null name");
+
+      if (option == null)
+         return;
+
+      synchronized (this)
+      {
+         if (options == null)
+            options = new HashMap<String, Object>();
+         options.put(name, option);
+      }
+   }
+
+   public void addOptions(Map<String, ?> map)
+   {
+      if (map == null)
+         throw new IllegalArgumentException("Null map");
+
+      for (Map.Entry<String, ?> entry : map.entrySet())
+      {
+         addOption(entry.getKey(), entry.getValue());
+      }
+   }
+
+   public void removeOption(String name)
+   {
+      if (name == null)
+         throw new IllegalArgumentException("Null name");
+
+      synchronized (this)
+      {
+         if (options == null)
+            return;
+         options.remove(name);
+      }
+   }
+
+   public Object getOption(String name)
+   {
+      if (name == null)
+         throw new IllegalArgumentException("Null name");
+
+      Object result;
+      synchronized (this)
+      {
+         if (options == null)
+            return null;
+         result = options.get(name);
+      }
+      if (result == null)
+         return null;
+
+      // Special case if the option is a future object
+      if (result instanceof Future)
+      {
+         try
+         {
+            return ((Future<?>) result).get();
+         }
+         catch (RuntimeException e)
+         {
+            throw e;
+         }
+         catch (Exception e)
+         {
+            throw new RuntimeException("Error getting option from future " + result, e);
+         }
+      }
+      return result;
+   }
+
+   public <T> T getOption(Class<T> expectedType)
+   {
+      if (expectedType == null)
+         throw new IllegalArgumentException("Null expectedType");
+
+      return getOption(expectedType.getName(), expectedType);
+   }
+
+   public <T> T getOption(String name, Class<T> expectedType)
+   {
+      if (expectedType == null)
+         throw new IllegalArgumentException("Null expectedType");
+
+      Object result = getOption(name);
+      if (result == null)
+         return null;
+      return expectedType.cast(result);      
+   }
+
+   public boolean getBooleanOption(String name)
+   {
+      Boolean result = getOption(name, Boolean.class);
+      return result != null && result;
+   }
+}

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java	2009-02-15 03:23:44 UTC (rev 84219)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java	2009-02-15 12:06:53 UTC (rev 84220)
@@ -290,7 +290,7 @@
     */
    public Options getAggregatedOptions()
    {
-      Options aggregatedOptions = new Options();
+      Options aggregatedOptions = createNewOptions();
       VFSContext peerContext = getPeerContext();
       if (peerContext != null)
          aggregatedOptions.merge(peerContext.getOptions());
@@ -358,8 +358,7 @@
          Options aggregatedOptions = getAggregatedOptions();
          boolean noReaper = Boolean.valueOf(aggregatedOptions.getOption(VFSUtils.NO_REAPER_QUERY, String.class));
          realURL = urlInfo.toURL();
-         Boolean isTemp = aggregatedOptions.getOption(VFSUtils.IS_TEMP_FILE, Boolean.class);
-         boolean isAutoClean = autoClean || (isTemp != null && isTemp);
+         boolean isAutoClean = autoClean || aggregatedOptions.getBooleanOption(VFSUtils.IS_TEMP_FILE);
          return new ZipFileWrapper(file, isAutoClean, noReaper);
       }
    }

Deleted: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/Options.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/Options.java	2009-02-15 03:23:44 UTC (rev 84219)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/Options.java	2009-02-15 12:06:53 UTC (rev 84220)
@@ -1,222 +0,0 @@
-/*
-  * JBoss, Home of Professional Open Source
-  * Copyright 2005, 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.spi;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.Future;
-
-/**
- * Options.
- *
- * @author <a href="ales.justin at jboss.com">Ales Justin</a>
- */
-public class Options
-{
-   /** The options */
-   private transient Map<String, Object> options;
-
-   /**
-    * Get options size.
-    *
-    * @return the size
-    */
-   public int size()
-   {
-      return options == null ? 0 : options.size();
-   }
-
-   /**
-    * Merge options.
-    *
-    * @param other the other options
-    */
-   public void merge(Options other)
-   {
-      if (other == null)
-         throw new IllegalArgumentException("Null other options");
-
-      Map<String, Object> map = other.options;
-      if (map == null || map.isEmpty())
-         return;
-
-      synchronized (this)
-      {
-         if (options == null)
-            options = new HashMap<String, Object>();
-
-         options.putAll(map);
-      }
-   }
-
-   /**
-    * Get all options that match type.
-    *
-    * @param exactType the exact type
-    * @param <T> the exact type
-    * @return matching options
-    */
-   public <T> Map<String, T> getOptions(Class<T> exactType)
-   {
-      if (exactType == null)
-         throw new IllegalArgumentException("Null exact type");
-
-      Map<String, T> result = new HashMap<String,T>();
-      if (options != null && options.isEmpty() == false)
-      {
-         for (Map.Entry<String, Object> entry : options.entrySet())
-         {
-            Object value = entry.getValue();
-            if (exactType.isInstance(value))
-            {
-               result.put(entry.getKey(), exactType.cast(value));
-            }
-         }
-      }
-      return result;
-   }
-
-   /**
-    * Set an option against the type.
-    * This is useful for caching information against a type.<p>
-    *
-    * If you add a future object, subsequent gets will wait for the result<p>
-    *
-    * WARNING: Be careful about what you put in here. Don't create
-    * references across classloaders, if you are not sure add a WeakReference
-    * to the information.
-    *
-    * @param name the name
-    * @param option the option, pass null to remove an option
-    * @throws IllegalArgumentException for a null name
-    */
-   public void addOption(String name, Object option)
-   {
-      if (name == null)
-         throw new IllegalArgumentException("Null name");
-
-      if (option == null)
-         return;
-
-      synchronized (this)
-      {
-         if (options == null)
-            options = new HashMap<String, Object>();
-         options.put(name, option);
-      }
-   }
-
-   /**
-    * Add options.
-    *
-    * @param map the options map
-    * @throws IllegalArgumentException for a null map
-    */
-   public void addOptions(Map<String, ?> map)
-   {
-      if (map == null)
-         throw new IllegalArgumentException("Null map");
-
-      for (Map.Entry<String, ?> entry : map.entrySet())
-      {
-         addOption(entry.getKey(), entry.getValue());
-      }
-   }
-
-   /**
-    * Remove an option
-    *
-    * @param name the name
-    * @throws IllegalArgumentException for a null name
-    */
-   public void removeOption(String name)
-   {
-      if (name == null)
-         throw new IllegalArgumentException("Null name");
-
-      synchronized (this)
-      {
-         if (options == null)
-            return;
-         options.remove(name);
-      }
-   }
-
-   /**
-    * Get an option from the type
-    *
-    * @param name the name
-    * @return the option
-    */
-   public Object getOption(String name)
-   {
-      if (name == null)
-         throw new IllegalArgumentException("Null name");
-
-      Object result;
-      synchronized (this)
-      {
-         if (options == null)
-            return null;
-         result = options.get(name);
-      }
-      if (result == null)
-         return null;
-
-      // Special case if the option is a future object
-      if (result instanceof Future)
-      {
-         try
-         {
-            return ((Future<?>) result).get();
-         }
-         catch (RuntimeException e)
-         {
-            throw e;
-         }
-         catch (Exception e)
-         {
-            throw new RuntimeException("Error getting option from future " + result, e);
-         }
-      }
-      return result;
-   }
-
-   /**
-    * Get the option.
-    *
-    * @param name the name
-    * @param expectedType the expected type
-    * @param <T> the expected type
-    * @return the option or null if no such matching exists
-    */
-   public <T> T getOption(String name, Class<T> expectedType)
-   {
-      if (expectedType == null)
-         throw new IllegalArgumentException("Null expectedType");
-
-      Object result = getOption(name);
-      if (result == null)
-         return null;
-      return expectedType.cast(result);      
-   }
-}

Added: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/Options.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/Options.java	                        (rev 0)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/Options.java	2009-02-15 12:06:53 UTC (rev 84220)
@@ -0,0 +1,122 @@
+/*
+ * 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;
+
+import java.util.Map;
+
+/**
+ * Options interface.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface Options
+{
+   /**
+    * Get options size.
+    *
+    * @return the size
+    */
+   int size();
+
+   /**
+    * Merge options.
+    *
+    * @param other the other options
+    */
+   void merge(Options other);
+
+   /**
+    * Get all options that match type.
+    *
+    * @param exactType the exact type
+    * @param <T> the exact type
+    * @return matching options
+    */
+   <T> Map<String, T> getOptions(Class<T> exactType);
+
+   /**
+    * Set an option against the type.
+    * This is useful for caching information against a type.<p>
+    *
+    * If you add a future object, subsequent gets will wait for the result<p>
+    *
+    * WARNING: Be careful about what you put in here. Don't create
+    * references across classloaders, if you are not sure add a WeakReference
+    * to the information.
+    *
+    * @param name the name
+    * @param option the option, pass null to remove an option
+    * @throws IllegalArgumentException for a null name
+    */
+   void addOption(String name, Object option);
+
+   /**
+    * Add options.
+    *
+    * @param map the options map
+    * @throws IllegalArgumentException for a null map
+    */
+   void addOptions(Map<String, ?> map);
+
+   /**
+    * Remove an option
+    *
+    * @param name the name
+    * @throws IllegalArgumentException for a null name
+    */
+   void removeOption(String name);
+
+   /**
+    * Get an option from the type
+    *
+    * @param name the name
+    * @return the option
+    */
+   Object getOption(String name);
+
+   /**
+    * Get option.
+    *
+    * @param expectedType the expected type.
+    * @param <T> the expectedType
+    * @return the option
+    */
+   <T> T getOption(Class<T> expectedType);
+
+   /**
+    * Get the option.
+    *
+    * @param name the name
+    * @param expectedType the expected type
+    * @param <T> the expected type
+    * @return the option or null if no such matching exists
+    */
+   <T> T getOption(String name, Class<T> expectedType);
+
+   /**
+    * Get boolean option.
+    *
+    * @param name the name
+    * @return boolean option value
+    */
+   boolean getBooleanOption(String name);
+}

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-02-15 03:23:44 UTC (rev 84219)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContext.java	2009-02-15 12:06:53 UTC (rev 84220)
@@ -82,62 +82,6 @@
    Options getOptions();
 
    /**
-    * Merge options.
-    *
-    * @param other other options
-    */
-   void mergeOptions(Options other);
-
-   /**
-    * Get an option from the type
-    *
-    * @param name the name
-    * @return the option
-    */
-   Object getOption(String name);
-
-   /**
-    * Get an option from the type,
-    * uses the expected type as both the name
-    * and to cast the resulting object.
-    *
-    * @param <T> the expected type
-    * @param expectedType the expected type
-    * @return the option
-    * @throws ClassCastException when the object is not of the expected type
-    */
-   <T> T getOption(Class<T> expectedType);
-
-   /**
-    * Get an option from the type,
-    * uses the expected type as both the name
-    * and to cast the resulting object.
-    *
-    * @param <T> the expected type
-    * @param name the name
-    * @param expectedType the expected type
-    * @return the option
-    * @throws ClassCastException when the object is not of the expected type
-    */
-   <T> T getOption(String name, Class<T> expectedType);
-
-   /**
-    * Set an option against the type.
-    * This is useful for caching information against a type.<p>
-    *
-    * If you add a future object, subsequent gets will wait for the result<p>
-    *
-    * WARNING: Be careful about what you put in here. Don't create
-    * references across classloaders, if you are not sure add a WeakReference
-    * to the information.
-    *
-    * @param name the name
-    * @param option the option, pass null to remove an option
-    * @throws IllegalArgumentException for a null name
-    */
-   void setOption(String name, Object option);
-
-   /**
     * Get the children
     * 
     * @param parent the parent




More information about the jboss-cvs-commits mailing list