[gxml/serialization: 105/106] Merge branch 'gsoc2013' into serialization



commit e0651b58ea64ea9357db80007e66d90647257200
Merge: 2a33ba7 69f18f1
Author: Daniel Espinosa <esodan gmail com>
Date:   Tue Jul 30 15:05:38 2013 -0500

    Merge branch 'gsoc2013' into serialization
    
    Conflicts:
        gxml/Node.vala
        gxml/NodeList.vala
        gxml/Serializable.vala
        gxml/Serialization.vala
        test/SerializableTest.vala

 configure.ac                               |    4 +-
 docs/Makefile.am                           |    1 -
 examples/c/Makefile                        |    5 +-
 examples/c/document_create.c               |   59 +++++
 examples/c/document_create_from_file.c     |   22 ++
 examples/c/document_create_from_path.c     |   16 ++
 examples/c/document_create_from_string.c   |   20 ++
 examples/c/document_create_minimal.c       |   55 ++++
 examples/c/document_factory.c              |   55 ++++
 examples/c/document_properties.c           |   37 +++
 examples/c/document_save_to_path.c         |   14 +
 examples/c/document_save_to_stream.c       |   20 ++
 examples/c/example.c                       |  240 -----------------
 examples/js/document_create.js             |   34 +++
 examples/js/document_create_from_file.js   |   13 +
 examples/js/document_create_from_path.js   |   11 +
 examples/js/document_create_from_string.js |   21 ++
 examples/js/document_factory.js            |   36 +++
 examples/js/document_properties.js         |   19 ++
 examples/js/document_save_to_path.js       |   11 +
 examples/js/example.js                     |   70 -----
 examples/vala/example.vala                 |   70 ++----
 gxml/Attr.vala                             |   50 ++--
 gxml/BackedNode.vala                       |   31 ++-
 gxml/CDATASection.vala                     |    2 +-
 gxml/CharacterData.vala                    |   95 ++++++-
 gxml/Comment.vala                          |    7 +-
 gxml/Document.vala                         |  323 ++++++++++++++++-------
 gxml/DocumentFragment.vala                 |    7 +-
 gxml/DocumentType.vala                     |   13 +-
 gxml/{DomError.vala => DomException.vala}  |   52 +++-
 gxml/Element.vala                          |  115 ++++++---
 gxml/Entity.vala                           |   14 +-
 gxml/EntityReference.vala                  |    2 +-
 gxml/Implementation.vala                   |   73 +++++-
 gxml/Makefile.am                           |    7 +-
 gxml/NamespaceAttr.vala                    |    2 +-
 gxml/{DomNode.vala => Node.vala}           |  215 +++++++++++-----
 gxml/NodeList.vala                         |  236 ++++++++++--------
 gxml/Notation.vala                         |    2 +-
 gxml/ProcessingInstruction.vala            |   18 +-
 gxml/Serializable.vala                     |   16 +-
 gxml/Serialization.vala                    |   39 ++--
 gxml/Text.vala                             |   25 ++-
 test/AttrTest.vala                         |    6 +-
 test/CharacterDataTest.vala                |   15 +-
 test/DocumentTest.vala                     |   49 +---
 test/ElementTest.vala                      |   42 ++--
 test/GXmlTest.vala                         |   26 ++-
 test/Makefile.am                           |    3 +-
 test/{DomNodeTest.vala => NodeTest.vala}   |  104 ++++----
 test/SerializableTest.vala                 |   18 ++-
 test/SerializationTest.vala                |    8 +-
 test/TextTest.vala                         |   21 +-
 test/valgrind/Makefile                     |   39 +++
 test/valgrind/attributes.vala              |   25 ++
 test/valgrind/document.c                   |   12 +
 test/valgrind/document_create_minimal.c    |   55 ++++
 test/valgrind/document_create_minimal_2.c  |   62 +++++
 test/valgrind/example.vala                 |   76 ++++++
 test/valgrind/gfile.c                      |   13 +
 test/valgrind/gio.supp                     |   29 ++
 test/valgrind/glib.supp                    |   22 ++
 test/valgrind/gobject.c                    |   12 +
 test/valgrind/gtype.supp                   |   50 ++++
 test/valgrind/libxml2.c                    |   28 ++
 test/valgrind/libxml2.supp                 |   43 +++
 test/valgrind/message.c                    |    7 +
 test/valgrind/scope.vala                   |   25 ++
 test/valgrind/small.vala                   |   24 ++
 test/valgrind/small2.vala                  |   24 ++
 test/valgrind/small2a.c                    |   28 ++
 test/valgrind/small2b.c                    |   25 ++
 test/valgrind/unlink_unattached_nodes.c    |   45 ++++
 vapi/libxml-2.0.vapi                       |  384 +++++++++++++++-------------
 75 files changed, 2408 insertions(+), 1089 deletions(-)
---
diff --cc gxml/NodeList.vala
index c756de6,f609ab6..61f7fe9
--- a/gxml/NodeList.vala
+++ b/gxml/NodeList.vala
@@@ -27,13 -27,21 +27,23 @@@ using Gee
  
  namespace GXml {
        /**
-        * A live list used to store { link GXml.DomNode}s. Usually the
-        * children of a { link GXml.DomNode}, or the results of
-        * { link GXml.Element.get_elements_by_tag_name}.
+        * A live list used to store { link GXml.Node}s.
+        *
+        * Usually contains the children of a { link GXml.Node}, or
+        * the results of { link GXml.Element.get_elements_by_tag_name}.
+        * { link GXml.NodeList} implements both the DOM Level 1 Core API for
+        * a NodeList, as well as the { link GLib.List} API, to make
+        * it more accessible and familiar to GLib programmers.
+        * Implementing classes also implement { link Gee.Iterable}, to make
+        * iteration in supporting languages (like Vala) nice and
+        * easy.
+        *
+        * Version: DOM Level 1 Core
+        * URL: [[http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-536297177]]
         */
-       public interface NodeList : Gee.Iterable<DomNode> {
+       public interface NodeList : Gee.Iterable<Node> {
 +
 +              public abstract ulong length { get; private set; }
                /* NOTE:
                 * children should define constructors like:
                 *     internal NodeList (Xml.Node* head, Document owner);
diff --cc gxml/Serializable.vala
index 276145e,53ac7fc..6a88e66
--- a/gxml/Serializable.vala
+++ b/gxml/Serializable.vala
@@@ -72,61 -70,38 +72,61 @@@ namespace GXml 
         */
        public interface Serializable : GLib.Object {
                /**
 -               * Handles deserializing individual properties.
 +               * Defines the way to set DomNode name.
                 *
 -               * Interface method to handle deserialization of an
 -               * individual property.  The implementing class
 -               * receives a description of the property and the
 -               * { link GXml.Node} that contains the content.  The
 -               * implementing { link GXml.Serializable} object can extract
 -               * the data from the { link GXml.Node} and store it in its
 -               * property itself. Note that the { link GXml.Node} may be
 -               * as simple as a { link GXml.Text} that stores the data as a
 -               * string.
 +               * By default is set to object's type's name lowercase.
 +               *
 +               * This property must be ignored on serialisation.
 +               */
 +              public abstract string serializable_node_name { get; protected set; }
 +
 +              public abstract bool serializable_property_use_nick { get; set; }
 +              /**
 +               * Store all properties to be ignored on serialization.
                 *
 -               * If the implementation has handled deserialization,
 -               * return true.  Return false if you want
 -               * { link GXml.Serialization} to try to automatically
 -               * deserialize it.  If { link GXml.Serialization} tries to
 -               * handle it, it will want either { link GXml.Serializable}'s
 -               * set_property (or at least { link GLib.Object.set_property})
 -               * to know about the property.
 +               * Implementors: By default { link list_serializable_properties} initialize
 +               * this property to store all public properties, except this one.
 +               */
 +              public abstract HashTable<string,GLib.ParamSpec>  ignored_serializable_properties { get; 
protected set; }
 +              /**
 +               * On deserialization stores any { link DomNode} not used on this
 +               * object, but exists in current XML file.
                 *
 -               * @param property_name the name of the property as a string
 -               * @param spec the { link GLib.ParamSpec} describing the property.
 -               * @param property_node the { link GXml.Node} encapsulating data to deserialize
 -               * @return `true` if the property was handled, `false` if { link GXml.Serialization} should 
handle it.
 +               * This property must be ignored on serialisation.
                 */
-               public abstract HashTable<string,GXml.DomNode>    unknown_serializable_property { get; 
protected set; }
 -              /*
 -               * @todo: consider not giving property_name, but
 -               * letting them get name from spec
 -               * @todo: consider returning { link GLib.Value} as out param
++              public abstract HashTable<string,GXml.Node>    unknown_serializable_property { get; protected 
set; }
 +
 +              /**
 +               * Used by to add content in an { link GXml.Element}.
 +               *
 +               * This property must be ignored on serialisation.
                 */
 -              public virtual bool deserialize_property (string property_name, /* out GLib.Value value,*/ 
GLib.ParamSpec spec, GXml.Node property_node) {
 -                      return false; // default deserialize_property gets used
 +              public abstract string?  serialized_xml_node_value { get; protected set; default = null; }
 +
 +              /**
 +               * Serialize this object.
 +               *
 +               * @doc an { link GXml.Document} object to serialise to 
 +               */
-               public virtual DomNode? serialize (DomNode node) throws DomError
++              public virtual Node? serialize (DomNode node) throws DomError
 +              {
 +                      Document doc;
 +                      if (node is Document)
 +                              doc = (Document) node;
 +                      else
 +                              doc = node.owner_document;
 +                      GLib.message ("Serialing on ..." + node.node_name);
 +                      var element = doc.create_element (serializable_node_name);
 +                      node.append_child (element);
 +                      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 element;
                }
  
                /**
@@@ -148,171 -123,17 +148,171 @@@
                 *
                 * @param property_name string name of a property to serialize.
                 * @param spec the { link GLib.ParamSpec} describing the property.
-                * @param doc the { link GXml.Document} the returned { link GXml.DomNode} should belong to
-                * @return a new { link GXml.DomNode}, or `null`
+                * @param doc the { link GXml.Document} the returned { link GXml.Node} should belong to
+                * @return a new { link GXml.Node}, or `null`
                 */
-               public virtual GXml.DomNode? serialize_property (Element element,
 -              /*
 -               * @todo: consider not giving property_name, let them get name from spec?
++              public virtual GXml.Node? serialize_property (Element element,
 +                                                               GLib.ParamSpec prop)
 +                                                               throws DomError
 +              {
 +                      if (prop.value_type.is_a (typeof (Serializable))) 
 +                      {
 +                              GLib.message (@"$(prop.name) Is a Serializable");
 +                              var v = Value (typeof (Object));
 +                              get_property (prop.name, ref v);
 +                              var obj = (Serializable) v.get_object ();
 +                              return obj.serialize (element);
 +                      }
 +                      DomNode node = null;
 +                      Value oval = Value (prop.value_type);
 +                      get_property (prop.name, ref oval);
 +                      string val = "";
 +                      if (Value.type_transformable (prop.value_type, typeof (string)))
 +                      {
 +                              Value rval = Value (typeof (string));
 +                              oval.transform (ref rval);
 +                              val = rval.dup_string ();
 +                              string attr_name = prop.name.down ();
 +                              var attr = element.get_attribute_node (attr_name);
 +                              if (attr == null) {
 +                                      GLib.message (@"New Attr to add... $(attr_name)");
 +                                      element.set_attribute (attr_name, val);
 +                              }
 +                              else
 +                                      attr.value = val;
 +                              return (DomNode) attr;
 +                      }
 +                      this.serialize_unknown_property (element, prop, out node);
 +                      return node;
 +              }
 +
 +              /**
 +               * Deserialize this object.
 +               *
 +               * @node { link GXml.DomNode} used to deserialize from.
 +               */
 +              public virtual DomNode? deserialize (DomNode node)
 +                                                   throws SerializableError,
 +                                                          DomError
 +              {
 +                      Document doc;
 +                      if (node is Document) {
 +                              doc = (Document) node;
 +                              return_val_if_fail (doc.document_element != null, null);
 +                      }
 +                      else
 +                              doc = node.owner_document;
 +                      Element element;
 +                      if (node is Element)
 +                              element = (Element) node;
 +                      else
 +                              element = (Element) doc.document_element;
 +                      return_val_if_fail (element.node_name.down () == serializable_node_name, null);
 +                      foreach (Attr attr in element.attributes.get_values ())
 +                      {
 +                              GLib.message (@"Deseralizing Attribute: $(attr.name)");
 +                              deserialize_property (attr);
 +                      }
 +                      if (element.has_child_nodes ())
 +                      {
 +                              GLib.message ("Have child Elements ...");
 +                              foreach (DomNode n in element.child_nodes)
 +                              {
 +                                      GLib.message (@"Deseralizing Element: $(n.node_name)");
 +                                      deserialize_property (n);
 +                              }
 +                      }
 +                      if (element.content != null)
 +                                      serialized_xml_node_value = element.content;
 +                      return null;
 +              }
 +              /**
 +               * Handles deserializing individual properties.
 +               *
 +               * Interface method to handle deserialization of an
 +               * individual property.  The implementing class
 +               * receives a description of the property and the
 +               * { link GXml.DomNode} that contains the content.  The
 +               * implementing { link GXml.Serializable} object can extract
 +               * the data from the { link GXml.DomNode} and store it in its
 +               * property itself. Note that the { link GXml.DomNode} may be
 +               * as simple as a { link GXml.Text} that stores the data as a
 +               * string.
 +               *
 +               * @param property_name the name of the property as a string
 +               * @param spec the { link GLib.ParamSpec} describing the property.
 +               * @param property_node the { link GXml.DomNode} encapsulating data to deserialize
 +               * @return `true` if the property was handled, `false` if { link GXml.Serialization} should 
handle it.
                 */
 -              public virtual GXml.Node? serialize_property (string property_name, /*GLib.Value value, */ 
GLib.ParamSpec spec, GXml.Document doc) {
 -                      return null; // default serialize_property gets used
 +              public virtual bool deserialize_property (GXml.DomNode property_node)
 +                                                        throws SerializableError,
 +                                                        DomError
 +              {
 +                      bool ret = false;
 +                      var prop = find_property_spec (property_node.node_name);
 +                      if (prop == null) {
 +                              GLib.message ("Found Unknown property: " + property_node.node_name);
 +                              // FIXME: Event emit
 +                              unknown_serializable_property.set (property_node.node_name, property_node);
 +                              return true;
 +                      }
 +                      if (prop.value_type.is_a (typeof (Serializable)))
 +                      {
 +                              GLib.message (@"$(prop.name): Is Serializable...");
 +                              Value vobj = Value (typeof(Object));
 +                              get_property (prop.name, ref vobj);
 +                              if (vobj.get_object () == null) {
 +                                      var obj = Object.new  (prop.value_type);
 +                                      ((Serializable) obj).deserialize (property_node);
 +                                      set_property (prop.name, obj);
 +                              }
 +                              else
 +                                      ((Serializable) vobj.get_object ()).deserialize (property_node);
 +                              return true;
 +                      }
 +                      else {
 +                              Value val = Value (prop.value_type);
 +                              if (Value.type_transformable (typeof (DomNode), prop.value_type))
 +                              {
 +                                      Value tmp = Value (typeof (DomNode));
 +                                      tmp.set_object (property_node);
 +                                      ret = tmp.transform (ref val);
 +                                      set_property (prop.name, val);
 +                                      return ret;
 +                              }
 +                              if (property_node is GXml.Attr)
 +                              {
 +                                      Value ptmp = Value (typeof (string));
 +                                      ptmp.set_string (property_node.node_value);
 +                                      if (Value.type_transformable (typeof (string), prop.value_type))
 +                                              ret = ptmp.transform (ref val);
 +                                      else
 +                                              ret = string_to_gvalue (property_node.node_value, ref val);
 +                                      set_property (prop.name, val);
 +                                      return ret;
 +                              }
 +                      }
 +                      // Attribute can't be deseralized with standard methods. Up to the implementor.
 +                      this.deserialize_unknown_property (property_node, prop);
 +                      return true;
                }
  
 -              /* Correspond to: g_object_class_{find_property,list_properties} */
 +              /**
 +               * Signal to serialize unknown properties.
 +               * 
 +               * @node a { link GXml.DomNode} to add attribute or child nodes to
 +               * @prop a { link GLib.ParamSpec} describing attribute to serialize
 +               * @attribute set to the { link GXml.Attr} representing this attribute
 +               */
 +              public signal void serialize_unknown_property (DomNode element, ParamSpec prop, out DomNode 
node);
 +
 +              /**
 +               * Signal to deserialize array properties.
 +               *
 +               * @node a { link GXml.DomNode} to get attribute from
 +               * @prop a { link GLib.ParamSpec} describing attribute to deserialize
 +               */
 +              public signal void deserialize_unknown_property (DomNode node, ParamSpec prop);
  
                /*
                 * Handles finding the { link GLib.ParamSpec} for a given property.
diff --cc gxml/Serialization.vala
index c1e1166,3103760..2cdd887
--- a/gxml/Serialization.vala
+++ b/gxml/Serialization.vala
@@@ -88,15 -87,10 +88,19 @@@ namespace GXml 
                 * { link GLib.Value} can transform into a string, and
                 * operates recursively.
                 */
++<<<<<<< HEAD
 +              private static GXml.DomNode serialize_property (GLib.Object object,
 +                                                              ParamSpec prop_spec,
 +                                                              GXml.Document doc)
 +                                                              throws SerializationError,
 +                                                                     DomError
 +              {
++=======
+               private static GXml.Node serialize_property (GLib.Object object, ParamSpec prop_spec, 
GXml.Document doc) throws SerializationError {
++>>>>>>> gsoc2013
                        Type type;
                        Value value;
-                       DomNode value_node;
+                       Node value_node;
                        Serializable serializable = null;
  
                        if (object.get_type ().is_a (typeof (Serializable))) {
@@@ -207,19 -201,10 +211,19 @@@
                 * unsupported, or the property isn't known to the object).
                 *
                 * @param object A { link GLib.Object} to serialize
-                * @return a { link GXml.DomNode} representing the serialized `object`
+                * @return a { link GXml.Node} representing the serialized `object`
                 */
-               public static GXml.DomNode serialize_object (GLib.Object object) 
 -              public static GXml.Node serialize_object (GLib.Object object) throws SerializationError {
++              public static GXml.Node serialize_object (GLib.Object object) 
 +                                                           throws SerializationError,
 +                                                                  DomError
 +              {
                        Document doc;
 +                      if (object is Serializable)
 +                      {
 +                              doc = new Document ();
 +                              return ((Serializable) object).serialize (doc);
 +                      }
 +
                        Element root;
                        ParamSpec[] prop_specs;
                        Element prop;
@@@ -388,14 -382,10 +392,14 @@@
                 * deserializing them or a { link GXml.SerializationError} will
                 * result.
                 *
-                * @param node { link GXml.DomNode} representing a { link GLib.Object}
+                * @param node { link GXml.Node} representing a { link GLib.Object}
                 * @return the deserialized { link GLib.Object}
                 */
-               public static GLib.Object deserialize_object (DomNode node)
 -              public static GLib.Object deserialize_object (Node node) throws SerializationError {
++              public static GLib.Object deserialize_object (Node node)
 +                                                            throws SerializationError,
 +                                                                   SerializableError,
 +                                                                   DomError
 +              {
                        Element obj_elem;
  
                        string otype;
diff --cc test/SerializableTest.vala
index 83432df,6980d66..a4bf7dd
--- a/test/SerializableTest.vala
+++ b/test/SerializableTest.vala
@@@ -94,19 -72,20 +94,28 @@@ public class SerializableCapsicum : GLi
                this.age = age;
                this.height = height;
                this.ratings = ratings;
 +              serializable_node_name = "capsicum";
        }
  
++<<<<<<< HEAD
 +      public bool deserialize_property (GXml.DomNode property_node)
 +                                    throws SerializableError,
 +                                                     DomError
 +      {
++=======
+       /* TODO: do we really need GLib.Value? or should we modify the object directly?
+          Want an example using GBoxed too
+          Perhaps these shouldn't be object methods, perhaps they should be static?
+          Can't have static methods in an interface :(, right? */
+       public bool deserialize_property (string property_name, /* out GLib.Value value, */
+                                         GLib.ParamSpec spec, GXml.Node property_node)  {
++>>>>>>> gsoc2013
                GLib.Value outvalue = GLib.Value (typeof (int));
  
 -              switch (property_name) {
 +              switch (property_node.node_name) {
                case "ratings":
                        this.ratings = new GLib.List<int> ();
-                       foreach (GXml.DomNode rating in property_node.child_nodes) {
+                       foreach (GXml.Node rating in property_node.child_nodes) {
                                int64.try_parse (((GXml.Element)rating).content, out outvalue);
                                this.ratings.append ((int)outvalue.get_int64 ());
                        }
@@@ -123,14 -101,11 +132,19 @@@
  
                return false;
        }
++<<<<<<< HEAD
 +      public GXml.DomNode? serialize_property (Element element,
 +                                           GLib.ParamSpec spec)
 +                                           throws DomError
 +      {
 +              GXml.Document doc = element.owner_document;
++=======
+       public GXml.Node? serialize_property (string property_name, /*GLib.Value value,*/ GLib.ParamSpec 
spec, GXml.Document doc) {
+               GXml.Element c_prop;
++>>>>>>> gsoc2013
                GXml.Element rating;
  
 -              switch (property_name) {
 +              switch (spec.name) {
                case "ratings":
                        GXml.DocumentFragment frag = doc.create_document_fragment ();
                        try {


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