[gxml] GomProperty.value is nullable; GomXsdArrayString no load by default



commit 7d0586b4153790c900b9a6ec6646512ea2dfde98
Author: Daniel Espinosa <esodan gmail com>
Date:   Mon Jan 30 17:29:39 2017 -0600

    GomProperty.value is nullable; GomXsdArrayString no load by default
    
    GomProperty.value is nullable and XParser ignores it if null.
    
    GomXsdArrayString now only load referenced XSD if load() is called.
    No more initializate_xsd() method for performance reasons.
    
    Removed more warnings.

 gxml/GomCollections.vala       |    2 +-
 gxml/GomElement.vala           |    5 +++
 gxml/GomProperty.vala          |   28 ++++++---------
 gxml/GomSchema.vala            |   76 +++++++++++++++++++++++++++++++--------
 gxml/XParser.vala              |    1 +
 po/POTFILES.in                 |    1 +
 po/POTFILES.skip               |    1 +
 test/GomSchemaTest.vala        |    1 +
 test/GomSerializationTest.vala |    2 +-
 9 files changed, 82 insertions(+), 35 deletions(-)
---
diff --git a/gxml/GomCollections.vala b/gxml/GomCollections.vala
index 3ee70b4..8c50f7a 100644
--- a/gxml/GomCollections.vala
+++ b/gxml/GomCollections.vala
@@ -194,7 +194,7 @@ public abstract class GXml.BaseCollection : Object {
     _items_type = items_type;
   }
   /**
-   * Initialize an {@link GomArrayList} to use an element as children's parent.
+   * Initialize an {@link GomCollection} to use an element as children's parent.
    * Searchs for all nodes, calling {@link GomCollection.search}
    * with {@link GomCollection.items_type}, using its
    * {@link DomElement.local_name} to find it.
diff --git a/gxml/GomElement.vala b/gxml/GomElement.vala
index d5d1052..a8fadf7 100644
--- a/gxml/GomElement.vala
+++ b/gxml/GomElement.vala
@@ -109,7 +109,9 @@ public class GXml.GomElement : GomNode,
     if (prefix != null) s = prefix;
     foreach (string k in attributes.keys) {
       if (!("xmlns" in k)) continue;
+#if DEBUG
       GLib.message ("Attribute: "+k);
+#endif
       string nsp = null;
       if (":" in k) {
         string[] sa = k.split (":");
@@ -311,7 +313,10 @@ public class GXml.GomElement : GomNode,
         attr = new GomAttr (_element, n, val);
       else
         attr = new GomAttr.namespace (_element, ns, p, n, val);
+
+#if DEBUG
       GLib.message ("Return: "+ attr.node_name+"="+attr.node_value);
+#endif
       return attr;
     }
     /**
diff --git a/gxml/GomProperty.vala b/gxml/GomProperty.vala
index 6178b61..e085eb3 100644
--- a/gxml/GomProperty.vala
+++ b/gxml/GomProperty.vala
@@ -44,7 +44,7 @@ public interface GXml.GomProperty : Object
    * Implementation should take care to validate value before to set or
    * parse from XML document.
    */
-  public abstract string value { owned get; set; }
+  public abstract string? value { owned get; set; }
   /**
    * Takes a string and check if it can be validated using
    */
@@ -74,7 +74,7 @@ public abstract class GXml.GomBaseProperty : Object, GXml.GomProperty {
   /**
    * {@inheritDoc}
    */
-  public abstract string value { owned get; set; }
+  public abstract string? value { owned get; set; }
   /**
    * Takes a string and check if it can be validated using
    * {@link validation_rule}.
@@ -88,7 +88,7 @@ public abstract class GXml.GomBaseProperty : Object, GXml.GomProperty {
  */
 public class GXml.GomString : GomBaseProperty {
   protected string _value = "";
-  public override string value {
+  public override string? value {
     owned get {
       return _value;
     }
@@ -148,7 +148,7 @@ public class GXml.GomArrayString : GomBaseProperty {
   /**
    * {inheritDoc}
    */
-  public override string value {
+  public override string? value {
     owned get {
       return _value;
     }
@@ -174,12 +174,7 @@ public class GXml.GomXsdArrayString : GomArrayString {
    */
   public string simple_type {
     get { return _simple_type; }
-    set {
-      _simple_type = value;
-      if (_source == null) return;
-      if (!_source.query_exists ()) return;
-      initialize_xsd ();
-    }
+    set { _simple_type = value; }
   }
   /**
    * A {@link GLib.File} source to read from, simple type definitions in
@@ -191,15 +186,14 @@ public class GXml.GomXsdArrayString : GomArrayString {
     set {
       if (!value.query_exists ()) return;
       _source = value;
-      initialize_xsd ();
     }
   }
   /**
-   * Initialize list of strings from a {@link GLib.File}, parsing using an
+   * Load list of strings from a {@link GLib.File}, parsing using an
    * {@link GomXsdSchema} object and searching for {@link XsdSimpleType}
    * definition with name {@link source_type}.
    */
-  public void initialize_xsd () {
+  public void load () throws GLib.Error {
 #if DEBUG
           message ("Initializing enumerations: ");
 #endif
@@ -255,7 +249,7 @@ public class GXml.GomXsdArrayString : GomArrayString {
  */
 public class GXml.GomDouble : GomBaseProperty {
   protected double _value = 0.0;
-  public override string value {
+  public override string? value {
     owned get {
       string s = "%."+decimals.to_string ()+"f";
       return s.printf (_value);
@@ -305,7 +299,7 @@ public class GXml.GomFloat : GomDouble {
  */
 public class GXml.GomInt : GomBaseProperty {
   protected int _value = 0;
-  public override string value {
+  public override string? value {
     owned get {
       return _value.to_string ();
     }
@@ -331,7 +325,7 @@ public class GXml.GomInt : GomBaseProperty {
  */
 public class GXml.GomBoolean : GomBaseProperty {
   protected bool _value = false;
-  public override string value {
+  public override string? value {
     owned get {
       return _value.to_string ();
     }
@@ -359,7 +353,7 @@ public class GXml.GomBoolean : GomBaseProperty {
 public class GXml.GomEnum : GomBaseProperty {
   protected int _value = 0;
   protected Type _enum_type;
-  public override string value {
+  public override string? value {
     owned get {
       string s = "";
       try {
diff --git a/gxml/GomSchema.vala b/gxml/GomSchema.vala
index b0f6ea2..0c21902 100644
--- a/gxml/GomSchema.vala
+++ b/gxml/GomSchema.vala
@@ -62,8 +62,6 @@ public class GXml.GomXsdTypeUnion : GomXsdTypeDefinition {}
 public class GXml.GomXsdTypeRestriction : GomXsdTypeDefinition {
   [Description (nick="::base")]
   public string base { get; set; }
-  [Description (nick="::id")]
-  public string id { get; set; }
   public GomXsdSimpleType simple_type { get; set; }
   public GomXsdListTypeRestrictionEnumerations enumerations { get; set; }
   public GomXsdListTypeRestrictionWhiteSpaces white_spaces { get; set; }
@@ -87,8 +85,6 @@ public class GXml.GomXsdTypeRestrictionLength : GomXsdTypeRestrictionDef {}
 public class GXml.GomXsdTypeRestrictionMinLength : GomXsdTypeRestrictionDef {}
 public class GXml.GomXsdTypeRestrictionMaxLength : GomXsdTypeRestrictionDef {}
 public class GXml.GomXsdTypeRestrictionEnumeration : GomXsdTypeRestrictionDef {
-  [Description (nick="::base")]
-  public string id { get; set; }
   [Description (nick="::value")]
   public string value { get; set; }
   construct {
@@ -100,8 +96,6 @@ public class GXml.GomXsdTypeRestrictionEnumeration : GomXsdTypeRestrictionDef {
 public class GXml.GomXsdTypeRestrictionWhiteSpace: GomXsdTypeRestrictionDef {
   [Description (nick="::fixed")]
   public Fixed fixed { get; set; }
-  [Description (nick="::id")]
-  public string id { get; set; }
   /**
    * (collapse | preserve | replace)
    */
@@ -159,6 +153,7 @@ public class GXml.GomXsdComplexType : GomXsdBaseType {
 }
 
 public class GXml.GomXsdExtension : GomElement {
+  [Description (nick="::base")]
   public string base { get; set; }
   construct {
     initialize_with_namespace (IXsdSchema.SCHEMA_NAMESPACE_URI,
@@ -171,46 +166,63 @@ public class GXml.GomXsdElement : GomElement {
   /**
   * attribute name = abstract
   */
+  [Description (nick="::abstract")]
   public bool abstract { get; set; }
   /**
    * (#all | List of (extension | restriction | substitution))
   */
+  [Description (nick="::block")]
   public string block { get; set; }
+  [Description (nick="::default")]
   public string default { get; set; }
   /**
    * (#all | List of (extension | restriction))
    */
+  [Description (nick="::final")]
   public string final { get; set; }
+  [Description (nick="::fixed")]
   public string fixed { get; set; }
   /**
    * (qualified | unqualified)
    */
+  [Description (nick="::form")]
   public string form { get; set; }
   /**
    * (nonNegativeInteger | unbounded)  : 1
    */
-  public string maxOccurs { get; set; }
+  [Description (nick="::maxOccurs")]
+  public string max_occurs { get; set; }
   /**
    * nonNegativeInteger : 1
    */
-  public string minOccurs { get; set; }
+  [Description (nick="::minOccurs")]
+  public string min_occurs { get; set; }
+  [Description (nick="::name")]
   public string name { get; set; }
+  [Description (nick="::nillable")]
   public bool nillable { get; set; default = false; }
-  public string ref { get; set; }
+  [Description (nick="::ref")]
+  public new string ref { get; set; }
   /**
    * substitutionGroup
    */
+  [Description (nick="::substitutionGroup")]
   public DomTokenList substitution_group { get; set; }
   /**
    * targetNamespace
    */
+  [Description (nick="::targetNamespace")]
   public string target_namespace { get; set; }
   /**
    * attribute name = 'type'
    */
+  [Description (nick="::type")]
   public string object_type { get; set; }
+  [Description (nick="::annotation")]
   public GomXsdAnnotation anotation { get; set; }
+  [Description (nick="::SimpleType")]
   public GomXsdSimpleType simple_type { get; set; }
+  [Description (nick="::ComplexType")]
   public GomXsdComplexType complex_type { get; set; }
   construct {
     initialize_with_namespace (IXsdSchema.SCHEMA_NAMESPACE_URI,
@@ -249,12 +261,19 @@ public class GXml.GomXsdList : GomArrayList {
     get { return (this as GomArrayList).length; }
   }
   public void remove (int index) {
-    element.remove_child (element.child_nodes.item (index));
+    try { element.remove_child (element.child_nodes.item (index)); }
+    catch (GLib.Error e) {
+      warning (_("Error removing Collection's element: %s").printf (e.message));
+    }
   }
   public int index_of (DomElement element) {
     if (element.parent_node != this.element) return -1;
     for (int i = 0; i < this.length; i++) {
-      if (get_item (i) == element) return i;
+      try {
+        if (get_item (i) == element) return i;
+      } catch (GLib.Error e) {
+        warning (_("Can't find element at possition: %i : %s").printf (i,e.message));
+      }
     }
     return -1;
   }/*
@@ -264,17 +283,42 @@ public class GXml.GomXsdList : GomArrayList {
 }
 
 public class GXml.GomXsdListElements : GomXsdList {
-  construct { initialize (typeof (GomXsdElement)); }
+  construct {
+    try { initialize (typeof (GomXsdElement)); }
+    catch (GLib.Error e) {
+      warning (_("Collection type %s, initialization error: %s").printf (get_type ().name(), e.message));
+    }
+  }
 }
 public class GXml.GomXsdListSimpleTypes : GomXsdList {
-  construct { initialize (typeof (GomXsdSimpleType)); }
+  construct {
+    try { initialize (typeof (GomXsdSimpleType)); }
+    catch (GLib.Error e) {
+      warning (_("Collection type %s, initialization error: %s").printf (get_type ().name(), e.message));
+    }
+  }
 }
 public class GXml.GomXsdListComplexTypes : GomXsdList {
-  construct { initialize (typeof (GomXsdComplexType)); }
+  construct {
+    try { initialize (typeof (GomXsdComplexType)); }
+    catch (GLib.Error e) {
+      warning (_("Collection type %s, initialization error: %s").printf (get_type ().name(), e.message));
+    }
+  }
 }
 public class GXml.GomXsdListTypeRestrictionEnumerations : GomXsdList {
-  construct { initialize (typeof (GomXsdTypeRestrictionEnumeration)); }
+  construct {
+    try { initialize (typeof (GomXsdTypeRestrictionEnumeration)); }
+    catch (GLib.Error e) {
+      warning (_("Collection type %s, initialization error: %s").printf (get_type ().name(), e.message));
+    }
+  }
 }
 public class GXml.GomXsdListTypeRestrictionWhiteSpaces : GomXsdList {
-  construct { initialize (typeof (GomXsdTypeRestrictionWhiteSpace)); }
+  construct {
+    try { initialize (typeof (GomXsdTypeRestrictionWhiteSpace)); }
+    catch (GLib.Error e) {
+      warning (_("Collection type %s, initialization error: %s").printf (get_type ().name(), e.message));
+    }
+  }
 }
diff --git a/gxml/XParser.vala b/gxml/XParser.vala
index 6354b2b..2cca983 100644
--- a/gxml/XParser.vala
+++ b/gxml/XParser.vala
@@ -634,6 +634,7 @@ public class GXml.XParser : Object, GXml.Parser {
       node.get_property (pspec.name, ref v);
       GomProperty gp = v.get_object () as GomProperty;
       if (gp == null) continue;
+      if (gp.value == null) continue;
       string attname = gp.attribute_name;
       if (attname == null) {
         if ("::" in pspec.get_nick ()) {
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 09a6580..7d8c1d4 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -29,3 +29,4 @@ gxml/SerializableProperty.vala
 gxml/Serializable.vala
 gxml/TDocument.vala
 gxml/XParser.vala
+gxml/GomSchema.vala
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 8c5c7d3..3beff0e 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -58,3 +58,4 @@ sub/gxml/SerializableObjectModel.c
 sub/gxml/SerializableProperty.c
 sub/gxml/TDocument.c
 sub/gxml/XParser.c
+gxml/GomSchema.c
diff --git a/test/GomSchemaTest.vala b/test/GomSchemaTest.vala
index 04c1a54..da47fb0 100644
--- a/test/GomSchemaTest.vala
+++ b/test/GomSchemaTest.vala
@@ -66,6 +66,7 @@ class GomSchemaTest : GXmlTest  {
                                var ars = new GomXsdArrayString ();
                                ars.simple_type = "MethodCode";
                                ars.source = f;
+                               ars.load ();
                                assert (ars.search ("01"));
                                assert (ars.search ("02"));
                                assert (ars.search ("03"));
diff --git a/test/GomSerializationTest.vala b/test/GomSerializationTest.vala
index 1b3c2ba..dd1467d 100644
--- a/test/GomSerializationTest.vala
+++ b/test/GomSerializationTest.vala
@@ -724,8 +724,8 @@ class GomSerializationTest : GXmlTest  {
       s = bs.to_string ();
 #if DEBUG
       GLib.message ("doc:"+s);
-#endif
       GLib.message ("Books: "+bs.books.length.to_string ());
+#endif
       assert (bs.books.length == 3);
       assert (bs.books.nodes_index.peek_nth (0) == 0);
       assert (bs.books.nodes_index.peek_nth (1) == 1);


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