// Dwivedi, Ajay kumar Adwiv@Yahoo.com\r
// Enomoto, Atsushi ginga@kit.hi-ho.ne.jp\r
//\r
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
using System;\r
using System.Collections;\r
using System.Xml;\r
internal bool ValidatedIsAbstract;\r
internal bool ParentIsSchema = false;\r
\r
- private static string xmlname = "complexType";\r
+ const string xmlname = "complexType";\r
\r
private static XmlSchemaComplexType anyType;\r
\r
anyType = new XmlSchemaComplexType ();\r
anyType.Name = ""; // In MS.NET, it is not "anyType"\r
anyType.QNameInternal = XmlQualifiedName.Empty; // Not xs:anyType as well.\r
+#if BUGGY_MS_COMPLIANT\r
+ anyType.validatableParticle = XmlSchemaParticle.Empty; // This code makes validator handles these schemas incorrectly: particlesIb001, mgM013, mgH014, ctE004, ctD004\r
+#else\r
anyType.validatableParticle = XmlSchemaAny.AnyTypeContent;\r
+#endif\r
anyType.contentTypeParticle = anyType.validatableParticle;\r
anyType.DatatypeInternal = XmlSchemaSimpleType.AnySimpleType;\r
anyType.isMixed = true;\r
+ anyType.resolvedContentType = XmlSchemaContentType.Mixed;\r
}\r
return anyType;\r
}\r
{\r
get{ return attributeWildcard; }\r
}\r
+\r
+#if NET_2_0\r
+ [XmlIgnore]\r
+ // LAMESPEC: This property is based on the premise that\r
+ // every particle has a unique name, but actually particles\r
+ // can be like:\r
+ // <sequence>\r
+ // <element name='foo'/>\r
+ // <element name='foo'>\r
+ // <annotation>\r
+ // <documentation>blah</documentation>\r
+ // </annotation>\r
+ // </element>\r
+ // </sequence>\r
+ //\r
+ // So with this signature this property can never be correct.\r
+ public XmlSchemaObjectTable LocalElements {\r
+ get { throw new NotImplementedException (); }\r
+ }\r
+#endif\r
+\r
#endregion\r
\r
internal XmlSchemaParticle ValidatableParticle \r
{\r
- get{ return validatableParticle; }\r
+ get{ return contentTypeParticle; }\r
}\r
\r
/// <remarks>\r
if (this.IsComplied (schema.CompilationId))\r
return errorCount;\r
\r
+#if NET_2_0\r
+ if (ContentModel != null)\r
+ ContentModel.Parent = this;\r
+ if (Particle != null)\r
+ Particle.Parent = this;\r
+ if (AnyAttribute != null)\r
+ AnyAttribute.Parent = this;\r
+ foreach (XmlSchemaObject obj in Attributes)\r
+ obj.Parent = this;\r
+#endif\r
+\r
ValidatedIsAbstract = isAbstract;\r
\r
if (isRedefinedComponent) {\r
}\r
else\r
{\r
- //TODO: Check what all is not allowed\r
if ((Block & XmlSchemaUtil.ComplexTypeBlockAllowed) != Block)\r
error (h, "Invalid block specification.");\r
blockResolved = Block & XmlSchemaUtil.ComplexTypeBlockAllowed;\r
error(h,"attributes, particles or anyattribute is not allowed if ContentModel is present");\r
errorCount += contentModel.Compile (h, schema);\r
\r
- XmlQualifiedName baseTypeName = null;\r
XmlSchemaSimpleContent smodel = ContentModel as XmlSchemaSimpleContent;\r
if(smodel != null)\r
{\r
XmlSchemaSimpleContentExtension sscx = smodel.Content as XmlSchemaSimpleContentExtension;\r
- if (sscx != null)\r
- baseTypeName = sscx.BaseTypeName;\r
- else {\r
+ if (sscx == null) {\r
XmlSchemaSimpleContentRestriction sscr = smodel.Content as XmlSchemaSimpleContentRestriction;\r
if (sscr != null) {\r
- baseTypeName = sscr.BaseTypeName;\r
if (sscr.BaseType != null) {\r
sscr.BaseType.Compile (h, schema);\r
BaseXmlSchemaTypeInternal = sscr.BaseType;\r
}\r
}\r
}\r
- else\r
- {\r
- XmlSchemaComplexContent cmodel = (XmlSchemaComplexContent) ContentModel;\r
- XmlSchemaComplexContentExtension sccx = cmodel.Content as XmlSchemaComplexContentExtension;\r
- if (sccx != null) {\r
- baseTypeName = sccx.BaseTypeName;\r
- }\r
- else {\r
- XmlSchemaComplexContentRestriction sccr = (XmlSchemaComplexContentRestriction) cmodel.Content;\r
- if (sccr != null) {\r
- baseTypeName = sccr.BaseTypeName;\r
- }\r
- }\r
- }\r
}\r
else\r
{\r
- if(Particle is XmlSchemaGroupRef)\r
- {\r
- XmlSchemaGroupRef xsgr = (XmlSchemaGroupRef)Particle;\r
- errorCount += xsgr.Compile(h,schema);\r
- }\r
- else if(Particle is XmlSchemaAll)\r
- {\r
- XmlSchemaAll xsa = (XmlSchemaAll)Particle;\r
- errorCount += xsa.Compile(h,schema);\r
- }\r
- else if(Particle is XmlSchemaChoice)\r
- {\r
- XmlSchemaChoice xsc = (XmlSchemaChoice)Particle;\r
- errorCount += xsc.Compile(h,schema);\r
- }\r
- else if(Particle is XmlSchemaSequence)\r
- {\r
- XmlSchemaSequence xss = (XmlSchemaSequence)Particle;\r
- errorCount += xss.Compile(h,schema);\r
- }\r
+ if (Particle != null)\r
+ errorCount += Particle.Compile (h, schema);\r
\r
if(this.anyAttribute != null)\r
{\r
CollectContentTypeFromContentModel (h, schema);\r
} else\r
CollectContentTypeFromImmediateContent ();\r
- contentTypeParticle = validatableParticle;//.GetParticleWithoutPointless ();\r
+ contentTypeParticle = validatableParticle.GetOptimizedParticle (true);\r
+ if (contentTypeParticle == XmlSchemaParticle.Empty && resolvedContentType == XmlSchemaContentType.ElementOnly)\r
+ resolvedContentType = XmlSchemaContentType.Empty;\r
\r
CollectProcessId = schema.CompilationId;\r
}\r
// leave resolvedDerivedBy as Empty\r
if (Particle != null)\r
validatableParticle = Particle;\r
+ if (this == AnyType) {\r
+ resolvedContentType = XmlSchemaContentType.Mixed;\r
+ return;\r
+ }\r
+\r
if (validatableParticle == XmlSchemaParticle.Empty) {\r
// note that this covers "Particle == null" case\r
if (this.IsMixed)\r
else\r
resolvedContentType = XmlSchemaContentType.ElementOnly;\r
}\r
+ if (this != AnyType)\r
+ BaseXmlSchemaTypeInternal = XmlSchemaComplexType.AnyType;\r
}\r
\r
private void CollectContentTypeFromContentModel (ValidationEventHandler h, XmlSchema schema)\r
validatableParticle = XmlSchemaParticle.Empty;\r
resolvedContentType = XmlSchemaContentType.Empty;\r
} else {\r
- validatableParticle = baseComplexType.ContentTypeParticle;\r
+ validatableParticle = baseComplexType.ValidatableParticle;\r
resolvedContentType = baseComplexType.resolvedContentType;\r
}\r
} else if (baseComplexType.validatableParticle == XmlSchemaParticle.Empty\r
} else {\r
// - 2.3 : create a new sequences that merges both contents.\r
XmlSchemaSequence seq = new XmlSchemaSequence ();\r
- seq.Items.Add (baseComplexType.ContentTypeParticle);\r
+ this.CopyInfo (seq);\r
+ seq.Items.Add (baseComplexType.validatableParticle);\r
seq.Items.Add (cce.Particle);\r
seq.Compile (h, schema);\r
seq.Validate (h, schema);\r
}\r
\r
// Additional support for 3.8.6 All Group Limited\r
- if (contentTypeParticle != null) {\r
- XmlSchemaAll termAll = contentTypeParticle.ActualParticle as XmlSchemaAll;\r
- if (termAll != null && (termAll.ValidatedMaxOccurs != 1 || contentTypeParticle.ValidatedMaxOccurs != 1)) // here contentTypeParticle is used to check occurence. FIXME: In the future contentTypeParticle will remove group references.\r
+ if (ContentTypeParticle != null) {\r
+ XmlSchemaAll termAll = contentTypeParticle.GetOptimizedParticle (true) as XmlSchemaAll;\r
+ if (termAll != null && (termAll.ValidatedMaxOccurs != 1 || contentTypeParticle.ValidatedMaxOccurs != 1)) // here contentTypeParticle is used to check occurence.\r
error (h, "Particle whose term is -all- and consists of complex type content particle must have maxOccurs = 1.");\r
}\r
\r
this.DatatypeInternal = baseType.Datatype;\r
} else if (BaseSchemaTypeName == XmlSchemaComplexType.AnyTypeName)\r
DatatypeInternal = XmlSchemaSimpleType.AnySimpleType;
- else if (BaseSchemaTypeName.Namespace == XmlSchema.Namespace) {\r
+ else if (XmlSchemaUtil.IsBuiltInDatatypeName (BaseSchemaTypeName)) {\r
DatatypeInternal = XmlSchemaDatatype.FromName (BaseSchemaTypeName);\r
}\r
\r
// base\r
if (BaseSchemaTypeName == XmlSchemaComplexType.AnyTypeName)\r
baseComplexType = XmlSchemaComplexType.AnyType;\r
- else if (BaseSchemaTypeName.Namespace == XmlSchema.Namespace)\r
+ else if (XmlSchemaUtil.IsBuiltInDatatypeName (BaseSchemaTypeName))\r
error (h, "Referenced base schema type is XML Schema datatype.");\r
else if (baseComplexType == null && !schema.IsNamespaceAbsent (BaseSchemaTypeName.Namespace))\r
error (h, "Referenced base schema type " + BaseSchemaTypeName + " was not complex type or not found in the corresponding schema.");\r
error (h, "Base schema complex type of a simple content must be simple content type. Base type is " + BaseSchemaTypeName);\r
} else if (sce == null && (baseSimpleType != null && BaseSchemaTypeName.Namespace != XmlSchema.Namespace)) {\r
error (h, "If a simple content is not an extension, base schema type must be complex type. Base type is " + BaseSchemaTypeName);\r
- } else if (BaseSchemaTypeName.Namespace == XmlSchema.Namespace) {\r
- if (XmlSchemaDatatype.FromName (BaseSchemaTypeName) == null)\r
- error (h, "Invalid schema data type was specified: " + BaseSchemaTypeName);\r
+ } else if (XmlSchemaUtil.IsBuiltInDatatypeName (BaseSchemaTypeName)) {\r
// do nothing for particle.\r
}\r
// otherwise, it might be missing sub components.\r
- else if (baseType == null && !schema.IsNamespaceAbsent (BaseSchemaTypeName.Namespace))// && schema.Schemas [baseTypeName.Namespace] != null)\r
+ else if (baseType == null && !schema.IsNamespaceAbsent (BaseSchemaTypeName.Namespace))\r
error (h, "Referenced base schema type " + BaseSchemaTypeName + " was not found in the corresponding schema.");\r
\r
// 3.4.3 Complex Type Definition Representation OK :: 2.\r
if (baseComplexType != null) {\r
if (baseComplexType.ContentType == XmlSchemaContentType.TextOnly) {\r
// 2.1.1\r
- } else if (scr != null && baseComplexType.ContentType == XmlSchemaContentType.Mixed && baseComplexType.Particle.ValidateIsEmptiable () && scr.BaseType != null) {\r
+ // Here "baseComplexType.Particle != null" is required for error-ignorant case\r
+ } else if (scr != null && baseComplexType.ContentType == XmlSchemaContentType.Mixed && baseComplexType.Particle != null && baseComplexType.Particle.ValidateIsEmptiable () && scr.BaseType != null) {\r
// 2.1.2 && 2.2: OK\r
}\r
else\r
// 1.3 attribute wildcard subset. (=> 3.10.6)\r
localAnyAttribute.ValidateWildcardSubset (baseAnyAttribute, h, schema);\r
\r
- // FIXME: Check 3.4.2 Complex Type Definition with complex content Schema Component\r
- // and its {attribute uses} and {attribute wildcard}\r
+ // 3.4.2 Complex Type Definition with complex content Schema Component\r
+ // and its {attribute uses} and {attribute wildcard} are done here (descendantly)\r
errorCount += XmlSchemaUtil.ValidateAttributesResolved (\r
this.attributeUses, h, schema, ccr.Attributes, \r
ccr.AnyAttribute, ref attributeWildcard, null);\r
\r
foreach (DictionaryEntry entry in baseComplexType.AttributeUses) {\r
XmlSchemaAttribute attr = (XmlSchemaAttribute) entry.Value;\r
+#if BUGGY_MS_COMPLIANT\r
+ if (attr.Use != XmlSchemaUse.Prohibited)\r
+ XmlSchemaUtil.AddToTable (attributeUses, attr, attr.QualifiedName, h);\r
+#endif\r
XmlSchemaUtil.AddToTable (attributeUses, attr, attr.QualifiedName, h);\r
}\r
}\r
if (localAnyAttribute != null && baseAnyAttribute != null)\r
// 1.3 attribute wildcard subset. (=> 3.10.6)\r
localAnyAttribute.ValidateWildcardSubset (baseAnyAttribute, h, schema);\r
- // TODO: 3.4.6 :: 5.1. Beware that There is an errata for 5.1!!\r
+ // 3.4.6 :: 5.1. Beware that There is an errata for 5.1!!\r
// http://www.w3.org/2001/05/xmlschema-errata#Errata1\r
\r
- // FIXME: Check 3.4.2 Complex Type Definition with simple content Schema Component\r
- // and its {attribute uses} and {attribute wildcard}\r
+ // 3.4.2 Complex Type Definition with simple content Schema Component\r
+ // and its {attribute uses} and {attribute wildcard} are done here (descendantly)\r
errorCount += XmlSchemaUtil.ValidateAttributesResolved (\r
this.attributeUses, h, schema, scr.Attributes, \r
scr.AnyAttribute, ref attributeWildcard, null);\r
}\r
\r
// Common process of AttributeWildcard.\r
- // TODO: Check 3.4.2 {attribute wildcard} to fill the complete wildcard.\r
if (localAnyAttribute != null) {\r
this.attributeWildcard = localAnyAttribute;\r
}\r
error (h, "Derivation type " + resolvedDerivedBy + " is prohibited by the base type.");\r
if (BaseXmlSchemaType == b) // 2.2\r
return;\r
- if (BaseXmlSchemaType == XmlSchemaComplexType.AnyType) { // 2.3.1\r
+ if (BaseXmlSchemaType == null || BaseXmlSchemaType == XmlSchemaComplexType.AnyType) { // 2.3.1\r
error (h, "Derived type's base schema type is anyType.");\r
return;\r
}\r
XmlSchemaAttribute da = AttributeUses [ba.QualifiedName] as XmlSchemaAttribute;\r
if (da == null)\r
error (h, "Invalid complex type derivation by extension was found. Missing attribute was found: " + ba.QualifiedName + " .");\r
- // TODO: How to evaluate "equal" type ...?\r
}\r
// 1.3 -> 3.10.6 Wildcard Subset.\r
if (AnyAttribute != null) {\r
}\r
// I think 3. is considered in 2.\r
// 4.\r
- if (this.AttributeWildcard != null) {\r
+ if (this.AttributeWildcard != null && baseType != XmlSchemaComplexType.AnyType) {\r
if (baseType.AttributeWildcard == null)\r
error (h, "Invalid attribute derivation by restriction because of attribute wildcard.");\r
else\r
}\r
\r
// 5.\r
+ if (this == AnyType)\r
+ return;\r
if (contentTypeParticle == XmlSchemaParticle.Empty) {\r
- // TODO: 5.1\r
- // 5.2\r
- if (baseType.ContentTypeParticle != XmlSchemaParticle.Empty &&\r
- !baseType.ContentTypeParticle.ValidateIsEmptiable ())\r
- error (h, "Invalid content type derivation.");\r
+ // 5.1\r
+ if (ContentType != XmlSchemaContentType.Empty) {\r
+ // TODO: 5.1.1\r
+// XmlSchemaSimpleType baseST = baseType as XmlSchemaSimpleType;\r
+ // 5.1.2\r
+ if (baseType.ContentType == XmlSchemaContentType.Mixed && !baseType.ContentTypeParticle.ValidateIsEmptiable ())\r
+ error (h, "Invalid content type derivation.");\r
+\r
+ } else {\r
+ // 5.2\r
+ if (baseType.ContentTypeParticle != XmlSchemaParticle.Empty &&\r
+ !baseType.ContentTypeParticle.ValidateIsEmptiable ())\r
+ error (h, "Invalid content type derivation.");\r
+ }\r
} else {\r
// 5.3 => 3.9.6 Particle Valid (Restriction)\r
if (baseType.ContentTypeParticle != null) {\r
// 3.9.6 - 1 : same particle.\r
// 3.9.6 - 2 is covered by using ActualParticle.\r
- if (!contentTypeParticle.ActualParticle.ParticleEquals (baseType.ContentTypeParticle.ActualParticle))\r
- contentTypeParticle.ActualParticle.ValidateDerivationByRestriction (\r
- baseType.ContentTypeParticle.ActualParticle, h, schema);\r
+ if (!contentTypeParticle.ParticleEquals (baseType.ContentTypeParticle))\r
+ contentTypeParticle.ValidateDerivationByRestriction (baseType.ContentTypeParticle, h, schema, true);\r
}\r
}\r
}\r