[gxml/serialization] Serializable API change for node's name and use_nick
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml/serialization] Serializable API change for node's name and use_nick
- Date: Tue, 12 Nov 2013 18:34:49 +0000 (UTC)
commit 67c82680a8839365f63469c2181f47b10acba62a
Author: Daniel Espinosa <esodan gmail com>
Date: Tue Nov 12 09:21:33 2013 -0600
Serializable API change for node's name and use_nick
* Renamed serializable_node_name to just node_name ()
* Renamed and convert as function serializable_property_user_nick
to property_use_nick
* Updated SerializableJson, SerializableObjectModel and Unit tests
gxml/Serializable.vala | 26 ++++++++++----------------
gxml/SerializableJson.vala | 8 ++++----
gxml/SerializableObjectModel.vala | 23 +++++++++++------------
test/SerializableObjectModelTest.vala | 22 +++++++---------------
4 files changed, 32 insertions(+), 47 deletions(-)
---
diff --git a/gxml/Serializable.vala b/gxml/Serializable.vala
index 98497d5..492a7f2 100644
--- a/gxml/Serializable.vala
+++ b/gxml/Serializable.vala
@@ -73,16 +73,6 @@ namespace GXml {
public interface Serializable : GLib.Object {
protected abstract ParamSpec[] properties { get; set; }
/**
- * Defines the way to set Node name.
- *
- * By default is set to object's type's name lowercase.
- *
- * This property is ignored on serialisation.
- */
- public abstract string serializable_node_name ();
-
- public abstract bool serializable_property_use_nick { get; set; }
- /**
* Store all properties to be ignored on serialization.
*
* Use property's cannonical name as key and its { link GLib.ParamSpec}. To
@@ -116,7 +106,15 @@ namespace GXml {
* This property is ignored on serialisation.
*/
public abstract string? serialized_xml_node_value { get; protected set; default = null; }
-
+ /**
+ * Defines the way to set Node name.
+ */
+ public abstract string node_name ();
+ /**
+ * Defines the way to set Node's property name, by using
+ * it's nick instead of default name.
+ */
+ public abstract bool property_use_nick ();
/**
* Serialize this object.
*
@@ -262,7 +260,7 @@ namespace GXml {
foreach (ParamSpec spec in props) {
if (spec.name.down () == property_name.down ())
return spec;
- if (serializable_property_use_nick)
+ if (property_use_nick ())
if (spec.get_nick ().down () == property_name.down ())
return spec;
}
@@ -291,10 +289,6 @@ namespace GXml {
get_class
().find_property("unknown-serializable-property"));
ignored_serializable_properties.set ("serialized-xml-node-value",
get_class
().find_property("serialized-xml-node-value"));
- ignored_serializable_properties.set ("serializable-property-use-nick",
- get_class
().find_property("serializable-property-use-nick"));
- ignored_serializable_properties.set ("serializable-node-name",
- get_class
().find_property("serializable-node-name"));
}
if (unknown_serializable_property == null) {
unknown_serializable_property = new HashTable<string,GXml.Node> (str_hash,
str_equal);
diff --git a/gxml/SerializableJson.vala b/gxml/SerializableJson.vala
index 13d36ad..b1d34eb 100644
--- a/gxml/SerializableJson.vala
+++ b/gxml/SerializableJson.vala
@@ -36,12 +36,12 @@ public class GXml.SerializableJson : GLib.Object, Serializable
{
/* Serializable Interface properties */
protected ParamSpec[] properties { get; set; }
- public bool serializable_property_use_nick { 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 string serializable_node_name () { return ""; }
- public string? serialized_xml_node_value { get; protected set; default = null; }
+ public string? serialized_xml_node_value { get; protected set; default = null; }
+
+ public virtual string node_name () { return "Object"; }
+ public virtual bool property_use_nick () { return false; }
public virtual GLib.ParamSpec? find_property_spec (string property_name)
{
diff --git a/gxml/SerializableObjectModel.vala b/gxml/SerializableObjectModel.vala
index 177ead1..1308647 100644
--- a/gxml/SerializableObjectModel.vala
+++ b/gxml/SerializableObjectModel.vala
@@ -25,23 +25,22 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
/* Serializable interface properties */
protected ParamSpec[] properties { get; set; }
public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
- public bool serializable_property_use_nick { get; set; }
public string? serialized_xml_node_value { get; protected set; default=null; }
public GLib.HashTable<string,GXml.Node> unknown_serializable_property { get; protected set; }
+ public virtual bool property_use_nick () { return false; }
- public virtual string serializable_node_name ()
+ public virtual string node_name ()
{
- return default_serializable_node_name ();
+ return default_node_name ();
}
- public string default_serializable_node_name ()
+ public string default_node_name ()
{
return get_type().name().down();
}
public SerializableObjectModel ()
{
- serializable_property_use_nick = false;
serialized_xml_node_value = null;
}
@@ -82,7 +81,7 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
public virtual Node? serialize (Node node)
throws GLib.Error
- requires (serializable_node_name () != null)
+ requires (node_name () != null)
requires (node is Document || node is Element)
{
return default_serialize (node);
@@ -95,7 +94,7 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
doc = (Document) node;
else
doc = node.owner_document;
- var element = doc.create_element (serializable_node_name ());
+ var element = doc.create_element (node_name ());
foreach (ParamSpec spec in list_serializable_properties ()) {
serialize_property (element, spec);
}
@@ -168,7 +167,7 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
}
}
string attr_name;
- if (serializable_property_use_nick &&
+ if (property_use_nick () &&
prop.get_nick () != null &&
prop.get_nick () != "")
attr_name = prop.get_nick ();
@@ -186,7 +185,7 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
public virtual Node? deserialize (Node node)
throws GLib.Error
- requires (serializable_node_name () != null)
+ requires (node_name () != null)
{
return default_deserialize (node);
}
@@ -206,12 +205,12 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
else
element = (Element) doc.document_element;
return_val_if_fail (element != null, null);
- if (serializable_node_name () == null) {
+ if (node_name () == null) {
message (@"WARNING: Object type '$(get_type ().name ())' have no Node Name defined");
assert_not_reached ();
}
- if (element.node_name.down () != serializable_node_name ().down ()) {
- message (@"WARNING: wrong node name is '$(element.node_name.down ())' is different to
'$(serializable_node_name ().down ())'");
+ if (element.node_name.down () != node_name ().down ()) {
+ message (@"WARNING: wrong node name is '$(element.node_name.down ())' is different to
'$(node_name ().down ())'");
}
foreach (Attr attr in element.attributes.get_values ())
{
diff --git a/test/SerializableObjectModelTest.vala b/test/SerializableObjectModelTest.vala
index 5eeda02..3fc2b6f 100644
--- a/test/SerializableObjectModelTest.vala
+++ b/test/SerializableObjectModelTest.vala
@@ -95,11 +95,11 @@ public class Package : ObjectModel
public string destiny { get; set; }
[Description (nick="tag", blurb="tags in package")]
public Array<string> tags { get {return _tags;} }
-
+
+ public override bool property_use_nick () { return true; }
public Package ()
{
- serializable_property_use_nick = true;
computer = new Computer ();
manual = new Manual ();
source = "Mexico";
@@ -142,10 +142,8 @@ public class Monitor : ObjectModel
public int ac_power { get; set; }
[Description (nick="DcPower")]
public int dc_power { get; set; }
- public Monitor ()
- {
- serializable_property_use_nick = true;
- }
+
+ public override bool property_use_nick () { return true; }
}
@@ -202,24 +200,18 @@ public class Cpu : ObjectModel
class NodeName : ObjectModel
{
public bool invalid { get; set; default = true; }
- public override string serializable_node_name ()
- {
- return "NodeName";
- }
+ public override string node_name () { return "NodeName"; }
}
class Configuration : ObjectModel
{
public bool invalid { get; set; default = true; }
public string device { get; set; }
- public override string serializable_node_name ()
- {
- return "Configuration";
- }
+ public override string node_name () { return "Configuration"; }
+ public override bool property_use_nick () { return true; }
public Configuration ()
{
- serializable_property_use_nick = true;
init_properties (); // initializing properties to be ignored by default
ignored_serializable_properties.set ("invalid",
get_class ().find_property("invalid"));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]