[jboss-cvs] JBossAS SVN: r57487 - projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Oct 7 08:51:38 EDT 2006


Author: scott.stark at jboss.org
Date: 2006-10-07 08:51:37 -0400 (Sat, 07 Oct 2006)
New Revision: 57487

Modified:
   projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java
Log:
An initial implementation of the jar entry getChildren.

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java	2006-10-07 11:34:43 UTC (rev 57486)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarEntryHandler.java	2006-10-07 12:51:37 UTC (rev 57487)
@@ -24,7 +24,9 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Enumeration;
 import java.util.List;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
@@ -49,6 +51,7 @@
    
    /** The jar entry */
    private final JarEntry entry;
+   private transient List<VirtualFileHandler> entryChildren;
    
    /**
     * Create a new JarHandler.
@@ -120,7 +123,9 @@
    public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
    {
       checkClosed();
-      return Collections.emptyList();
+      if( entryChildren == null )
+         entryChildren = findChildren(jar, this);
+      return entryChildren;
    }
 
    public VirtualFileHandler findChild(String path) throws IOException
@@ -132,4 +137,35 @@
       else
          return handler.findChild(getName() +"/" + path);
    }
+
+   /**
+    * Go through the jar entries and find the entries that are the immeadiate children of
+    * the given parent entry. This is based on the entry name being a substring of the
+    * parent name, and the number of '/' separarted paths in the name being equal to the
+    * parent paths + 1.
+    * @param jar
+    * @param parent
+    * @return
+    * @throws IOException
+    */
+   public static List<VirtualFileHandler> findChildren(JarFile jar, JarEntryHandler parent)
+      throws IOException
+   {
+      ArrayList<VirtualFileHandler> children = new ArrayList<VirtualFileHandler>();
+      String parentName = parent.getEntry().getName();
+      String[] parentPaths = parentName.split("/");
+      Enumeration<JarEntry> entries = jar.entries();
+      while( entries.hasMoreElements() )
+      {
+         JarEntry entry = entries.nextElement();
+         String name = entry.getName();
+         if( name.startsWith(parentName) && name.split("/").length == parentPaths.length+1 )
+         {
+            URL childURL = new URL(parent.getURL(), name.substring(parentName.length()));
+            JarEntryHandler child = new JarEntryHandler(parent.getVFSContext(), parent, parent.jar, entry, childURL);
+            children.add(child);
+         }
+      }
+      return children;
+   }
 }




More information about the jboss-cvs-commits mailing list