Author: imario
Date: Mon Oct  2 12:10:50 2006
New Revision: 452175

URL: http://svn.apache.org/viewvc?view=rev&rev=452175
Log:
VFS-7: Thanks to Edgar Poce for this contribution

Modified:
    
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileData.java
    
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileObject.java
    
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystem.java
    
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystemConfigBuilder.java
    
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/CustomRamProviderTest.java
    
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/RamProviderTestCase.java
    
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/ProviderCacheStrategyTests.java

Modified: 
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileData.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileData.java?view=diff&rev=452175&r1=452174&r2=452175
==============================================================================
--- 
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileData.java
 (original)
+++ 
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileData.java
 Mon Oct  2 12:10:50 2006
@@ -71,7 +71,7 @@
        /**
         * @return Returns the buffer.
         */
-       public byte[] getBuffer()
+       byte[] getBuffer()
        {
                return buffer;
        }
@@ -79,7 +79,7 @@
        /**
         * @param buffer
         */
-       public void setBuffer(byte[] buffer)
+       void setBuffer(byte[] buffer)
        {
                updateLastModified();
                this.buffer = buffer;
@@ -88,7 +88,7 @@
        /**
         * @return Returns the lastModified.
         */
-       public long getLastModified()
+       long getLastModified()
        {
                return lastModified;
        }
@@ -97,7 +97,7 @@
         * @param lastModified
         *            The lastModified to set.
         */
-       public void setLastModified(long lastModified)
+       void setLastModified(long lastModified)
        {
                this.lastModified = lastModified;
        }
@@ -105,7 +105,7 @@
        /**
         * @return Returns the type.
         */
-       public FileType getType()
+       FileType getType()
        {
                return type;
        }
@@ -114,7 +114,7 @@
         * @param type
         *            The type to set.
         */
-       public void setType(FileType type)
+       void setType(FileType type)
        {
                this.type = type;
        }
@@ -122,7 +122,7 @@
        /**
         * 
         */
-       public void clear()
+       void clear()
        {
                this.buffer = new byte[0];
                updateLastModified();
@@ -139,7 +139,7 @@
        /**
         * @return Returns the name.
         */
-       public FileName getName()
+       FileName getName()
        {
                return name;
        }
@@ -159,7 +159,7 @@
         * 
         * @param data
         */
-       public void addChild(RamFileData data) throws FileSystemException
+       void addChild(RamFileData data) throws FileSystemException
        {
                if (!this.getType().equals(FileType.FOLDER))
                {
@@ -187,7 +187,7 @@
         * @param data
         * @throws FileSystemException
         */
-       public void removeChild(RamFileData data) throws FileSystemException
+       void removeChild(RamFileData data) throws FileSystemException
        {
                if (!this.getType().equals(FileType.FOLDER))
                {
@@ -205,7 +205,7 @@
        /**
         * @return Returns the children.
         */
-       public Collection getChildren()
+       Collection getChildren()
        {
                if (name == null)
                {
@@ -235,7 +235,7 @@
                return this.getName().hashCode();
        }
 
-       public boolean hasChildren(RamFileData data)
+       boolean hasChildren(RamFileData data)
        {
                return this.children.contains(data);
        }
@@ -243,7 +243,7 @@
        /**
         * @return Returns the size of the buffer
         */
-       public int size()
+       int size()
        {
                return buffer.length;
        }
@@ -253,7 +253,7 @@
         * 
         * @param newSize
         */
-       public void resize(int newSize)
+       void resize(int newSize)
        {
                int size = this.size();
                byte[] newBuf = new byte[newSize];

Modified: 
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileObject.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileObject.java?view=diff&rev=452175&r1=452174&r2=452175
==============================================================================
--- 
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileObject.java
 (original)
+++ 
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileObject.java
 Mon Oct  2 12:10:50 2006
@@ -189,7 +189,7 @@
        /**
         * @return Returns the data.
         */
-       public RamFileData getData()
+       RamFileData getData()
        {
                return data;
        }
@@ -198,7 +198,7 @@
         * @param data
         *            The data to set.
         */
-       public void setData(RamFileData data)
+       void setData(RamFileData data)
        {
                this.data = data;
        }
@@ -228,7 +228,7 @@
        /**
         * @return Returns the size of the RAMFileData
         */
-       public int size()
+       int size()
        {
                if (data == null)
                {
@@ -242,7 +242,7 @@
         * @throws IOException
         *             if the new size exceeds the limit
         */
-       public synchronized void resize(int newSize) throws IOException
+       synchronized void resize(int newSize) throws IOException
        {
                if (fs.getFileSystemOptions() != null)
                {

Modified: 
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystem.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystem.java?view=diff&rev=452175&r1=452174&r2=452175
==============================================================================
--- 
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystem.java
 (original)
+++ 
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystem.java
 Mon Oct  2 12:10:50 2006
@@ -29,8 +29,6 @@
 
 import org.apache.commons.vfs.FileName;
 import org.apache.commons.vfs.FileObject;
-import org.apache.commons.vfs.FileSelectInfo;
-import org.apache.commons.vfs.FileSelector;
 import org.apache.commons.vfs.FileSystemException;
 import org.apache.commons.vfs.FileSystemOptions;
 import org.apache.commons.vfs.FileType;
@@ -41,10 +39,6 @@
  */
 public class RamFileSystem extends AbstractFileSystem implements Serializable
 {
-       /** config builder */
-       private static RamFileSystemConfigBuilder confBuilder = 
RamFileSystemConfigBuilder
-                       .getInstance();
-
        /**
         * Cache of RAM File Data
         */
@@ -52,7 +46,6 @@
 
        /**
         * @param rootName
-        * @param parentLayer
         * @param fileSystemOptions
         */
        protected RamFileSystem(FileName rootName,
@@ -60,6 +53,11 @@
        {
                super(rootName, null, fileSystemOptions);
                this.cache = Collections.synchronizedMap(new HashMap());
+        // create root
+        RamFileData rootData = new RamFileData(rootName) ;
+        rootData.setType(FileType.FOLDER);
+        rootData.setLastModified(System.currentTimeMillis());
+        this.cache.put(rootName, rootData);
        }
 
        /*
@@ -87,7 +85,7 @@
         * @param name
         * @return children
         */
-       public String[] listChildren(FileName name)
+       String[] listChildren(FileName name)
        {
         RamFileData data = (RamFileData) this.cache.get(name);
                Collection children = data.getChildren();
@@ -112,14 +110,19 @@
         * @param file
         * @throws FileSystemException
         */
-       public void delete(RamFileObject file) throws FileSystemException
+       void delete(RamFileObject file) throws FileSystemException
        {
+           // root is read only check
+        if (file.getParent()==null) {
+            throw new FileSystemException("unable to delete root");
+        }
+        
                // Remove reference from cache
                this.cache.remove(file.getName());
                // Notify the parent
-               RamFileObject parent = (RamFileObject) this.resolveFile(file
-                               .getParent().getName());
-               parent.getData().removeChild(file.getData());
+        RamFileObject parent = (RamFileObject) this.resolveFile(file
+                .getParent().getName());
+        parent.getData().removeChild(file.getData());
                parent.close();
                // Close the file
                file.getData().clear();
@@ -132,7 +135,7 @@
         * @param file
         * @throws FileSystemException
         */
-       public void save(final RamFileObject file) throws FileSystemException
+       void save(final RamFileObject file) throws FileSystemException
        {
 
                // Validate name
@@ -142,59 +145,6 @@
                                        "The data has no name. " + file));
                }
 
-               // Validate file system size
-               // if (size() > confBuilder.getMaxSize(this
-               // .getFileSystemOptions())) {
-               // throw new FileSystemException(
-               // "The maximum size ("
-               // + confBuilder.getMaxSize(this
-               // .getFileSystemOptions())
-               // + ") was exceeded.");
-               // }
-
-               // Validate against the predicate
-               FileSelector predicate = confBuilder.getPredicate(this
-                               .getFileSystemOptions());
-               
-               FileSelectInfo info = new FileSelectInfo()
-               {
-                       public FileObject getBaseFolder()
-                       {
-                               try
-                               {
-                                       return getRoot();
-                               }
-                               catch (FileSystemException e)
-                               {
-                                       throw new 
RuntimeException(e.getLocalizedMessage());
-                               }
-                       }
-
-                       public FileObject getFile()
-                       {
-                               return file;
-                       }
-
-                       public int getDepth()
-                       {
-                               return -1;
-                       }
-               };
-               
-               try
-               {
-                       if (predicate != null && !predicate.includeFile(info))
-                       {
-                               throw new FileSystemException(
-                                               "Unable to save file, it was 
rejected by the predicate "
-                                                               + 
predicate.getClass().getName() + ".");
-                       }
-               }
-               catch (Exception e)
-               {
-                       throw new FileSystemException(e);
-               }
-
                // Add to the parent
                if (file.getName().getDepth() > 0)
                {
@@ -215,11 +165,11 @@
        }
 
        /**
-        * @param object
-        * @param newfile
+        * @param from
+        * @param to
         * @throws FileSystemException
         */
-       public void rename(RamFileObject from, RamFileObject to)
+       void rename(RamFileObject from, RamFileObject to)
                        throws FileSystemException
        {
                if (!this.cache.containsKey(from.getName()))
@@ -254,10 +204,7 @@
        /**
         * Import a Tree
         * 
-        * @param fs
-        *            RAM FileSyste
         * @param file
-        * @param root
         * @throws FileSystemException
         */
        public void importTree(File file) throws FileSystemException
@@ -273,7 +220,7 @@
         * @param root
         * @throws FileSystemException
         */
-       public void toRamFileObject(FileObject fo, FileObject root)
+       void toRamFileObject(FileObject fo, FileObject root)
                        throws FileSystemException
        {
                RamFileObject memFo = (RamFileObject) 
this.resolveFile(fo.getName()
@@ -337,7 +284,7 @@
        /**
         * @return Returns the size of the FileSystem
         */
-       public int size()
+       int size()
        {
                int size = 0;
                Iterator iter = cache.values().iterator();

Modified: 
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystemConfigBuilder.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystemConfigBuilder.java?view=diff&rev=452175&r1=452174&r2=452175
==============================================================================
--- 
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystemConfigBuilder.java
 (original)
+++ 
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/ram/RamFileSystemConfigBuilder.java
 Mon Oct  2 12:10:50 2006
@@ -15,7 +15,6 @@
  */
 package org.apache.commons.vfs.provider.ram;
 
-import org.apache.commons.vfs.FileSelector;
 import org.apache.commons.vfs.FileSystemConfigBuilder;
 import org.apache.commons.vfs.FileSystemOptions;
 
@@ -28,9 +27,6 @@
        /** max size key */
        private static final String MAX_SIZE_KEY = "maxsize";
 
-       /** predicate key */
-       private static final String PREDICATE_KEY = "predicate";
-
        /** config builder singleton */
        private static RamFileSystemConfigBuilder singleton = new 
RamFileSystemConfigBuilder();
 
@@ -85,25 +81,6 @@
        public void setMaxSize(FileSystemOptions opts, int sizeInBytes)
        {
                setParam(opts, MAX_SIZE_KEY, new Integer(sizeInBytes));
-       }
-
-       /**
-        * @param opts
-        * @return
-        * @see #setPredicate
-        */
-       public FileSelector getPredicate(FileSystemOptions opts)
-       {
-               return (FileSelector) getParam(opts, PREDICATE_KEY);
-       }
-
-       /**
-        * sets a predicate that performs a validation test before adding it to 
the
-        * file system
-        */
-       public void setPredicate(FileSystemOptions opts, FileSelector predicate)
-       {
-               setParam(opts, PREDICATE_KEY, predicate);
        }
 
 }

Modified: 
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/CustomRamProviderTest.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/CustomRamProviderTest.java?view=diff&rev=452175&r1=452174&r2=452175
==============================================================================
--- 
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/CustomRamProviderTest.java
 (original)
+++ 
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/CustomRamProviderTest.java
 Mon Oct  2 12:10:50 2006
@@ -20,10 +20,9 @@
 import junit.framework.TestCase;
 
 import org.apache.commons.vfs.FileObject;
-import org.apache.commons.vfs.FileSelectInfo;
-import org.apache.commons.vfs.FileSelector;
 import org.apache.commons.vfs.FileSystemException;
 import org.apache.commons.vfs.FileSystemOptions;
+import org.apache.commons.vfs.FileType;
 import org.apache.commons.vfs.impl.DefaultFileSystemManager;
 import org.apache.commons.vfs.provider.ram.RamFileProvider;
 import org.apache.commons.vfs.provider.ram.RamFileSystemConfigBuilder;
@@ -43,9 +42,9 @@
 
        FileSystemOptions smallSized = new FileSystemOptions();
 
-       FileSystemOptions predicated = new FileSystemOptions();
+    FileSystemOptions defaultRamFs = new FileSystemOptions();
 
-       protected void setUp() throws Exception
+    protected void setUp() throws Exception
        {
                super.setUp();
 
@@ -56,31 +55,6 @@
                // File Systems Options
                RamFileSystemConfigBuilder.getInstance().setMaxSize(zeroSized, 
0);
                RamFileSystemConfigBuilder.getInstance().setMaxSize(smallSized, 
10);
-               FileSelector predicate = new FileSelector()
-               {
-                       public boolean includeFile(FileSelectInfo fileInfo) 
throws Exception
-                       {
-                               return 
"txt".equals(fileInfo.getFile().getName().getExtension());
-                       }
-
-                       public boolean traverseDescendents(FileSelectInfo 
fileInfo) throws Exception
-                       {
-                               // not required
-                               return true;
-                       }
-                       
-               };
-               /*
-               Predicate predicate = new Predicate()
-               {
-                       public boolean evaluate(Object o)
-                       {
-                               RamFileObject file = (RamFileObject) o;
-                               return 
file.getName().getBaseName().endsWith("txt");
-                       }
-               };
-               */
-               
RamFileSystemConfigBuilder.getInstance().setPredicate(predicated, predicate);
        }
 
        protected void tearDown() throws Exception
@@ -99,7 +73,7 @@
                                .getFileSystem() == fo2.getFileSystem());
 
                // Small FS
-               FileObject fo3 = manager.resolveFile("ram:/", smallSized);
+               FileObject fo3 = manager.resolveFile("ram:/fo3", smallSized);
                FileObject fo4 = manager.resolveFile("ram:/", smallSized);
                assertTrue("Both files should exist in different fs 
instances.", fo3
                                .getFileSystem() == fo4.getFileSystem());
@@ -133,23 +107,24 @@
 
        }
 
-       public void testPredicatedFS() throws FileSystemException
-       {
-               FileObject predFo = null;
-               try
-               {
-                       predFo = 
manager.resolveFile("ram:/myfile.anotherExtension",
-                                       predicated);
-                       predFo.createFile();
-                       fail("It should only accept files with .txt 
extensions");
-               }
-               catch (FileSystemException e)
-               {
-                       // Do nothing
-               }
-               predFo = manager
-                               .resolveFile("ram:/myfile.anotherExtension", 
predicated);
-               assertTrue(!predFo.exists());
-       }
+    /**
+     * 
+     * Checks root folder exists
+     * 
+     * @throws FileSystemException
+     */
+    public void testRootFolderExists() throws FileSystemException {
+        FileObject root = manager.resolveFile("ram:///", defaultRamFs);
+        assertTrue(root.getType().equals(FileType.FOLDER));
+
+        try {
+            root.delete();
+            fail();
+        } catch (FileSystemException e) {
+            
+        }
+
+    }
 
+    
 }

Modified: 
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/RamProviderTestCase.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/RamProviderTestCase.java?view=diff&rev=452175&r1=452174&r2=452175
==============================================================================
--- 
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/RamProviderTestCase.java
 (original)
+++ 
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/ram/test/RamProviderTestCase.java
 Mon Oct  2 12:10:50 2006
@@ -37,8 +37,9 @@
 public class RamProviderTestCase extends AbstractProviderTestConfig implements
                ProviderTestConfig
 {
+    private boolean inited = false;
 
-       /** logger */
+    /** logger */
        private static Log log = LogFactory.getLog(RamProviderTestCase.class);
 
        /**
@@ -49,7 +50,7 @@
                return new ProviderTestSuite(new RamProviderTestCase());
        }
 
-       /**
+    /**
         * Prepares the file system manager.
         * 
         * Imports test data from the disk.
@@ -64,11 +65,6 @@
                {
                        manager.addProvider("ram", new RamFileProvider());
                        manager.addProvider("file", new 
DefaultLocalFileProvider());
-                       FileObject fo = manager.resolveFile("ram:/");
-                       // Import the test tree
-                       RamFileSystem fs = (RamFileSystem) fo.getFileSystem();
-                       fs.importTree(new File("target/test-data"));
-                       fo.close();
                }
                catch (Exception e)
                {
@@ -83,7 +79,18 @@
        public FileObject getBaseTestFolder(final FileSystemManager manager)
                        throws Exception
        {
-               final String uri = "ram:/";
+        if (!inited)
+        {
+            // Import the test tree
+            FileObject fo = manager.resolveFile("ram:/");
+                       RamFileSystem fs = (RamFileSystem) fo.getFileSystem();
+                       fs.importTree(new File("target/test-data"));
+                       fo.close();
+            
+            inited=true;
+        }
+
+        final String uri = "ram:/";
                return manager.resolveFile(uri);
        }
 }

Modified: 
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/ProviderCacheStrategyTests.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/ProviderCacheStrategyTests.java?view=diff&rev=452175&r1=452174&r2=452175
==============================================================================
--- 
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/ProviderCacheStrategyTests.java
 (original)
+++ 
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/test/ProviderCacheStrategyTests.java
 Mon Oct  2 12:10:50 2006
@@ -19,6 +19,8 @@
 import org.apache.commons.vfs.Capability;
 import org.apache.commons.vfs.FileObject;
 import org.apache.commons.vfs.Selectors;
+import org.apache.commons.vfs.provider.ram.RamFileObject;
+import org.apache.commons.vfs.util.FileObjectUtils;
 import org.apache.commons.vfs.impl.DefaultFileSystemManager;
 
 /**
@@ -47,6 +49,12 @@
      */
     public void testManualCache() throws Exception
     {
+        if (FileObjectUtils.isInstanceOf(getBaseFolder(), RamFileObject.class))
+        {
+            // cant check ram filesystem as every manager holds its own ram 
filesystem data
+            return;
+        }
+
         FileObject scratchFolder = getWriteFolder();
         scratchFolder.delete(Selectors.EXCLUDE_SELF);
         
@@ -74,6 +82,12 @@
      */
     public void testOnResolveCache() throws Exception
     {
+        if (FileObjectUtils.isInstanceOf(getBaseFolder(), RamFileObject.class))
+        {
+            // cant check ram filesystem as every manager holds its own ram 
filesystem data
+            return;
+        }
+
         FileObject scratchFolder = getWriteFolder();
         scratchFolder.delete(Selectors.EXCLUDE_SELF);
         
@@ -101,6 +115,12 @@
      */
     public void testOnCallCache() throws Exception
     {
+        if (FileObjectUtils.isInstanceOf(getBaseFolder(), RamFileObject.class))
+        {
+            // cant check ram filesystem as every manager holds its own ram 
filesystem data
+            return;
+        }
+
         FileObject scratchFolder = getWriteFolder();
         scratchFolder.delete(Selectors.EXCLUDE_SELF);
         



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to