[gxml] GomObject: Fixed list just instantiable properties



commit 299e90db3557e81de8cf9792fc701cbc85d85bcc
Author: Daniel Espinosa <esodan gmail com>
Date:   Thu Oct 26 17:08:39 2017 -0500

    GomObject: Fixed list just instantiable properties

 gxml/GomObject.vala      |    5 +++--
 gxml/Parser.vala         |    1 +
 test/GomElementTest.vala |   27 +++++++++++++++++++++++++++
 3 files changed, 31 insertions(+), 2 deletions(-)
---
diff --git a/gxml/GomObject.vala b/gxml/GomObject.vala
index 34ddb31..df29f27 100644
--- a/gxml/GomObject.vala
+++ b/gxml/GomObject.vala
@@ -109,8 +109,9 @@ public interface GXml.GomObject : GLib.Object,
   public virtual List<ParamSpec> get_property_element_list () {
     var l = new List<ParamSpec> ();
     foreach (ParamSpec spec in this.get_class ().list_properties ()) {
-      if (spec.value_type.is_a (typeof (GomObject))
-          || spec.value_type.is_a (typeof (GomCollection))) {
+      if ((spec.value_type.is_a (typeof (GomObject))
+          || spec.value_type.is_a (typeof (GomCollection)))
+          && spec.value_type.is_instantiatable ()) {
 #if DEBUG
         GLib.message ("Object Name: "+spec.name+ " Nick: "+spec.get_nick ());
 #endif
diff --git a/gxml/Parser.vala b/gxml/Parser.vala
index 397df58..1fa1f4e 100644
--- a/gxml/Parser.vala
+++ b/gxml/Parser.vala
@@ -215,6 +215,7 @@ public interface GXml.Parser : Object {
     foreach (ParamSpec pspec in
               (parent as GomObject).get_property_element_list ()) {
       if (pspec.value_type.is_a (typeof (GomCollection))) continue;
+      //if (!pspec.value_type.is_instantiatable ()) continue;
       var obj = Object.new (pspec.value_type,
                             "owner-document", node.owner_document) as DomElement;
       if (obj.local_name.down ()
diff --git a/test/GomElementTest.vala b/test/GomElementTest.vala
index c71d9b9..4a1600f 100644
--- a/test/GomElementTest.vala
+++ b/test/GomElementTest.vala
@@ -22,6 +22,10 @@
 
 using GXml;
 
+public interface NoInstantiatable : Object, GomObject {
+       public abstract string name { get; set; }
+}
+
 class GomElementTest : GXmlTest  {
        public class ParsedDelayed : GomElement {
                construct {
@@ -30,6 +34,17 @@ class GomElementTest : GXmlTest  {
                        parse_children = false;
                }
        }
+       public class Instantiatable : GomElement, NoInstantiatable {
+               [Description (nick="::name")]
+               public string name { get; set; }
+               construct { initialize ("Instantiatable"); }
+       }
+       public class Top : GomElement {
+               public NoInstantiatable inst {
+                       get { return inst_i; } set { inst_i = value as Instantiatable; } }
+               public Instantiatable inst_i { get; set; }
+               construct { initialize ("Top"); }
+       }
        public static void add_tests () {
        Test.add_func ("/gxml/gom-element/read/namespace_uri", () => {
                        DomDocument doc = null;
@@ -412,5 +427,17 @@ class GomElementTest : GXmlTest  {
                    assert_not_reached ();
                  }
                });
+               Test.add_func ("/gxml/gom-element/no-instantiatable", () => {
+                       try {
+                               string str = """<Top><Instantiatable name="Nop"/></Top>""";
+                               var t = new Top ();
+                               t.read_from_string (str);
+                               assert (t.inst != null);
+                               assert (t.inst.name == "Nop");
+                       } 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]