2003-10-21 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
authorAtsushi Eno <atsushieno@gmail.com>
Tue, 21 Oct 2003 17:09:32 +0000 (17:09 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Tue, 21 Oct 2003 17:09:32 +0000 (17:09 -0000)
* XsdKeyTable.cs : Reduced compilation warning.
* XsdParticleValidationState.cs : Reduced NotImplementedException.
* XsdValidatingReader.cs : Removed XmlResolver. Implemented more simple
  type validation, such as list, union and facets.

svn path=/trunk/mcs/; revision=19277

mcs/class/System.XML/Mono.Xml.Schema/ChangeLog
mcs/class/System.XML/Mono.Xml.Schema/XsdKeyTable.cs
mcs/class/System.XML/Mono.Xml.Schema/XsdParticleValidationState.cs
mcs/class/System.XML/Mono.Xml.Schema/XsdValidatingReader.cs

index bd057b29bb648aeb72c4bd0c9cabc69b22e7c918..88066c24529c5488f45442354e4f1c3d976f9d03 100644 (file)
@@ -1,3 +1,10 @@
+2003-10-21  Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
+
+       * XsdKeyTable.cs : Reduced compilation warning.
+       * XsdParticleValidationState.cs : Reduced NotImplementedException.
+       * XsdValidatingReader.cs : Removed XmlResolver. Implemented more simple
+         type validation, such as list, union and facets.
+
 2003-09-30  Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
 
        * added XsdIdentityPath.cs, XsdIdentityState.cs, XsdKeyTable.cs
index 235a1b88c72841ff239cda8a2ae4ecec29a3c2ff..35d66a671ed6201c63e90887ea0ed9e652fce9aa 100644 (file)
@@ -100,12 +100,10 @@ namespace Mono.Xml.Schema
                                if (reader.Depth - this.StartDepth < path.OrderedSteps.Length - 1)\r
                                        continue;\r
 \r
-                               bool isAttributePath = false;\r
                                int iter = path.OrderedSteps.Length;\r
-                               if (path.OrderedSteps [iter-1].IsAttribute) {\r
-                                       isAttributePath = true;\r
+                               if (path.OrderedSteps [iter-1].IsAttribute)\r
                                        iter--;\r
-                               }\r
+\r
                                if (path.Descendants && reader.Depth < this.StartDepth + iter)\r
                                        continue;\r
                                else if (!path.Descendants && reader.Depth != this.StartDepth + iter)\r
index 87a0f754b6ff64f5efb0baa66d04b6132aeb9409..92b16531c99c15debccb2c56f21e3a925fdbe414 100644 (file)
@@ -81,7 +81,7 @@ namespace Mono.Xml.Schema
                        case "XmlSchemaParticleEmpty":  // Mono
                                return AddEmpty ();
                        default:
-                               throw new NotImplementedException ();
+                               throw new InvalidOperationException (); // Should not occur.
                        }
                }
 
index bbfa91ba524733947a12ea92fdc757f60c4870b4..21d3106ac04a3be12f8bdd8f1240209eb9366a1a 100644 (file)
@@ -6,6 +6,11 @@
 //
 //     (C)2003 Atsushi Enomoto
 //
+// Note:
+//
+// This class doesn't support set_XmlResolver, since it isn't common to XmlReader interface. 
+// Try to set that of xml reader which is used to construct this object.
+//
 using System;
 using System.Collections;
 using System.Collections.Specialized;
@@ -143,10 +148,6 @@ namespace Mono.Xml.Schema
                        }
                }
 
-               public XmlResolver XmlResolver {
-                       set { throw new NotImplementedException (); }
-               }
-
                // It is used only for independent XmlReader use, not for XmlValidatingReader.
                public object ReadTypedValue ()
                {
@@ -507,8 +508,8 @@ namespace Mono.Xml.Schema
                        XmlSchemaSimpleType st = context.ActualType as XmlSchemaSimpleType;
                        if (dt == null) {
                                if (st != null) {
-                                       if (st.Variety == XmlSchemaDerivationMethod.Restriction)
-                                               dt = st.Datatype;
+//                                     if (st.Variety == XmlSchemaDerivationMethod.Restriction)
+                                       dt = st.Datatype;
                                } else {
                                        XmlSchemaComplexType ct = context.ActualType as XmlSchemaComplexType;
                                        dt = ct.Datatype;
@@ -526,10 +527,8 @@ namespace Mono.Xml.Schema
                                if (context.Element != null && context.Element.ValidatedFixedValue != null)
                                        if (value != context.Element.ValidatedFixedValue)
                                                HandleError ("Fixed value constraint was not satisfied.");
-
                                AssessStringValid (st, dt, value);
                        }
-                       // TODO: facet validation
 
                        // Identity field value
                        while (this.currentKeyFieldConsumers.Count > 0) {
@@ -547,7 +546,6 @@ namespace Mono.Xml.Schema
                                }
                                if (identity == null)
                                        identity = value;
-                               // TODO: validity check
                                
                                if (!field.SetIdentityField (identity, dt as XsdAnySimpleType, this))
                                        HandleError ("Two or more identical key value was found: '" + value + "' .");
@@ -558,29 +556,94 @@ namespace Mono.Xml.Schema
                }
 
                // 3.14.4 String Valid 
-               private void AssessStringValid (XmlSchemaSimpleType st, XmlSchemaDatatype dt, string value)
+               private void AssessStringValid (XmlSchemaSimpleType st,
+                       XmlSchemaDatatype dt, string value)
                {
-                       try {
-                               if (st != null) {
-                                       switch (st.DerivedBy) {
-                                       case XmlSchemaDerivationMethod.List:
-                                               string [] values = dt.Normalize (value).Split (wsChars);
-                                               foreach (string each in values)
-                                                       dt.ParseValue (each, NameTable, ParserContext.NamespaceManager);
-                                               break;
-                                       case XmlSchemaDerivationMethod.Union:
-                                               XmlSchemaSimpleTypeUnion union = st.Content as XmlSchemaSimpleTypeUnion;
-                                               // TODO: validate.
-                                               break;
-                                       // TODO: rest
+                       XmlSchemaDatatype validatedDatatype = dt;
+                       if (st != null) {
+                               string normalized = validatedDatatype.Normalize (value);
+                               string [] values;
+                               XmlSchemaDatatype itemDatatype;
+                               XmlSchemaSimpleType itemSimpleType;
+                               switch (st.DerivedBy) {
+                               case XmlSchemaDerivationMethod.List:
+                                       XmlSchemaSimpleTypeList listContent = st.Content as XmlSchemaSimpleTypeList;
+                                       values = normalized.Split (wsChars);
+                                       itemDatatype = listContent.ValidatedListItemType as XmlSchemaDatatype;
+                                       itemSimpleType = listContent.ValidatedListItemType as XmlSchemaSimpleType;
+                                       foreach (string each in values) {
+                                               if (each == String.Empty)
+                                                       continue;
+                                               // validate against ValidatedItemType
+                                               if (itemDatatype != null) {
+                                                       try {
+                                                               itemDatatype.ParseValue (each, NameTable, ParserContext.NamespaceManager);
+                                                       } catch (Exception ex) { // FIXME: better exception handling ;-(
+                                                               HandleError ("List type value contains one or more invalid values.", ex);
+                                                               break;
+                                                       }
+                                               }
+                                               else
+                                                       AssessStringValid (itemSimpleType, itemSimpleType.Datatype, each);
                                        }
+                                       break;
+                               case XmlSchemaDerivationMethod.Union:
+                                       XmlSchemaSimpleTypeUnion union = st.Content as XmlSchemaSimpleTypeUnion;
+//                                     values = normalized.Split (wsChars);
+                               {
+string each = normalized;
+//                                     foreach (string each in values) {
+//                                             if (each == String.Empty)
+//                                                     continue;
+                                               // validate against ValidatedItemType
+                                               bool passed = false;
+                                               foreach (object eachType in union.ValidatedTypes) {
+                                                       itemDatatype = eachType as XmlSchemaDatatype;
+                                                       itemSimpleType = eachType as XmlSchemaSimpleType;
+                                                       if (itemDatatype != null) {
+                                                               try {
+                                                                       itemDatatype.ParseValue (each, NameTable, ParserContext.NamespaceManager);
+                                                               } catch (Exception) { // FIXME: better exception handling ;-(
+                                                                       continue;
+                                                               }
+                                                       }
+                                                       else {
+                                                               try {
+                                                                       AssessStringValid (itemSimpleType, itemSimpleType.Datatype, each);
+                                                               } catch (XmlSchemaException) {
+                                                                       continue;
+                                                               }
+                                                       }
+                                                       passed = true;
+                                                       break;
+                                               }
+                                               if (!passed) {
+                                                       HandleError ("Union type value contains one or more invalid values.");
+                                                       break;
+                                               }
+                                       }
+                                       break;
+                               // TODO: rest
+                               case XmlSchemaDerivationMethod.Restriction:
+                                       XmlSchemaSimpleTypeRestriction str = st.Content as XmlSchemaSimpleTypeRestriction;
+                                       // facet validation
+                                       if (str != null) {
+                                               if (!str.ValidateValueWithFacets (normalized, NameTable)) {
+                                                       HandleError ("Specified value was invalid against the facets.");
+                                                       break;
+                                               }
+                                       }
+                                       validatedDatatype = st.Datatype;
+                                       break;
+                               }
+                       }
+                       if (validatedDatatype != null) {
+                               try {
+                                       validatedDatatype.ParseValue (value, NameTable, ParserContext.NamespaceManager);
+                               } catch (Exception ex) {        // FIXME: It is really bad design ;-P
+                                       HandleError ("Invalidly typed data was specified.", ex);
                                }
-                               else
-                                       dt.ParseValue (value, NameTable, ParserContext.NamespaceManager);
-                       } catch (Exception ex) {        // FIXME: It is really bad design ;-P
-                               HandleError ("Invalidly typed data was specified.");
                        }
-
                }
 
                private object GetLocalTypeDefinition (string name)