[gxml/serialization] Fixed bug when using custome node name
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml/serialization] Fixed bug when using custome node name
- Date: Fri, 1 Nov 2013 20:01:33 +0000 (UTC)
commit 234aef6a98689eda38d385baf8b0d024d9e29c54
Author: Daniel Espinosa <esodan gmail com>
Date: Thu Oct 31 18:21:51 2013 -0600
Fixed bug when using custome node name
* Added test case for custome node name
* Added test case when overriding deserialize
* Added documentation to Serializable.ignored_serializable_properties
gxml/Serializable.vala | 11 +++++-
gxml/SerializableObjectModel.vala | 2 +-
test/SerializableObjectModelTest.vala | 65 +++++++++++++++++++++++++++++++--
3 files changed, 73 insertions(+), 5 deletions(-)
---
diff --git a/gxml/Serializable.vala b/gxml/Serializable.vala
index 4961cc0..0b5b110 100644
--- a/gxml/Serializable.vala
+++ b/gxml/Serializable.vala
@@ -85,10 +85,19 @@ namespace GXml {
/**
* Store all properties to be ignored on serialization.
*
+ * Use property's cannonical name as key and its { link GLib.ParamSpec}. To
+ * get the last one use { link GLib.get_class} and use, again, property's
+ * cannonical name to find it.
+ *
+ * Long named properties like this 'ignored_serializable_properties' are stored
+ * by GObject using its cannonical name, then you must use it as key, in this
+ * case use 'ignored-serializable-properties'.
+ *
* This property is ignored on serialisation.
*
* Implementors: By default { link list_serializable_properties} initialize
- * this property to store all public properties, except this one.
+ * this property to store all public properties, except this one. Make shure t
+ * call { link init_properties()} before add new propeties.
*/
public abstract HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get;
protected set; }
/**
diff --git a/gxml/SerializableObjectModel.vala b/gxml/SerializableObjectModel.vala
index 32dd54b..a20aa18 100644
--- a/gxml/SerializableObjectModel.vala
+++ b/gxml/SerializableObjectModel.vala
@@ -169,7 +169,7 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
element = (Element) node;
else
element = (Element) doc.document_element;
- return_val_if_fail (element.node_name.down () == serializable_node_name, null);
+ return_val_if_fail (element.node_name.down () == serializable_node_name.down (), null);
foreach (Attr attr in element.attributes.get_values ())
{
//GLib.message (@"Deseralizing Attribute: $(attr.name)");
diff --git a/test/SerializableObjectModelTest.vala b/test/SerializableObjectModelTest.vala
index 82e2d91..e4be236 100644
--- a/test/SerializableObjectModelTest.vala
+++ b/test/SerializableObjectModelTest.vala
@@ -205,24 +205,50 @@ public class Cpu : ObjectModel
}
}
+class NodeName : ObjectModel
+{
+ public bool invalid { get; set; default = true; }
+ public NodeName ()
+ {
+ serializable_node_name = "NodeName";
+ }
+}
+
class Configuration : ObjectModel
{
+ public bool invalid { get; set; default = true; }
public string device { get; set; }
public Configuration ()
{
serializable_property_use_nick = true;
serializable_node_name = "Configuration";
+ init_properties (); // initializing properties to be ignored by default
+ ignored_serializable_properties.set ("invalid",
+ get_class ().find_property("invalid"));
}
public override GXml.Node? serialize (GXml.Node node) throws GLib.Error
{
- //stdout.printf ("CONFIGURATION: Before serialize\n");
var n = default_serialize (node);
- //stdout.printf ("CONFIGURATION: After serialize\n");
n.add_namespace_attr ("http://www.gnome.org/gxml/0.4", "om");
- //stdout.printf (@"CONFIGURATION: Created Node: $node\n");
return n;
}
+ public override GXml.Node? deserialize (GXml.Node node) throws GLib.Error
+ {
+ //stdout.printf (@"CONFIGURATOR: Namespaces Check");
+ GXml.Node n;
+ if (node is Document)
+ n = (GXml.Node) (((GXml.Document) node).document_element);
+ else
+ n = node;
+
+ foreach (GXml.Node ns in n.namespace_definitions) {
+ //stdout.printf (@"Namespace = $(ns.node_value)");
+ if (ns.node_name == "om" && ns.node_value == "http://www.gnome.org/gxml/0.4")
+ invalid = false;
+ }
+ return default_deserialize (node);
+ }
}
class SerializableObjectModelTest : GXmlTest
@@ -667,6 +693,39 @@ class SerializableObjectModelTest : GXmlTest
assert_not_reached ();
}
});
+ Test.add_func ("/gxml/serializable/object_model/override_deserialize",
+ () => {
+ var doc = new Document.from_string ("""<?xml version="1.0"?>
+<Configuration xmlns:om="http://www.gnome.org/gxml/0.4" device="Sampler"/>""");
+ var configuration = new Configuration ();
+ try {
+ //stdout.printf (@"$doc");
+ configuration.deserialize (doc);
+ if (configuration.invalid == true) {
+ stdout.printf ("CONFIGURATION: deserialize is INVALID\n");
+ foreach (GXml.Node n in doc.document_element.namespace_definitions) {
+ stdout.printf (@"CONFIGURATION: namespace:
$(n.node_value)\n");
+ }
+ assert_not_reached ();
+ }
+ }
+ catch (GLib.Error e) {
+ stdout.printf (@"Error: $(e.message)");
+ assert_not_reached ();
+ }
+ });
+ Test.add_func ("/gxml/serializable/object_model/custome_node_name",
+ () => {
+ var doc = new Document.from_string ("""<?xml version="1.0"?><NodeName />""");
+ var nodename = new NodeName ();
+ try {
+ nodename.deserialize (doc);
+ }
+ catch (GLib.Error e) {
+ stdout.printf (@"Error: $(e.message)");
+ assert_not_reached ();
+ }
+ });
}
static void serialize_manual_check (Element element, Manual manual)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]