[gxml] Implemented Document.create_element()



commit 7c1936e29352ed0b65f483a1d790c5104c5bd935
Author: Daniel Espinosa <esodan gmail com>
Date:   Wed Apr 15 18:31:04 2015 -0500

    Implemented Document.create_element()

 gxml/Document.vala                      |    1 +
 gxml/SerializableJson.vala              |    6 ++--
 gxml/SerializableObjectModel.vala       |    2 +-
 gxml/Serialization.vala                 |    6 ++--
 gxml/libxml-Document.vala               |    4 +-
 test/DocumentTest.vala                  |   18 ++++++------
 test/ElementTest.vala                   |   42 +++++++++++++++---------------
 test/GXmlTest.vala                      |    2 +-
 test/NamespaceTest.vala                 |    8 +++---
 test/NodeTest.vala                      |    2 +-
 test/SerializableGeeArrayListTest.vala  |    2 +-
 test/SerializableGeeDualKeyMapTest.vala |    2 +-
 test/SerializableGeeHashMapTest.vala    |    2 +-
 test/SerializableGeeTreeMapTest.vala    |    2 +-
 test/SerializableObjectModelTest.vala   |    2 +-
 test/SerializableTest.vala              |    2 +-
 16 files changed, 52 insertions(+), 51 deletions(-)
---
diff --git a/gxml/Document.vala b/gxml/Document.vala
index 22ce14c..dc12372 100644
--- a/gxml/Document.vala
+++ b/gxml/Document.vala
@@ -26,4 +26,5 @@ public interface GXml.Document : Object, GXml.Node
 {
   public abstract GXml.Node root { get; }
   public abstract GLib.File file { get; set; }
+  public abstract GXml.Node create_element (string name);
 }
diff --git a/gxml/SerializableJson.vala b/gxml/SerializableJson.vala
index c6d2698..bc4c48f 100644
--- a/gxml/SerializableJson.vala
+++ b/gxml/SerializableJson.vala
@@ -128,7 +128,7 @@ public class GXml.SerializableJson : GLib.Object, GXml.Serializable
     else
       doc = node.owner_document;
 
-    root = doc.create_element ("Object");
+    root = (xElement) doc.create_element ("Object");
     doc.append_child (root);
     root.set_attribute ("otype", this.get_type ().name ());
     root.set_attribute ("oid", oid);
@@ -157,7 +157,7 @@ public class GXml.SerializableJson : GLib.Object, GXml.Serializable
     }
 
     var doc = element.owner_document;
-    prop_node = doc.create_element ("Property");
+    prop_node = (xElement) doc.create_element ("Property");
     prop_node.set_attribute ("ptype", prop.value_type.name ());
     prop_node.set_attribute ("pname", prop.name);
     element.append_child (prop_node);
@@ -198,7 +198,7 @@ public class GXml.SerializableJson : GLib.Object, GXml.Serializable
       this.get_property_value (prop, ref val);
       child_object = val.get_object ();
       xDocument value_doc = Serialization.serialize_object (child_object);
-      value_node = doc.create_element ("fake");
+      value_node = (xNode) doc.create_element ("fake");
       value_doc.document_element.copy (ref value_node, true);
       //value_node = doc.copy_node (value_doc.document_element);
       prop_node.append_child (value_node);
diff --git a/gxml/SerializableObjectModel.vala b/gxml/SerializableObjectModel.vala
index 7ebe8c5..6f4a608 100644
--- a/gxml/SerializableObjectModel.vala
+++ b/gxml/SerializableObjectModel.vala
@@ -110,7 +110,7 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
       doc = (xDocument) node;
     else
       doc = node.owner_document;
-    var element = doc.create_element (node_name ());
+    var element = (xElement) doc.create_element (node_name ());
     node.append_child (element);
     if (serialize_set_namespace != null) {
       string[] str = serialize_set_namespace.split ("|", 2);
diff --git a/gxml/Serialization.vala b/gxml/Serialization.vala
index 381536c..147ca5c 100644
--- a/gxml/Serialization.vala
+++ b/gxml/Serialization.vala
@@ -238,7 +238,7 @@ namespace GXml {
                        // first, check if its been serialised already, and if so, just return an ObjectRef 
element for it.
                        if (oid != "" && Serialization.serialize_cache.contains (oid)) {
                                // GLib.message ("cache hit on oid %s", oid);
-                               root = doc.create_element ("ObjectRef");
+                               root = (xElement) doc.create_element ("ObjectRef");
                                doc.append_child (root);
                                root.set_attribute ("otype", object.get_type ().name ());
                                root.set_attribute ("oid", oid);
@@ -251,7 +251,7 @@ namespace GXml {
                                return doc;
                        }
                        // For now and on assume is not a Serializable object
-                       root = doc.create_element ("Object");
+                       root = (xElement) doc.create_element ("Object");
                        doc.append_child (root);
                        root.set_attribute ("otype", object.get_type ().name ());
                        root.set_attribute ("oid", oid);
@@ -269,7 +269,7 @@ namespace GXml {
                           strings. (Too bad deserialising isn't that
                           easy w.r.t. string conversion.) */
                        foreach (ParamSpec prop_spec in prop_specs) {
-                               prop = doc.create_element ("Property");
+                               prop = (xElement) doc.create_element ("Property");
                                prop.set_attribute ("ptype", prop_spec.value_type.name ());
                                prop.set_attribute ("pname", prop_spec.name);
                                value_prop = Serialization.serialize_property (object, prop_spec, doc);
diff --git a/gxml/libxml-Document.vala b/gxml/libxml-Document.vala
index 44dec78..525cfc9 100644
--- a/gxml/libxml-Document.vala
+++ b/gxml/libxml-Document.vala
@@ -242,7 +242,7 @@ namespace GXml {
                        this.implementation = impl;
 
                        xNode root;
-                       root = this.create_element (qualified_name); // TODO: we do not currently support 
namespaces, but when we do, this new node will want one
+                       root = (xNode) this.create_element (qualified_name); // TODO: we do not currently 
support namespaces, but when we do, this new node will want one
                        this.append_child (root);
 
                        this.namespace_uri = namespace_uri;
@@ -606,7 +606,7 @@ namespace GXml {
                 *
                 * @return A new { link GXml.xElement}; this should not be freed
                 */
-               public unowned xElement create_element (string tag_name) {
+               public GXml.Node create_element (string tag_name) {
                        // TODO: what should we be passing for ns other than old_ns?  Figure it out; needed 
for level 2+ support
                        Xml.Node *xmlelem;
 
diff --git a/test/DocumentTest.vala b/test/DocumentTest.vala
index c02b8db..394ed39 100644
--- a/test/DocumentTest.vala
+++ b/test/DocumentTest.vala
@@ -1,4 +1,4 @@
-/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
 /* Notation.vala
  *
  * Copyright (C) 2011-2013  Richard Schwarting <aquarichy gmail com>
@@ -232,12 +232,12 @@ class DocumentTest : GXmlTest {
                                xDocument doc = get_doc ();
                                xElement elem = null;
 
-                               elem = doc.create_element ("Banana");
+                               elem = (xElement) doc.create_element ("Banana");
                                test_error (DomException.NONE);
                                assert (elem.tag_name == "Banana");
                                assert (elem.tag_name != "banana");
 
-                               elem = doc.create_element ("ØÏØÏدÏØÏ  ²øœ³¤ïØ£");
+                               elem = (xElement) doc.create_element ("ØÏØÏدÏØÏ  ²øœ³¤ïØ£");
                                test_error (DomException.INVALID_CHARACTER);
                                // assert (elem == null); // TODO: decide what we want returned on 
DomExceptions
                        });
@@ -246,18 +246,18 @@ class DocumentTest : GXmlTest {
                                DocumentFragment fragment = doc.create_document_fragment ();
 
                                // TODO: can we set XML in the content, and actually have that translate into 
real libxml2 underlying nodes?
-                               xElement percy = doc.create_element ("Author");
-                               xElement percy_name = doc.create_element ("Name");
-                               xElement percy_email = doc.create_element ("Email");
+                               xElement percy = (xElement) doc.create_element ("Author");
+                               xElement percy_name = (xElement) doc.create_element ("Name");
+                               xElement percy_email = (xElement) doc.create_element ("Email");
                                percy_name.content = "Percy";
                                percy_email.content = "pweasley hogwarts co uk";
                                percy.append_child (percy_name);
                                percy.append_child (percy_email);
                                fragment.append_child (percy);
 
-                               xElement ginny = doc.create_element ("Author");
-                               xElement ginny_name = doc.create_element ("Name");
-                               xElement ginny_email = doc.create_element ("Email");
+                               xElement ginny = (xElement) doc.create_element ("Author");
+                               xElement ginny_name = (xElement) doc.create_element ("Name");
+                               xElement ginny_email = (xElement) doc.create_element ("Email");
                                ginny_name.content = "Ginny";
                                ginny_email.content = "weasleyg hogwarts co uk";
                                ginny.append_child (ginny_name);
diff --git a/test/ElementTest.vala b/test/ElementTest.vala
index c3dddab..e3d5d06 100644
--- a/test/ElementTest.vala
+++ b/test/ElementTest.vala
@@ -131,7 +131,7 @@ class ElementTest : GXmlTest  {
 
                                doc = get_doc ();
 
-                               elem = doc.create_element ("alphanumeric");
+                               elem = (xElement) doc.create_element ("alphanumeric");
 
                                attributes = elem.attributes;
                                assert (attributes != null);
@@ -322,21 +322,21 @@ class ElementTest : GXmlTest  {
                                assert (ts.length == 5);
 
                                // Test adding direct child
-                               bs.append_child (t1 = doc.create_element ("t"));
+                               bs.append_child (t1 = (xElement) doc.create_element ("t"));
                                assert (ts.length == 6);
 
                                // Test adding descendant
-                               b3.append_child (doc.create_element ("t"));
+                               b3.append_child ((xElement) doc.create_element ("t"));
                                assert (ts.length == 7);
 
                                // Test situation where we add a node tree
                                GXml.xNode b4;
                                GXml.xNode d, d2;
 
-                               b4 = doc.create_element ("B");
-                               b4.append_child (doc.create_element ("t"));
-                               d = doc.create_element ("D");
-                               d.append_child (t2 = doc.create_element ("t"));
+                               b4 = (xElement) doc.create_element ("B");
+                               b4.append_child ((xElement) doc.create_element ("t"));
+                               d = (xElement) doc.create_element ("D");
+                               d.append_child (t2 = (xElement) doc.create_element ("t"));
                                b4.append_child (d);
 
                                bs.append_child (b4);
@@ -344,8 +344,8 @@ class ElementTest : GXmlTest  {
                                assert (ts.length == 9);
 
                                // Test situation where we use insert_before
-                               d2 = doc.create_element ("D");
-                               d2.append_child (doc.create_element ("t"));
+                               d2 = (xElement) doc.create_element ("D");
+                               d2.append_child ((xElement) doc.create_element ("t"));
                                b4.insert_before (d2, d);
 
                                assert (ts.length == 10);
@@ -354,12 +354,12 @@ class ElementTest : GXmlTest  {
                                DocumentFragment frag;
 
                                frag = doc.create_document_fragment ();
-                               frag.append_child (doc.create_element ("t"));
-                               d = doc.create_element ("D");
-                               d.append_child (doc.create_element ("t"));
+                               frag.append_child ((xElement) doc.create_element ("t"));
+                               d = (xElement) doc.create_element ("D");
+                               d.append_child ((xElement) doc.create_element ("t"));
                                frag.append_child (d);
-                               d2 = doc.create_element ("D");
-                               d2.append_child (doc.create_element ("t"));
+                               d2 = (xElement) doc.create_element ("D");
+                               d2.append_child ((xElement) doc.create_element ("t"));
                                frag.insert_before (d2, d);
 
                                b4.append_child (frag);
@@ -411,8 +411,8 @@ class ElementTest : GXmlTest  {
                        });
                Test.add_func ("/gxml/element/content/set", () =>{
                        var doc = new xDocument ();
-                       var root = doc.create_element ("root");
-                       doc.append_child (root);
+                       var root = (xElement) doc.create_element ("root");
+                       doc.append_child ((xNode) root);
                        root.content = "TEXT1";
                        string d = """<?xml version="1.0"?>
 <root>TEXT1</root>
@@ -424,9 +424,9 @@ class ElementTest : GXmlTest  {
                });
                Test.add_func ("/gxml/element/content/overwrite_child_nodes", () =>{
                        var doc = new xDocument ();
-                       var root = doc.create_element ("root");
+                       var root = (xElement) doc.create_element ("root");
                        doc.append_child (root);
-                       var n = doc.create_element ("child");
+                       var n = (xElement) doc.create_element ("child");
                        root.append_child (n);
                        // This will remove all child nodes
                        root.content = "TEXT1";
@@ -440,12 +440,12 @@ class ElementTest : GXmlTest  {
                });
                Test.add_func ("/gxml/element/content/keep_child_nodes", () =>{
                        var doc = new xDocument ();
-                       var root = doc.create_element ("root");
+                       var root = (xElement) doc.create_element ("root");
                        doc.append_child (root);
-                       var n = doc.create_element ("child");
+                       var n = (xElement) doc.create_element ("child");
                        root.append_child (n);
                        // This will remove all child nodes
-                       var t = doc.create_text_node ("TEXT1");
+                       var t = (xElement) doc.create_text_node ("TEXT1");
                        root.append_child (t);
                        string d = """<?xml version="1.0"?>
 <root><child/>TEXT1</root>
diff --git a/test/GXmlTest.vala b/test/GXmlTest.vala
index dbf14db..aada789 100644
--- a/test/GXmlTest.vala
+++ b/test/GXmlTest.vala
@@ -114,7 +114,7 @@ class GXmlTest {
        }
 
        internal static xElement get_elem (string name, xDocument doc) {
-               xElement elem = doc.create_element (name);
+               xElement elem = (xElement) doc.create_element (name);
                return elem;
        }
 
diff --git a/test/NamespaceTest.vala b/test/NamespaceTest.vala
index 3a8f9f0..0de4b5a 100644
--- a/test/NamespaceTest.vala
+++ b/test/NamespaceTest.vala
@@ -27,22 +27,22 @@ class NamespaceTest : GXmlTest {
        public static void add_tests () {
                Test.add_func ("/gxml/domnode/namespace", () => {
                  var d = new xDocument ();
-                 var e = d.create_element ("root");
+                 var e = (xElement) d.create_element ("root");
                  e.add_namespace_attr ("http://www.gnome.org/GXml";, "gxml");
                  e.add_namespace_attr ("http://www.gnome.org/GXmlSerializable";, "gxmls");
                  d.append_child (e);
                  assert (e.to_string () == "<root xmlns:gxml=\"http://www.gnome.org/GXml\"; 
xmlns:gxmls=\"http://www.gnome.org/GXmlSerializable\"/>");
                  assert (e.set_namespace ("http://www.gnome.org/GXml";, "gxml"));
                  assert (e.to_string () == "<gxml:root xmlns:gxml=\"http://www.gnome.org/GXml\"; 
xmlns:gxmls=\"http://www.gnome.org/GXmlSerializable\"/>");
-                 var c = d.create_element ("child");
+                 var c = (xElement) d.create_element ("child");
                  e.append_child (c);
                  assert (c.set_namespace ("http://www.gnome.org/GXml";, "gxml"));
                  assert (c.to_string () == "<gxml:child/>");
-                 var c2 = d.create_element ("subchild");
+                 var c2 = (xElement) d.create_element ("subchild");
                  e.append_child (c2);
                  assert (c2.set_namespace ("http://www.gnome.org/GXmlSerializable";, "gxmls"));
                  assert (c2.to_string () == "<gxmls:subchild/>");
-                 var c3 = d.create_element ("testnode");
+                 var c3 = (xElement) d.create_element ("testnode");
                  // Check if an Element with no namespaces will not fail and go to root
                  e.append_child (c3);
                  c3.set_namespace ("http://www.gnome.org/GXml";, "gxml");
diff --git a/test/NodeTest.vala b/test/NodeTest.vala
index ea5a034..9c6bbac 100644
--- a/test/NodeTest.vala
+++ b/test/NodeTest.vala
@@ -124,7 +124,7 @@ class NodeTest : GXmlTest {
 
                                GXml.xNode node;
 
-                               node = doc.create_element ("elem");
+                               node = (xElement) doc.create_element ("elem");
                                assert (node.node_value == null);
 
                                node = doc.create_attribute ("name");
diff --git a/test/SerializableGeeArrayListTest.vala b/test/SerializableGeeArrayListTest.vala
index 8e76f6e..8d765a7 100644
--- a/test/SerializableGeeArrayListTest.vala
+++ b/test/SerializableGeeArrayListTest.vala
@@ -73,7 +73,7 @@ class SerializableGeeArrayListTest : GXmlTest
         c.add (o1);
         c.add (o2);
         var doc = new xDocument ();
-        var root = doc.create_element ("root");
+        var root = (xElement) doc.create_element ("root");
         doc.append_child (root);
         c.serialize (root);
         if (!root.has_child_nodes ()) {
diff --git a/test/SerializableGeeDualKeyMapTest.vala b/test/SerializableGeeDualKeyMapTest.vala
index ac963f9..7b28c6e 100644
--- a/test/SerializableGeeDualKeyMapTest.vala
+++ b/test/SerializableGeeDualKeyMapTest.vala
@@ -143,7 +143,7 @@ class SerializableGeeDualKeyMapTest : GXmlTest
         c.set (o3.owner, o3.name, o3);
         c.set (o4.owner, o4.name, o4);
         var doc = new xDocument ();
-        var root = doc.create_element ("root");
+        var root = (xElement) doc.create_element ("root");
         doc.append_child (root);
         c.serialize (root);
         if (!root.has_child_nodes ()) {
diff --git a/test/SerializableGeeHashMapTest.vala b/test/SerializableGeeHashMapTest.vala
index 74b57bd..9c7cac0 100644
--- a/test/SerializableGeeHashMapTest.vala
+++ b/test/SerializableGeeHashMapTest.vala
@@ -112,7 +112,7 @@ class SerializableGeeHashMapTest : GXmlTest
         c.set (o1.name, o1);
         c.set (o2.name, o2);
         var doc = new xDocument ();
-        var root = doc.create_element ("root");
+        var root = (xElement) doc.create_element ("root");
         doc.append_child (root);
         c.serialize (root);
         if (!root.has_child_nodes ()) {
diff --git a/test/SerializableGeeTreeMapTest.vala b/test/SerializableGeeTreeMapTest.vala
index 013a72d..ad5e900 100644
--- a/test/SerializableGeeTreeMapTest.vala
+++ b/test/SerializableGeeTreeMapTest.vala
@@ -102,7 +102,7 @@ class SerializableGeeTreeMapTest : GXmlTest
         c.set (o1.name, o1);
         c.set (o2.name, o2);
         var doc = new xDocument ();
-        var root = doc.create_element ("root");
+        var root = (xElement) doc.create_element ("root");
         doc.append_child (root);
         c.serialize (root);
         if (!root.has_child_nodes ()) {
diff --git a/test/SerializableObjectModelTest.vala b/test/SerializableObjectModelTest.vala
index 0fda03b..824a785 100644
--- a/test/SerializableObjectModelTest.vala
+++ b/test/SerializableObjectModelTest.vala
@@ -131,7 +131,7 @@ public class Package : ObjectModel
       {
         for (int i = 0; i < tags.length; i++) {
           var str = tags.index (i);
-          node = element.owner_document.create_element ("tag");
+          node = (xElement) element.owner_document.create_element ("tag");
           ((xElement) node).content = str;
           element.append_child (node);
         }
diff --git a/test/SerializableTest.vala b/test/SerializableTest.vala
index 8fdf5b6..b467658 100644
--- a/test/SerializableTest.vala
+++ b/test/SerializableTest.vala
@@ -126,7 +126,7 @@ public class SerializableCapsicum : GXml.SerializableJson {
                switch (prop.name) {
                case "ratings":
                        foreach (int rating_int in ratings) {
-                               xElement n = doc.create_element ("rating");
+                               xElement n = (xElement) doc.create_element ("rating");
                                n.content = "%d".printf (rating_int);
                                element.append_child (n);
                        }


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