[gxml] GomCollection: renamed element_name to items_name



commit 67256d7af7efa6f2c61cc26f91ae35ab03f15970
Author: Daniel Espinosa <esodan gmail com>
Date:   Sun Nov 6 10:32:45 2016 -0600

    GomCollection: renamed element_name to items_name
    
    Improved documention.
    
    Added initial test case.

 gxml/GomCollections.vala       |   27 +++++++++++++++++----------
 test/GomSerializationTest.vala |   27 +++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 10 deletions(-)
---
diff --git a/gxml/GomCollections.vala b/gxml/GomCollections.vala
index 38ff5ce..ce73487 100644
--- a/gxml/GomCollections.vala
+++ b/gxml/GomCollections.vala
@@ -33,14 +33,15 @@ public interface GXml.GomCollection : Object
    */
   public abstract List<int> nodes_index { get; }
   /**
-   * A {@link DomElement} with all child elements.
+   * A {@link DomElement} with all child elements in collection. Only
+   *{@link GomElement} objects are supported.
    */
   public abstract DomElement element { get; construct set; }
   /**
    * Local name of {@link DomElement} objects of {@link element}, which could be
    * contained in this collection.
    */
-  public abstract string element_name { get; construct set; }
+  public abstract string items_name { get; construct set; }
   /**
    * Search and add references to all {@link GomObject} nodes as child of
    * {@link element} with same, case insensitive, name of {@link element_name}
@@ -67,21 +68,27 @@ public interface GXml.GomCollection : Object
 public class GXml.GomArrayList : Object, GomCollection {
   protected List<int> _nodes_index = new List<int> ();
   protected GomElement _element;
-  protected string _element_name;
+  protected string _items_name;
   public List<int> nodes_index { get { return _nodes_index; } }
   public DomElement element {
     get { return _element; }
     construct set {
-      if (value is GomElement)
-        _element = value as GomElement;
-      else
-        GLib.warning (_("Invalid element type only GXmlGomElement is supported"));
+      if (value != null) {
+        if (value is GomElement)
+          _element = value as GomElement;
+        else
+          GLib.warning (_("Invalid element type only GXmlGomElement is supported"));
+      }
     }
   }
-  public string element_name {
-    get { return _element_name; } construct set { _element_name = value; }
+  public string items_name {
+    get { return _items_name; } construct set { _items_name = value; }
   }
 
+  public GomArrayList.initialize (GomElement element, string items_name) {
+    _element = element;
+    _items_name = items_name;
+  }
   /**
    * Adds an {@link DomElement} of type {@link GomObject} as a child of
    * {@link element}
@@ -103,7 +110,7 @@ public class GXml.GomArrayList : Object, GomCollection {
     for (int i = 0; i < _element.child_nodes.size; i++) {
       var n = _element.child_nodes.get (i);
       if (n is GomObject) {
-        if ((n as DomElement).local_name.down () == element_name.down ()) {
+        if ((n as DomElement).local_name.down () == items_name.down ()) {
           _nodes_index.append (i);
         }
       }
diff --git a/test/GomSerializationTest.vala b/test/GomSerializationTest.vala
index 8f714a4..16853ee 100644
--- a/test/GomSerializationTest.vala
+++ b/test/GomSerializationTest.vala
@@ -77,6 +77,18 @@ class GomSerializationTest : GXmlTest  {
       return parser.write_string ();
     }
   }
+  public class BookStand : GomElement {
+    [Description (nick="::Classification")]
+    public string classification { get; set; default = "Science"; }
+    public GomArrayList registers { get; set; }
+    construct {
+      _local_name = "BookStand";
+    }
+    public string to_string () {
+      var parser = new XParser (this);
+      return parser.write_string ();
+    }
+  }
   public static void add_tests () {
     Test.add_func ("/gxml/gom-serialization/write/properties", () => {
       var b = new Book ();
@@ -128,6 +140,21 @@ class GomSerializationTest : GXmlTest  {
       assert ("TaxFree=\"true\"" in s);
       GLib.message ("DOC:"+s);
     });
+    Test.add_func ("/gxml/gom-serialization/write/property-arraylist", () => {
+      var bs = new BookStand ();
+      string s = bs.to_string ();
+      assert (s != null);
+      assert ("<BookStand Classification=\"Science\"/>" in s);
+      GLib.message ("DOC:"+s);
+      var br = new BookRegister ();
+      br.year = 2016;
+      assert (bs.registers == null);
+      bs.registers = new GomArrayList.initialize (bs,br.local_name);
+      s = bs.to_string ();
+      assert (s != null);
+      assert ("<BookStand Classification=\"Science\"/>" in s);
+      GLib.message ("DOC:"+s);
+    });
     Test.add_func ("/gxml/gom-serialization/read/properties", () => {
       var b = new Book ();
       var parser = new XParser (b);


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