BUG-1431: make InstnaceIdentifier serializable 06/9406/2
authorRobert Varga <rovarga@cisco.com>
Mon, 28 Jul 2014 20:43:38 +0000 (22:43 +0200)
committerRobert Varga <rovarga@cisco.com>
Mon, 28 Jul 2014 21:02:29 +0000 (23:02 +0200)
Straightforward fix for serializability.

Change-Id: I6681e6c85a4ebb8bf23d4dc239204b3a757ea942
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/InstanceIdentifier.java
yang/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/KeyedInstanceIdentifier.java

index e97b5ab98d3a5efbfc1d5e9a1bc708887110404b..9a597152c3ce4f3aa1a4e04e8ff94c230378e0c4 100644 (file)
@@ -14,6 +14,8 @@ import com.google.common.collect.ImmutableCollection;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 
+import java.io.IOException;
+import java.io.Serializable;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
@@ -52,7 +54,8 @@ import org.opendaylight.yangtools.util.HashCodeBuilder;
  * This would be the same as using a path like so, "/nodes/node/openflow:1" to refer to the openflow:1 node
  *
  */
-public class InstanceIdentifier<T extends DataObject> implements Path<InstanceIdentifier<? extends DataObject>>, Immutable {
+public class InstanceIdentifier<T extends DataObject> implements Path<InstanceIdentifier<? extends DataObject>>, Immutable, Serializable {
+    private static final long serialVersionUID = 1L;
     /*
      * Protected to differentiate internal and external access. Internal
      * access is required never to modify the contents. References passed
@@ -497,7 +500,8 @@ public class InstanceIdentifier<T extends DataObject> implements Path<InstanceId
         Class<? extends DataObject> getType();
     }
 
-    private static abstract class AbstractPathArgument<T extends DataObject> implements PathArgument {
+    private static abstract class AbstractPathArgument<T extends DataObject> implements PathArgument, Serializable {
+        private static final long serialVersionUID = 1L;
         private final Class<T> type;
 
         protected AbstractPathArgument(final Class<T> type) {
@@ -542,6 +546,8 @@ public class InstanceIdentifier<T extends DataObject> implements Path<InstanceId
      * @param <T>
      */
     public static final class Item<T extends DataObject> extends AbstractPathArgument<T> {
+        private static final long serialVersionUID = 1L;
+
         public Item(final Class<T> type) {
             super(type);
         }
@@ -560,6 +566,7 @@ public class InstanceIdentifier<T extends DataObject> implements Path<InstanceId
      * @param <T> The identifier of the object
      */
     public static final class IdentifiableItem<I extends Identifiable<T> & DataObject, T extends Identifier<I>> extends AbstractPathArgument<I> {
+        private static final long serialVersionUID = 1L;
         private final T key;
 
         public IdentifiableItem(final Class<I> type, final T key) {
@@ -644,4 +651,18 @@ public class InstanceIdentifier<T extends DataObject> implements Path<InstanceId
          */
         InstanceIdentifier<T> build();
     }
+
+    private void writeObject(final java.io.ObjectOutputStream out) throws IOException {
+        out.writeObject(targetType);
+        out.writeBoolean(wildcarded);
+        out.writeInt(hash);
+        out.write(Iterables.size(pathArguments));
+        for (Object o : pathArguments) {
+            out.writeObject(o);
+        }
+    }
+
+    private void readObject(final java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
+        // TODO Auto-generated method stub
+    }
 }
index 60f891631ae26590e12faba89779ee4f2555e920..88ec004a5b176c76a3ae9d5ca9e795bade96553f 100644 (file)
@@ -15,6 +15,7 @@ package org.opendaylight.yangtools.yang.binding;
  * @param <K> Target key type
  */
 public class KeyedInstanceIdentifier<T extends Identifiable<K> & DataObject, K extends Identifier<T>> extends InstanceIdentifier<T> {
+    private static final long serialVersionUID = 1L;
     private final K key;
 
     KeyedInstanceIdentifier(final Class<T> type, final Iterable<PathArgument> pathArguments, final boolean wildcarded, final int hash, final K key) {