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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jun 23 16:48:01 EDT 2008


Author: mstruk
Date: 2008-06-23 16:48:01 -0400 (Mon, 23 Jun 2008)
New Revision: 74914

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/DelegatingHandler.java
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARSerializationUnitTestCase.java
Log:
JBVFS-36, fixed navigation / serialization issues that exposed incomplete peer model implementation

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-06-23 19:15:07 UTC (rev 74913)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java	2008-06-23 20:48:01 UTC (rev 74914)
@@ -49,6 +49,7 @@
  * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @author Scott.Stark at jboss.org
+ * @author <a href="strukelj at parsek.net">Marko Strukelj</a>
  * @version $Revision: 1.1 $
  */
 public abstract class AbstractVirtualFileHandler implements VirtualFileHandler
@@ -191,6 +192,11 @@
       return name;
    }
 
+   /**
+    * Get a pathName relative to most outer context (contexts can be mounted one within other)
+    *
+    * @return  pathName
+    */
    public String getPathName()
    {
       if (vfsPath == null)
@@ -212,11 +218,16 @@
       this.vfsPath = path;
    }
 
+   /**
+    * Get a pathName relative to local context
+    *
+    * @return pathName
+    */
    public String getLocalPathName()
    {
       try
       {
-         VirtualFileHandler handler = getVFSContext().getRoot();
+         VirtualFileHandler handler = getLocalVFSContext().getRoot();
          String rootPathName = handler.getPathName();
          String pathName = getPathName();
          int len = rootPathName.length();
@@ -229,7 +240,7 @@
       }
       catch (IOException ex)
       {
-         log.warn("Failed to compose local path name: context: " + getVFSContext() + ", name: " + getName(), ex);
+         log.warn("Failed to compose local path name: context: " + getLocalVFSContext() + ", name: " + getName(), ex);
       }
 
       return getPathName();
@@ -350,20 +361,60 @@
       increment();
       return new VirtualFile(this);
    }
-   
+
+   /**
+    * Get this handler's parent.
+    * If this handler represents a root of the context mounted within another context
+    * a parent from the outer context will be returned.
+    *
+    * @return parent handler
+    * @throws IOException for any error
+    */
    public VirtualFileHandler getParent() throws IOException
    {
       checkClosed();
+      if (parent == null)
+      {
+         if (context instanceof AbstractVFSContext)
+         {
+            AbstractVFSContext avfs = (AbstractVFSContext) context;
+            VirtualFileHandler peer = avfs.getRootPeer();
+            if (peer != null)
+               return peer.getParent();
+         }
+      }
       return parent;
    }
-   
+
+   /**
+    * Get this handler's most outer context (contexts can be mounted one within other).
+    *
+    * @return context
+    */
    public VFSContext getVFSContext()
    {
       checkClosed();
+      if (context instanceof AbstractVFSContext)
+      {
+         AbstractVFSContext avfs = (AbstractVFSContext) context;
+         VirtualFileHandler peer = avfs.getRootPeer();
+         if (peer != null)
+            return peer.getVFSContext();
+      }
       return context;
    }
 
    /**
+    * Get this handler's local context
+    *
+    * @return context
+    */
+   public VFSContext getLocalVFSContext()
+   {
+      return context;
+   }
+
+   /**
     * Increment the reference count
     * 
     * @return the resulting count
@@ -391,7 +442,7 @@
    protected void checkClosed() throws IllegalStateException 
    {
       if (references.get() < 0)
-         throw new IllegalStateException("Closed " + this);
+         throw new IllegalStateException("Closed " + toStringLocal());
    }
    
    public void close() 
@@ -524,12 +575,25 @@
       buffer.append('@');
       buffer.append(System.identityHashCode(this));
       buffer.append("[path=").append(getPathName());
+      buffer.append(" context=").append(getVFSContext().getRootURI());
+      buffer.append(" real=").append(safeToURLString());
+      buffer.append(']');
+      return buffer.toString();
+   }
+
+   public String toStringLocal()
+   {
+      StringBuilder buffer = new StringBuilder();
+      buffer.append(getClass().getSimpleName());
+      buffer.append('@');
+      buffer.append(System.identityHashCode(this));
+      buffer.append("[path=").append(getLocalPathName());
       buffer.append(" context=").append(context.getRootURI());
       buffer.append(" real=").append(safeToURLString());
       buffer.append(']');
       return buffer.toString();
    }
-   
+
    @Override
    public int hashCode()
    {
@@ -580,7 +644,7 @@
       throws IOException
    {
       PutField fields = out.putFields();
-      fields.put("rootURI", getVFSContext().getRootURI());
+      fields.put("rootURI", getLocalVFSContext().getRootURI());
       fields.put("parent", parent);
       fields.put("name", name);
       fields.put("vfsUrl", vfsUrl);

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-06-23 19:15:07 UTC (rev 74913)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/DelegatingHandler.java	2008-06-23 20:48:01 UTC (rev 74914)
@@ -88,20 +88,13 @@
       return delegate;
    }
 
-   public VirtualFileHandler getParent() throws IOException
-   {
-      VirtualFileHandler parent = getDelegate().getParent();
-      if (parent != null)
-         return parent;
-
-      return super.getParent();
-   }
-
    public VirtualFileHandler getChild(String path) throws IOException
    {
-      if ("".equals(path))
+      VirtualFileHandler child = getDelegate().getChild(path);
+      if (getDelegate().equals(child))
          return this;
-      return getDelegate().getChild(path);
+      else
+         return child;
    }
 
    public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java	2008-06-23 19:15:07 UTC (rev 74913)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java	2008-06-23 20:48:01 UTC (rev 74914)
@@ -88,16 +88,19 @@
 
    public long getLastModified() throws IOException
    {
+      checkClosed();
       return getZipEntryContext().getLastModified(this);
    }
 
    public long getSize() throws IOException
    {
+      checkClosed();
       return getZipEntryContext().getSize(this);
    }
 
    public boolean exists() throws IOException
    {
+      checkClosed();
       return getZipEntryContext().exists(this);
    }
 
@@ -126,11 +129,13 @@
 
    public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
    {
+      checkClosed();
       return getZipEntryContext().getChildren(this, ignoreErrors);
    }
 
    public VirtualFileHandler getChild(String path) throws IOException
    {
+      checkClosed();
       return structuredFindChild(path);
    }
 
@@ -149,6 +154,6 @@
 
    private ZipEntryContext getZipEntryContext()
    {
-      return ((ZipEntryContext) getVFSContext());
+      return ((ZipEntryContext) getLocalVFSContext());
    }
 }

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARSerializationUnitTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARSerializationUnitTestCase.java	2008-06-23 19:15:07 UTC (rev 74913)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JARSerializationUnitTestCase.java	2008-06-23 20:48:01 UTC (rev 74914)
@@ -264,7 +264,7 @@
       three = serializeDeserialize(three, VirtualFile.class);
       testVirtualFileAdaptor(three, "test3.txt");
       textThree = three.findChild("test3.txt");
-      testVirtualFileAdaptor(textThree, "../text3.txt");
+      testVirtualFileAdaptor(textThree, "../test3.txt");
 
       two = serializeDeserialize(two, VirtualFile.class);
       testVirtualFileAdaptor(two, "test2.txt");




More information about the jboss-cvs-commits mailing list