[gxml] GomObject: Added get string object properties
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml] GomObject: Added get string object properties
- Date: Thu, 3 Nov 2016 23:04:00 +0000 (UTC)
commit 436d930af6a9c8741e7dd7d816468a54e205787e
Author: Daniel Espinosa <esodan gmail com>
Date: Thu Nov 3 15:14:01 2016 -0600
GomObject: Added get string object properties
gxml/GomElement.vala | 19 +++++++++++++++++++
gxml/GomObject.vala | 10 +++++++---
test/GomSerializationTest.vala | 7 ++++++-
3 files changed, 32 insertions(+), 4 deletions(-)
---
diff --git a/gxml/GomElement.vala b/gxml/GomElement.vala
index e32fb0b..7d19b26 100644
--- a/gxml/GomElement.vala
+++ b/gxml/GomElement.vala
@@ -183,6 +183,9 @@ public class GXml.GomElement : GomNode,
_namespace_uri = namespace_uri;
_prefix = prefix;
}
+
+ public virtual bool use_nick_name () { return true; }
+
/**
* Holds attributes in current node, using attribute's name as key
* and it's value as value. Appends namespace prefix to attribute's name as
@@ -197,8 +200,24 @@ public class GXml.GomElement : GomNode,
_element = element;
}
+ public GLib.List<string> get_attribute_list () {
+ GLib.List<string> l = new GLib.List<string> ();
+ foreach (string k in _element.attributes.keys) {
+ l.prepend (k);
+ }
+ foreach (ParamSpec spec in this.get_class ().list_properties ()) {
+ if (_element.use_nick_name ())
+ l.prepend (spec.name);
+ }
+ return l;
+ }
+
public DomNode? get_named_item (string name) {
if (name == "") return null;
+ var ov = (_element as GomObject).get_attribute (name);
+ if (ov != null) {
+ return new GomAttr (_element, name, ov);
+ }
string p = "";
string ns = null;
string n = name;
diff --git a/gxml/GomObject.vala b/gxml/GomObject.vala
index 54c1f59..8cb5c3f 100644
--- a/gxml/GomObject.vala
+++ b/gxml/GomObject.vala
@@ -54,13 +54,17 @@ public interface GXml.GomObject : GLib.Object,
GLib.message ("GomObject: attribute: "+name);
var prop = get_class ().find_property (name); // FIXME: Find by nick and lower case
if (prop != null) {
+ GLib.message ("Found attribute");
+ var v = Value(prop.value_type);
+ get_property (name, ref v);
if (prop.value_type == typeof(SerializableProperty)) {
- var ov = Value(prop.value_type);
- get_property (name, ref ov);
- SerializableProperty so = (Object) ov as SerializableProperty;
+ SerializableProperty so = (Object) v as SerializableProperty;
if (so == null) return null;
return so.get_serializable_property_value ();
}
+ if (prop.value_type.is_a (typeof (string))) {
+ return (string) v;
+ }
}
return null;
}
diff --git a/test/GomSerializationTest.vala b/test/GomSerializationTest.vala
index cd1a43e..0643419 100644
--- a/test/GomSerializationTest.vala
+++ b/test/GomSerializationTest.vala
@@ -35,7 +35,12 @@ class GomSerializationTest : GXmlTest {
public static void add_tests () {
Test.add_func ("/gxml/gom-serialization/write", () => {
var b = new Book ();
- GLib.message ("DOC:"+b.to_string ());
+ string s = b.to_string ();
+ assert ("<Book/>" in s);
+ b.name = "My Book";
+ assert (b.get_attribute ("name") == "My Book");
+ s = b.to_string ();
+ GLib.message ("DOC:"+s);
});
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]