[jboss-osgi-commits] JBoss-OSGI SVN: r102131 - in projects/jboss-osgi/projects/vfs/trunk: vfs30/src/main/java/org/jboss/osgi/vfs30 and 1 other directory.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Tue Mar 9 09:57:54 EST 2010


Author: thomas.diesler at jboss.com
Date: 2010-03-09 09:57:53 -0500 (Tue, 09 Mar 2010)
New Revision: 102131

Removed:
   projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/AssemblyAdaptor21.java
Modified:
   projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/VFSAdaptor21.java
   projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/VirtualFileAdaptor21.java
   projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VFSAdaptor30.java
   projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VirtualFileAdaptor30.java
Log:
Remove VirtualFileAssembly

Deleted: projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/AssemblyAdaptor21.java
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/AssemblyAdaptor21.java	2010-03-09 14:56:02 UTC (rev 102130)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/AssemblyAdaptor21.java	2010-03-09 14:57:53 UTC (rev 102131)
@@ -1,109 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.osgi.vfs21;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.List;
-import java.util.jar.JarFile;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Manifest;
-import java.util.zip.ZipEntry;
-
-import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.osgi.vfs.VirtualFileAssembly;
-import org.jboss.virtual.AssembledDirectory;
-import org.jboss.virtual.VFS;
-
-/**
- * An adaptor to the jboss-vfs-2.1.x VirtualFile. 
- * 
- * @author thomas.diesler at jboss.com
- * @since 02-Mar-2010
- */
-class AssemblyAdaptor21 extends VirtualFileAdaptor21 implements VirtualFileAssembly
-{
-   private AssembledDirectory delegate;
-   
-   public AssemblyAdaptor21(AssembledDirectory assembly) throws IOException, URISyntaxException
-   {
-      super(assembly);
-      this.delegate = assembly;
-   }
-
-   public void addClass(Class<?> clazz) throws IOException
-   {
-      delegate.addClass(clazz);
-   }
-
-   public void addPackage(Class<?> clazz) throws IOException
-   {
-      ClassLoader loader = clazz.getClassLoader();
-      String packageName = clazz.getName().replace('.', '/');
-      packageName = packageName.substring(0, packageName.lastIndexOf('/'));
-      
-      URL rootURL = loader.getResource(packageName);
-      for (org.jboss.virtual.VirtualFile child : VFS.getRoot(rootURL).getChildren())
-      {
-         if (child.getName().endsWith(".class"))
-            delegate.addChild(child);
-      }
-   }
-
-   public void addManifest(Manifest manifest) throws IOException
-   {
-      ByteArrayOutputStream baos = new ByteArrayOutputStream();
-      manifest.write(baos);
-      AssembledDirectory dir = delegate.mkdir("META-INF");
-      dir.addBytes(baos.toByteArray(), "MANIFEST.MF");
-   }
-
-   public File pack() throws IOException
-   {
-      File tmpFile = File.createTempFile("assembly", ".jar");
-      tmpFile.deleteOnExit();
-      
-      FileOutputStream fos = new FileOutputStream(tmpFile);
-      JarOutputStream jos = new JarOutputStream(fos);
-      for (org.jboss.virtual.VirtualFile child : delegate.getChildrenRecursively())
-      {
-         ZipEntry ze = new ZipEntry(child.getName());
-         jos.putNextEntry(ze);
-         
-      }
-      return null;
-   }
-
-   public void addPath(VirtualFile file) throws IOException
-   {
-      delegate.addPath(((VirtualFileAdaptor21)file).getDelegate());
-   }
-
-   public void addResources(Class<?> reference, String[] includes, String[] excludes)
-   {
-      delegate.addResources(reference, includes, excludes);
-   }
-}

Modified: projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/VFSAdaptor21.java
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/VFSAdaptor21.java	2010-03-09 14:56:02 UTC (rev 102130)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/VFSAdaptor21.java	2010-03-09 14:57:53 UTC (rev 102131)
@@ -22,13 +22,10 @@
 package org.jboss.osgi.vfs21;
 
 import java.io.IOException;
-import java.net.URISyntaxException;
 import java.net.URL;
 
 import org.jboss.osgi.vfs.VFSAdaptor;
 import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.osgi.vfs.VirtualFileAssembly;
-import org.jboss.virtual.AssembledDirectory;
 
 /**
  * An adaptor to the jboss-vfs-2.1.x VFS. 
@@ -41,33 +38,42 @@
    public VirtualFile getChild(URL url) throws IOException
    {
       org.jboss.virtual.VirtualFile root = org.jboss.virtual.VFS.getRoot(url);
-      return new VirtualFileAdaptor21(root);
+      return new VirtualFileAdaptor21(root, root);
    }
 
-   public VirtualFileAssembly createVirtualFileAssembly(String name) throws IOException, URISyntaxException
-   {
-      AssembledDirectory assembly = AssembledDirectory.createAssembledDirectory(name, "");
-      return new AssemblyAdaptor21(assembly);
-   }
-
    public VirtualFile adapt(Object virtualFile)
    {
       if (virtualFile == null)
          return null;
-      
+
       if (virtualFile instanceof org.jboss.virtual.VirtualFile == false)
          throw new IllegalArgumentException("Not a org.jboss.virtual.VirtualFile: " + virtualFile);
+
+      org.jboss.virtual.VirtualFile file = (org.jboss.virtual.VirtualFile)virtualFile;
+      org.jboss.virtual.VirtualFile root = file;
+      try
+      {
+         org.jboss.virtual.VirtualFile parent = file.getParent();
+         while (parent != null)
+         {
+            root = parent;
+            parent = parent.getParent();
+         }
+      }
+      catch (IOException ex)
+      {
+         throw new IllegalStateException("Cannot obtain root", ex);
+      }
       
-      return new VirtualFileAdaptor21((org.jboss.virtual.VirtualFile)virtualFile);
+      return new VirtualFileAdaptor21(root, file);
    }
 
    public Object adapt(VirtualFile virtualFile)
    {
       if (virtualFile == null)
          return null;
-      
+
       VirtualFileAdaptor21 adaptor = (VirtualFileAdaptor21)virtualFile;
       return adaptor.getDelegate();
    }
 }
-

Modified: projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/VirtualFileAdaptor21.java
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/VirtualFileAdaptor21.java	2010-03-09 14:56:02 UTC (rev 102130)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/VirtualFileAdaptor21.java	2010-03-09 14:57:53 UTC (rev 102131)
@@ -32,6 +32,7 @@
 import java.util.List;
 
 import org.jboss.osgi.vfs.VirtualFile;
+import org.jboss.virtual.VFSUtils;
 
 /**
  * An adaptor to the jboss-vfs-2.1.x VirtualFile. 
@@ -41,13 +42,18 @@
  */
 class VirtualFileAdaptor21 implements VirtualFile
 {
+   private org.jboss.virtual.VirtualFile root;
    private org.jboss.virtual.VirtualFile delegate;
 
-   VirtualFileAdaptor21(org.jboss.virtual.VirtualFile delegate)
+   VirtualFileAdaptor21(org.jboss.virtual.VirtualFile root, org.jboss.virtual.VirtualFile delegate) 
    {
+      if (root == null)
+         throw new IllegalStateException("Null root");
       if (delegate == null)
          throw new IllegalStateException("Null delegate");
+      
       this.delegate = delegate;
+      this.root = root;
    }
 
    org.jboss.virtual.VirtualFile getDelegate()
@@ -62,7 +68,17 @@
 
    public String getPathName()
    {
-      return delegate.getPathName();
+      String pathName = "";
+      try
+      {
+         pathName = VFSUtils.getRealURL(root).getPath();
+      }
+      catch (Exception ex)
+      {
+         // ignore
+      }
+      pathName += delegate.getPathName();
+      return pathName;
    }
 
    public boolean isFile() throws IOException
@@ -70,6 +86,11 @@
       return delegate.isLeaf();
    }
 
+   public boolean isDirectory() throws IOException
+   {
+      return delegate.isLeaf() == false;
+   }
+
    public URL toURL() throws MalformedURLException, URISyntaxException
    {
       return delegate.toURL();
@@ -80,20 +101,26 @@
       delegate.close();
    }
 
+   public VirtualFile getParent() throws IOException
+   {
+      org.jboss.virtual.VirtualFile parent = delegate.getParent();
+      return parent != null ? new VirtualFileAdaptor21(root, parent) : null;
+   }
+
    public VirtualFile getChild(String path) throws IOException
    {
       org.jboss.virtual.VirtualFile child = delegate.getChild(path);
       if (child == null)
          return null;
 
-      return new VirtualFileAdaptor21(child);
+      return new VirtualFileAdaptor21(root, child);
    }
 
    public List<VirtualFile> getChildrenRecursively() throws IOException
    {
       List<VirtualFile> files = new ArrayList<VirtualFile>();
       for (org.jboss.virtual.VirtualFile child : delegate.getChildrenRecursively())
-         files.add(new VirtualFileAdaptor21(child));
+         files.add(new VirtualFileAdaptor21(root, child));
 
       return Collections.unmodifiableList(files);
    }

Modified: projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VFSAdaptor30.java
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VFSAdaptor30.java	2010-03-09 14:56:02 UTC (rev 102130)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VFSAdaptor30.java	2010-03-09 14:57:53 UTC (rev 102131)
@@ -27,7 +27,6 @@
 
 import org.jboss.osgi.vfs.VFSAdaptor;
 import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.osgi.vfs.VirtualFileAssembly;
 import org.jboss.vfs.util.automount.Automounter;
 
 /**
@@ -55,11 +54,6 @@
       return new VirtualFileAdaptor30(root);
    }
 
-   public VirtualFileAssembly createVirtualFileAssembly(String name) throws IOException, URISyntaxException
-   {
-      throw new IllegalArgumentException("not implemented");
-   }
-
    public VirtualFile adapt(Object virtualFile)
    {
       if (virtualFile == null)

Modified: projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VirtualFileAdaptor30.java
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VirtualFileAdaptor30.java	2010-03-09 14:56:02 UTC (rev 102130)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VirtualFileAdaptor30.java	2010-03-09 14:57:53 UTC (rev 102131)
@@ -71,11 +71,22 @@
       return delegate.isFile();
    }
 
+   public boolean isDirectory() throws IOException
+   {
+      return delegate.isDirectory();
+   }
+
    public URL toURL() throws MalformedURLException, URISyntaxException
    {
       return delegate.toURL();
    }
 
+   public VirtualFile getParent()
+   {
+      org.jboss.vfs.VirtualFile parent = delegate.getParent();
+      return parent != null ? new VirtualFileAdaptor30(parent) : null;
+   }
+
    public VirtualFile getChild(String path) throws IOException
    {
       org.jboss.vfs.VirtualFile child = delegate.getChild(path);
@@ -137,4 +148,22 @@
       if (Automounter.isMounted(delegate))
          Automounter.cleanup(delegate);
    }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      return delegate.equals(obj);
+   }
+
+   @Override
+   public int hashCode()
+   {
+      return delegate.hashCode();
+   }
+
+   @Override
+   public String toString()
+   {
+      return delegate.toString();
+   }
 }



More information about the jboss-osgi-commits mailing list