[gxml] Moved Xom to its own library libxom
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] Moved Xom to its own library libxom
- Date: Mon, 14 Apr 2014 00:38:24 +0000 (UTC)
commit de2cb220d6abdedce91017f4bef86864fe822b14
Author: Daniel Espinosa <esodan gmail com>
Date: Sun Apr 13 19:31:48 2014 -0500
Moved Xom to its own library libxom
Xom is a library dependent of GXml to serialize GObjects to XML,
providing a .NET Serialization like framework with a flexible,
overriadable implementation. Xom.Serializable interface allows
to create your own implementations. Xom provides serializable
Gee collections to store a set of Serializabe implementors
objects and serialize them to a XML document or an XML Element.
configure.ac | 8 +
gxml/Makefile.am | 13 +-
gxml/{ => xom}/Enumeration.vala | 2 +-
gxml/xom/Makefile.am | 179 ++++++
gxml/xom/Serializable.vala | 567 ++++++++++++++++++++
gxml/{ => xom}/SerializableContainer.vala | 5 +-
gxml/{ => xom}/SerializableGeeArrayList.vala | 16 +-
gxml/{ => xom}/SerializableGeeDualKeyMap.vala | 20 +-
gxml/{ => xom}/SerializableGeeHashMap.vala | 20 +-
gxml/{ => xom}/SerializableGeeTreeMap.vala | 24 +-
gxml/{ => xom}/SerializableMapDualKey.vala | 2 +-
gxml/{ => xom}/SerializableMapKey.vala | 2 +-
gxml/{ => xom}/SerializableObjectModel.vala | 39 +-
.../namespace-info.vala.in} | 19 +-
gxml/xom/xom-0.4.pc.in | 14 +
gxml/xom/xom.symbols | 191 +++++++
test/EnumerationTest.vala | 3 +-
test/GXmlTest.vala | 2 +-
test/Makefile.am | 13 +-
test/SerializableBasicTypesTest.vala | 2 +
test/SerializableGeeArrayListTest.vala | 1 +
test/SerializableGeeCollectionsTest.vala | 1 +
test/SerializableGeeDualKeyMapTest.vala | 1 +
test/SerializableGeeHashMapTest.vala | 1 +
test/SerializableGeeTreeMapTest.vala | 1 +
test/SerializableObjectModelTest.vala | 8 +-
test/SerializableTest.vala | 5 +-
test/{test.xml => test.xml.in} | 0
test/{test_invalid.xml => test_invalid.xml.in} | 0
..._expected.xml => test_out_path_expected.xml.in} | 0
...xpected.xml => test_out_stream_expected.xml.in} | 0
test/{test_with_ns.xml => test_with_ns.xml.in} | 0
32 files changed, 1063 insertions(+), 96 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index a08eac4..cd5a7eb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -194,7 +194,15 @@ Makefile
gxml/namespace-info.vala
gxml/gxml-0.4.pc
gxml/Makefile
+gxml/xom/namespace-info.vala
+gxml/xom/Makefile
+gxml/xom/xom-0.4.pc
test/Makefile
+test/test.xml
+test/test_invalid.xml
+test/test_out_path_expected.xml
+test/test_out_stream_expected.xml
+test/test_with_ns.xml
docs/Makefile
examples/Makefile
examples/c/Makefile
diff --git a/gxml/Makefile.am b/gxml/Makefile.am
index d9c7dc4..ae2f5d7 100644
--- a/gxml/Makefile.am
+++ b/gxml/Makefile.am
@@ -1,5 +1,7 @@
-include $(top_srcdir)/git.mk
+SUBDIRS = . xom
+
# Empty variable to be added elements later
CLEANFILES=
@@ -35,17 +37,8 @@ sources = \
ProcessingInstruction.vala \
Text.vala \
Serializable.vala \
- Enumeration.vala \
- SerializableObjectModel.vala \
SerializableJson.vala \
- Serialization.vala \
- SerializableGeeTreeMap.vala \
- SerializableGeeHashMap.vala \
- SerializableMapKey.vala \
- SerializableGeeDualKeyMap.vala \
- SerializableMapDualKey.vala \
- SerializableGeeArrayList.vala \
- SerializableContainer.vala
+ Serialization.vala
### General Compilation flags
diff --git a/gxml/Enumeration.vala b/gxml/xom/Enumeration.vala
similarity index 99%
rename from gxml/Enumeration.vala
rename to gxml/xom/Enumeration.vala
index b86f957..a2dcfe6 100644
--- a/gxml/Enumeration.vala
+++ b/gxml/xom/Enumeration.vala
@@ -22,7 +22,7 @@
using GXml;
-namespace GXml {
+namespace Xom {
public class Enumeration
{
/**
diff --git a/gxml/xom/Makefile.am b/gxml/xom/Makefile.am
new file mode 100644
index 0000000..1a31949
--- /dev/null
+++ b/gxml/xom/Makefile.am
@@ -0,0 +1,179 @@
+-include $(top_srcdir)/git.mk
+
+# Empty variable to be added elements later
+CLEANFILES=
+
+
+### Library
+
+# Library to create
+lib_LTLIBRARIES = libxom-0.4.la
+
+# Vala source code
+sources = \
+ namespace-info.vala \
+ Serializable.vala \
+ Enumeration.vala \
+ SerializableObjectModel.vala \
+ SerializableGeeTreeMap.vala \
+ SerializableGeeHashMap.vala \
+ SerializableMapKey.vala \
+ SerializableGeeDualKeyMap.vala \
+ SerializableMapDualKey.vala \
+ SerializableGeeArrayList.vala \
+ SerializableContainer.vala
+
+
+### General Compilation flags
+AM_CPPFLAGS = \
+ -include $(CONFIG_HEADER) \
+ -DPACKAGE_DATA_DIR=\""$(datadir)"\" \
+ -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
+ -DPACKAGE_SRC_DIR=\""$(srcdir)"\" \
+ -DG_LOG_DOMAIN=\"gxml\" \
+ $(NULL)
+
+AM_CFLAGS = \
+ -g \
+ $(GLIB_CFLAGS) \
+ $(LIBXML_CFLAGS) \
+ $(GIO_CFLAGS) \
+ $(GEE_CFLAGS) \
+ $(VALA_CFLAGS) \
+ $(NULL)
+
+# -Wall # TODO: add this back when we can properly handle more libxml2/vala warnings
+
+
+# library flags
+AM_VALAFLAGS = \
+ $(ERROR_VALAFLAGS) \
+ --library=xom-0.4 \
+ $(top_srcdir)/vapi/config.vapi \
+ --vapidir=. \
+ --vapidir=$(top_srcdir)/vapi \
+ --vapidir=../gxml \
+ --pkg gxml-0.4 \
+ --pkg libxml-2.0 \
+ --pkg gee-0.8 \
+ --pkg gobject-2.0 \
+ --pkg gio-2.0 \
+ --includedir gxml \
+ --vapi xom-0.4.vapi \
+ -H $(builddir)/../xom.h \
+ -C \
+ $(NULL)
+
+libxom_0_4_la_LIBADD = \
+ $(GEE_LIBS) \
+ $(GIO_LIBS) \
+ $(GLIB_LIBS) \
+ $(LIBXML_LIBS) \
+ $(VALA_LIBS) \
+ ../libgxml-0.4.la \
+ $(NULL)
+
+libxom_0_4_la_LDFLAGS = \
+ -version-info "$(LT_CURRENT)":"$(LT_REVISION)":"$(LT_AGE)"
+
+xom_0_4_la_vala.stamp: $(sources)
+ $(VALAC) $(AM_VALAFLAGS) $^
+
+libxom_0_4_la_SOURCES=$(sources:.vala=.c)
+
+# .h header file
+xom.h: xom_0_4_la_vala.stamp
+xomdir= $(includedir)/gxml-$(API_VERSION)/gxml
+xom_HEADERS = $(builddir)/../xom.h
+
+# .vapi Vala API file
+xom-0.4.vapi: xom_0_4_la_vala.stamp
+vapidir = $(datadir)/vala/vapi
+dist_vapi_DATA = \
+ xom-0.4.vapi \
+ xom-0.4.deps \
+ $(NULL)
+
+# .pc pkg-config file
+pkgconfig_in = xom-0.4.pc.in
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = $(pkgconfig_in:.in=)
+
+EXTRA_DIST = \
+ $(sources) \
+ $(pkgconfig_in) \
+ $(NULL)
+
+GITIGNOREFILES = \
+ $(libxom_0_4_la_SOURCES:.vala=.c) \
+ libxom_0_4_la_vala.stamp \
+ $(NULL)
+
+
+
+### GObject Introspection
+# dlname:
+# Extract our dlname like libfolks does, see bgo#658002 and bgo#585116
+# This is what g-ir-scanner does.
+libxom_dlname = \
+ `$(SED) -n "s/^dlname='\([A-Za-z0-9.+-]\+\)'/\1/p" libxom-0.4.la`
+
+# This makes GObject Introspection optional and requires to use --enable-instrospection switch on configure
+if HAVE_INTROSPECTION
+
+AM_VALAFLAGS += \
+ --gir=Xom-$(API_VERSION).gir
+
+INTROSPECTION_GIRS = Xom-$(API_VERSION).gir
+INTROSPECTION_COMPILER_ARGS = --includedir=. -l $(libxom_dlname)
+
+Xom-0.4.gir: libxom-0.4.la
+
+Xom-0.4.typelib: $(INTROSPECTION_GIRS)
+ $(INTROSPECTION_COMPILER) $(INTROSPECTION_COMPILER_ARGS) $< -o $@
+
+girdir = $(INTROSPECTION_GIRDIR)
+gir_DATA = $(INTROSPECTION_GIRS)
+typelibdir = $(INTROSPECTION_TYPELIBDIR)
+typelib_DATA = Xom-0.4.typelib
+CLEANFILES += $(gir_DATA) $(typelibs_DATA)
+endif
+
+if PLATFORM_WIN32
+libxom_0_4_la_LDFLAGS += -export-symbols $(builddir)/libxom-0.4.def
+libxom_0_4_la_DEPENDENCIES = libxom-0.4.def
+
+libxom-0.4.def: xom.symbols
+ (echo -e EXPORTS; $(CPP) -P $(DEF_FLAGS) - <$(srcdir)/xom.symbols | sed -e '/^$$/d' -e 's/^/ /' -e
's/G_GNUC_[^ ]*//g' | sort) > gxml.def.tmp && mv gxml.def.tmp libxom-0.4.def
+
+libxom-0.4.lib: libxom-0.4.def
+ $(DLLTOOL) --dllname libxom-0.4.a --def libxom-0.4.def --output-lib libxom-0.4.lib
+
+libxom-0.4.lib: libxom-0.4.la
+libxomlibdir=$(libdir)
+libxomlib_DATA=libxom-0.4.lib
+
+libxom-0.4.def: libxom-0.4.la
+libxomdefdir=$(libdir)
+libxomdef_DATA=libxom-0.4.def
+
+endif
+
+
+
+### Files to clean
+BUILT_SOURCES = \
+ xom_0_4_la_vala.stamp \
+ $(builddir)/../xom.h \
+ xom-0.4.vapi \
+ $(NULL)
+
+CLEANFILES += \
+ $(pkgconfig_DATA) \
+ namespace-info.vala \
+ $(sources:.vala=.c) \
+ xom-0.4.vapi \
+ $(builddir)/../xom.h \
+ $(gir_DATA) \
+ $(typelib_DATA)
+
diff --git a/gxml/xom/Serializable.vala b/gxml/xom/Serializable.vala
new file mode 100644
index 0000000..92efca0
--- /dev/null
+++ b/gxml/xom/Serializable.vala
@@ -0,0 +1,567 @@
+/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 3; tab-width: 3 -*- */
+/* Serializable.vala
+ *
+ * Copyright (C) 2013 Daniel Espinosa <esodan gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Daniel Espinosa <esodan gmail com>
+ */
+using GXml;
+
+namespace Xom {
+ /**
+ * Interface allowing implementors direct control over serialisation of properties and other data
+ */
+ public interface Serializable : GLib.Object {
+ /**
+ * Convenient property to store serializable properties
+ */
+ protected abstract ParamSpec[] properties { get; set; }
+ /**
+ * Store all properties to be ignored on serialization.
+ *
+ * Use property's cannonical name as key and its { link GLib.ParamSpec}. To
+ * get the last one use { link GLib.get_class} and use, again, property's
+ * cannonical name to find it.
+ *
+ * Long named properties like this 'ignored_serializable_properties' are stored
+ * by GObject using its cannonical name, then you must use it as key, in this
+ * case use 'ignored-serializable-properties'.
+ *
+ * This property is ignored on serialisation.
+ *
+ * Implementors: By default { link list_serializable_properties} initialize
+ * this property to store all public properties, except this one. Make shure t
+ * call { link init_properties()} before add new propeties.
+ */
+ public abstract HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
+ /**
+ * Return { link false} if you want ignore unknown properties and { link GXml.Node}'s
+ * not in your class definition.
+ *
+ * Take care, disabling this feature you can lost data on serialization, because any unknown
+ * property or element will be ignored.
+ */
+ public abstract bool get_enable_unknown_serializable_property ();
+ /**
+ * On deserialization stores any { link GXml.Node} not used on this
+ * object, but exists in current XML file.
+ *
+ * Node's name is used as key to find stored { link GXml.Node}.
+ *
+ * This property is ignored on serialisation.
+ */
+ public abstract HashTable<string,GXml.Node> unknown_serializable_property { get; protected set; }
+
+ /**
+ * Used to add content in an { link GXml.Element}.
+ *
+ * By default no contents is serialized/deseralized. Implementors must implement
+ * { link Serializable.serialize_use_xml_node_value} function returning
+ * { link true} in order to use this property.
+ *
+ * This property is ignored by default. Implementors must implement
+ * { link serialize_use_xml_node_value ()} to return { link true}.
+ *
+ * This property is ignored on serialisation.
+ */
+ public abstract string? serialized_xml_node_value { get; protected set; default = null; }
+ /**
+ * Used to check { link GXml.Element}'s contents must be deseralized.
+ *
+ * By default no contents is serialized/deseralized. Implementors must implement
+ * this function returning { link true} in order to use { link serialized_xml_node_value}
+ * property's value in serialization to set { link GXml.Element}'s contents.
+ *
+ */
+ public abstract bool serialize_use_xml_node_value ();
+ /**
+ * Defines the way to set Node name.
+ */
+ public abstract string node_name ();
+ /**
+ * Defines the way to set Node's property name, by using
+ * it's nick instead of default name.
+ */
+ public abstract bool property_use_nick ();
+ /**
+ * Serialize this object.
+ *
+ * @doc an { link GXml.Document} object to serialise to
+ */
+ public abstract GXml.Node? serialize (GXml.Node node) throws GLib.Error;
+
+ /**
+ * Handles serializing individual properties.
+ *
+ * Interface method to handle serialization of an
+ * individual property. The implementing class
+ * receives a description of it, and should create a
+ * { link GXml.Node} that encapsulates the property.
+ * { link GXml.Serialization} will embed the { link GXml.Node} into
+ * a "Property" { link GXml.Element}, so the { link GXml.Node}
+ * returned can often be something as simple as
+ * { link GXml.Text}.
+ *
+ * To let { link GXml.Serialization} attempt to automatically
+ * serialize the property itself, do not implement
+ * this method. If the method returns %NULL,
+ * { link GXml.Serialization} will attempt handle it itsel.
+ *
+ * Implementors:
+ * Use Serializable.get_property_value in order to allow derived classes to
+ * override the properties to serialize.
+ *
+ * @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.Node} should belong to
+ * @return a new { link GXml.Node}, or %NULL
+ */
+ public abstract GXml.Node? serialize_property (GXml.Element element,
+ GLib.ParamSpec prop)
+ throws GLib.Error;
+
+ /**
+ * Deserialize this object.
+ *
+ * @node { link GXml.Node} used to deserialize from.
+ */
+ public abstract GXml.Node? deserialize (GXml.Node node)
+ throws GLib.Error;
+ /**
+ * 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.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.
+ *
+ * Implementors:
+ * Use Serializable.get_property_value in order to allow derived classes to
+ * override the properties to serialize.
+ *
+ * @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.
+ */
+ public abstract bool deserialize_property (GXml.Node property_node)
+ throws GLib.Error;
+
+ /**
+ * Signal to serialize unknown properties. Any new node must be added to
+ * @element before return the new @node added.
+ *
+ * @element a { link GXml.Node} to add attribute or child nodes to
+ * @prop a { link GLib.ParamSpec} describing attribute to serialize
+ * @node set to the { link GXml.Node} representing this attribute
+ */
+ public signal void serialize_unknown_property (GXml.Node element, ParamSpec prop, out GXml.Node node);
+
+ /**
+ * Signal to serialize unknown properties. Any new node must be added to
+ * @element before return the new @node added.
+ *
+ * @element a { link GXml.Node} to add attribute or child nodes to
+ * @prop a { link GLib.ParamSpec} describing attribute to serialize
+ * @node set to the { link GXml.Node} representing this attribute
+ */
+ public signal void serialize_unknown_property_type (GXml.Node element, ParamSpec prop, out GXml.Node
node);
+
+ /**
+ * Signal to deserialize unknown properties.
+ *
+ * @node a { link GXml.Node} to get attribute from
+ * @prop a { link GLib.ParamSpec} describing attribute to deserialize
+ */
+ public signal void deserialize_unknown_property (GXml.Node node, ParamSpec prop);
+
+ /**
+ * Signal to deserialize unknown properties' type.
+ *
+ * @node a { link GXml.Node} to get attribute from
+ * @prop a { link GLib.ParamSpec} describing attribute to deserialize
+ */
+ public signal void deserialize_unknown_property_type (GXml.Node node, ParamSpec prop);
+
+ /**
+ * Handles finding the { link GLib.ParamSpec} for a given property.
+ *
+ * @param property_name the name of a property to obtain a { link GLib.ParamSpec} for
+ * @return a { link GLib.ParamSpec} describing the named property
+ *
+ * { link GXml.Serialization} uses { link
+ * GLib.ObjectClass.find_property} (as well as { link
+ * GLib.ObjectClass.list_properties}, { link
+ * GLib.Object.get_property}, and { link
+ * GLib.Object.set_property}) to manage serialization
+ * of properties. { link GXml.Serializable} gives the
+ * implementing class an opportunity to override
+ * { link GLib.ObjectClass.find_property} to control
+ * what properties exist for { link GXml.Serialization}'s
+ * purposes.
+ *
+ * For instance, if an object has private data fields
+ * that are not installed public properties, but that
+ * should be serialized, find_property can be defined
+ * to return a { link GLib.ParamSpec} for non-installed
+ * properties. Other { link GXml.Serializable} functions
+ * should be consistent with it.
+ *
+ * An implementing class might wish to maintain such
+ * { link GLib.ParamSpec} s separately, rather than creating new
+ * ones for each call.
+ */
+ public abstract GLib.ParamSpec? find_property_spec (string property_name);
+
+ /**
+ * Default implementation for find_property_spec ().
+ *
+ */
+ public virtual GLib.ParamSpec? default_find_property_spec (string property_name) {
+ init_properties ();
+ var props = list_serializable_properties ();
+ foreach (ParamSpec spec in props) {
+ if (spec.name.down () == property_name.down ())
+ return spec;
+ if (property_use_nick ())
+ if (spec.get_nick ().down () == property_name.down ())
+ return spec;
+ if ("-" in spec.name) {
+ string[] sp = spec.name.split ("-");
+ string n = "";
+ foreach (string s in sp) {
+ n += @"$(s[0])".up () + @"$(s[1:s.length])";
+ }
+ if (n.down () == property_name.down ())
+ return spec;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Used internally to initialize { link ignored_serializable_properties} property
+ * and default not to be serialized properties. Unless you override any function
+ * is not required to be called at class implementor's construction time.
+ *
+ */
+ public abstract void init_properties ();
+
+ /**
+ * Default implementation for init_properties ().
+ *
+ */
+ public virtual void default_init_properties ()
+ {
+ if (ignored_serializable_properties == null) {
+ ignored_serializable_properties = new HashTable<string,ParamSpec> (str_hash, str_equal);
+ ignored_serializable_properties.set ("ignored-serializable-properties",
+ 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-value",
+ get_class ().find_property("serialized-xml-node-value"));
+ }
+ if (unknown_serializable_property == null) {
+ unknown_serializable_property = new HashTable<string,GXml.Node> (str_hash, str_equal);
+ }
+ }
+
+ /**
+ * List the known properties for an object's class
+ *
+ * @return an array of { link GLib.ParamSpec} of
+ * "properties" for the object.
+ *
+ * { link GXml.Serialization} uses
+ * { link GLib.ObjectClass.list_properties} (as well as
+ * { link GLib.ObjectClass.find_property},
+ * { link GLib.Object.get_property}, and { link GLib.Object.set_property})
+ * to manage serialization of an object's properties.
+ * { link GXml.Serializable} gives an implementing class an
+ * opportunity to override
+ * { link GLib.ObjectClass.list_properties} to control which
+ * properties exist for { link GXml.Serialization}'s purposes.
+ *
+ * For instance, if an object has private data fields
+ * that are not installed public properties, but that
+ * should be serialized, list_properties can be
+ * defined to return a list of { link GLib.ParamSpec} s covering
+ * all the "properties" to serialize. Other
+ * { link GXml.Serializable} functions should be consistent
+ * with it.
+ *
+ * An implementing class might wish to maintain such
+ * { link GLib.ParamSpec} s separately, rather than creating new
+ * ones for each call.
+ */
+ public abstract GLib.ParamSpec[] list_serializable_properties ();
+ /**
+ * Default implementation for list_serializable_properties ().
+ *
+ */
+ public virtual GLib.ParamSpec[] default_list_serializable_properties ()
+ {
+ init_properties ();
+ if (properties == null) {
+ ParamSpec[] props = {};
+ foreach (ParamSpec spec in this.get_class ().list_properties ()) {
+ if (!ignored_serializable_properties.contains (spec.name)) {
+ props += spec;
+ }
+ }
+ properties = props;
+ }
+ return properties;
+ }
+
+ /**
+ * Get a string version of the specified property
+ *
+ * @param spec The property we're retrieving as a string
+ *
+ * { link GXml.Serialization} uses { link GLib.Object.get_property} (as
+ * well as { link GLib.ObjectClass.find_property},
+ * { link GLib.ObjectClass.list_properties}, and
+ * { link GLib.Object.set_property}) to manage serialization of
+ * an object's properties. { link GXml.Serializable} gives an
+ * implementing class an opportunity to override
+ * { link GLib.Object.get_property} to control what value is
+ * returned for a given parameter.
+ *
+ * For instance, if an object has private data fields
+ * that are not installed public properties, but that
+ * should be serialized,
+ * { link GXml.Serializable.get_property} can be used to
+ * handle this case as a virtual property, supported
+ * by the other { link GXml.Serializable} functions.
+ *
+ * `spec` is usually obtained from list_properties or find_property.
+ */
+ public abstract void get_property_value (GLib.ParamSpec spec, ref Value val);
+ /**
+ * Default implementation for get_property_value ().
+ *
+ */
+ public virtual void default_get_property_value (GLib.ParamSpec spec, ref Value val)
+ {
+ if (!ignored_serializable_properties.contains (spec.name))
+ ((GLib.Object)this).get_property (spec.name, ref val);
+ }
+ /**
+ * Set a property's value.
+ *
+ * @param spec Specifies the property whose value will be set
+ * @param val The value to set the property to.
+ *
+ * { link GXml.Serialization} uses { link GLib.Object.set_property} (as
+ * well as { link GLib.ObjectClass.find_property},
+ * { link GLib.ObjectClass.list_properties}, and
+ * { link GLib.Object.get_property}) to manage serialization of
+ * an object's properties. { link GXml.Serializable} gives an
+ * implementing class an opportunity to override
+ * { link GLib.Object.set_property} to control how a property's
+ * value is set.
+ *
+ * For instance, if an object has private data fields
+ * that are not installed public properties, but that
+ * should be serialized,
+ * { link GXml.Serializable.set_property} can be used to
+ * handle this case as a virtual property, supported
+ * by the other { link GXml.Serializable} functions.
+ */
+ public abstract void set_property_value (GLib.ParamSpec spec, GLib.Value val);
+ /**
+ * Default implementation for set_property_value ().
+ *
+ */
+ public virtual void default_set_property_value (GLib.ParamSpec spec, GLib.Value val)
+ {
+ if (!ignored_serializable_properties.contains (spec.name)) {
+ ((GLib.Object)this).set_property (spec.name, val);
+ }
+ }
+
+ /**
+ * Method to provide custome transformations from strings to
+ * a { link GLib.Value}. Could be used on { link serialize} or simple
+ * transformations from string.
+ *
+ * Some specialized classes, like derived from { link Serializable} class
+ * implementator, can provide custome transformations.
+ *
+ * Returns: { link true} if transformation was handled, { link false} otherwise.
+ *
+ * Implementors:
+ * To be overrided by derived classes of implementators to provide custome
+ * transformations. Declare it as virtual if you want derived classes of
+ * implementators to provide custome transformations.
+ * Call this method before use standard Serializable or implementator ones.
+ *
+ * @node a { link GXml.Node} to get attribute from
+ * @prop a { link GLib.ParamSpec} describing attribute to deserialize
+ */
+ public abstract bool transform_from_string (string str, ref GLib.Value dest);
+
+ /**
+ * Transforms a string into another type hosted by { link GLib.Value}.
+ *
+ * A utility function that handles converting a string
+ * representation of a value into the type specified by the
+ * 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
+ * @param dest the #GValue out parameter that will contain the parsed value from the string
+ * @return `true` if parsing succeeded, otherwise `false`
+ */
+ public static bool string_to_gvalue (string str, ref GLib.Value dest)
+ throws SerializableError
+ {
+ Type t = dest.type ();
+ GLib.Value dest2 = Value (t);
+ bool ret = false;
+
+ if (t == typeof (int64)) {
+ int64 val;
+ if (ret = int64.try_parse (str, out val)) {
+ dest2.set_int64 (val);
+ }
+ } else if (t == typeof (int)) {
+ int64 val;
+ if (ret = int64.try_parse (str, out val)) {
+ dest2.set_int ((int)val);
+ }
+ } else if (t == typeof (long)) {
+ int64 val;
+ if (ret = int64.try_parse (str, out val)) {
+ dest2.set_long ((long)val);
+ }
+ } else if (t == typeof (uint)) {
+ uint64 val;
+ if (ret = uint64.try_parse (str, out val)) {
+ dest2.set_uint ((uint)val);
+ }
+ } else if (t == typeof (ulong)) {
+ uint64 val;
+ if (ret = uint64.try_parse (str, out val)) {
+ dest2.set_ulong ((ulong)val);
+ }
+ } else if (t == typeof (bool)) {
+ bool val;
+ if (ret = bool.try_parse (str.down (), out val)) {
+ dest2.set_boolean (val);
+ }
+ } else if (t == typeof (float)) {
+ double val;
+ if (ret = double.try_parse (str, out val)) {
+ dest2.set_float ((float)val);
+ }
+ } else if (t == typeof (double)) {
+ double val;
+ if (ret = double.try_parse (str, out val)) {
+ dest2.set_double (val);
+ }
+ } else if (t == typeof (string)) {
+ dest2.set_string (str);
+ ret = true;
+ } else if (t == typeof (char)) {
+ int64 val;
+ if (ret = int64.try_parse (str, out val)) {
+ dest2.set_char ((char)val);
+ }
+ } else if (t == typeof (uchar)) {
+ int64 val;
+ if (ret = int64.try_parse (str, out val)) {
+ dest2.set_uchar ((uchar)val);
+ }
+ } else if (t == Type.BOXED) {
+ } else if (t.is_enum ()) {
+ int64 val;
+ if (ret = int64.try_parse (str, out val)) {
+ dest2.set_enum ((int)val);
+ }
+ } else if (t.is_flags ()) {
+ } else if (t.is_object ()) {
+ } else {
+ }
+
+ if (ret == true) {
+ dest = dest2;
+ return true;
+ } else {
+ throw new SerializableError.UNSUPPORTED_TYPE ("%s/%s", t.name (), t.to_string ());
+ }
+ }
+
+ /**
+ * Method to provide custome transformations from
+ * a { link GLib.Value} to strings. Could be used on { link deserialize} or simple
+ * transformations to strings.
+ *
+ * Some specialized classes, like derived from { link Serializable} class
+ * implementator, can provide custome transformations.
+ *
+ * Returns: { link true} if transformation was handled, { link false} otherwise.
+ *
+ * Implementors:
+ * To be overrided by derived classes of implementators to provide custome
+ * transformations. Declare it as virtual if you want derived classes of
+ * implementators to provide custome transformations.
+ * Call this method before use standard Serializable or implementator ones.
+ *
+ * @node a { link GXml.Node} to get attribute from
+ * @prop a { link GLib.ParamSpec} describing attribute to deserialize
+ */
+ public abstract bool transform_to_string (GLib.Value val, ref string str);
+ /**
+ * Transforms a { link GLib.Value} to its string representation.
+ *
+ * By default use GObject standard transformations.
+ *
+ */
+ public static string gvalue_to_string (GLib.Value val)
+ throws SerializableError
+ {
+ Value ret = "";
+ if (Value.type_transformable (val.type (), typeof (string)))
+ {
+ val.transform (ref ret);
+ return ret.dup_string ();
+ }
+ else
+ {
+ throw new SerializableError.UNSUPPORTED_TYPE ("Can't transform '%s' to string", val.type ().name ());
+ }
+ }
+ }
+
+ /**
+ * 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/SerializableContainer.vala b/gxml/xom/SerializableContainer.vala
similarity index 88%
rename from gxml/SerializableContainer.vala
rename to gxml/xom/SerializableContainer.vala
index f17dc7a..cb72f47 100644
--- a/gxml/SerializableContainer.vala
+++ b/gxml/xom/SerializableContainer.vala
@@ -23,7 +23,8 @@
* Any class having a collection managed list of nodes must implement this
* abstract class.
*/
-public abstract class GXml.SerializableContainer : SerializableObjectModel
+
+public abstract class Xom.SerializableContainer : Xom.SerializableObjectModel
{
/* Xom interface properties */
public abstract void init_containers ();
@@ -32,7 +33,7 @@ public abstract class GXml.SerializableContainer : SerializableObjectModel
/**
* Fake interface to be implemented by any collection.
*/
-public interface GXml.SerializableCollection : Object, Serializable
+public interface Xom.SerializableCollection : Object, Xom.Serializable
{
public virtual bool is_collection () { return true; }
}
diff --git a/gxml/SerializableGeeArrayList.vala b/gxml/xom/SerializableGeeArrayList.vala
similarity index 88%
rename from gxml/SerializableGeeArrayList.vala
rename to gxml/xom/SerializableGeeArrayList.vala
index 4ca42a6..1334621 100644
--- a/gxml/SerializableGeeArrayList.vala
+++ b/gxml/xom/SerializableGeeArrayList.vala
@@ -22,7 +22,7 @@
using GXml;
using Gee;
-public class GXml.SerializableArrayList<G> : Gee.ArrayList<G>, Serializable, SerializableCollection
+public class Xom.SerializableArrayList<G> : Gee.ArrayList<G>, Xom.Serializable, Xom.SerializableCollection
{
protected ParamSpec[] properties { get; set; }
public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
@@ -36,7 +36,7 @@ public class GXml.SerializableArrayList<G> : Gee.ArrayList<G>, Serializable, Ser
public virtual string node_name ()
{
- return ((Serializable) Object.new (element_type)).node_name ();
+ return ((Xom.Serializable) Object.new (element_type)).node_name ();
}
public virtual GLib.ParamSpec? find_property_spec (string property_name)
@@ -84,10 +84,10 @@ public class GXml.SerializableArrayList<G> : Gee.ArrayList<G>, Serializable, Ser
throws GLib.Error
requires (node is Element)
{
- if (element_type.is_a (typeof (Serializable))) {
+ if (element_type.is_a (typeof (Xom.Serializable))) {
for (int i =0; i < size; i++) {
G e = get (i);
- ((GXml.Serializable) e).serialize (node);
+ ((Xom.Serializable) e).serialize (node);
}
}
return node;
@@ -113,15 +113,15 @@ public class GXml.SerializableArrayList<G> : Gee.ArrayList<G>, Serializable, Ser
public GXml.Node? default_deserialize (GXml.Node node)
throws GLib.Error
{
- if (!element_type.is_a (typeof (GXml.Serializable))) {
- throw new SerializableError.UNSUPPORTED_TYPE ("%s: Value type '%s' is unsupported",
+ if (!element_type.is_a (typeof (Xom.Serializable))) {
+ throw new Xom.SerializableError.UNSUPPORTED_TYPE ("%s: Value type '%s' is unsupported",
this.get_type ().name (), element_type.name ());
}
if (node is Element) {
foreach (GXml.Node n in node.child_nodes) {
if (n is Element) {
- var obj = (Serializable) Object.new (element_type);
- if (n.node_name == ((Serializable) obj).node_name ()) {
+ var obj = (Xom.Serializable) Object.new (element_type);
+ if (n.node_name == ((Xom.Serializable) obj).node_name ()) {
obj.deserialize (n);
add (obj);
}
diff --git a/gxml/SerializableGeeDualKeyMap.vala b/gxml/xom/SerializableGeeDualKeyMap.vala
similarity index 89%
rename from gxml/SerializableGeeDualKeyMap.vala
rename to gxml/xom/SerializableGeeDualKeyMap.vala
index 667bdfe..0847977 100644
--- a/gxml/SerializableGeeDualKeyMap.vala
+++ b/gxml/xom/SerializableGeeDualKeyMap.vala
@@ -22,7 +22,7 @@
using GXml;
using Gee;
-public class GXml.SerializableDualKeyMap<P,S,V> : Object, Serializable, SerializableCollection
+public class Xom.SerializableDualKeyMap<P,S,V> : Object, Xom.Serializable, Xom.SerializableCollection
{
protected Gee.HashMultiMap<P,HashMap<S,V>> storage;
@@ -118,7 +118,7 @@ public class GXml.SerializableDualKeyMap<P,S,V> : Object, Serializable, Serializ
public virtual string node_name ()
{
- return ((Serializable) Object.new (value_type)).node_name ();
+ return ((Xom.Serializable) Object.new (value_type)).node_name ();
}
public virtual GLib.ParamSpec? find_property_spec (string property_name)
@@ -167,8 +167,8 @@ public class GXml.SerializableDualKeyMap<P,S,V> : Object, Serializable, Serializ
requires (node is Element)
{
foreach (V v in values ()) {
- if (v is Serializable)
- ((GXml.Serializable) v).serialize (node);;
+ if (v is Xom.Serializable)
+ ((Xom.Serializable) v).serialize (node);;
}
return node;
}
@@ -194,16 +194,16 @@ public class GXml.SerializableDualKeyMap<P,S,V> : Object, Serializable, Serializ
throws GLib.Error
requires (node is Element)
{
- if (!(value_type.is_a (typeof (GXml.Serializable)) &&
- value_type.is_a (typeof (SerializableMapDualKey)))) {
- throw new SerializableError.UNSUPPORTED_TYPE ("%s: Value type '%s' is unsupported",
+ if (!(value_type.is_a (typeof (Xom.Serializable)) &&
+ value_type.is_a (typeof (Xom.SerializableMapDualKey)))) {
+ throw new Xom.SerializableError.UNSUPPORTED_TYPE ("%s: Value type '%s' is unsupported",
this.get_type ().name (), value_type.name ());
}
foreach (GXml.Node n in node.child_nodes) {
if (n is Element) {
- var obj = (SerializableMapDualKey<P,S>) Object.new (value_type);
- if (n.node_name == ((Serializable) obj).node_name ()) {
- ((Serializable) obj).deserialize (n);
+ var obj = (Xom.SerializableMapDualKey<P,S>) Object.new (value_type);
+ if (n.node_name == ((Xom.Serializable) obj).node_name ()) {
+ ((Xom.Serializable) obj).deserialize (n);
@set (obj.get_map_primary_key (), obj.get_map_secondary_key (), obj);
}
}
diff --git a/gxml/SerializableGeeHashMap.vala b/gxml/xom/SerializableGeeHashMap.vala
similarity index 86%
rename from gxml/SerializableGeeHashMap.vala
rename to gxml/xom/SerializableGeeHashMap.vala
index a7ce625..3c8c526 100644
--- a/gxml/SerializableGeeHashMap.vala
+++ b/gxml/xom/SerializableGeeHashMap.vala
@@ -21,7 +21,7 @@
*/
using GXml;
-public class GXml.SerializableHashMap<K,V> : Gee.HashMap<K,V>, Serializable, SerializableCollection
+public class Xom.SerializableHashMap<K,V> : Gee.HashMap<K,V>, Xom.Serializable, Xom.SerializableCollection
{
protected ParamSpec[] properties { get; set; }
public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
@@ -34,7 +34,7 @@ public class GXml.SerializableHashMap<K,V> : Gee.HashMap<K,V>, Serializable, Ser
public virtual string node_name ()
{
- return ((Serializable) Object.new (value_type)).node_name ();
+ return ((Xom.Serializable) Object.new (value_type)).node_name ();
}
public virtual GLib.ParamSpec? find_property_spec (string property_name)
@@ -82,9 +82,9 @@ public class GXml.SerializableHashMap<K,V> : Gee.HashMap<K,V>, Serializable, Ser
throws GLib.Error
requires (node is Element)
{
- if (value_type.is_a (typeof (Serializable))) {
+ if (value_type.is_a (typeof (Xom.Serializable))) {
foreach (V v in values) {
- ((GXml.Serializable) v).serialize (node);
+ ((Xom.Serializable) v).serialize (node);
}
}
return node;
@@ -110,9 +110,9 @@ public class GXml.SerializableHashMap<K,V> : Gee.HashMap<K,V>, Serializable, Ser
public GXml.Node? default_deserialize (GXml.Node node)
throws GLib.Error
{
- if (!(value_type.is_a (typeof (GXml.Serializable)) &&
- value_type.is_a (typeof (SerializableMapKey)))) {
- throw new SerializableError.UNSUPPORTED_TYPE ("%s: Value type '%s' is unsupported",
+ if (!(value_type.is_a (typeof (Xom.Serializable)) &&
+ value_type.is_a (typeof (Xom.SerializableMapKey)))) {
+ throw new Xom.SerializableError.UNSUPPORTED_TYPE ("%s: Value type '%s' is unsupported",
this.get_type ().name (), value_type.name ());
}
if (node is Element) {
@@ -122,9 +122,9 @@ public class GXml.SerializableHashMap<K,V> : Gee.HashMap<K,V>, Serializable, Ser
stdout.printf (@"Node $(node.node_name) for type '$(get_type ().name ())'\n");
#endif
var obj = Object.new (value_type);
- if (n.node_name == ((Serializable) obj).node_name ()) {
- ((Serializable) obj).deserialize (n);
- @set (((SerializableMapKey<K>) obj).get_map_key (), obj);
+ if (n.node_name == ((Xom.Serializable) obj).node_name ()) {
+ ((Xom.Serializable) obj).deserialize (n);
+ @set (((Xom.SerializableMapKey<K>) obj).get_map_key (), obj);
}
}
}
diff --git a/gxml/SerializableGeeTreeMap.vala b/gxml/xom/SerializableGeeTreeMap.vala
similarity index 84%
rename from gxml/SerializableGeeTreeMap.vala
rename to gxml/xom/SerializableGeeTreeMap.vala
index 4f3efd2..f3825bf 100644
--- a/gxml/SerializableGeeTreeMap.vala
+++ b/gxml/xom/SerializableGeeTreeMap.vala
@@ -21,7 +21,7 @@
*/
using GXml;
-public class GXml.SerializableTreeMap<K,V> : Gee.TreeMap<K,V>, Serializable, SerializableCollection
+public class Xom.SerializableTreeMap<K,V> : Gee.TreeMap<K,V>, Xom.Serializable, Xom.SerializableCollection
{
protected ParamSpec[] properties { get; set; }
public GLib.HashTable<string,GLib.ParamSpec> ignored_serializable_properties { get; protected set; }
@@ -34,8 +34,8 @@ public class GXml.SerializableTreeMap<K,V> : Gee.TreeMap<K,V>, Serializable, Ser
public virtual string node_name ()
{
- if (value_type.is_a (typeof (Serializable)))
- return ((Serializable) Object.new (value_type)).node_name ();
+ if (value_type.is_a (typeof (Xom.Serializable)))
+ return ((Xom.Serializable) Object.new (value_type)).node_name ();
else
return get_type ().name ();
}
@@ -85,9 +85,9 @@ public class GXml.SerializableTreeMap<K,V> : Gee.TreeMap<K,V>, Serializable, Ser
throws GLib.Error
requires (node is Element)
{
- if (value_type.is_a (typeof (Serializable))) {
+ if (value_type.is_a (typeof (Xom.Serializable))) {
foreach (V v in values) {
- ((GXml.Serializable) v).serialize (node);
+ ((Xom.Serializable) v).serialize (node);
}
}
return node;
@@ -113,21 +113,21 @@ public class GXml.SerializableTreeMap<K,V> : Gee.TreeMap<K,V>, Serializable, Ser
public GXml.Node? default_deserialize (GXml.Node node)
throws GLib.Error
{
- if (!(value_type.is_a (typeof (GXml.Serializable)) &&
- value_type.is_a (typeof (SerializableMapKey)))) {
- throw new SerializableError.UNSUPPORTED_TYPE ("%s: Value type '%s' is unsupported",
+ if (!(value_type.is_a (typeof (Xom.Serializable)) &&
+ value_type.is_a (typeof (Xom.SerializableMapKey)))) {
+ throw new Xom.SerializableError.UNSUPPORTED_TYPE ("%s: Value type '%s' is unsupported",
this.get_type ().name (), value_type.name ());
}
- if (node is Element) {
+ if (node is GXml.Element) {
foreach (GXml.Node n in node.child_nodes) {
if (n is Element) {
#if DEBUG
stdout.printf (@"Node $(node.node_name) for type '$(get_type ().name ())'\n");
#endif
var obj = Object.new (value_type);
- if (n.node_name == ((Serializable) obj).node_name ()) {
- ((Serializable) obj).deserialize (n);
- @set (((SerializableMapKey<K>) obj).get_map_key (), obj);
+ if (n.node_name == ((Xom.Serializable) obj).node_name ()) {
+ ((Xom.Serializable) obj).deserialize (n);
+ @set (((Xom.SerializableMapKey<K>) obj).get_map_key (), obj);
}
}
}
diff --git a/gxml/SerializableMapDualKey.vala b/gxml/xom/SerializableMapDualKey.vala
similarity index 94%
rename from gxml/SerializableMapDualKey.vala
rename to gxml/xom/SerializableMapDualKey.vala
index 5bfbf94..6776df4 100644
--- a/gxml/SerializableMapDualKey.vala
+++ b/gxml/xom/SerializableMapDualKey.vala
@@ -20,7 +20,7 @@
* Daniel Espinosa <esodan gmail com>
*/
using GXml;
-public interface GXml.SerializableMapDualKey<P,S> : Object
+public interface Xom.SerializableMapDualKey<P,S> : Object
{
public abstract P get_map_primary_key ();
public abstract S get_map_secondary_key ();
diff --git a/gxml/SerializableMapKey.vala b/gxml/xom/SerializableMapKey.vala
similarity index 94%
copy from gxml/SerializableMapKey.vala
copy to gxml/xom/SerializableMapKey.vala
index 944b1b0..77882f8 100644
--- a/gxml/SerializableMapKey.vala
+++ b/gxml/xom/SerializableMapKey.vala
@@ -21,7 +21,7 @@
*/
using GXml;
-public interface GXml.SerializableMapKey<K> : Object
+public interface Xom.SerializableMapKey<K> : Object
{
public abstract K get_map_key ();
}
diff --git a/gxml/SerializableObjectModel.vala b/gxml/xom/SerializableObjectModel.vala
similarity index 93%
rename from gxml/SerializableObjectModel.vala
rename to gxml/xom/SerializableObjectModel.vala
index c0e3146..0e68881 100644
--- a/gxml/SerializableObjectModel.vala
+++ b/gxml/xom/SerializableObjectModel.vala
@@ -19,8 +19,9 @@
* Authors:
* Daniel Espinosa <esodan gmail com>
*/
+using GXml;
-public abstract class GXml.SerializableObjectModel : Object, Serializable
+public abstract class Xom.SerializableObjectModel : Object, Serializable
{
/* Serializable interface properties */
protected ParamSpec[] properties { get; set; }
@@ -79,7 +80,7 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
public virtual GXml.Node? serialize (GXml.Node node)
throws GLib.Error
requires (node_name () != null)
- requires (node is Document || node is Element)
+ requires (node is GXml.Document || node is Element)
{
return default_serialize (node);
}
@@ -89,9 +90,9 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
#if DEBUG
stdout.printf (@"$(get_type ().name ()): Serializing on node: $(node.node_name)\n");
#endif
- Document doc;
- if (node is Document)
- doc = (Document) node;
+ GXml.Document doc;
+ if (node is GXml.Document)
+ doc = (GXml.Document) node;
else
doc = node.owner_document;
var element = doc.create_element (node_name ());
@@ -99,15 +100,15 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
serialize_property (element, spec);
}
if (get_enable_unknown_serializable_property ()) {
- foreach (Node n in unknown_serializable_property.get_values ()) {
- if (n is Element) {
- var e = (Node) doc.create_element (n.node_name);
+ foreach (GXml.Node n in unknown_serializable_property.get_values ()) {
+ if (n is GXml.Element) {
+ var e = (GXml.Node) doc.create_element (n.node_name);
n.copy (ref e, true);
element.append_child (e);
}
if (n is Attr) {
element.set_attribute (n.node_name, n.node_value);
- var a = (Node) element.get_attribute_node (n.node_name);
+ var a = (GXml.Node) element.get_attribute_node (n.node_name);
n.copy (ref a);
}
if (n is Text) {
@@ -173,7 +174,7 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
val = rval.dup_string ();
}
else {
- Node node = null;
+ GXml.Node node = null;
this.serialize_unknown_property (element, prop, out node);
return node;
}
@@ -193,7 +194,7 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
}
else
attr.value = val;
- return (Node) attr;
+ return (GXml.Node) attr;
}
public virtual GXml.Node? deserialize (GXml.Node node)
@@ -205,18 +206,18 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
public GXml.Node? default_deserialize (GXml.Node node)
throws GLib.Error
{
- Document doc;
- if (node is Document) {
- doc = (Document) node;
+ GXml.Document doc;
+ if (node is GXml.Document) {
+ doc = (GXml.Document) node;
return_val_if_fail (doc.document_element != null, null);
}
else
doc = node.owner_document;
- Element element;
- if (node is Element)
+ GXml.Element element;
+ if (node is GXml.Element)
element = (Element) node;
else
- element = (Element) doc.document_element;
+ element = (GXml.Element) doc.document_element;
return_val_if_fail (element != null, null);
if (node_name () == null) {
message (@"WARNING: Object type '$(get_type ().name ())' have no Node Name defined");
@@ -262,7 +263,7 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
}
}
}
- foreach (Node n in element.child_nodes)
+ foreach (GXml.Node n in element.child_nodes)
{
if (n is Text) {
if (serialize_use_xml_node_value ()) {
@@ -277,7 +278,7 @@ public abstract class GXml.SerializableObjectModel : Object, Serializable
}
}
}
- if (n is Element && !cnodes.has_key (n.node_name)) {
+ if (n is GXml.Element && !cnodes.has_key (n.node_name)) {
#if DEBUG
stdout.printf (@"$(get_type ().name ()): DESERIALIZING ELEMENT '$(n.node_name)'\n");
#endif
diff --git a/gxml/SerializableMapKey.vala b/gxml/xom/namespace-info.vala.in
similarity index 62%
rename from gxml/SerializableMapKey.vala
rename to gxml/xom/namespace-info.vala.in
index 944b1b0..f1b6e43 100644
--- a/gxml/SerializableMapKey.vala
+++ b/gxml/xom/namespace-info.vala.in
@@ -1,27 +1,24 @@
-/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* SerializableGeeTreeModel.vala
+/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
+/* namespace-info.vala
*
- * Copyright (C) 2013 Daniel Espinosa <esodan gmail com>
+ * Copyright (C) 2011 Daniel Espinosa <esodan gmail com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
- *
+
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
* Daniel Espinosa <esodan gmail com>
*/
-using GXml;
-
-public interface GXml.SerializableMapKey<K> : Object
-{
- public abstract K get_map_key ();
-}
+[CCode (gir_namespace = "Xom", gir_version = "@API_VERSION@")]
+namespace Xom {}
diff --git a/gxml/xom/xom-0.4.pc.in b/gxml/xom/xom-0.4.pc.in
new file mode 100644
index 0000000..66b1972
--- /dev/null
+++ b/gxml/xom/xom-0.4.pc.in
@@ -0,0 +1,14 @@
+prefix= prefix@
+exec_prefix= exec_prefix@
+libdir= libdir@
+datarootdir= datarootdir@
+datadir= datadir@
+includedir= includedir@
+
+Name: libxom
+Description: GObject Serialization library to XML
+URL: http://live.gnome.org/XML
+Version: @VERSION@
+Requires: glib-2.0 gobject-2.0 gee-0.8 libxml-2.0 gxml-0.4
+Libs: -L${libdir} -lxom- API_VERSION@
+Cflags: -I${includedir}/gxml- API_VERSION@
diff --git a/gxml/xom/xom.symbols b/gxml/xom/xom.symbols
new file mode 100644
index 0000000..5000d2c
--- /dev/null
+++ b/gxml/xom/xom.symbols
@@ -0,0 +1,191 @@
+xom_enumeration_construct
+xom_enumeration_get_nick
+xom_enumeration_get_nick_camelcase
+xom_enumeration_get_string
+xom_enumeration_get_type
+xom_enumeration_new
+xom_enumeration_parse
+xom_enumeration_ref
+xom_enumeration_to_array
+xom_enumeration_unref
+xom_param_spec_enumeration
+xom_serializable_array_list_construct
+xom_serializable_array_list_default_deserialize
+xom_serializable_array_list_default_deserialize_property
+xom_serializable_array_list_default_serialize
+xom_serializable_array_list_default_serialize_property
+xom_serializable_array_list_deserialize
+xom_serializable_array_list_deserialize_property
+xom_serializable_array_list_find_property_spec
+xom_serializable_array_list_get_property_value
+xom_serializable_array_list_get_type
+xom_serializable_array_list_init_properties
+xom_serializable_array_list_list_serializable_properties
+xom_serializable_array_list_new
+xom_serializable_array_list_node_name
+xom_serializable_array_list_property_use_nick
+xom_serializable_array_list_serialize
+xom_serializable_array_list_serialize_property
+xom_serializable_array_list_serialize_use_xml_node_value
+xom_serializable_array_list_set_property_value
+xom_serializable_array_list_transform_from_string
+xom_serializable_array_list_transform_to_string
+xom_serializable_collection_get_type
+xom_serializable_collection_is_collection
+xom_serializable_container_construct
+xom_serializable_container_get_type
+xom_serializable_container_init_containers
+xom_serializable_default_find_property_spec
+xom_serializable_default_get_property_value
+xom_serializable_default_init_properties
+xom_serializable_default_list_serializable_properties
+xom_serializable_default_set_property_value
+xom_serializable_deserialize
+xom_serializable_deserialize_property
+xom_serializable_dual_key_map_construct
+xom_serializable_dual_key_map_default_deserialize
+xom_serializable_dual_key_map_default_deserialize_property
+xom_serializable_dual_key_map_default_serialize
+xom_serializable_dual_key_map_default_serialize_property
+xom_serializable_dual_key_map_deserialize
+xom_serializable_dual_key_map_deserialize_property
+xom_serializable_dual_key_map_find_property_spec
+xom_serializable_dual_key_map_get
+xom_serializable_dual_key_map_get_enable_unknown_serializable_property
+xom_serializable_dual_key_map_get_primary_key_type
+xom_serializable_dual_key_map_get_primary_keys
+xom_serializable_dual_key_map_get_property_value
+xom_serializable_dual_key_map_get_secondary_key_type
+xom_serializable_dual_key_map_get_size
+xom_serializable_dual_key_map_get_type
+xom_serializable_dual_key_map_get_value_type
+xom_serializable_dual_key_map_init_properties
+xom_serializable_dual_key_map_list_serializable_properties
+xom_serializable_dual_key_map_new
+xom_serializable_dual_key_map_node_name
+xom_serializable_dual_key_map_property_use_nick
+xom_serializable_dual_key_map_secondary_keys
+xom_serializable_dual_key_map_serialize
+xom_serializable_dual_key_map_serialize_property
+xom_serializable_dual_key_map_serialize_use_xml_node_value
+xom_serializable_dual_key_map_set
+xom_serializable_dual_key_map_set_property_value
+xom_serializable_dual_key_map_transform_from_string
+xom_serializable_dual_key_map_transform_to_string
+xom_serializable_dual_key_map_values
+xom_serializable_dual_key_map_values_for_key
+xom_serializable_find_property_spec
+xom_serializable_get_enable_unknown_serializable_property
+xom_serializable_get_ignored_serializable_properties
+xom_serializable_get_properties
+xom_serializable_get_property_value
+xom_serializable_get_serialized_xml_node_value
+xom_serializable_get_type
+xom_serializable_get_unknown_serializable_property
+xom_serializable_gvalue_to_string
+xom_serializable_hash_map_construct
+xom_serializable_hash_map_default_deserialize
+xom_serializable_hash_map_default_deserialize_property
+xom_serializable_hash_map_default_serialize
+xom_serializable_hash_map_default_serialize_property
+xom_serializable_hash_map_deserialize
+xom_serializable_hash_map_deserialize_property
+xom_serializable_hash_map_find_property_spec
+xom_serializable_hash_map_get_enable_unknown_serializable_property
+xom_serializable_hash_map_get_property_value
+xom_serializable_hash_map_get_type
+xom_serializable_hash_map_init_properties
+xom_serializable_hash_map_list_serializable_properties
+xom_serializable_hash_map_new
+xom_serializable_hash_map_node_name
+xom_serializable_hash_map_property_use_nick
+xom_serializable_hash_map_serialize
+xom_serializable_hash_map_serialize_property
+xom_serializable_hash_map_serialize_use_xml_node_value
+xom_serializable_hash_map_set_property_value
+xom_serializable_hash_map_transform_from_string
+xom_serializable_hash_map_transform_to_string
+xom_serializable_init_properties
+xom_serializable_json_construct
+xom_serializable_json_deserialize_property
+xom_serializable_json_find_property_spec
+xom_serializable_json_get_enable_unknown_serializable_property
+xom_serializable_json_get_property_value
+xom_serializable_json_get_type
+xom_serializable_json_init_properties
+xom_serializable_json_list_serializable_properties
+xom_serializable_json_new
+xom_serializable_json_node_name
+xom_serializable_json_property_use_nick
+xom_serializable_json_serialize_property
+xom_serializable_json_serialize_use_xml_node_value
+xom_serializable_json_set_property_value
+xom_serializable_json_transform_from_string
+xom_serializable_json_transform_to_string
+xom_serializable_list_serializable_properties
+xom_serializable_map_dual_key_get_map_primary_key
+xom_serializable_map_dual_key_get_map_secondary_key
+xom_serializable_map_dual_key_get_type
+xom_serializable_map_key_get_map_key
+xom_serializable_map_key_get_type
+xom_serializable_node_name
+xom_serializable_object_model_construct
+xom_serializable_object_model_default_deserialize
+xom_serializable_object_model_default_deserialize_property
+xom_serializable_object_model_default_node_name
+xom_serializable_object_model_default_serialize
+xom_serializable_object_model_default_serialize_property
+xom_serializable_object_model_deserialize
+xom_serializable_object_model_deserialize_property
+xom_serializable_object_model_equals
+xom_serializable_object_model_find_property_spec
+xom_serializable_object_model_get_enable_unknown_serializable_property
+xom_serializable_object_model_get_property_value
+xom_serializable_object_model_get_type
+xom_serializable_object_model_init_properties
+xom_serializable_object_model_list_serializable_properties
+xom_serializable_object_model_node_name
+xom_serializable_object_model_property_use_nick
+xom_serializable_object_model_serialize
+xom_serializable_object_model_serialize_property
+xom_serializable_object_model_serialize_use_xml_node_value
+xom_serializable_object_model_set_property_value
+xom_serializable_object_model_to_string
+xom_serializable_object_model_transform_from_string
+xom_serializable_object_model_transform_to_string
+xom_serializable_property_use_nick
+xom_serializable_serialize
+xom_serializable_serialize_property
+xom_serializable_serialize_use_xml_node_value
+xom_serializable_set_ignored_serializable_properties
+xom_serializable_set_properties
+xom_serializable_set_property_value
+xom_serializable_set_serialized_xml_node_value
+xom_serializable_set_unknown_serializable_property
+xom_serializable_string_to_gvalue
+xom_serializable_transform_from_string
+xom_serializable_transform_to_string
+xom_serializable_tree_map_construct
+xom_serializable_tree_map_default_deserialize
+xom_serializable_tree_map_default_deserialize_property
+xom_serializable_tree_map_default_serialize
+xom_serializable_tree_map_default_serialize_property
+xom_serializable_tree_map_deserialize
+xom_serializable_tree_map_deserialize_property
+xom_serializable_tree_map_find_property_spec
+xom_serializable_tree_map_get_property_value
+xom_serializable_tree_map_get_type
+xom_serializable_tree_map_init_properties
+xom_serializable_tree_map_list_serializable_properties
+xom_serializable_tree_map_new
+xom_serializable_tree_map_node_name
+xom_serializable_tree_map_property_use_nick
+xom_serializable_tree_map_serialize
+xom_serializable_tree_map_serialize_property
+xom_serializable_tree_map_serialize_use_xml_node_value
+xom_serializable_tree_map_set_property_value
+xom_serializable_tree_map_transform_from_string
+xom_serializable_tree_map_transform_to_string
+xom_value_get_enumeration
+xom_value_set_enumeration
+xom_value_take_enumeration
diff --git a/test/EnumerationTest.vala b/test/EnumerationTest.vala
index 4b689e4..344bd45 100644
--- a/test/EnumerationTest.vala
+++ b/test/EnumerationTest.vala
@@ -24,6 +24,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using GXml;
+using Xom;
using Gee;
public enum OptionsEnum
@@ -212,4 +213,4 @@ class SerializableEnumerationTest : GXmlTest
}
});
}
-}
\ No newline at end of file
+}
diff --git a/test/GXmlTest.vala b/test/GXmlTest.vala
index 148eafa..5cbffb6 100644
--- a/test/GXmlTest.vala
+++ b/test/GXmlTest.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 -*- */
using GXml;
class GXmlTest {
diff --git a/test/Makefile.am b/test/Makefile.am
index dffcccb..538a8ec 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -15,8 +15,8 @@ AM_CFLAGS = \
$(GEE_CFLAGS) \
$(LIBXML_CFLAGS) \
$(GIO_CFLAGS) \
- -I$(top_srcdir) \
- -DTEST_DIR=\""$(top_srcdir)/test"\" \
+ -I../gxml \
+ -DTEST_DIR=\"$(builddir)\" \
$(NULL)
@@ -54,11 +54,13 @@ gxml_test_VALAFLAGS = \
$(top_srcdir)/vapi/config.vapi \
$(top_srcdir)/vapi/gxml-test.vapi \
--vapidir=$(top_srcdir)/vapi \
- --vapidir=$(top_srcdir)/gxml \
+ --vapidir=../gxml \
+ --vapidir=../gxml/xom \
--pkg gio-2.0 \
--pkg gee-0.8 \
--pkg posix \
--pkg gxml-0.4 \
+ --pkg xom-0.4 \
--pkg libxml-2.0 \
-X -DTEST_DIR=$(top_srcdir)/test \
$(NULL)
@@ -70,7 +72,8 @@ gxml_test_LDADD = \
$(GXML_LIBS) \
$(LIBXML_LIBS) \
$(GIO_LIBS) \
- ../gxml/libgxml-0.4.la
+ ../gxml/libgxml-0.4.la\
+ ../gxml/xom/libxom-0.4.la \
$(NULL)
gxml_test_LDFLAGS = $(AM_LDFLAGS)
@@ -92,6 +95,8 @@ CLEANFILES = $(gxml_test_SOURCES:.vala=.c) $(BUILT_SOURCES) gxml_test
DISTCLEANFILES = _serialization_test_*.xml
EXTRA_DIST += \
+ test_invalid.xml \
+ test_with_ns.xml \
test_out_path_expected.xml \
test_out_stream_expected.xml \
test.xml \
diff --git a/test/SerializableBasicTypesTest.vala b/test/SerializableBasicTypesTest.vala
index b3655ef..96ba63f 100644
--- a/test/SerializableBasicTypesTest.vala
+++ b/test/SerializableBasicTypesTest.vala
@@ -24,6 +24,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using GXml;
+using Xom;
+
class SerializableBasicTypeTest : GXmlTest {
public class BasicType : SerializableObjectModel
{
diff --git a/test/SerializableGeeArrayListTest.vala b/test/SerializableGeeArrayListTest.vala
index 82a5b62..ce316e2 100644
--- a/test/SerializableGeeArrayListTest.vala
+++ b/test/SerializableGeeArrayListTest.vala
@@ -24,6 +24,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using GXml;
+using Xom;
using Gee;
class AElement : SerializableObjectModel
diff --git a/test/SerializableGeeCollectionsTest.vala b/test/SerializableGeeCollectionsTest.vala
index 3022be0..38dffe6 100644
--- a/test/SerializableGeeCollectionsTest.vala
+++ b/test/SerializableGeeCollectionsTest.vala
@@ -24,6 +24,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using GXml;
+using Xom;
using Gee;
class SerializableGeeCollectionsTest : GXmlTest
diff --git a/test/SerializableGeeDualKeyMapTest.vala b/test/SerializableGeeDualKeyMapTest.vala
index 01a0a8f..3db02c2 100644
--- a/test/SerializableGeeDualKeyMapTest.vala
+++ b/test/SerializableGeeDualKeyMapTest.vala
@@ -24,6 +24,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using GXml;
+using Xom;
using Gee;
class Spaces : SerializableObjectModel, SerializableMapDualKey<string,string>
diff --git a/test/SerializableGeeHashMapTest.vala b/test/SerializableGeeHashMapTest.vala
index ad48795..24073b4 100644
--- a/test/SerializableGeeHashMapTest.vala
+++ b/test/SerializableGeeHashMapTest.vala
@@ -24,6 +24,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using GXml;
+using Xom;
using Gee;
class SerializableGeeHashMapTest : GXmlTest
diff --git a/test/SerializableGeeTreeMapTest.vala b/test/SerializableGeeTreeMapTest.vala
index 87c2c61..7214fdd 100644
--- a/test/SerializableGeeTreeMapTest.vala
+++ b/test/SerializableGeeTreeMapTest.vala
@@ -24,6 +24,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using GXml;
+using Xom;
using Gee;
class SerializableGeeTreeMapTest : GXmlTest
diff --git a/test/SerializableObjectModelTest.vala b/test/SerializableObjectModelTest.vala
index 3325464..47571ec 100644
--- a/test/SerializableObjectModelTest.vala
+++ b/test/SerializableObjectModelTest.vala
@@ -24,7 +24,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using GXml;
+using Xom;
using Gee;
+
const string XML_COMPUTER_FILE =
"""<?xml version="1.0"?>
<computer manufacturer="ThecnicalGroup" model="YH576G" cores="4" ghz="2.8"/>""";
@@ -124,7 +126,7 @@ public class Package : ObjectModel
manual = new Manual ();
source = "Mexico";
destiny = "World";
- ((Serializable) this).serialize_unknown_property.connect ( (element, prop, out node) => {
+ ((Xom.Serializable) this).serialize_unknown_property.connect ( (element, prop, out node) => {
//GLib.message (@"Serializing Unknown Property: $(prop.name) | $(prop.get_nick ())");
if (prop.name == "tags")
{
@@ -136,7 +138,7 @@ public class Package : ObjectModel
}
}
});
- ((Serializable) this).deserialize_unknown_property.connect ( (element, prop) => {
+ ((Xom.Serializable) this).deserialize_unknown_property.connect ( (element, prop) => {
//GLib.message (@"Deserializing Unknown Property: $(prop.name) | $(prop.get_nick ())");
if (element.node_name == "tag") {
tags.append_val (((Element) element).content);
@@ -964,4 +966,4 @@ class SerializableObjectModelTest : GXmlTest
assert_not_reached ();
}
}
-}
\ No newline at end of file
+}
diff --git a/test/SerializableTest.vala b/test/SerializableTest.vala
index aea2044..7b914d7 100644
--- a/test/SerializableTest.vala
+++ b/test/SerializableTest.vala
@@ -25,6 +25,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using GXml;
+using Xom;
using Gee;
/**
@@ -96,8 +97,8 @@ public class SerializableCapsicum : GXml.SerializableJson {
this.age = age;
this.height = height;
this.ratings = ratings;
- ((Serializable)this).serialize_unknown_property_type.connect
(serialize_unknown_property_type);
- ((Serializable)this).deserialize_unknown_property_type.connect
(deserialize_unknown_property_type);
+ ((GXml.Serializable)this).serialize_unknown_property_type.connect
(serialize_unknown_property_type);
+ ((GXml.Serializable)this).deserialize_unknown_property_type.connect
(deserialize_unknown_property_type);
}
/* TODO: do we really need GLib.Value? or should we modify the object directly?
diff --git a/test/test.xml b/test/test.xml.in
similarity index 100%
rename from test/test.xml
rename to test/test.xml.in
diff --git a/test/test_invalid.xml b/test/test_invalid.xml.in
similarity index 100%
rename from test/test_invalid.xml
rename to test/test_invalid.xml.in
diff --git a/test/test_out_path_expected.xml b/test/test_out_path_expected.xml.in
similarity index 100%
rename from test/test_out_path_expected.xml
rename to test/test_out_path_expected.xml.in
diff --git a/test/test_out_stream_expected.xml b/test/test_out_stream_expected.xml.in
similarity index 100%
rename from test/test_out_stream_expected.xml
rename to test/test_out_stream_expected.xml.in
diff --git a/test/test_with_ns.xml b/test/test_with_ns.xml.in
similarity index 100%
rename from test/test_with_ns.xml
rename to test/test_with_ns.xml.in
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]