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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jan 16 05:06:10 EST 2008


Author: alesj
Date: 2008-01-16 05:06:10 -0500 (Wed, 16 Jan 2008)
New Revision: 69021

Modified:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/VFS.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.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/DelegatingHandler.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/StructuredVirtualFileHandler.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileHandler.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/LinkHandler.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractStructuredJarHandler.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryContents.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NoCopyNestedJarHandler.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/memory/MemoryContextHandler.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledDirectoryHandler.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/ByteArrayHandler.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContext.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/MockSimpleVirtualFileHandler.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/MockStructuredVirtualFileHandler.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSUnitTestCase.java
Log:
Adding getChild on VFS and VirtualFile.

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/VFS.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/VFS.java	2008-01-16 09:30:35 UTC (rev 69020)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VFS.java	2008-01-16 10:06:10 UTC (rev 69021)
@@ -192,27 +192,45 @@
    
    /**
     * Find a child from the root
-    * 
+    *
     * @param path the child path
     * @return the child
     * @throws IOException for any problem accessing the VFS (including the child does not exist)
     * @throws IllegalArgumentException if the path is null
+    * @deprecated use getChild, and handle null if not found
     */
+   @Deprecated
    public VirtualFile findChild(String path) throws IOException
    {
       if (path == null)
          throw new IllegalArgumentException("Null path");
       
       VirtualFileHandler handler = context.getRoot();
-      path = VFSUtils.fixName(path);
-      VirtualFileHandler result = context.findChild(handler, path);
+      VirtualFileHandler result = context.findChild(handler, VFSUtils.fixName(path));
       return result.getVirtualFile();
    }
    
    /**
+   * Get a child
+   *
+   * @param path the child path
+   * @return the child or <code>null</code> if not found
+   * @throws IOException if a real problem occurs
+   */
+   public VirtualFile getChild(String path) throws IOException
+   {
+      if (path == null)
+         throw new IllegalArgumentException("Null path");
+
+      VirtualFileHandler handler = context.getRoot();
+      VirtualFileHandler result = context.getChild(handler, VFSUtils.fixName(path));
+      return result != null ? result.getVirtualFile() : null;
+   }
+
+   /**
     * Find a child from the root
     * 
-    * @Deprecated use {@link #findChild(String)}
+    * @deprecated use {@link #findChild(String)}
     * @param path the child path
     * @return the child
     * @throws IOException for any problem accessing the VFS (including the child does not exist)

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.java	2008-01-16 09:30:35 UTC (rev 69020)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/VirtualFile.java	2008-01-16 10:06:10 UTC (rev 69021)
@@ -371,7 +371,9 @@
     * @throws IOException for any problem accessing the VFS (including the child does not exist)
     * @throws IllegalArgumentException if the path is null
     * @throws IllegalStateException if the file is closed or it is a leaf node
+    * @deprecated use getChild, and handle null if not found
     */
+   @Deprecated
    public VirtualFile findChild(String path) throws IOException
    {
       VirtualFileHandler handler = getHandler();
@@ -379,11 +381,30 @@
       if (handler.isLeaf())
          throw new IllegalStateException("File cannot contain children: " + this);
 
-      path = VFSUtils.fixName(path);
-      VirtualFileHandler child = handler.findChild(path);
+      VirtualFileHandler child = handler.findChild(VFSUtils.fixName(path));
       return child.getVirtualFile();
    }
 
+   /**
+    * Get a child
+    *
+    * @param path the path
+    * @return the child or <code>null</code> if not found
+    * @throws IOException for any problem accessing the VFS
+    * @throws IllegalArgumentException if the path is null
+    * @throws IllegalStateException if the file is closed or it is a leaf node
+    */
+   public VirtualFile getChild(String path) throws IOException
+   {
+      VirtualFileHandler handler = getHandler();
+      VirtualFileHandler child = null;
+      if (handler.isLeaf() == false)
+      {
+         child = handler.getChild(VFSUtils.fixName(path));
+      }
+      return child != null ? child.getVirtualFile() : null;
+   }
+
    @Override
    public String toString()
    {
@@ -406,5 +427,4 @@
       VirtualFile other = (VirtualFile) obj;
       return handler.equals(other.handler);
    }
-
 }

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	2008-01-16 09:30:35 UTC (rev 69020)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java	2008-01-16 10:06:10 UTC (rev 69021)
@@ -125,6 +125,15 @@
       return parent.findChild(path);
    }
 
+   public VirtualFileHandler getChild(VirtualFileHandler parent, String path) throws IOException
+   {
+      if (parent == null)
+         throw new IllegalArgumentException("Null parent");
+      if (path == null)
+         throw new IllegalArgumentException("Null path");
+      return parent.getChild(path);
+   }
+
    public void visit(VirtualFileHandler handler, VirtualFileHandlerVisitor visitor) throws IOException
    {
       if (handler == null)
@@ -138,8 +147,7 @@
       boolean ignoreErrors = attributes.isIgnoreErrors();
       boolean includeHidden = attributes.isIncludeHidden();
       VirtualFileFilter recurseFilter = attributes.getRecurseFilter();
-      visit(handler, visitor, includeRoot, leavesOnly, ignoreErrors,
-            includeHidden, recurseFilter);
+      visit(handler, visitor, includeRoot, leavesOnly, ignoreErrors, includeHidden, recurseFilter);
    }
 
    /**

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	2008-01-16 09:30:35 UTC (rev 69020)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java	2008-01-16 10:06:10 UTC (rev 69021)
@@ -370,6 +370,55 @@
    }
 
    /**
+    * Structured implementation of get child
+    *
+    * @param path the path
+    * @return the handler or <code>null</code> if it doesn't exist
+    * @throws IOException for any error accessing the virtual file system
+    * @throws IllegalArgumentException for a null name
+    */
+   public VirtualFileHandler structuredGetChild(String path) throws IOException
+   {
+      checkClosed();
+
+      // Parse the path
+      String[] tokens = PathTokenizer.getTokens(path);
+      if (tokens == null || tokens.length == 0)
+         return this;
+
+      // Go through each context starting from ours
+      // check the parents are not leaves.
+      VirtualFileHandler current = this;
+      for (int i = 0; i < tokens.length; ++i)
+      {
+         if (current == null || current.isLeaf())
+            return null;
+
+         if (PathTokenizer.isReverseToken(tokens[i]))
+         {
+            VirtualFileHandler parent = current.getParent();
+            if (parent == null)
+               throw new IOException("Using reverse path on top file handler: " + current + ", " + path);
+            else
+               current = parent;
+         }
+         else if (current instanceof StructuredVirtualFileHandler)
+         {
+            StructuredVirtualFileHandler structured = (StructuredVirtualFileHandler) current;
+            current = structured.getChildHandler(tokens[i]);
+         }
+         else
+         {
+            String remainingPath = PathTokenizer.getRemainingPath(tokens, i);
+            return current.getChild(remainingPath);
+         }
+      }
+
+      // The last one is the result
+      return current;
+   }
+
+   /**
     * Simple implementation of findChild
     * 
     * @param path the path
@@ -379,6 +428,20 @@
     */
    public VirtualFileHandler simpleFindChild(String path) throws IOException
    {
+      return simpleFindChild(path, false);     
+   }
+
+   /**
+    * Simple implementation of findChild
+    *
+    * @param path the path
+    * @param allowNull do we allow null
+    * @return the handler or <code>null</code> if not found
+    * @throws IOException for any error accessing the virtual file system
+    * @throws IllegalArgumentException for a null name
+    */
+   protected VirtualFileHandler simpleFindChild(String path, boolean allowNull) throws IOException
+   {
       if (path == null)
          throw new IllegalArgumentException("Null path");
 
@@ -393,7 +456,10 @@
          if (child.getName().equals(appliedPath))
             return child;
       }
-      throw new IOException("Child not found " + path + " for " + this);
+      if (allowNull)
+         return null;
+      else
+         throw new IOException("Child not found " + path + " for " + this);
    }
 
    @Override

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java	2008-01-16 09:30:35 UTC (rev 69020)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java	2008-01-16 10:06:10 UTC (rev 69021)
@@ -70,6 +70,11 @@
       return delegate.findChild(path);
    }
 
+   public VirtualFileHandler getChild(String path) throws IOException
+   {
+      return delegate.getChild(path);
+   }
+
    public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
    {
       return delegate.getChildren(ignoreErrors);

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/StructuredVirtualFileHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/StructuredVirtualFileHandler.java	2008-01-16 09:30:35 UTC (rev 69020)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/StructuredVirtualFileHandler.java	2008-01-16 10:06:10 UTC (rev 69021)
@@ -43,4 +43,14 @@
     * @throws IllegalArgumentException for a null name
     */
    VirtualFileHandler createChildHandler(String name) throws IOException;
+
+   /**
+    * Get a virtual file context
+    *
+    * @param name the name
+    * @return the handler or <code>null</code> if cannot create one
+    * @throws IOException for any error accessing the virtual file system
+    * @throws IllegalArgumentException for a null name
+    */
+   VirtualFileHandler getChildHandler(String name) throws IOException;
 }

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileHandler.java	2008-01-16 09:30:35 UTC (rev 69020)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/FileHandler.java	2008-01-16 10:06:10 UTC (rev 69021)
@@ -217,6 +217,17 @@
       return handler;
    }
 
+   public VirtualFileHandler getChild(String path) throws IOException
+   {
+      return structuredGetChild(path);
+   }
+
+   // TODO - this OK?
+   public VirtualFileHandler getChildHandler(String name) throws IOException
+   {
+      return createChildHandler(name);
+   }
+
    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
    {
       in.defaultReadObject();

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/LinkHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/LinkHandler.java	2008-01-16 09:30:35 UTC (rev 69020)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/file/LinkHandler.java	2008-01-16 10:06:10 UTC (rev 69021)
@@ -90,6 +90,16 @@
          return children.get(name);
       }
 
+      public VirtualFileHandler getChild(String path) throws IOException
+      {
+         return structuredGetChild(path);
+      }
+
+      public VirtualFileHandler getChildHandler(String name) throws IOException
+      {
+         return children.get(name);
+      }
+
       public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
       {
          return null;
@@ -198,13 +208,22 @@
    public VirtualFileHandler createChildHandler(String name) throws IOException
    {
       VirtualFileHandler handler = linkTargets.get(name);
-      if( handler == null )
-      {
-         throw new FileNotFoundException("Failed to find link for: "+name+", parent: "+this);
-      }
+      if(handler == null)
+         throw new FileNotFoundException("Failed to find link for: " + name + ", parent: " + this);
+
       return handler;
    }
 
+   public VirtualFileHandler getChild(String path) throws IOException
+   {
+      return structuredGetChild(path);
+   }
+
+   public VirtualFileHandler getChildHandler(String name) throws IOException
+   {
+      return linkTargets.get(name);
+   }
+
    @Override
    protected void doClose()
    {

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractStructuredJarHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractStructuredJarHandler.java	2008-01-16 09:30:35 UTC (rev 69020)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/AbstractStructuredJarHandler.java	2008-01-16 10:06:10 UTC (rev 69021)
@@ -272,6 +272,16 @@
       return child;
    }
 
+   public VirtualFileHandler getChild(String path) throws IOException
+   {
+      return structuredGetChild(path);
+   }
+
+   public VirtualFileHandler getChildHandler(String name) throws IOException
+   {
+      return entryMap.get(name);
+   }
+
    /**
     * Create a new virtual file handler
     *

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryContents.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryContents.java	2008-01-16 09:30:35 UTC (rev 69020)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryContents.java	2008-01-16 10:06:10 UTC (rev 69021)
@@ -160,8 +160,52 @@
 
    public VirtualFileHandler createChildHandler(String name) throws IOException
    {
+      return findChildHandler(name, false);
+   }
+
+   public VirtualFileHandler getChild(String path) throws IOException
+   {
+      if (path == null)
+         throw new IllegalArgumentException("Null path");
+
+      if ("".equals(path))
+         return this;
+
+      if (isJar)
+      {
+         initNestedJar();
+         return njar.findChild(path);
+      }
+      else if (getEntry().isDirectory())
+      {
+         return structuredGetChild(path);
+      }
+      return null;
+   }
+
+   public VirtualFileHandler getChildHandler(String name) throws IOException
+   {
+      return findChildHandler(name, true);
+   }
+
+   /**
+    * Find the handler.
+    * TODO: synchronization on lazy entryMap creation
+    *
+    * @param name the path name
+    * @param allowNull do we allow nulls
+    * @return handler or <code>null</code> is it doesn't exist
+    * @throws IOException for any error
+    */
+   protected synchronized VirtualFileHandler findChildHandler(String name, boolean allowNull) throws IOException
+   {
       if (entryChildren == null)
+      {
+         if (allowNull)
+            return null;
          throw new FileNotFoundException(this + " has no children");
+      }
+
       if (entryMap == null)
       {
          entryMap = new HashMap<String, VirtualFileHandler>();
@@ -169,7 +213,7 @@
             entryMap.put(child.getName(), child);
       }
       VirtualFileHandler child = entryMap.get(name);
-      if (child == null)
+      if (child == null && allowNull == false)
          throw new FileNotFoundException(this + " has no child: " + name);
       return child;
    }

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java	2008-01-16 09:30:35 UTC (rev 69020)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java	2008-01-16 10:06:10 UTC (rev 69021)
@@ -149,13 +149,39 @@
       return getJar().getInputStream(getEntry());
    }
 
+   public VirtualFileHandler createChildHandler(String name) throws IOException
+   {
+      return findChildHandler(name, false);
+   }
+
+   public VirtualFileHandler getChild(String path) throws IOException
+   {
+      return structuredGetChild(path);
+   }
+
+   public VirtualFileHandler getChildHandler(String name) throws IOException
+   {
+      return findChildHandler(name, true);
+   }
+
    /**
+    * Find the handler.
     * TODO: synchronization on lazy entryMap creation
+    *
+    * @param name the path name
+    * @param allowNull do we allow nulls
+    * @return handler or <code>null</code> is it doesn't exist
+    * @throws IOException for any error
     */
-   public VirtualFileHandler createChildHandler(String name) throws IOException
+   protected synchronized VirtualFileHandler findChildHandler(String name, boolean allowNull) throws IOException
    {
       if (entryChildren == null)
+      {
+         if (allowNull)
+            return null;
          throw new FileNotFoundException(this + " has no children");
+      }
+
       if (entryMap == null)
       {
          entryMap = new HashMap<String, VirtualFileHandler>();
@@ -163,7 +189,7 @@
             entryMap.put(child.getName(), child);
       }
       VirtualFileHandler child = entryMap.get(name);
-      if (child == null)
+      if (child == null && allowNull == false)
          throw new FileNotFoundException(this + " has no child: " + name);
       return child;
    }

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NoCopyNestedJarHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NoCopyNestedJarHandler.java	2008-01-16 09:30:35 UTC (rev 69020)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/NoCopyNestedJarHandler.java	2008-01-16 10:06:10 UTC (rev 69021)
@@ -130,6 +130,17 @@
       return njar.findChild(path);
    }
 
+   public VirtualFileHandler getChild(String path) throws IOException
+   {
+      if (path == null)
+         throw new IllegalArgumentException("Null path");
+
+      if ("".equals(path))
+         return this;
+
+      return njar.getChild(path);
+   }
+
    public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
    {
       return njar.getChildren(ignoreErrors);

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java	2008-01-16 09:30:35 UTC (rev 69020)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/jar/SynthenticDirEntryHandler.java	2008-01-16 10:06:10 UTC (rev 69021)
@@ -162,11 +162,39 @@
     * @throws IOException - thrown if there are no children or the
     *                     name does not match a child
     */
-   public synchronized VirtualFileHandler createChildHandler(String name)
-         throws IOException
+   public synchronized VirtualFileHandler createChildHandler(String name) throws IOException
    {
+      return findChildHandler(name, false);
+   }
+
+   public VirtualFileHandler getChild(String path) throws IOException
+   {
+      return structuredGetChild(path);
+   }
+
+   public VirtualFileHandler getChildHandler(String name) throws IOException
+   {
+      return findChildHandler(name, true);
+   }
+
+   /**
+    * Find the handler.
+    * TODO: synchronization on lazy entryMap creation
+    *
+    * @param name the path name
+    * @param allowNull do we allow nulls
+    * @return handler or <code>null</code> is it doesn't exist
+    * @throws IOException for any error
+    */
+   protected synchronized VirtualFileHandler findChildHandler(String name, boolean allowNull) throws IOException
+   {
       if (entryChildren == null)
+      {
+         if (allowNull)
+            return null;
          throw new FileNotFoundException(this + " has no children");
+      }
+
       if (entryMap == null)
       {
          entryMap = new HashMap<String, VirtualFileHandler>();
@@ -174,7 +202,7 @@
             entryMap.put(child.getName(), child);
       }
       VirtualFileHandler child = entryMap.get(name);
-      if (child == null)
+      if (child == null && allowNull == false)
          throw new FileNotFoundException(this + " has no child: " + name);
       return child;
    }

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/memory/MemoryContextHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/memory/MemoryContextHandler.java	2008-01-16 09:30:35 UTC (rev 69020)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/memory/MemoryContextHandler.java	2008-01-16 10:06:10 UTC (rev 69021)
@@ -109,6 +109,16 @@
       return child;
    }
 
+   public VirtualFileHandler getChild(String path) throws IOException
+   {
+      return structuredGetChild(path);
+   }
+
+   public VirtualFileHandler getChildHandler(String name) throws IOException
+   {
+      return entryMap.get(name);
+   }
+
    @Override
    public boolean exists() throws IOException
    {

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledDirectoryHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledDirectoryHandler.java	2008-01-16 09:30:35 UTC (rev 69020)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/AssembledDirectoryHandler.java	2008-01-16 10:06:10 UTC (rev 69021)
@@ -136,6 +136,11 @@
       return structuredFindChild(path);
    }
 
+   public VirtualFileHandler getChildHandler(String name) throws IOException
+   {
+      return childrenMap.get(name);
+   }
+
    @Override
    public VirtualFile getVirtualFile()
    {

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/ByteArrayHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/ByteArrayHandler.java	2008-01-16 09:30:35 UTC (rev 69020)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/vfs/ByteArrayHandler.java	2008-01-16 10:06:10 UTC (rev 69021)
@@ -103,4 +103,9 @@
    {
       throw new IOException("File cannot have children");
    }
+
+   public VirtualFileHandler getChild(String path) throws IOException
+   {
+      throw new IOException("File cannot have children");
+   }
 }

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	2008-01-16 09:30:35 UTC (rev 69020)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VFSContext.java	2008-01-16 10:06:10 UTC (rev 69021)
@@ -89,6 +89,17 @@
    VirtualFileHandler findChild(VirtualFileHandler parent, String path) throws IOException;
    
    /**
+    * Get a child
+    *
+    * @param parent the parent
+    * @param path the path
+    * @return the child or <code>null</code> if not found
+    * @throws IOException for any problem accessing the VFS
+    * @throws IllegalArgumentException for a null parent or name
+    */
+   VirtualFileHandler getChild(VirtualFileHandler parent, String path) throws IOException;
+
+   /**
     * Visit the virtual file system
     * 
     * @param handler the reference handler

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java	2008-01-16 09:30:35 UTC (rev 69020)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java	2008-01-16 10:06:10 UTC (rev 69021)
@@ -174,6 +174,16 @@
    VirtualFileHandler findChild(String path) throws IOException;
 
    /**
+    * Get a child
+    *
+    * @param path the path
+    * @return the child or <code>null</code> if not found
+    * @throws IOException for an error accessing the file system
+    * @throws IllegalStateException if closed
+    */
+   VirtualFileHandler getChild(String path) throws IOException;
+
+   /**
     * Get the VFSContext this file belongs to
     * 
     * @return the context

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/MockSimpleVirtualFileHandler.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/MockSimpleVirtualFileHandler.java	2008-01-16 09:30:35 UTC (rev 69020)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/MockSimpleVirtualFileHandler.java	2008-01-16 10:06:10 UTC (rev 69021)
@@ -53,4 +53,10 @@
       throwIOException("findChild");
       return simpleFindChild(path);
    }
+
+   public VirtualFileHandler getChild(String path) throws IOException
+   {
+      throwIOException("getChild");
+      return simpleFindChild(path, true);
+   }
 }

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/MockStructuredVirtualFileHandler.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/MockStructuredVirtualFileHandler.java	2008-01-16 09:30:35 UTC (rev 69020)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/support/MockStructuredVirtualFileHandler.java	2008-01-16 10:06:10 UTC (rev 69021)
@@ -63,4 +63,19 @@
       }
       throw new IOException("Child not found: " + name + " for " + toURI());
    }
+
+   public VirtualFileHandler getChild(String path) throws IOException
+   {
+      return structuredGetChild(path);
+   }
+
+   public VirtualFileHandler getChildHandler(String name) throws IOException
+   {
+      for (VirtualFileHandler child : getChildren(false))
+      {
+         if (name.equals(child.getName()))
+            return child;
+      }
+      return null;
+   }
 }

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-01-16 09:30:35 UTC (rev 69020)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/VFSUnitTestCase.java	2008-01-16 10:06:10 UTC (rev 69021)
@@ -639,19 +639,36 @@
       }
    }
 
+   public void testGetChildNullPath() throws Exception
+   {
+      MockVFSContext context = registerSimpleVFSContextWithChildren();
+
+      try
+      {
+         VFS vfs = VFS.getVFS(context.getRootURI());
+         vfs.getChild(null);
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IllegalArgumentException.class, t);
+      }
+   }
+
    public void testFindChildSimpleDoesNotExist() throws Exception
    {
       MockVFSContext context = registerSimpleVFSContextWithChildren();
 
+      VFS vfs = VFS.getVFS(context.getRootURI());
       try
       {
-         VFS vfs = VFS.getVFS(context.getRootURI());
          vfs.findChild("doesnotexist");
          fail("Should not be here");
       }
       catch (Throwable t)
       {
          checkThrowable(IOException.class, t);
+         assertNull(vfs.getChild("doesnotexist"));
       }
    }
 
@@ -659,15 +676,16 @@
    {
       MockVFSContext context = registerStructuredVFSContextWithSubChildren();
 
+      VFS vfs = VFS.getVFS(context.getRootURI());
       try
       {
-         VFS vfs = VFS.getVFS(context.getRootURI());
          vfs.findChild("child1/doesnotexist");
          fail("Should not be here");
       }
       catch (Throwable t)
       {
          checkThrowable(IOException.class, t);
+         assertNull(vfs.getChild("child1/doesnotexist"));
       }
    }
 
@@ -688,6 +706,23 @@
       }
    }
 
+   public void testGetChildIOException() throws Exception
+   {
+      MockVFSContext context = registerSimpleVFSContextWithChildren();
+      context.getMockRoot().setIOException("getChild");
+
+      try
+      {
+         VFS vfs = VFS.getVFS(context.getRootURI());
+         vfs.getChild("child1");
+         fail("Should not be here");
+      }
+      catch (Throwable t)
+      {
+         checkThrowable(IOException.class, t);
+      }
+   }
+
    public void testGetAllChildren() throws Exception
    {
       MockVFSContext context = registerSimpleVFSContextWithChildren();




More information about the jboss-cvs-commits mailing list