[gxml] More XSD implementations for GOM



commit 9d786f6349b8df0905cb988df5de17a2af37ce7c
Author: Daniel Espinosa <esodan gmail com>
Date:   Sun Jan 22 22:46:11 2017 -0600

    More XSD implementations for GOM

 gxml/GomDocument.vala |    2 +-
 gxml/GomElement.vala  |   12 +++++-
 gxml/GomSchema.vala   |   99 ++++++++++++++++++++++++++++++++++++-------------
 gxml/Schema.vala      |   37 ++++++++++++------
 test/GXmlTest.vala    |    3 +-
 test/Makefile.am      |    2 +
 test/schema-test.xsd  |   28 ++++++++++++++
 7 files changed, 142 insertions(+), 41 deletions(-)
---
diff --git a/gxml/GomDocument.vala b/gxml/GomDocument.vala
index bbf9651..c6d5fd4 100644
--- a/gxml/GomDocument.vala
+++ b/gxml/GomDocument.vala
@@ -164,7 +164,7 @@ public class GXml.GomDocument : GomNode,
       throw new DomError.NAMESPACE_ERROR
         (_("Only xmlns prefixs can be used with http://www.w3.org/2000/xmlns/";));
     var e = new GomElement ();
-    e.initialize_with_namespace (this, namespace_uri, nsp, n);
+    e.initialize_document_with_namespace (this, namespace_uri, nsp, n);
     return e;
   }
 
diff --git a/gxml/GomElement.vala b/gxml/GomElement.vala
index de547f7..dc9e2b8 100644
--- a/gxml/GomElement.vala
+++ b/gxml/GomElement.vala
@@ -245,9 +245,19 @@ public class GXml.GomElement : GomNode,
   }
   /**
    * Convenient function to initialize, at construction time, a {@link GomElement}
+   * using given local name and namespace.
+   */
+  public void initialize_with_namespace (string? namespace_uri,
+                              string? prefix, string local_name) {
+    _local_name = local_name;
+    _namespace_uri = namespace_uri;
+    _prefix = prefix;
+  }
+  /**
+   * Convenient function to initialize, at construction time, a {@link GomElement}
    * using given local name, document and namespace.
    */
-  public void initialize_with_namespace (DomDocument doc, string? namespace_uri,
+  public void initialize_document_with_namespace (DomDocument doc, string? namespace_uri,
                               string? prefix, string local_name) {
     _document = doc;
     _local_name = local_name;
diff --git a/gxml/GomSchema.vala b/gxml/GomSchema.vala
index 9d173b2..ff9d93c 100644
--- a/gxml/GomSchema.vala
+++ b/gxml/GomSchema.vala
@@ -1,7 +1,7 @@
 /* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
 /*
  *
- * Copyright (C) 2016  Daniel Espinosa <esodan gmail com>
+ * Copyright (C) 2017  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
@@ -22,13 +22,12 @@
 using GXml;
 
 public class GXml.GomXsdSchema : GomElement, XsdSchema {
-  public XsdList elements { get; set; }
-  public XsdList simple_types { get; set; }
+  public XsdListElements elements { get; set; }
+  public XsdListSimpleTypes simple_types { get; set; }
   construct {
-    initialize (XsdSchema.SCHEMA_NODE_NAME);
-    set_attribute_ns ("http://www.w3.org/2000/xmlns/";,
-                      "xmlns:"+XsdSchema.SCHEMA_NAMESPACE_PREFIX,
-                      XsdSchema.SCHEMA_NAMESPACE_URI);
+    initialize_with_namespace (XsdSchema.SCHEMA_NAMESPACE_URI,
+                              XsdSchema.SCHEMA_NAMESPACE_PREFIX,
+                              XsdSchema.SCHEMA_NODE_NAME);
   }
 }
 
@@ -59,26 +58,40 @@ public class GXml.GomXsdTypeRestrictionDefinition : GomElement,
               XsdTypeRestrictionDefinition {
   public XsdAnnotation annotation { get; set; }
 }
-public class GXml.GomXsdTypeRestrictionMinExclusive : GomXsdTypeRestrictionDefinition {}
-public class GXml.GomXsdTypeRestrictionMinInclusive : GomXsdTypeRestrictionDefinition {}
-public class GXml.GomXsdTypeRestrictionMaxExclusive : GomXsdTypeRestrictionDefinition {}
-public class GXml.GomXsdTypeRestrictionMaxInclusive : GomXsdTypeRestrictionDefinition {}
-public class GXml.GomXsdTypeRestrictionTotalDigits : GomXsdTypeRestrictionDefinition {}
-public class GXml.GomXsdTypeRestrictionFractionDigits : GomXsdTypeRestrictionDefinition {}
-public class GXml.GomXsdTypeRestrictionLength : GomXsdTypeRestrictionDefinition {}
-public class GXml.GomXsdTypeRestrictionMinLength : GomXsdTypeRestrictionDefinition {}
-public class GXml.GomXsdTypeRestrictionMaxLength : GomXsdTypeRestrictionDefinition {}
-public class GXml.GomXsdTypeRestrictionEnumeration : GomXsdTypeRestrictionDefinition {
+public class GXml.GomXsdTypeRestrictionMinExclusive : GomXsdTypeRestrictionDefinition,
+              XsdTypeRestrictionMinExclusive {}
+public class GXml.GomXsdTypeRestrictionMinInclusive : GomXsdTypeRestrictionDefinition,
+              XsdTypeRestrictionMinInclusive {}
+public class GXml.GomXsdTypeRestrictionMaxExclusive : GomXsdTypeRestrictionDefinition,
+              XsdTypeRestrictionMaxExclusive {}
+public class GXml.GomXsdTypeRestrictionMaxInclusive : GomXsdTypeRestrictionDefinition,
+              XsdTypeRestrictionMaxInclusive {}
+public class GXml.GomXsdTypeRestrictionTotalDigits : GomXsdTypeRestrictionDefinition,
+              XsdTypeRestrictionTotalDigits {}
+public class GXml.GomXsdTypeRestrictionFractionDigits : GomXsdTypeRestrictionDefinition,
+              XsdTypeRestrictionFractionDigits {}
+public class GXml.GomXsdTypeRestrictionLength : GomXsdTypeRestrictionDefinition,
+              XsdTypeRestrictionLength {}
+public class GXml.GomXsdTypeRestrictionMinLength : GomXsdTypeRestrictionDefinition,
+              XsdTypeRestrictionMinLength {}
+public class GXml.GomXsdTypeRestrictionMaxLength : GomXsdTypeRestrictionDefinition,
+              XsdTypeRestrictionMaxLength {}
+public class GXml.GomXsdTypeRestrictionEnumeration : GomXsdTypeRestrictionDefinition,
+              XsdTypeRestrictionEnumeration {
   public string id { get; set; }
   public string value { get; set; }
   construct { initialize (GXml.XsdTypeRestrictionEnumeration.SCHEMA_NODE_NAME); }
 }
-public class GXml.GomXsdTypeRestrictionWhiteSpace: GomXsdTypeRestrictionDefinition {}
-public class GXml.GomXsdTypeRestrictionPattern : GomXsdTypeRestrictionDefinition {}
-public class GXml.GomXsdTypeRestrictionAssertion : GomXsdTypeRestrictionDefinition {}
-public class GXml.GomXsdTypeRestrictionExplicitTimezone : GomXsdTypeRestrictionDefinition {}
+public class GXml.GomXsdTypeRestrictionWhiteSpace: GomXsdTypeRestrictionDefinition,
+              XsdTypeRestrictionWhiteSpace {}
+public class GXml.GomXsdTypeRestrictionPattern : GomXsdTypeRestrictionDefinition,
+              XsdTypeRestrictionPattern {}
+public class GXml.GomXsdTypeRestrictionAssertion : GomXsdTypeRestrictionDefinition,
+              XsdTypeRestrictionAssertion {}
+public class GXml.GomXsdTypeRestrictionExplicitTimezone : GomXsdTypeRestrictionDefinition,
+              XsdTypeRestrictionExplicitTimezone {}
 
-public class GXml.GomXsdComplexType : GomElement, DomElement, XsdBaseType {
+public class GXml.GomXsdComplexType : GomXsdBaseType, XsdComplexType {
   protected XsdList _type_attributes = null;
   protected XsdList _group_attributes = null;
   /**
@@ -99,7 +112,6 @@ public class GXml.GomXsdComplexType : GomElement, DomElement, XsdBaseType {
    * defaultAttributesApply
    */
   public bool default_attributes_apply { get; set; default = true; }
-  public XsdList anotations { get; set; }
   /**
    * A {@link XsdComplexType} or {@link XsdSimpleType}
    */
@@ -115,12 +127,12 @@ public class GXml.GomXsdComplexType : GomElement, DomElement, XsdBaseType {
   construct { initialize (GXml.XsdComplexType.SCHEMA_NODE_NAME); }
 }
 
-public class GXml.GomXsdExtension : GomElement, DomElement {
+public class GXml.GomXsdExtension : GomElement, XsdExtension {
   public string base { get; set; }
   construct { initialize (GXml.XsdExtension.SCHEMA_NODE_NAME); }
 }
 
-public class GXml.GomXsdElement : GomElement, DomElement {
+public class GXml.GomXsdElement : GomElement, XsdElement {
   /**
   * attribute name = abstract
   */
@@ -166,10 +178,35 @@ public class GXml.GomXsdElement : GomElement, DomElement {
   /**
    * A {@link XsdComplexType} or {@link XsdSimpleType} list of elements
    */
-  public XsdList type_definition { get; set; }
+  public XsdListBaseTypes type_definitions { get; set; }
   construct { initialize (GXml.XsdElement.SCHEMA_NODE_NAME); }
 }
 
+
+public class GXml.GomXsdAnnotation : GomElement, XsdAnnotation {
+}
+
+public class GXml.GomXsdBaseType : GomElement, XsdBaseType {
+  public XsdAnnotation anotation { get; set; }
+}
+
+public class GXml.GomXsdBaseContent : GomElement, XsdBaseContent {
+  public XsdAnnotation anotation { get; set; }
+}
+public class GXml.GomXsdSimpleContent : GomXsdBaseContent, XsdBaseContent {
+  construct { initialize (GXml.XsdSimpleContent.SCHEMA_NODE_NAME); }
+}
+public class GXml.GomXsdComplexContent : GomXsdBaseContent, XsdBaseContent {
+  construct { initialize (GXml.XsdComplexContent.SCHEMA_NODE_NAME); }
+}
+public class GXml.GomXsdOpenContent : GomXsdBaseContent, XsdBaseContent {}
+
+public class GXml.GomXsdBaseAttribute : GomElement, XsdBaseAttribute  {
+  public XsdAnnotation anotation { get; set; }
+}
+public class GXml.GomXsdAttribute : GomXsdBaseAttribute, XsdAttribute {}
+public class GXml.GomXsdAttributeGroup : GomXsdBaseAttribute, XsdAttributeGroup {}
+
 public class GXml.GomXsdList : GomArrayList, XsdList {
   public new int length {
     get { return (this as GomArrayList).length; }
@@ -188,3 +225,13 @@ public class GXml.GomXsdList : GomArrayList, XsdList {
     return (this as GomArrayList).get_item (index);
   }
 }
+
+public class GXml.GomXsdListElements : GomXsdList, XsdListElements {
+  construct { initialize (typeof (GomXsdElement)); }
+}
+public class GXml.GomXsdListSimpleTypes : GomXsdList, XsdListSimpleTypes {
+  construct { initialize (typeof (GomXsdSimpleType)); }
+}
+public class GXml.GomXsdListBaseTypes : GomXsdList, XsdListBaseTypes {
+  construct { initialize (typeof (GomXsdBaseType)); }
+}
diff --git a/gxml/Schema.vala b/gxml/Schema.vala
index 3bd7f49..acf502f 100644
--- a/gxml/Schema.vala
+++ b/gxml/Schema.vala
@@ -1,7 +1,7 @@
 /* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
 /*
  *
- * Copyright (C) 2016  Daniel Espinosa <esodan gmail com>
+ * Copyright (C) 2017  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
@@ -25,13 +25,18 @@ public interface GXml.XsdSchema : 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 XsdList elements { get; set; }
-  public abstract XsdList simple_types { get; set; }
+  public abstract XsdListElements elements { get; set; }
+  public abstract XsdListSimpleTypes simple_types { get; set; }
 }
 
 public errordomain GXml.SchemaError {
   INVALIDATION_ERROR
 }
+
+public interface GXml.XsdBaseType : Object {
+  public abstract XsdAnnotation anotation { get; set; }
+}
+
 public interface GXml.XsdSimpleType: Object, DomElement, XsdBaseType {
   public const string SCHEMA_NODE_NAME = "simpleType";
   /**
@@ -47,7 +52,6 @@ public interface GXml.XsdSimpleTypeDefinition : Object {}
 public interface GXml.XsdTypeRestriction : Object, XsdSimpleTypeDefinition {
   public abstract string base { get; set; }
   public abstract string id { get; set; }
-  public abstract XsdAnnotation annotation { get; set; }
   public abstract XsdSimpleType simple_type { get; set; }
   /**
    * List of {link XsdTypeRestrictionDefinition} objects
@@ -100,7 +104,6 @@ public interface GXml.XsdComplexType : Object, DomElement, XsdBaseType {
    * defaultAttributesApply
    */
   public abstract bool default_attributes_apply { get; set; default = true; }
-  public abstract XsdList anotations { get; set; }
   /**
    * A {@link XsdComplexType} or {@link XsdSimpleType}
    */
@@ -168,15 +171,15 @@ public interface GXml.XsdElement : Object, DomElement {
   /**
    * A {@link XsdComplexType} or {@link XsdSimpleType} list of elements
    */
-  public abstract XsdList type_definition { get; set; }
+  public abstract XsdListBaseTypes type_definitions { get; set; }
   // TODO: Missing: ((simpleType | complexType)?, alternative*, (unique | key | keyref)*))
 }
 
 public interface GXml.XsdAnnotation : Object {}
 
-public interface GXml.XsdBaseType : Object {}
-
-public interface GXml.XsdBaseContent : Object {}
+public interface GXml.XsdBaseContent : Object {
+  public abstract XsdAnnotation anotation { get; set; }
+}
 public interface GXml.XsdSimpleContent : Object, XsdBaseContent {
   public const string SCHEMA_NODE_NAME = "simpleContent";
 }
@@ -185,9 +188,15 @@ public interface GXml.XsdComplexContent : Object, XsdBaseContent {
 }
 public interface GXml.XsdOpenContent : Object, XsdBaseContent {}
 
-public interface GXml.XsdBaseAttribute : Object {}
-public interface GXml.XsdAttribute : Object {}
-public interface GXml.XsdAttributeGroup : Object {}
+public interface GXml.XsdBaseAttribute : Object {
+  public abstract XsdAnnotation anotation { get; set; }
+}
+public interface GXml.XsdAttribute : Object {
+  public const string SCHEMA_NODE_NAME = "attribute";
+}
+public interface GXml.XsdAttributeGroup : Object {
+  public const string SCHEMA_NODE_NAME = "attributeGroup";
+}
 
 public interface GXml.XsdList : Object, GomCollection {
   public abstract DomElement element { get; construct set; }
@@ -199,3 +208,7 @@ public interface GXml.XsdList : Object, GomCollection {
   public abstract void remove (int index);
   public abstract int index_of (DomElement element);
 }
+
+public interface GXml.XsdListElements : Object, XsdList {}
+public interface GXml.XsdListSimpleTypes : Object, XsdList {}
+public interface GXml.XsdListBaseTypes : Object, XsdList {}
diff --git a/test/GXmlTest.vala b/test/GXmlTest.vala
index 88c97e6..c1c81f3 100644
--- a/test/GXmlTest.vala
+++ b/test/GXmlTest.vala
@@ -64,8 +64,9 @@ class GXmlTest {
                GomDocumentTest.add_tests ();
                GomElementTest.add_tests ();
                GomSerializationTest.add_tests ();
+               GomSchemaTest.add_tests ();
 
-               Test.run ();
+                               Test.run ();
 
                return 0;
        }
diff --git a/test/Makefile.am b/test/Makefile.am
index 8cfcde2..9fcdd85 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -61,6 +61,7 @@ sources = \
        GomDocumentTest.vala \
        GomElementTest.vala \
        GomSerializationTest.vala \
+       GomSchemaTest.vala \
        $(NULL)
 
 vala-stamp: $(sources)
@@ -160,5 +161,6 @@ EXTRA_DIST += \
        index.html \
        t-read-test.xml \
        gdocument-read.xml \
+       schema-test.xsd \
        $(NULL)
 
diff --git a/test/schema-test.xsd b/test/schema-test.xsd
new file mode 100644
index 0000000..c3e03bf
--- /dev/null
+++ b/test/schema-test.xsd
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:catCFDI="http://www.sat.gob.mx/sitio_internet/cfd/catalogos"; 
xmlns:xs="http://www.w3.org/2001/XMLSchema"; 
targetNamespace="http://www.sat.gob.mx/sitio_internet/cfd/catalogos"; elementFormDefault="unqualified" 
attributeFormDefault="unqualified">
+  <xs:simpleType name="MethodCode">
+    <xs:restriction base="xs:string">
+      <xs:whiteSpace value="collapse"/>
+      <xs:enumeration value="01"/>
+      <xs:enumeration value="02"/>
+      <xs:enumeration value="03"/>
+      <xs:enumeration value="04"/>
+      <xs:enumeration value="05"/>
+      <xs:enumeration value="06"/>
+      <xs:enumeration value="08"/>
+      <xs:enumeration value="12"/>
+      <xs:enumeration value="13"/>
+      <xs:enumeration value="14"/>
+      <xs:enumeration value="15"/>
+      <xs:enumeration value="17"/>
+      <xs:enumeration value="23"/>
+      <xs:enumeration value="24"/>
+      <xs:enumeration value="25"/>
+      <xs:enumeration value="26"/>
+      <xs:enumeration value="27"/>
+      <xs:enumeration value="28"/>
+      <xs:enumeration value="29"/>
+      <xs:enumeration value="99"/>
+    </xs:restriction>
+  </xs:simpleType>
+</xs:schema>


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