[gxml/serialization] Fixed Serializable Gee Collection with multiple type nodes



commit 479a73942627fe0c889c28afa97d8120afafb4ef
Author: Daniel Espinosa <esodan gmail com>
Date:   Thu Nov 28 10:33:39 2013 -0600

    Fixed Serializable Gee Collection with multiple type nodes
    
    * SerializableObjectModel fixed warnning message and just show
      when DEBUG is defined

 gxml/SerializableGeeArrayList.vala      |    9 ++++++---
 gxml/SerializableGeeDualKeyMap.vala     |    9 ++++++---
 gxml/SerializableGeeTreeMap.vala        |    9 ++++++---
 gxml/SerializableObjectModel.vala       |    4 ++--
 test/SerializableGeeDualKeyMapTest.vala |    2 +-
 5 files changed, 21 insertions(+), 12 deletions(-)
---
diff --git a/gxml/SerializableGeeArrayList.vala b/gxml/SerializableGeeArrayList.vala
index 567e7c0..357c524 100644
--- a/gxml/SerializableGeeArrayList.vala
+++ b/gxml/SerializableGeeArrayList.vala
@@ -114,14 +114,17 @@ public class GXml.SerializableArrayList<G> : Gee.ArrayList<G>, Serializable
                     throws GLib.Error
   {
     if (!element_type.is_a (typeof (GXml.Serializable))) {
-      throw new SerializableError.UNSUPPORTED_TYPE ("Value type '%s' is unsupported", element_type.name ());
+      throw new SerializableError.UNSUPPORTED_TYPE ("%s: Value type '%s' is unsupported", 
+                                                    this.get_type ().name (), element_type.name ());
     }
     if (node is Element) {
       foreach (GXml.Node n in node.child_nodes) {
         if (n is Element) {
           var obj = (Serializable) Object.new (element_type);
-          obj.deserialize (n);
-          add (obj);
+          if (n.node_name == ((Serializable) obj).node_name ()) {
+            obj.deserialize (n);
+            add (obj);
+          }
         }
       }
     }
diff --git a/gxml/SerializableGeeDualKeyMap.vala b/gxml/SerializableGeeDualKeyMap.vala
index 16814e0..bd56620 100644
--- a/gxml/SerializableGeeDualKeyMap.vala
+++ b/gxml/SerializableGeeDualKeyMap.vala
@@ -199,14 +199,17 @@ public class GXml.SerializableDualKeyMap<P,S,V> : Object, Serializable
   {
     if (!(value_type.is_a (typeof (GXml.Serializable)) &&
         value_type.is_a (typeof (SerializableMapDualId)))) {
-      throw new SerializableError.UNSUPPORTED_TYPE ("Value type '%s' is unsupported", value_type.name ());
+      throw new SerializableError.UNSUPPORTED_TYPE ("%s: Value type '%s' is unsupported", 
+                                                    this.get_type ().name (), value_type.name ());
     }
     if (node is Element) {
       foreach (GXml.Node n in node.child_nodes) {
         if (n is Element) {
           var obj = (SerializableMapDualId<P,S>) Object.new (value_type);
-          ((Serializable) obj).deserialize (n);
-          @set (obj.primary_id (), obj.secondary_id (), obj);
+          if (n.node_name == ((Serializable) obj).node_name ()) {
+            ((Serializable) obj).deserialize (n);
+            @set (obj.primary_id (), obj.secondary_id (), obj);
+          }
         }
       }
     }
diff --git a/gxml/SerializableGeeTreeMap.vala b/gxml/SerializableGeeTreeMap.vala
index f414e68..5cd85c8 100644
--- a/gxml/SerializableGeeTreeMap.vala
+++ b/gxml/SerializableGeeTreeMap.vala
@@ -114,7 +114,8 @@ public class GXml.SerializableTreeMap<K,V> : Gee.TreeMap<K,V>, Serializable
   {
     if (!(value_type.is_a (typeof (GXml.Serializable)) &&
         value_type.is_a (typeof (SerializableMapId)))) {
-      throw new SerializableError.UNSUPPORTED_TYPE ("Value type '%s' is unsupported", value_type.name ());
+      throw new SerializableError.UNSUPPORTED_TYPE ("%s: Value type '%s' is unsupported", 
+                                                    this.get_type ().name (), value_type.name ());
     }
     if (node is Element) {
       foreach (GXml.Node n in node.child_nodes) {
@@ -123,8 +124,10 @@ public class GXml.SerializableTreeMap<K,V> : Gee.TreeMap<K,V>, Serializable
           stdout.printf (@"Node $(node.node_name) for type '$(get_type ().name ())'\n");
 #endif
           var obj = Object.new (value_type);
-          ((Serializable) obj).deserialize (n);
-          @set (((SerializableMapId<K>) obj).id (), obj);
+          if (n.node_name == ((Serializable) obj).node_name ()) {
+            ((Serializable) obj).deserialize (n);
+            @set (((SerializableMapId<K>) obj).id (), obj);
+          }
         }
       }
     }
diff --git a/gxml/SerializableObjectModel.vala b/gxml/SerializableObjectModel.vala
index b2eaf70..6f4131d 100644
--- a/gxml/SerializableObjectModel.vala
+++ b/gxml/SerializableObjectModel.vala
@@ -204,10 +204,10 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
       message (@"WARNING: Object type '$(get_type ().name ())' have no Node Name defined");
       assert_not_reached ();
     }
+#if DEBUG
     if (element.node_name.down () != node_name ().down ()) {
-      message (@"WARNING: wrong node name is '$(element.node_name.down ())' is different to '$(node_name 
().down ())'");
+      GLib.warning (@"Actual node's name is '$(element.node_name.down ())' expected '$(node_name ().down 
())'");
     }
-#if DEBUG
     stdout.printf (@"Deserialize Node: $(element.node_name)\n");
     stdout.printf (@"Node is: $(element)\n\n");
     stdout.printf (@"Attributes in Node: $(element.node_name)\n");
diff --git a/test/SerializableGeeDualKeyMapTest.vala b/test/SerializableGeeDualKeyMapTest.vala
index 3a28c53..cb9b71a 100644
--- a/test/SerializableGeeDualKeyMapTest.vala
+++ b/test/SerializableGeeDualKeyMapTest.vala
@@ -167,7 +167,7 @@ class SerializableGeeDualKeyMapTest : GXmlTest
     () => {
       try {
         var doc = new Document.from_string ("""<?xml version="1.0"?>
-<root><spaces name="Small" owner="Wall"/><spaces name="Smallest" owner="Wall"/><spaces name="Big" 
owner="Floor"/><spaces name="Bigger" owner="Floor"/></root>""");
+<root><spaces name="Small" owner="Wall"/><spaces name="Smallest" owner="Wall"/><spaces name="Big" 
owner="Floor"/><spaces name="Bigger" owner="Floor"/><spark /></root>""");
         var c = new SerializableDualKeyMap<string,string,Spaces> ();
         c.deserialize (doc.document_element);
         if (c.size != 4) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]