[cp-patches] FYI: BeanContextSupport.serialize() and deserialize() implemented

David Gilbert david.gilbert at object-refinery.com
Thu Nov 23 09:58:20 UTC 2006


This patch (committed) implements a couple of utility methods in the 
BeanContextSupport class:

2006-11-23  David Gilbert  <david.gilbert at object-refinery.com>

    * java/beans/beancontext/BeanContextSupport.java
    (deserialize): Implemented,
    (serialize): Implemented.

I'll commit the corresponding Mauve tests shortly.

Regards,

Dave
-------------- next part --------------
Index: java/beans/beancontext/BeanContextSupport.java
===================================================================
RCS file: /sources/classpath/classpath/java/beans/beancontext/BeanContextSupport.java,v
retrieving revision 1.20
diff -u -r1.20 BeanContextSupport.java
--- java/beans/beancontext/BeanContextSupport.java	22 Nov 2006 22:45:11 -0000	1.20
+++ java/beans/beancontext/BeanContextSupport.java	23 Nov 2006 09:23:11 -0000
@@ -422,10 +422,25 @@
     return new BCSChild(targetChild, peer);
   }
 
+  /**
+   * Deserializes objects (written by {@link #serialize(ObjectOutputStream, 
+   * Collection)}) and adds them to the specified collection.
+   * 
+   * @param ois  the input stream (<code>null</code> not permitted).
+   * @param coll  the collection to add the objects to (<code>null</code> not
+   *     permitted).
+   *     
+   * @throws ClassNotFoundException
+   * @throws IOException
+   * 
+   * @see #serialize(ObjectOutputStream, Collection)
+   */
   protected final void deserialize (ObjectInputStream ois, Collection coll)
-    throws ClassNotFoundException, IOException, NotImplementedException
+    throws ClassNotFoundException, IOException
   {
-    throw new Error ("Not implemented");
+    int itemCount = ois.readInt();
+    for (int i = 0; i < itemCount; i++)
+      coll.add(ois.readObject());
   }
 
   /**
@@ -829,10 +844,34 @@
     throw new UnsupportedOperationException();
   }
 
-  protected final void serialize (ObjectOutputStream oos, Collection coll)
-    throws IOException, NotImplementedException
+  /**
+   * Writes the items in the collection to the specified output stream.  Items
+   * in the collection that are not instances of {@link Serializable} 
+   * (this includes <code>null</code>) are simply ignored.
+   * 
+   * @param oos  the output stream (<code>null</code> not permitted).
+   * @param coll  the collection (<code>null</code> not permitted).
+   * 
+   * @throws IOException
+   * 
+   * @see #deserialize(ObjectInputStream, Collection)
+   */
+  protected final void serialize(ObjectOutputStream oos, Collection coll)
+    throws IOException
   {
-    throw new Error ("Not implemented");
+    Object[] items = coll.toArray();
+    int itemCount = 0;
+    for (int i = 0; i < items.length; i++)
+      {
+        if (items[i] instanceof Serializable)
+          itemCount++;
+      }
+    oos.writeInt(itemCount);
+    for (int i = 0; i < items.length; i++)
+      {
+        if (items[i] instanceof Serializable)
+          oos.writeObject(items[i]);
+      }
   }
 
   /**


More information about the Classpath-patches mailing list