[gxml] Added new GXml.GomXsdArrayString for XSD enumerations



commit b29f6e797c83716d909c84486cbbd05710b27945
Author: Daniel Espinosa <esodan gmail com>
Date:   Mon Jan 23 12:19:29 2017 -0600

    Added new GXml.GomXsdArrayString for XSD enumerations
    
    GXml.GomXsdArrayString allows to read enumeration values
    and use them as restrictions in a GomElement attribute

 gxml/GomProperty.vala |   43 +++++++++++++++++++++++++++++++++++++++++++
 gxml/GomSchema.vala   |    2 +-
 gxml/Schema.vala      |    5 +++--
 3 files changed, 47 insertions(+), 3 deletions(-)
---
diff --git a/gxml/GomProperty.vala b/gxml/GomProperty.vala
index 51b22a6..d7fbf58 100644
--- a/gxml/GomProperty.vala
+++ b/gxml/GomProperty.vala
@@ -171,6 +171,49 @@ public class GXml.GomArrayString : GomBaseProperty {
   }
 }
 
+
+/**
+ * Convenient class to handle a {@link GomElement}'s attribute
+ * using a list of pre-defined and unmutable values, taken from
+ * an {@link XsdSimpleType} definition
+ */
+public class GXml.GomXsdArrayString : GomArrayString {
+  protected GLib.File source = null;
+  protected string path = null;
+  public void initalize_xsd (GLib.File file) {
+    if (file.query_exists ()) return;
+    if (path == null) return;
+    if (!("/" in path)) return;
+    string[] nodes = path.split("/");
+    if (nodes.length < 1) return;
+    var xsd = new GomXsdSchema ();
+    xsd.read_from_file (file);
+    if (xsd.simple_type_definitions == null) return;
+    if (xsd.simple_type_definitions.length == 0) return;
+    foreach (string str in nodes) {
+      if (str.down () == "schema") continue;
+      for (int i = 0; i < xsd.simple_type_definitions.length; i++) {
+        var st = xsd.simple_type_definitions.get_item (i) as GomXsdSimpleType;
+        if (st == null) continue;
+        if (st.name == null) continue;
+        if (str.down () == st.name.down ()) {
+          if (st.restriction == null) continue;
+          if (st.restriction.enumerations == null) continue;
+          if (st.restriction.enumerations.length == 0) continue;
+          string[] vals = {};
+          for (int j = 0; j < st.restriction.enumerations.length; j++) {
+            var en = st.restriction.enumerations.get_item (j) as GomXsdTypeRestrictionEnumeration;
+            if (en == null) continue;
+            if (en.value == null) continue;
+              vals += en.value;
+          }
+          initialize_strings (vals);
+        }
+      }
+    }
+  }
+}
+
 /**
  * Convenient class to handle {@link GomElement}'s attributes
  * using double pressition floats as sources of values.
diff --git a/gxml/GomSchema.vala b/gxml/GomSchema.vala
index 8e0936a..bf63547 100644
--- a/gxml/GomSchema.vala
+++ b/gxml/GomSchema.vala
@@ -25,7 +25,7 @@ using GXml;
  * Reference interfaces for XSD support.
  */
 public class GXml.GomXsdSchema : GomElement {
-  public GomXsdListElements elements { get; set; }
+  public GomXsdListElements element_definitions { get; set; }
   public GomXsdListSimpleTypes simple_type_definitions { get; set; }
   public GomXsdListComplexTypes complex_type_definitions { get; set; }
   construct {
diff --git a/gxml/Schema.vala b/gxml/Schema.vala
index ee46e1c..cc7deb4 100644
--- a/gxml/Schema.vala
+++ b/gxml/Schema.vala
@@ -28,8 +28,9 @@ public interface GXml.IXsdSchema : GLib.Object, DomElement {
   public const string SCHEMA_NODE_NAME = "schema";
   public const string SCHEMA_NAMESPACE_URI = "http://www.w3.org/2001/XMLSchema";;
   public const string SCHEMA_NAMESPACE_PREFIX = "xs";
-  public abstract IXsdListElements elements { get; set; }
-  public abstract IXsdListSimpleTypes simple_types { get; set; }
+  public abstract IXsdListElements element_definitions { get; set; }
+  public abstract IXsdListSimpleTypes simple_type_definitions { get; set; }
+  public abstract IXsdListComplexTypes complex_type_definitions { get; set; }
 }
 
 public errordomain GXml.IXsdSchemaError {


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