[gxml/serialization: 33/33] Serializable API change unknown properties disable by default
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml/serialization: 33/33] Serializable API change unknown properties disable by default
- Date: Fri, 20 Dec 2013 21:33:41 +0000 (UTC)
commit 51c043f602265c1447c2b4236158d8b00655b16d
Author: Daniel Espinosa <esodan gmail com>
Date: Thu Dec 19 15:11:57 2013 -0600
Serializable API change unknown properties disable by default
* Serializable deseralize/serialize unknown properties disable by
default. Override get_enable_unknown_serializable_property
gxml/Serializable.vala | 6 +++-
gxml/SerializableGeeArrayList.vala | 1 +
gxml/SerializableGeeDualKeyMap.vala | 1 +
gxml/SerializableGeeHashMap.vala | 1 +
gxml/SerializableGeeTreeMap.vala | 1 +
gxml/SerializableJson.vala | 1 +
gxml/SerializableObjectModel.vala | 40 +++++++++++++++++++----------
test/SerializableGeeCollectionsTest.vala | 23 +++++------------
test/SerializableObjectModelTest.vala | 4 +-
9 files changed, 45 insertions(+), 33 deletions(-)
---
diff --git a/gxml/Serializable.vala b/gxml/Serializable.vala
index 1f79bd6..1e5588a 100644
--- a/gxml/Serializable.vala
+++ b/gxml/Serializable.vala
@@ -1,4 +1,4 @@
-/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 3; tab-width: 3 -*- */
/* Serializable.vala
*
* Copyright (C) 2011-2013 Richard Schwarting <aquarichy gmail com>
@@ -91,6 +91,10 @@ namespace GXml {
*/
public abstract HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
/**
+ *
+ */
+ public abstract bool get_enable_unknown_serializable_property ();
+ /**
* On deserialization stores any { link GXml.Node} not used on this
* object, but exists in current XML file.
*
diff --git a/gxml/SerializableGeeArrayList.vala b/gxml/SerializableGeeArrayList.vala
index 0dd1459..0e6bd80 100644
--- a/gxml/SerializableGeeArrayList.vala
+++ b/gxml/SerializableGeeArrayList.vala
@@ -27,6 +27,7 @@ public class GXml.SerializableArrayList<G> : Gee.ArrayList<G>, Serializable
protected ParamSpec[] properties { get; set; }
public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
public string? serialized_xml_node_value { get; protected set; default=null; }
+ public bool get_enable_unknown_serializable_property () { return false; }
public GLib.HashTable<string,GXml.Node> unknown_serializable_property { get; protected set; }
public virtual bool serialize_use_xml_node_value () { return false; }
diff --git a/gxml/SerializableGeeDualKeyMap.vala b/gxml/SerializableGeeDualKeyMap.vala
index cb9de0f..36bd836 100644
--- a/gxml/SerializableGeeDualKeyMap.vala
+++ b/gxml/SerializableGeeDualKeyMap.vala
@@ -110,6 +110,7 @@ public class GXml.SerializableDualKeyMap<P,S,V> : Object, Serializable
protected ParamSpec[] properties { get; set; }
public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
public string? serialized_xml_node_value { get; protected set; default=null; }
+ public bool get_enable_unknown_serializable_property () { return false; }
public GLib.HashTable<string,GXml.Node> unknown_serializable_property { get; protected set; }
public virtual bool serialize_use_xml_node_value () { return false; }
diff --git a/gxml/SerializableGeeHashMap.vala b/gxml/SerializableGeeHashMap.vala
index 4ff1a12..d478859 100644
--- a/gxml/SerializableGeeHashMap.vala
+++ b/gxml/SerializableGeeHashMap.vala
@@ -26,6 +26,7 @@ public class GXml.SerializableHashMap<K,V> : Gee.HashMap<K,V>, Serializable
protected ParamSpec[] properties { get; set; }
public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
public string? serialized_xml_node_value { get; protected set; default=null; }
+ public bool get_enable_unknown_serializable_property () { return false; }
public GLib.HashTable<string,GXml.Node> unknown_serializable_property { get; protected set; }
public virtual bool serialize_use_xml_node_value () { return false; }
diff --git a/gxml/SerializableGeeTreeMap.vala b/gxml/SerializableGeeTreeMap.vala
index 2ba8d99..b6144f4 100644
--- a/gxml/SerializableGeeTreeMap.vala
+++ b/gxml/SerializableGeeTreeMap.vala
@@ -26,6 +26,7 @@ public class GXml.SerializableTreeMap<K,V> : Gee.TreeMap<K,V>, Serializable
protected ParamSpec[] properties { get; set; }
public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
public string? serialized_xml_node_value { get; protected set; default=null; }
+ public bool get_enable_unknown_serializable_property () { return false; }
public GLib.HashTable<string,GXml.Node> unknown_serializable_property { get; protected set; }
public virtual bool serialize_use_xml_node_value () { return false; }
diff --git a/gxml/SerializableJson.vala b/gxml/SerializableJson.vala
index b505e34..095049a 100644
--- a/gxml/SerializableJson.vala
+++ b/gxml/SerializableJson.vala
@@ -38,6 +38,7 @@ public class GXml.SerializableJson : GLib.Object, Serializable
protected ParamSpec[] properties { get; set; }
public HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
public HashTable<string,GXml.Node> unknown_serializable_property { get; protected set; }
+ public virtual bool get_enable_unknown_serializable_property () { return false; }
public string? serialized_xml_node_value { get; protected set; default = null; }
public virtual bool serialize_use_xml_node_value () { return false; }
diff --git a/gxml/SerializableObjectModel.vala b/gxml/SerializableObjectModel.vala
index baa4907..5651b6a 100644
--- a/gxml/SerializableObjectModel.vala
+++ b/gxml/SerializableObjectModel.vala
@@ -1,4 +1,4 @@
-/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 0; tab-width: 4 -*- */
/* ObjectModel.vala
*
* Copyright (C) 2013 Daniel Espinosa <esodan gmail com>
@@ -26,6 +26,7 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
protected ParamSpec[] properties { get; set; }
public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
public string? serialized_xml_node_value { get; protected set; default=null; }
+ public virtual bool get_enable_unknown_serializable_property () { return false; }
public GLib.HashTable<string,GXml.Node> unknown_serializable_property { get; protected set; }
public virtual bool serialize_use_xml_node_value () { return false; }
@@ -85,7 +86,9 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
public GXml.Node? default_serialize (GXml.Node node) throws GLib.Error
{
+#if DEBUG
stdout.printf (@"$(get_type ().name ()): Serializing on node: $(node.node_name)\n");
+#endif
Document doc;
if (node is Document)
doc = (Document) node;
@@ -95,17 +98,19 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
foreach (ParamSpec spec in list_serializable_properties ()) {
serialize_property (element, spec);
}
- foreach (Node n in unknown_serializable_property.get_values ()) {
- if (n is Element) {
- var e = (Node) doc.create_element (n.node_name);
- n.copy (ref e, true);
- element.append_child (e);
- }
- if (n is Attr) {
- element.set_attribute (n.node_name, n.node_value);
- var a = (Node) element.get_attribute_node (n.node_name);
- n.copy (ref a);
- }
+ if (get_enable_unknown_serializable_property ()) {
+ foreach (Node n in unknown_serializable_property.get_values ()) {
+ if (n is Element) {
+ var e = (Node) doc.create_element (n.node_name);
+ n.copy (ref e, true);
+ element.append_child (e);
+ }
+ if (n is Attr) {
+ element.set_attribute (n.node_name, n.node_value);
+ var a = (Node) element.get_attribute_node (n.node_name);
+ n.copy (ref a);
+ }
+ }
}
// Setting element content
if (serialize_use_xml_node_value ()) {
@@ -114,7 +119,9 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
if (serialized_xml_node_value != null)
t = serialized_xml_node_value;
var tn = doc.create_text_node (t);
+#if DEBUG
stdout.printf (@"SETTING CONTENT FOR: $(get_type ().name ()): $(element.node_name): content '$t'\n");
+#endif
element.append_child (tn);
}
@@ -233,7 +240,9 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
if (n is Text) {
if (serialize_use_xml_node_value ()) {
serialized_xml_node_value = n.node_value;
+#if DEBUG
stdout.printf (@"$(get_type ().name ()): NODE '$(element.node_name)' CONTENT
'$(n.node_value)'\n");
+#endif
}
}
else if (n is Element)
@@ -306,8 +315,11 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
}
}
// Attribute can't be deseralized with standard methods. Up to the implementor.
- this.deserialize_unknown_property (property_node, prop);
- return true;
+ if (get_enable_unknown_serializable_property ()) {
+ this.deserialize_unknown_property (property_node, prop);
+ return true;
+ }
+ return false;
}
public abstract string to_string ();
diff --git a/test/SerializableGeeCollectionsTest.vala b/test/SerializableGeeCollectionsTest.vala
index 9021275..5ecd0fd 100644
--- a/test/SerializableGeeCollectionsTest.vala
+++ b/test/SerializableGeeCollectionsTest.vala
@@ -336,46 +336,37 @@ class SerializableGeeCollectionsTest : GXmlTest
</storage>
</base>""");
var s = new SpaceBase ();
- stdout.printf ("\nDeserializing doc\n");
s.deserialize (doc);
- // Check First Deserialize iteration
if (s.charge_zone == null) {
- stdout.printf (@"ERROR: (1de) No charge zone\n");
+ stdout.printf (@"ERROR: (1de) No charge zone\n");
assert_not_reached ();
}
if (s.charge_zone.spaceships == null) {
- stdout.printf (@"ERROR: (1de) No spaceships\n");
+ stdout.printf (@"ERROR: (1de) No spaceships\n");
assert_not_reached ();
}
if (s.charge_zone.spaceships.size != 2) {
- stdout.printf (@"ERROR: (1de) incorrect spaceships number. Expected 2, got
$(s.charge_zone.spaceships.size)\n");
+ stdout.printf (@"ERROR: (1de) incorrect spaceships number. Expected 2, got
$(s.charge_zone.spaceships.size)\n");
assert_not_reached ();
}
var s1 = s.charge_zone.spaceships.get ("MacToy", "A1234");
if (s1 == null) {
- stdout.printf (@"ERROR: No spaceship MacToy/A1234 found\n");
+ stdout.printf (@"ERROR: No spaceship MacToy/A1234 found\n");
assert_not_reached ();
}
if (s1.spaces == null) {
- stdout.printf (@"ERROR: No spaces for spaceship MacToy/A1234 found\n");
+ stdout.printf (@"ERROR: No spaces for spaceship MacToy/A1234 found\n");
assert_not_reached ();
}
if (s1.spaces.size != 2) {
- stdout.printf (@"ERROR: Incorrect spaces size for spaceship MacToy/A1234. Expected 2, got:
$(s1.spaces.size)\n");
+ stdout.printf (@"ERROR: Incorrect spaces size for spaceship MacToy/A1234. Expected 2, got:
$(s1.spaces.size)\n");
assert_not_reached ();
}
// Check First serialize
- stdout.printf ("\nSerializing to new doc\n");
var ndoc = new Document ();
s.serialize (ndoc);
- stdout.printf (@"Seralized new doc:\n$ndoc\n");
- assert_not_reached ();
- // Check Second deserialize
- stdout.printf ("\nDeserializing new doc\n");
var ns = new SpaceBase ();
ns.deserialize (ndoc);
- //stdout.printf (@"$ndoc");
- //assert_not_reached ();
if (ns.serialized_xml_node_value != null) {
stdout.printf (@"ERROR: wrong base node content, should be '' got:
'$(ns.serialized_xml_node_value)''");
assert_not_reached ();
@@ -419,7 +410,7 @@ class SerializableGeeCollectionsTest : GXmlTest
}
}
}
- if (i != 5) {
+ if (i != 2) {
stdout.printf (@"ERROR: Bad ROOT child nodes. Expected 5, got $(i)\n");
assert_not_reached ();
}
diff --git a/test/SerializableObjectModelTest.vala b/test/SerializableObjectModelTest.vala
index 2260b64..b1010a3 100644
--- a/test/SerializableObjectModelTest.vala
+++ b/test/SerializableObjectModelTest.vala
@@ -74,8 +74,6 @@ public class Manual : ObjectModel
document = "MANUAL DOCUMENTATION";
pages = 3;
set_contents ("TEXT INTO THE MANUAL DOCUMENT");
- init_properties ();
- ignored_serializable_properties.set ("contents", get_class ().find_property ("contents"));
}
public override string to_string ()
@@ -96,6 +94,7 @@ public class Package : ObjectModel
public Array<string> tags { get {return _tags;} }
public override bool property_use_nick () { return true; }
+ public override bool get_enable_unknown_serializable_property () { return true; }
public Package ()
{
@@ -248,6 +247,7 @@ class UnknownAttribute : ObjectModel
public string name { get; set; }
public Gee.ArrayList<int> array { get; set; }
public FakeSerializable fake { get; set; }
+ public override bool get_enable_unknown_serializable_property () { return true; }
}
public enum OptionsEnum
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]