sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1479135 - in /sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata: TreeNode.java TreeTableView.java
Date Sat, 04 May 2013 16:23:49 GMT
Author: desruisseaux
Date: Sat May  4 16:23:48 2013
New Revision: 1479135

URL: http://svn.apache.org/r1479135
Log:
More conservative serialization strategy.

Modified:
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNode.java
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/TreeTableView.java

Modified: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNode.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNode.java?rev=1479135&r1=1479134&r2=1479135&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNode.java [UTF-8]
(original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/TreeNode.java [UTF-8]
Sat May  4 16:23:48 2013
@@ -22,7 +22,6 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.NoSuchElementException;
 import java.util.ConcurrentModificationException;
-import java.io.Serializable;
 import org.apache.sis.util.Debug;
 import org.apache.sis.util.Classes;
 import org.apache.sis.util.iso.Types;
@@ -49,19 +48,21 @@ import org.apache.sis.util.resources.Voc
  *
  * <p>The {@link #newChild()} operation is supported if the node is not a leaf. The
user shall
  * set the identifier and the value, in that order, before any other operation on the new
child.
- * See {@code newChild()} javadpc for an example.</p>
+ * See {@code newChild()} javadoc for an example.</p>
+ *
+ * {@note This class is not serializable because the values of the <code>indexInData</code>
and
+ *        <code>indexInList</code> fields may not be stable. The former may be
invalid if the node
+ *        is serialized and deserialized by two different versions of Apache SIS having properties
+ *        in different order. The second may be invalid if the collection is not guaranteed
to
+ *        preserve order on serialization (e.g. <code>CodeListSet</code> with
user-supplied elements,
+ *        in which case the elements order depends on the instantiation order).}
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
  * @version 0.3
  * @module
  */
-class TreeNode implements Node, Serializable {
-    /**
-     * For cross-version compatibility.
-     */
-    private static final long serialVersionUID = -3499128444388320L;
-
+class TreeNode implements Node {
     /**
      * The collection of {@linkplain #children} to return when the node does not allow children
      * (i.e. is a leaf). This constant is also used as a sentinel value by {@link #isLeaf()}.
@@ -238,11 +239,6 @@ class TreeNode implements Node, Serializ
      */
     static class Element extends TreeNode {
         /**
-         * For cross-version compatibility.
-         */
-        private static final long serialVersionUID = -1837090036924521907L;
-
-        /**
          * The accessor to use for fetching the property names, types and values from the
          * {@link #metadata} object. Note that the value of this field is the same for all
          * siblings.
@@ -340,11 +336,6 @@ class TreeNode implements Node, Serializ
      */
     static final class CollectionElement extends Element {
         /**
-         * For cross-version compatibility.
-         */
-        private static final long serialVersionUID = -1156865958960250473L;
-
-        /**
          * Index of the element in the collection, in iteration order.
          */
         final int indexInList;

Modified: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/TreeTableView.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/TreeTableView.java?rev=1479135&r1=1479134&r2=1479135&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/TreeTableView.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/TreeTableView.java
[UTF-8] Sat May  4 16:23:48 2013
@@ -19,6 +19,9 @@ package org.apache.sis.metadata;
 import java.util.List;
 import java.text.Format;
 import java.io.Serializable;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import org.apache.sis.util.collection.TreeTable;
 import org.apache.sis.util.collection.TableColumn;
 import org.apache.sis.util.collection.TreeTableFormat;
@@ -65,8 +68,10 @@ final class TreeTableView implements Tre
 
     /**
      * The root of the metadata tree.
+     * Consider this field as final - it is modified only on
+     * deserialization by {@link #readObject(ObjectInputStream)}.
      */
-    private final Node root;
+    private transient TreeNode root;
 
     /**
      * The metadata standard implemented by the metadata objects.
@@ -127,4 +132,20 @@ final class TreeTableView implements Tre
             return format.format(this);
         }
     }
+
+    /**
+     * Invoked on serialization. Write the metadata object instead of the {@linkplain #root}
node.
+     */
+    private void writeObject(final ObjectOutputStream out) throws IOException {
+        out.defaultWriteObject();
+        out.writeObject(root.metadata);
+    }
+
+    /**
+     * Invoked on deserialization. Recreate the {@linkplain #root} node from the metadata
object.
+     */
+    private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException
{
+        in.defaultReadObject();
+        root = new TreeNode(this, in.readObject());
+    }
 }



Mime
View raw message