[gxml] Fixes on GomObject instantiate GomElement's



commit 9cbd29f7ab3bf1baac001ef4c2b03de2c7e9b4af
Author: Daniel Espinosa <esodan gmail com>
Date:   Thu Feb 2 15:35:32 2017 -0600

    Fixes on GomObject instantiate GomElement's

 gxml/GomObject.vala            |    8 ++++++--
 test/GomSerializationTest.vala |   26 ++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)
---
diff --git a/gxml/GomObject.vala b/gxml/GomObject.vala
index 3ee3d1a..bf8317e 100644
--- a/gxml/GomObject.vala
+++ b/gxml/GomObject.vala
@@ -80,6 +80,8 @@ public interface GXml.GomObject : GLib.Object,
    */
   public virtual ParamSpec? find_object_property_name (string pname) {
     foreach (ParamSpec spec in this.get_class ().list_properties ()) {
+      message ("Prop: '"+spec.name+"' : "+spec.value_type.is_a (typeof (GomObject)).to_string ());
+      message ("Search for: "+pname+" :"+(spec.name.down () == pname.down ()).to_string ());
       if (spec.name.down () == pname.down ()) {
         if (spec.value_type.is_a (typeof (GomObject))
             || spec.value_type.is_a (typeof (GomCollection))) {
@@ -327,6 +329,7 @@ public interface GXml.GomObject : GLib.Object,
    public bool create_instance_property (string name) {
       var prop = find_object_property_name (name);
       if (prop == null) return false;
+      message ("Found: "+prop.name);
       Value v = Value (prop.value_type);
       Object obj;
       if (prop.value_type.is_a (typeof (GomCollection))) {
@@ -336,13 +339,14 @@ public interface GXml.GomObject : GLib.Object,
         return true;
       }
       if (prop.value_type.is_a (typeof (GomElement))) {
-        obj = Object.new (prop.value_type);
-        try { (obj as GomNode).set_parent (this); }
+        obj = Object.new (prop.value_type,"owner_document", this.owner_document);
+        try { this.append_child (obj as GomElement); }
         catch (GLib.Error e) {
           warning (_("Error while atemting to instantiate property object: %s").printf (e.message));
         }
         v.set_object (obj);
         set_property (prop.name, v);
+        return true;
       }
       return false;
    }
diff --git a/test/GomSerializationTest.vala b/test/GomSerializationTest.vala
index f3e6d2f..c1e34fa 100644
--- a/test/GomSerializationTest.vala
+++ b/test/GomSerializationTest.vala
@@ -232,6 +232,9 @@ class GomSerializationTest : GXmlTest  {
   public class BookStand : GomElement {
     [Description (nick="::Classification")]
     public string classification { get; set; default = "Science"; }
+    [Description (nick="::DimensionX")]
+    public Dimension dimension_x { get; set; }
+    public DimensionY dimension_y { get; set; }
     public Registers registers { get; set; }
     public Books books { get; set; }
     construct {
@@ -248,6 +251,20 @@ class GomSerializationTest : GXmlTest  {
       }
       return s;
     }
+    public class Dimension : GomElement {
+      [Description (nick="::Length")]
+      public double length { get; set; default = 1.0; }
+      [Description (nick="::Type")]
+      public string dtype { get; set; default = "x"; }
+      construct {
+        try { initialize ("Dimension"); } catch { assert_not_reached (); }
+      }
+    }
+    public class DimensionY : Dimension {
+      construct {
+        dtype = "y";
+      }
+    }
   }
 
   public class Registers : GomArrayList {
@@ -443,6 +460,15 @@ class GomSerializationTest : GXmlTest  {
       assert ((bs.registers.get_item (0) as BookRegister).year == 2016);
       assert ((bs.registers.get_item (1) as BookRegister).year == 2010);
       assert ((bs.registers.get_item (2) as BookRegister).year == 2000);
+      assert (bs.create_instance_property("Dimension-X"));
+      assert (bs.dimension_x != null);
+      assert (bs.dimension_x.length == 1.0);
+      s = bs.to_string ();
+      assert (s != null);
+//#if DEBUG
+      GLib.message ("DOC:"+s);
+//#endif
+      assert ("<BookStand Classification=\"Science\"><BookRegister Year=\"2016\"/><BookRegister 
Year=\"2010\"/><Test/><BookRegister Year=\"2000\"/><Dimension Length=\"1\" Type=\"x\"/></BookStand>" in s);
     } catch (GLib.Error e) {
       GLib.message ("Error: "+e.message);
       assert_not_reached ();


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