[gxml/serialization] Bugs and warnning messages fixes. * Not used Serializable.serialized_xml_node removed * Serializable



commit c8430c044b7510f0f7f0c15b8353eea5a69802b9
Author: Daniel Espinosa <esodan gmail com>
Date:   Wed Jul 24 12:36:49 2013 -0500

    Bugs and warnning messages fixes.
    * Not used Serializable.serialized_xml_node removed
    * Serializable.deserealize fixed return value
    * Fixed a bug adding content to top level Element
    * Removed warnnings
    * Added SerializableError error domain

 gxml/Serializable.vala            |   54 ++++++++++++++++++------------------
 gxml/SerializableObjectModel.vala |    2 -
 gxml/Serialization.vala           |   18 +++++++-----
 test/SerializableTest.vala        |    5 +---
 4 files changed, 39 insertions(+), 40 deletions(-)
---
diff --git a/gxml/Serializable.vala b/gxml/Serializable.vala
index ff016c3..05ce8b6 100644
--- a/gxml/Serializable.vala
+++ b/gxml/Serializable.vala
@@ -88,14 +88,7 @@ namespace GXml {
                public abstract HashTable<string,GXml.DomNode>    unknown_serializable_property { get; 
protected set; }
 
                /**
-                * Used by to add properties and values to DomNode.
-                *
-                * This property must be ignored on serialisation.
-                */
-               public abstract Element  serialized_xml_node { get; protected set; default = null; }
-
-               /**
-                * Used by to add properties and values to DomNode.
+                * Used by to add content in an { link GXml.Element}.
                 *
                 * This property must be ignored on serialisation.
                 */
@@ -116,15 +109,15 @@ namespace GXml {
                        GLib.message ("Serialing on ..." + node.node_name);
                        var element = doc.create_element (this.get_type().name());
                        node.append_child (element);
-                       GLib.message ("Is NULL VALUE ?" + (serialized_xml_node_value == null).to_string ());
                        if (serialized_xml_node_value != null)
                                element.content = serialized_xml_node_value;
+                       GLib.message ("Node Value is: ?" + element.content);
                        foreach (ParamSpec spec in list_serializable_properties ()) {
                                GLib.message ("Property to Serialize: " + spec.name);
                                serialize_property (element, spec);
                        }
                        GLib.message ("Added a new top node: " + element.node_name);
-                       return serialized_xml_node;
+                       return element;
                }
 
                /**
@@ -187,7 +180,8 @@ namespace GXml {
                 * @node { link GXml.DomNode} used to deserialize from.
                 */
                public virtual DomNode? deserialize (DomNode node)
-                                                    throws DomError
+                                                    throws SerializableError,
+                                                           DomError
                {
                        Document doc;
                        if (node is Document) {
@@ -196,23 +190,20 @@ namespace GXml {
                        }
                        else
                                doc = node.owner_document;
-                       if (node is Element)
-                               serialized_xml_node = (Element) node;
-                       else
-                               serialized_xml_node = (Element) doc.document_element;
-                       return_val_if_fail (serialized_xml_node.node_name.down () == 
get_type().name().down(), null);
-                       foreach (Attr attr in serialized_xml_node.attributes.get_values ())
+                       var element = (Element) doc.document_element;
+                       return_val_if_fail (element.node_name.down () == get_type().name().down(), null);
+                       foreach (Attr attr in element.attributes.get_values ())
                        {
                                deserialize_property (attr);
                        }
-                       if (serialized_xml_node.has_child_nodes ())
+                       if (element.has_child_nodes ())
                        {
-                               foreach (DomNode n in serialized_xml_node.child_nodes)
+                               foreach (DomNode n in element.child_nodes)
                                {
                                        deserialize_property (n);
                                }
-                               if (serialized_xml_node.content != null)
-                                       serialized_xml_node_value = serialized_xml_node.content;
+                               if (serialized_xml_node_value != null)
+                                       element.content = serialized_xml_node_value;
                        }
                        return null;
                }
@@ -235,7 +226,8 @@ namespace GXml {
                 * @return `true` if the property was handled, `false` if { link GXml.Serialization} should 
handle it.
                 */
                public virtual bool deserialize_property (GXml.DomNode property_node)
-                                                         throws Error
+                                                         throws SerializableError,
+                                                         DomError
                {
                        bool ret = false;
                        var prop = find_property_spec (property_node.node_name);
@@ -335,8 +327,6 @@ namespace GXml {
                                                                                                              
                                                                  get_class 
().find_property("ignored-serializable-properties"));
                                ignored_serializable_properties.set ("unknown-serializable-property",
                                                                                                              
                                                                  get_class 
().find_property("unknown-serializable-property"));
-                               ignored_serializable_properties.set ("serialized-xml-node",
-                                                                                                             
                                                                  get_class 
().find_property("serialized-xml-node"));
                                ignored_serializable_properties.set ("serialized-xml-node-value",
                                                                                                              
                                                                  get_class 
().find_property("serialized-xml-node-value"));
                                ignored_serializable_properties.set ("serializable-property-use-nick",
@@ -469,7 +459,7 @@ namespace GXml {
                 *
                 * A utility function that handles converting a string
                 * representation of a value into the type specified by the
-                * supplied #GValue dest.  A #GXmlSerializationError will be
+                * supplied #GValue dest.  A #GXmlSerializableError will be
                 * set if the string cannot be parsed into the desired type.
                 *
                 * @param str the string to transform into the given #GValue object
@@ -481,7 +471,7 @@ namespace GXml {
                 * they throw an exception?  NULL/0/FALSE?
                 */
                public static bool string_to_gvalue (string str, ref GLib.Value dest)
-                               throws SerializationError
+                                                    throws SerializableError
                {
                        Type t = dest.type ();
                        GLib.Value dest2 = Value (t);
@@ -559,8 +549,18 @@ namespace GXml {
                                dest = dest2;
                                return true;
                        } else {
-                               throw new SerializationError.UNSUPPORTED_TYPE ("%s/%s", t.name (), 
t.to_string ());
+                               throw new SerializableError.UNSUPPORTED_TYPE ("%s/%s", t.name (), t.to_string 
());
                        }
                }
        }
+
+       /**
+        * Errors from { link Serialization}.
+        */
+       public errordomain SerializableError {
+               /**
+                * An object with a known { link GLib.Type} that we do not support was encountered.
+                */
+               UNSUPPORTED_TYPE
+       }
 }
diff --git a/gxml/SerializableObjectModel.vala b/gxml/SerializableObjectModel.vala
index f8303aa..f4cbdc6 100644
--- a/gxml/SerializableObjectModel.vala
+++ b/gxml/SerializableObjectModel.vala
@@ -25,7 +25,6 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
        /* Serializable interface properties */
        public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
        public bool serializable_property_use_nick { get; set; }
-       public GXml.Element serialized_xml_node { get; protected set; }
        public string? serialized_xml_node_value { get; protected set; default=null; }
        public GLib.HashTable<string,GXml.DomNode> unknown_serializable_property { get; protected set; }
 
@@ -41,7 +40,6 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
        {
                if (b.get_type () == a.get_type ()) {
                        var alp = ((Serializable)a).list_serializable_properties ();
-                       var blp = ((Serializable)b).list_serializable_properties ();
                        bool ret = true;
                        foreach (ParamSpec p in alp) {
                                var bp = ((Serializable)b).find_property_spec (p.name);
diff --git a/gxml/Serialization.vala b/gxml/Serialization.vala
index 70a1555..c1e1166 100644
--- a/gxml/Serialization.vala
+++ b/gxml/Serialization.vala
@@ -91,8 +91,7 @@ namespace GXml {
                private static GXml.DomNode serialize_property (GLib.Object object,
                                                                ParamSpec prop_spec,
                                                                GXml.Document doc)
-                                                               throws Error,
-                                                                      SerializationError,
+                                                               throws SerializationError,
                                                                       DomError
                {
                        Type type;
@@ -211,8 +210,7 @@ namespace GXml {
                 * @return a { link GXml.DomNode} representing the serialized `object`
                 */
                public static GXml.DomNode serialize_object (GLib.Object object) 
-                                                            throws Error,
-                                                                   SerializationError,
+                                                            throws SerializationError,
                                                                    DomError
                {
                        Document doc;
@@ -301,7 +299,9 @@ namespace GXml {
                private static void deserialize_property (ParamSpec spec,
                                                          Element prop_elem,
                                                          out Value val)
-                                                         throws SerializationError
+                                                         throws SerializationError,
+                                                                SerializableError,
+                                                                DomError
                {
                        Type type;
 
@@ -343,7 +343,7 @@ namespace GXml {
                                        // We don't want this one caught by deserialize_object, or we'd have 
a cascading error message.  Hmm, not so bad if it does, though.
                                        e.message += "\nXML [%s]".printf (prop_elem.to_string ());
                                        throw e;
-                               }
+                               } 
                        }
 
                        if (transformed == false) {
@@ -391,7 +391,11 @@ namespace GXml {
                 * @param node { link GXml.DomNode} representing a { link GLib.Object}
                 * @return the deserialized { link GLib.Object}
                 */
-               public static GLib.Object deserialize_object (DomNode node) throws SerializationError {
+               public static GLib.Object deserialize_object (DomNode node)
+                                                             throws SerializationError,
+                                                                    SerializableError,
+                                                                    DomError
+               {
                        Element obj_elem;
 
                        string otype;
diff --git a/test/SerializableTest.vala b/test/SerializableTest.vala
index 07dbf76..32e87ff 100644
--- a/test/SerializableTest.vala
+++ b/test/SerializableTest.vala
@@ -30,7 +30,6 @@ public class SerializableTomato : GLib.Object, GXml.Serializable
        /*  Serializable abstract properties */
        public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; private set; }
        public bool serializable_property_use_nick { get; set; }
-       public GXml.Element serialized_xml_node { get; protected set; }
        public string? serialized_xml_node_value { get; protected set; }
        public GLib.HashTable<string,GXml.DomNode> unknown_serializable_property { get; private set; }
 
@@ -68,7 +67,6 @@ public class SerializableCapsicum : GLib.Object, GXml.Serializable
        /*  Serializable abstract properties */
        public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; private set; }
        public bool serializable_property_use_nick { get; set; }
-       public GXml.Element serialized_xml_node { get; protected set; }
        public string? serialized_xml_node_value { get; protected set; }
        public GLib.HashTable<string,GXml.DomNode> unknown_serializable_property { get; private set; }
 
@@ -124,7 +122,7 @@ public class SerializableCapsicum : GLib.Object, GXml.Serializable
                                            GLib.ParamSpec spec)
                                            throws DomError
        {
-               GXml.Document doc = serialized_xml_node.owner_document;
+               GXml.Document doc = element.owner_document;
                GXml.Element c_prop;
                GXml.Element rating;
 
@@ -160,7 +158,6 @@ public class SerializableBanana : GLib.Object, GXml.Serializable
        /*  Serializable abstract properties */
        public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; private set; }
        public bool serializable_property_use_nick { get; set; }
-       public GXml.Element serialized_xml_node { get; protected set; }
        public string? serialized_xml_node_value { get; protected set; }
        public GLib.HashTable<string,GXml.DomNode> unknown_serializable_property { get; private set; }
 


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