[jboss-cvs] JBossAS SVN: r71370 - in projects/vfs/trunk/src: main/java/org/jboss/virtual/protocol/vfsmemory and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Mar 28 06:51:36 EDT 2008


Author: alesj
Date: 2008-03-28 06:51:36 -0400 (Fri, 28 Mar 2008)
New Revision: 71370

Modified:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfsmemory/Handler.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractMockVFSTest.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSUnitTestCase.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VirtualFileUnitTestCase.java
Log:
[JBVFS-10] returning empty list on isLeaf instead of throwing exception.

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.java	2008-03-28 07:17:42 UTC (rev 71369)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.java	2008-03-28 10:51:36 UTC (rev 71370)
@@ -302,7 +302,7 @@
    public List<VirtualFile> getChildren(VirtualFileFilter filter) throws IOException
    {
       if (isLeaf())
-         throw new IllegalStateException("File cannot contain children: " + this);
+         return Collections.emptyList();
 
       if (filter == null)
          filter = MatchAllVirtualFileFilter.INSTANCE;
@@ -338,7 +338,7 @@
    public List<VirtualFile> getChildrenRecursively(VirtualFileFilter filter) throws IOException
    {
       if (isLeaf())
-         throw new IllegalStateException("File cannot contain children: " + this);
+         return Collections.emptyList();
 
       if (filter == null)
          filter = MatchAllVirtualFileFilter.INSTANCE;

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfsmemory/Handler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfsmemory/Handler.java	2008-03-28 07:17:42 UTC (rev 71369)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/protocol/vfsmemory/Handler.java	2008-03-28 10:51:36 UTC (rev 71370)
@@ -22,7 +22,6 @@
 package org.jboss.virtual.protocol.vfsmemory;
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLStreamHandler;
@@ -53,37 +52,4 @@
 
       return new VirtualFileURLConnection(u, vf);
    }
-
-   public static void main(String[] args) throws Exception
-   {
-      System.setProperty("java.protocol.handler.pkgs", "org.jboss.virtual.protocol");
-      //URL url = new URL("vfsfile:/c:/tmp/urlstream.java");
-      //URL url = new URL("vfsfile:/C:\\jboss\\jboss-head\\build\\output\\jboss-5.0.0.Beta\\server\\default\\lib\\jboss.jar\\schema\\xml.xsd");
-//      URL url = new URL("vfsjar:file:/c:/tmp/parent.jar!/foo.jar/urlstream.java");
-      
-      URL rootURL = new URL("vfsmemory://aopdomain2");
-      MemoryContextFactory.getInstance().createRoot(rootURL);
-
-      URL url = new URL("vfsmemory://aopdomain2/org/foo/Test.class");
-      MemoryContextFactory.getInstance().putFile(url, new byte[] {'a', 'b', 'c'});
-      URL url2 = new URL("vfsmemory://aopdomain2/org/bar/Test.class");
-      MemoryContextFactory.getInstance().putFile(url2, new byte[] {'d', 'e', 'f'});
-      
-      System.out.println("---------");
-      InputStream is = url.openStream();
-      while (is.available() != 0)
-      {
-         System.out.print((char)is.read());
-      }
-      is.close();
-
-      System.out.println("---------");
-      MemoryContextFactory.getInstance().createRoot(rootURL);
-      InputStream is2 = url2.openStream();
-      while (is2.available() != 0)
-      {
-         System.out.print((char)is2.read());
-      }
-      is.close();
-   }
 }

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractMockVFSTest.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractMockVFSTest.java	2008-03-28 07:17:42 UTC (rev 71369)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/AbstractMockVFSTest.java	2008-03-28 10:51:36 UTC (rev 71370)
@@ -23,6 +23,7 @@
 
 import java.io.IOException;
 import java.net.URI;
+import java.util.List;
 
 import org.jboss.test.virtual.support.MockSimpleVirtualFileHandler;
 import org.jboss.test.virtual.support.MockStructuredVirtualFileHandler;
@@ -30,6 +31,7 @@
 import org.jboss.test.virtual.support.MockVFSContextFactory;
 import org.jboss.virtual.VFS;
 import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
 import org.jboss.virtual.spi.VFSContext;
 import org.jboss.virtual.spi.VFSContextFactoryLocator;
 import org.jboss.virtual.spi.VirtualFileHandler;
@@ -38,6 +40,7 @@
  * AbstractMockVFSTest.
  * 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @version $Revision: 1.1 $
  */
 public abstract class AbstractMockVFSTest extends AbstractVFSTest
@@ -312,4 +315,58 @@
       assertEquals(expected, found);
       return found;
    }
+
+   protected void assertChildrenOnLeaf(VirtualFile file) throws Exception
+   {
+      assertNotNull(file);
+      assertChildrenOnLeaf(file.getChildren());
+   }
+
+   protected void assertChildrenOnLeaf(VFS vfs) throws Exception
+   {
+      assertNotNull(vfs);
+      assertChildrenOnLeaf(vfs.getChildren());
+   }
+
+   protected void assertChildrenOnLeaf(VirtualFile file, VirtualFileFilter filter) throws Exception
+   {
+      assertNotNull(file);
+      assertChildrenOnLeaf(file.getChildren(filter));
+   }
+
+   protected void assertChildrenOnLeaf(VFS vfs, VirtualFileFilter filter) throws Exception
+   {
+      assertNotNull(vfs);
+      assertChildrenOnLeaf(vfs.getChildren(filter));
+   }
+
+   protected void assertChildrenOnLeafRecursively(VirtualFile file) throws Exception
+   {
+      assertNotNull(file);
+      assertChildrenOnLeaf(file.getChildrenRecursively());
+   }
+
+   protected void assertChildrenOnLeafRecursively(VFS vfs) throws Exception
+   {
+      assertNotNull(vfs);
+      assertChildrenOnLeaf(vfs.getChildrenRecursively());
+   }
+
+   protected void assertChildrenOnLeafRecursively(VirtualFile file, VirtualFileFilter filter) throws Exception
+   {
+      assertNotNull(file);
+      assertChildrenOnLeaf(file.getChildrenRecursively(filter));
+   }
+
+   protected void assertChildrenOnLeafRecursively(VFS vfs, VirtualFileFilter filter) throws Exception
+   {
+      assertNotNull(vfs);
+      assertChildrenOnLeaf(vfs.getChildrenRecursively(filter));
+   }
+
+   protected void assertChildrenOnLeaf(List<VirtualFile> children) throws Exception
+   {
+      assertNotNull(children);
+      assertEmpty(children);
+   }
 }

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-03-28 07:17:42 UTC (rev 71369)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSUnitTestCase.java	2008-03-28 10:51:36 UTC (rev 71370)
@@ -778,15 +778,7 @@
       MockVFSContext context = registerSimpleVFSContext();
       
       VFS vfs = VFS.getVFS(context.getRootURI());
-      try
-      {
-         vfs.getChildren();
-         fail("Should not be here!");
-      }
-      catch (Throwable t)
-      {
-         checkThrowable(IllegalStateException.class, t);
-      }
+      assertChildrenOnLeaf(vfs);
    }
 
    public void testGetAllChildrenIOException() throws Exception
@@ -861,15 +853,7 @@
       MockVFSContext context = registerSimpleVFSContext();
       
       VFS vfs = VFS.getVFS(context.getRootURI());
-      try
-      {
-         vfs.getChildren(null);
-         fail("Should not be here!");
-      }
-      catch (Throwable t)
-      {
-         checkThrowable(IllegalStateException.class, t);
-      }
+      assertChildrenOnLeaf(vfs, null);
    }
 
    public void testGetAllChildrenWithNullFilterIOException() throws Exception
@@ -951,15 +935,7 @@
       
       VFS vfs = VFS.getVFS(context.getRootURI());
       MockVirtualFileFilter filter = new MockVirtualFileFilter();
-      try
-      {
-         vfs.getChildren(filter);
-         fail("Should not be here!");
-      }
-      catch (Throwable t)
-      {
-         checkThrowable(IllegalStateException.class, t);
-      }
+      assertChildrenOnLeaf(vfs, filter);
    }
 
    public void testGetAllChildrenWithFilterIOException() throws Exception
@@ -1047,15 +1023,7 @@
       MockVFSContext context = registerSimpleVFSContext();
       
       VFS vfs = VFS.getVFS(context.getRootURI());
-      try
-      {
-         vfs.getChildrenRecursively();
-         fail("Should not be here!");
-      }
-      catch (Throwable t)
-      {
-         checkThrowable(IllegalStateException.class, t);
-      }
+      assertChildrenOnLeafRecursively(vfs);
    }
 
    public void testGetAllChildrenRecursivelyIOException() throws Exception
@@ -1142,15 +1110,7 @@
       MockVFSContext context = registerSimpleVFSContext();
       
       VFS vfs = VFS.getVFS(context.getRootURI());
-      try
-      {
-         vfs.getChildrenRecursively(null);
-         fail("Should not be here!");
-      }
-      catch (Throwable t)
-      {
-         checkThrowable(IllegalStateException.class, t);
-      }
+      assertChildrenOnLeafRecursively(vfs, null);
    }
 
    public void testGetAllChildrenRecursivelyWithNullFilterIOException() throws Exception
@@ -1244,15 +1204,7 @@
       
       VFS vfs = VFS.getVFS(context.getRootURI());
       MockVirtualFileFilter filter = new MockVirtualFileFilter();
-      try
-      {
-         vfs.getChildren(filter);
-         fail("Should not be here!");
-      }
-      catch (Throwable t)
-      {
-         checkThrowable(IllegalStateException.class, t);
-      }
+      assertChildrenOnLeafRecursively(vfs, filter);
    }
 
    public void testGetAllChildrenRecursivelyWithFilterIOException() throws Exception

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VirtualFileUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VirtualFileUnitTestCase.java	2008-03-28 07:17:42 UTC (rev 71369)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VirtualFileUnitTestCase.java	2008-03-28 10:51:36 UTC (rev 71370)
@@ -581,15 +581,7 @@
       MockVFSContext context = registerSimpleVFSContext();
       
       VirtualFile file = VFS.getRoot(context.getRootURI());
-      try
-      {
-         file.getChildren();
-         fail("Should not be here!");
-      }
-      catch (Throwable t)
-      {
-         checkThrowable(IllegalStateException.class, t);
-      }
+      assertChildrenOnLeaf(file);
    }
 
    public void testGetAllChildrenIOException() throws Exception
@@ -664,15 +656,7 @@
       MockVFSContext context = registerSimpleVFSContext();
       
       VirtualFile file = VFS.getRoot(context.getRootURI());
-      try
-      {
-         file.getChildren(null);
-         fail("Should not be here!");
-      }
-      catch (Throwable t)
-      {
-         checkThrowable(IllegalStateException.class, t);
-      }
+      assertChildrenOnLeaf(file, null);
    }
 
    public void testGetAllChildrenWithNullFilterIOException() throws Exception
@@ -754,15 +738,7 @@
       
       VirtualFile file = VFS.getRoot(context.getRootURI());
       MockVirtualFileFilter filter = new MockVirtualFileFilter();
-      try
-      {
-         file.getChildren(filter);
-         fail("Should not be here!");
-      }
-      catch (Throwable t)
-      {
-         checkThrowable(IllegalStateException.class, t);
-      }
+      assertChildrenOnLeaf(file, filter);
    }
 
    public void testGetAllChildrenWithFilterIOException() throws Exception
@@ -850,15 +826,7 @@
       MockVFSContext context = registerSimpleVFSContext();
       
       VirtualFile file = VFS.getRoot(context.getRootURI());
-      try
-      {
-         file.getChildrenRecursively();
-         fail("Should not be here!");
-      }
-      catch (Throwable t)
-      {
-         checkThrowable(IllegalStateException.class, t);
-      }
+      assertChildrenOnLeafRecursively(file);
    }
 
    public void testGetAllChildrenIOExceptionRecursively() throws Exception
@@ -945,15 +913,7 @@
       MockVFSContext context = registerSimpleVFSContext();
       
       VirtualFile file = VFS.getRoot(context.getRootURI());
-      try
-      {
-         file.getChildrenRecursively(null);
-         fail("Should not be here!");
-      }
-      catch (Throwable t)
-      {
-         checkThrowable(IllegalStateException.class, t);
-      }
+      assertChildrenOnLeafRecursively(file, null);
    }
 
    public void testGetAllChildrenRecursivelyWithNullFilterIOException() throws Exception
@@ -1047,15 +1007,7 @@
       
       VirtualFile file = VFS.getRoot(context.getRootURI());
       MockVirtualFileFilter filter = new MockVirtualFileFilter();
-      try
-      {
-         file.getChildren(filter);
-         fail("Should not be here!");
-      }
-      catch (Throwable t)
-      {
-         checkThrowable(IllegalStateException.class, t);
-      }
+      assertChildrenOnLeafRecursively(file, filter);
    }
 
    public void testGetAllChildrenRecursivelyWithFilterIOException() throws Exception




More information about the jboss-cvs-commits mailing list