[jboss-cvs] JBossAS SVN: r74799 - projects/metadata/trunk/src/main/java/org/jboss/metadata/serviceref.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jun 18 11:44:04 EDT 2008


Author: alesj
Date: 2008-06-18 11:44:03 -0400 (Wed, 18 Jun 2008)
New Revision: 74799

Modified:
   projects/metadata/trunk/src/main/java/org/jboss/metadata/serviceref/VirtualFileAdaptor.java
Log:
Fix VFA serialization #2.
They might have . or .. in find child path, hence needing parent.

Modified: projects/metadata/trunk/src/main/java/org/jboss/metadata/serviceref/VirtualFileAdaptor.java
===================================================================
--- projects/metadata/trunk/src/main/java/org/jboss/metadata/serviceref/VirtualFileAdaptor.java	2008-06-18 15:39:04 UTC (rev 74798)
+++ projects/metadata/trunk/src/main/java/org/jboss/metadata/serviceref/VirtualFileAdaptor.java	2008-06-18 15:44:03 UTC (rev 74799)
@@ -22,6 +22,10 @@
 package org.jboss.metadata.serviceref;
 
 import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamField;
+import java.net.URISyntaxException;
 import java.net.URL;
 
 import org.jboss.virtual.VFS;
@@ -39,22 +43,35 @@
  */
 public class VirtualFileAdaptor implements UnifiedVirtualFile
 {
-   private static final long serialVersionUID = 5585747711410469878L;
+   private static final long serialVersionUID = -4509594124653184347L;
 
-   private URL url;
-   private transient VirtualFile root;
+   private static final ObjectStreamField[] serialPersistentFields =
+   {
+      new ObjectStreamField("rootUrl", URL.class),
+      new ObjectStreamField("path", String.class),
+   };
 
+   /** Min info to get full vfs file structure */
+   private URL rootUrl;
+   private String path;
+   /** The virtual file */
+   private transient VirtualFile file;
+
    @Deprecated
-   public VirtualFileAdaptor(VirtualFile root)
+   public VirtualFileAdaptor(VirtualFile file)
    {
-      this.root = root;
+      this.file = file;
    }
 
-   public VirtualFileAdaptor(URL url)
+   public VirtualFileAdaptor(URL rootUrl, String path)
    {
-      if (url == null)
-         throw new IllegalArgumentException("Null url");
-      this.url = url;
+      if (rootUrl == null)
+         throw new IllegalArgumentException("Null root url");
+      if (path == null)
+         throw new IllegalArgumentException("Null path");
+
+      this.rootUrl = rootUrl;
+      this.path = path;
    }
 
    /**
@@ -64,17 +81,21 @@
     * @return virtual file root
     * @throws IOException for any error
     */
-   protected VirtualFile getRoot() throws IOException
+   @SuppressWarnings("deprecation")
+   protected VirtualFile getFile() throws IOException
    {
-      if (root == null)
-         root = VFS.getRoot(url);
-      return root;
+      if (file == null)
+      {
+         VirtualFile root = VFS.getRoot(rootUrl);
+         file = root.findChild(path);
+      }
+      return file;
    }
 
    @SuppressWarnings("deprecation")
    public UnifiedVirtualFile findChild(String child) throws IOException
    {
-      VirtualFile vf = getRoot().findChild(child);
+      VirtualFile vf = getFile().findChild(child);
       return new VirtualFileAdaptor(vf);
    }
 
@@ -82,9 +103,7 @@
    {
       try
       {
-         if (url == null)
-            url = getRoot().toURL();
-         return url;
+         return getFile().toURL();
       }
       catch (Exception e)
       {
@@ -92,13 +111,28 @@
       }
    }
 
-   private void writeObject(java.io.ObjectOutputStream oos) throws java.io.IOException
+   private void writeObject(ObjectOutputStream out) throws IOException, URISyntaxException
    {
-      oos.writeObject(toURL());
+      URL url = rootUrl;
+      if (url == null)
+      {
+         VFS vfs = getFile().getVFS();
+         url = vfs.getRoot().toURL();
+      }
+      String pathName = path;
+      if (pathName == null)
+         pathName = getFile().getPathName();
+
+      ObjectOutputStream.PutField fields = out.putFields();
+      fields.put("rootUrl", url);
+      fields.put("path", pathName);
+      out.writeFields();
    }
 
-   private void readObject(java.io.ObjectInputStream ois) throws java.io.IOException, java.lang.ClassNotFoundException
+   private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
    {
-      url = (URL)ois.readObject();
+      ObjectInputStream.GetField fields = in.readFields();
+      rootUrl = (URL) fields.get("rootUrl", null);
+      path = (String) fields.get("path", null);
    }
 }




More information about the jboss-cvs-commits mailing list