diff --git a/gxml/GomObject.vala b/gxml/GomObject.vala index 5c97c33c0757fe50f1aa767ed23f78310cf00cdc..7a4acf5d56dbd41cb5afceff3065086fcfe7834e 100644 --- a/gxml/GomObject.vala +++ b/gxml/GomObject.vala @@ -39,6 +39,16 @@ public interface GXml.GomObject : GLib.Object, * attribute use property's nick name as declared in {@link GLib.ParamSpec} */ public virtual bool use_nick_name () { return true; } + public virtual HashTable get_properties_map () { + var l = new HashTable (str_hash, str_equal); + foreach (ParamSpec spec in this.get_class ().list_properties ()) { + if ("::" in spec.get_nick ()) { + GLib.message ("Name: "+spec.name+ " Nick: "+spec.get_nick ()); + l.insert (spec.name, spec.get_nick ()); + } + } + return l; + } /** * Search for properties in objects, it should be * an {@link GLib.Object}'s property. If found a diff --git a/gxml/XParser.vala b/gxml/XParser.vala index fc50c411b1b0758f30db5201b4ddf94709e08406..a6609e7f7d6cd78ab817d3638c2267eb393eb943 100644 --- a/gxml/XParser.vala +++ b/gxml/XParser.vala @@ -364,6 +364,17 @@ public class GXml.XParser : Object, GXml.Parser { if (size > 1500) tw.flush (); } + // GomObject serialisation + var opm = (node as GomObject).get_properties_map (); + foreach (string pk in opm.get_keys ()) { + string v = (node as GomObject).get_attribute (pk); + if (v == null) continue; + string pn = opm.lookup (pk); + size += tw.write_attribute (pn.replace ("::",""), v); + size += tw.end_attribute (); + if (size > 1500) + tw.flush (); + } } // Non Elements #if DEBUG diff --git a/test/GomSerializationTest.vala b/test/GomSerializationTest.vala index 450a3aa58ed99e3e8f295019e6457b3f437ca51e..39b24fa7fa9e4376c43bcfa6e4e9eb79d55eeab3 100644 --- a/test/GomSerializationTest.vala +++ b/test/GomSerializationTest.vala @@ -24,8 +24,9 @@ using GXml; class GomSerializationTest : GXmlTest { public class Book : GomElement { + [Description (nick="::Name")] public string name { get; set; } - public Book () { + construct { _local_name = "Book"; } public string to_string () { return (_document as GomDocument).to_string (); } @@ -40,6 +41,10 @@ class GomSerializationTest : GXmlTest { assert (b.get_attribute ("name") == "My Book"); s = b.to_string (); GLib.message ("DOC:"+s); + foreach (ParamSpec spec in b.get_class ().list_properties ()) { + if ("::" in spec.get_nick ()) + GLib.message ("Name: "+spec.name+ " Nick: "+spec.get_nick ()); + } }); } }