[gxml] SerializableCollection added Error thrown. Post-serialization HashMap
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] SerializableCollection added Error thrown. Post-serialization HashMap
- Date: Wed, 24 Feb 2016 19:48:42 +0000 (UTC)
commit b9a54c0f0dea1545e595561c57eba08a7c0add3a
Author: Daniel Espinosa <esodan gmail com>
Date: Wed Feb 24 13:05:50 2016 -0600
SerializableCollection added Error thrown. Post-serialization HashMap
gxml/SerializableContainer.vala | 4 +-
gxml/SerializableGeeArrayList.vala | 4 +-
gxml/SerializableGeeDualKeyMap.vala | 4 +-
gxml/SerializableGeeHashMap.vala | 58 +++++++++++++++++++++--------------
gxml/SerializableGeeTreeMap.vala | 4 +-
5 files changed, 43 insertions(+), 31 deletions(-)
---
diff --git a/gxml/SerializableContainer.vala b/gxml/SerializableContainer.vala
index 362f5fd..b177eb1 100644
--- a/gxml/SerializableContainer.vala
+++ b/gxml/SerializableContainer.vala
@@ -68,7 +68,7 @@ public interface GXml.SerializableCollection : Object, Gee.Traversable<Serializa
*
* This could override existing objects in collection.
*/
- public abstract bool deserialize_node (GXml.Node node);
+ public abstract bool deserialize_node (GXml.Node node) throws GLib.Error;
/**
* Executes a deserialization from all children nodes in a { link GXml.Node}. After this operation
* { link GXml.SerializableCollection.deserialized} should return true. This
@@ -77,7 +77,7 @@ public interface GXml.SerializableCollection : Object, Gee.Traversable<Serializa
*
* This could override existing objects in collection.
*/
- public abstract bool deserialize_children ();
+ public abstract bool deserialize_children () throws GLib.Error;
/**
* Convenient function to detect Serializable Collections.
*/
diff --git a/gxml/SerializableGeeArrayList.vala b/gxml/SerializableGeeArrayList.vala
index a1ae8b0..79bf514 100644
--- a/gxml/SerializableGeeArrayList.vala
+++ b/gxml/SerializableGeeArrayList.vala
@@ -37,7 +37,7 @@ public class GXml.SerializableArrayList<G> : Gee.ArrayList<G>, Serializable, Ser
public virtual bool deserialize_proceed () { return true; }
public virtual bool deserialized () { return _deserialized; }
public virtual bool is_prepared () { return (_node is GXml.Node); }
- public virtual bool deserialize_node (GXml.Node node) {
+ public virtual bool deserialize_node (GXml.Node node) throws GLib.Error {
if (!element_type.is_a (typeof (GXml.Serializable))) {
throw new SerializableError.UNSUPPORTED_TYPE_ERROR (_("%s: Value type '%s' is unsupported"),
this.get_type ().name (), element_type.name ());
@@ -51,7 +51,7 @@ public class GXml.SerializableArrayList<G> : Gee.ArrayList<G>, Serializable, Ser
}
return true;
}
- public virtual bool deserialize_children () {
+ public virtual bool deserialize_children () throws GLib.Error {
if (!is_prepared ()) return false;
if (!element_type.is_a (typeof (GXml.Serializable))) {
throw new SerializableError.UNSUPPORTED_TYPE_ERROR (_("%s: Value type '%s' is unsupported"),
diff --git a/gxml/SerializableGeeDualKeyMap.vala b/gxml/SerializableGeeDualKeyMap.vala
index 91e0706..33cf7b4 100644
--- a/gxml/SerializableGeeDualKeyMap.vala
+++ b/gxml/SerializableGeeDualKeyMap.vala
@@ -37,8 +37,8 @@ public class GXml.SerializableDualKeyMap<P,S,V> : Object, Gee.Traversable <V>, S
public virtual bool deserialize_proceed () { return true; }
public virtual bool deserialized () { return true; }
public virtual bool is_prepared () { return (_node is GXml.Node); }
- public virtual bool deserialize_node (GXml.Node node) { return false; }
- public virtual bool deserialize_children () { return false; }
+ public virtual bool deserialize_node (GXml.Node node) throws GLib.Error { return false; }
+ public virtual bool deserialize_children () throws GLib.Error { return false; }
construct { Init.init (); }
diff --git a/gxml/SerializableGeeHashMap.vala b/gxml/SerializableGeeHashMap.vala
index 8eaf69b..3161619 100644
--- a/gxml/SerializableGeeHashMap.vala
+++ b/gxml/SerializableGeeHashMap.vala
@@ -34,8 +34,34 @@ public class GXml.SerializableHashMap<K,V> : Gee.HashMap<K,V>, Serializable, Ser
public virtual bool deserialize_proceed () { return true; }
public virtual bool deserialized () { return true; }
public virtual bool is_prepared () { return (_node is GXml.Node); }
- public virtual bool deserialize_node (GXml.Node node) { return false; }
- public virtual bool deserialize_children () { return false; }
+ public virtual bool deserialize_node (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_ERROR (_("%s: Value type '%s' is unsupported"),
+ this.get_type ().name (), value_type.name ());
+ }
+ if (node is Element) {
+ var obj = Object.new (value_type);
+ if (node.name.down () == ((Serializable) obj).node_name ().down ()) {
+ ((Serializable) obj).deserialize (node);
+ @set (((SerializableMapKey<K>) obj).get_map_key (), obj);
+ }
+ }
+ return true;
+ }
+ public virtual bool deserialize_children () throws GLib.Error {
+ if (!(value_type.is_a (typeof (GXml.Serializable)) &&
+ value_type.is_a (typeof (SerializableMapKey)))) {
+ throw new SerializableError.UNSUPPORTED_TYPE_ERROR (_("%s: Value type '%s' is unsupported"),
+ this.get_type ().name (), value_type.name ());
+ }
+ if (_node is Element) {
+ foreach (GXml.Node n in _node.children) {
+ deserialize_node (n);
+ }
+ }
+ return true;
+ }
// Construct
construct { Init.init (); }
@@ -115,26 +141,10 @@ public class GXml.SerializableHashMap<K,V> : Gee.HashMap<K,V>, Serializable, Ser
public bool 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_ERROR (_("%s: Value type '%s' is unsupported"),
- this.get_type ().name (), value_type.name ());
- }
- if (node is Element) {
- foreach (GXml.Node n in node.children) {
- if (n is Element) {
-#if DEBUG
- GLib.message (@"Node $(node.name) for type '$(get_type ().name ())'\n");
-#endif
- var obj = Object.new (value_type);
- if (n.name.down () == ((Serializable) obj).node_name ().down ()) {
- ((Serializable) obj).deserialize (n);
- @set (((SerializableMapKey<K>) obj).get_map_key (), obj);
- }
- }
- }
- }
- return true;
+ _node = node;
+ if (deserialize_proceed ())
+ return deserialize_children ();
+ return false;
}
public virtual bool deserialize_property (GXml.Node property_node)
throws GLib.Error
@@ -144,6 +154,8 @@ public class GXml.SerializableHashMap<K,V> : Gee.HashMap<K,V>, Serializable, Ser
public bool default_deserialize_property (GXml.Node property_node)
throws GLib.Error
{
- return true;
+ if (is_prepared ())
+ return deserialize_node (property_node);
+ return false;
}
}
diff --git a/gxml/SerializableGeeTreeMap.vala b/gxml/SerializableGeeTreeMap.vala
index 020e8d3..36d931b 100644
--- a/gxml/SerializableGeeTreeMap.vala
+++ b/gxml/SerializableGeeTreeMap.vala
@@ -34,8 +34,8 @@ public class GXml.SerializableTreeMap<K,V> : Gee.TreeMap<K,V>, Serializable, Ser
public virtual bool deserialize_proceed () { return true; }
public virtual bool deserialized () { return true; }
public virtual bool is_prepared () { return (_node is GXml.Node); }
- public virtual bool deserialize_node (GXml.Node node) { return false; }
- public virtual bool deserialize_children () { return false; }
+ public virtual bool deserialize_node (GXml.Node node) throws GLib.Error { return false; }
+ public virtual bool deserialize_children () throws GLib.Error { return false; }
construct { Init.init (); }
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]