[gxml] DomNode: API change, can set document at construct



commit 3e2d9a2053bfe39ffdcd8af749b2dabfd81056aa
Author: Daniel Espinosa <esodan gmail com>
Date:   Sat Nov 5 20:49:42 2016 -0600

    DomNode: API change, can set document at construct
    
    This is a convenient change to allow use Object.new
    for GomObject/GomElement derived classes creation
    and set its parent document

 gxml/DomNode.vala              |    2 +-
 gxml/GXmlNode.vala             |    5 ++++-
 gxml/GomNode.vala              |    7 +++++--
 test/GomSerializationTest.vala |   13 ++++++++-----
 4 files changed, 18 insertions(+), 9 deletions(-)
---
diff --git a/gxml/DomNode.vala b/gxml/DomNode.vala
index 127abb4..2dbda1d 100644
--- a/gxml/DomNode.vala
+++ b/gxml/DomNode.vala
@@ -41,7 +41,7 @@ public interface GXml.DomNode : GLib.Object, GXml.DomEventTarget {
 
   public abstract string? base_uri { get; }
 
-  public abstract DomDocument? owner_document { get; }
+  public abstract DomDocument? owner_document { get; construct set; }
   public abstract DomNode? parent_node { owned get; }
   public abstract DomElement? parent_element { owned get; }
   public abstract DomNodeList child_nodes { owned get; }
diff --git a/gxml/GXmlNode.vala b/gxml/GXmlNode.vala
index 451d110..504cf1d 100644
--- a/gxml/GXmlNode.vala
+++ b/gxml/GXmlNode.vala
@@ -159,7 +159,10 @@ public abstract class GXml.GNode : Object,
   protected string _base_uri = null;
   public string? base_uri { get { return _base_uri; } }
 
-  public DomDocument? owner_document { get { return (GXml.DomDocument?) document; } }
+  public DomDocument? owner_document {
+    get { return _doc; }
+    construct set { _doc = value as GDocument; }
+  }
   public DomNode? parent_node { owned get { return parent as DomNode?; } }
   public DomElement? parent_element {
     owned get {
diff --git a/gxml/GomNode.vala b/gxml/GomNode.vala
index cf2f44c..2f5134a 100644
--- a/gxml/GomNode.vala
+++ b/gxml/GomNode.vala
@@ -46,7 +46,10 @@ public class GXml.GomNode : Object,
   public string? base_uri { get { return _base_uri; } }
 
   protected GXml.DomDocument _document;
-  public DomDocument? owner_document { get { return (GXml.DomDocument?) _document; } }
+  public DomDocument? owner_document {
+    get { return _document; }
+    construct set { _document = value; }
+  }
 
   public DomNode? parent_node { owned get { return _parent as DomNode?; } }
   public DomElement? parent_element {
@@ -108,7 +111,7 @@ public class GXml.GomNode : Object,
     }
     set {
       try {
-        var t = owner_document.create_text_node (text_content);
+        var t = _document.create_text_node (text_content);
         child_nodes.add (t);
       } catch (GLib.Error e) {
         GLib.warning (_("Text content in element can't be created"));
diff --git a/test/GomSerializationTest.vala b/test/GomSerializationTest.vala
index 51f4bff..d92f23e 100644
--- a/test/GomSerializationTest.vala
+++ b/test/GomSerializationTest.vala
@@ -128,11 +128,6 @@ class GomSerializationTest : GXmlTest  {
       assert ("TaxFree=\"true\"" in s);
       GLib.message ("DOC:"+s);
     });
-    Test.add_func ("/gxml/gom-serialization/write/object-property", () => {
-      /*var b = new BookRegister ();
-      string s = b.to_string ();
-      assert ("<BookRegister><Book/></BookRegister>" in s);*/
-    });
     Test.add_func ("/gxml/gom-serialization/read/properties", () => {
       var b = new Book ();
       var parser = new XParser (b);
@@ -160,5 +155,13 @@ class GomSerializationTest : GXmlTest  {
         assert_not_reached ();
       } catch {}
     });
+    Test.add_func ("/gxml/gom-serialization/read/object-property", () => {
+      /*var b = new BookRegister ();
+      var parser = new XParser (b);
+      parser.read_string ("<BookRegister><Book/></BookRegister>", null);
+      string s = b.to_string ();
+      GLib.message ("doc:"+s);
+      assert ("<BookRegister><Book/></BookRegister>" in s);*/
+    });
   }
 }


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