[gxml] Serialization.vala: stop pretending that the only nodes deserialize_object might get are Documents,



commit 3ade1e8db6711e89a81a7c29bb7e011735940e70
Author: Richard Schwarting <aquarichy gmail com>
Date:   Wed Nov 27 12:38:59 2013 -0500

    Serialization.vala: stop pretending that the only nodes deserialize_object might get are Documents, but 
handle getting either a Document or an Element node.  serialize_object () needs to return a Document, as if 
it tried to just return a an object from one, its owner document would cease to be in scope and its memory 
would be freed.  However, because a serialization document might contain multiple objects in a hierarchy 
(like with a collection), anyone implementing Serializable who wants to override how a collection 
deserializes its members would need to be able to call deserialize_object () on individual nodes 
(representing the members) and wouldn't have a Document for each one (since they're all in the collection's 
document)

 gxml/Serialization.vala |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
---
diff --git a/gxml/Serialization.vala b/gxml/Serialization.vala
index 24b32b3..4a5fa0a 100644
--- a/gxml/Serialization.vala
+++ b/gxml/Serialization.vala
@@ -332,7 +332,7 @@ namespace GXml {
                                prop_elem_child = prop_elem.first_child;
 
                                try {
-                                       property_object = Serialization.deserialize_object_from_node 
(prop_elem_child);
+                                       property_object = Serialization.deserialize_object (prop_elem_child);
                                        val.set_object (property_object);
                                        transformed = true;
                                } catch (GXml.SerializationError e) {
@@ -388,10 +388,7 @@ namespace GXml {
                 * @param doc { link GXml.Document} representing a { link GLib.Object}
                 * @return the deserialized { link GLib.Object}
                 */
-               public static GLib.Object deserialize_object (GXml.Document doc) throws SerializationError {
-                       return deserialize_object_from_node (doc.document_element);
-               }
-               internal static GLib.Object deserialize_object_from_node (GXml.Node obj_node) throws 
SerializationError {
+               public static GLib.Object deserialize_object (GXml.Node node) throws SerializationError {
                        Element obj_elem;
                        string otype;
                        string oid;
@@ -401,7 +398,11 @@ namespace GXml {
                        ParamSpec[] specs;
                        Serializable serializable = null;
 
-                       obj_elem = (Element)obj_node;
+                       if (node.get_type ().is_a (typeof (GXml.Document))) {
+                               obj_elem = (node as GXml.Document).document_element as GXml.Element;
+                       } else {
+                               obj_elem = node as GXml.Element;
+                       }
 
                        // If the object has been deserialised before, get it from cache
                        oid = obj_elem.get_attribute ("oid");


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