فهرست منبع

2005-11-07 Atsushi Enomoto <[email protected]>

	* XmlValueGetter.cs, XmlSchemaValidator.cs, XmlSchemaException.cs,
	  XmlSchemaAttribute.cs : Updated API to match 2.0 RTM. Most of the
	  changes are related to XmlValueGetter change.

	* XsdValidatingReader.cs, XmlSchemaValidatingReader.cs,
	  XsdIdentityState.cs :
	  Dependent changes caused by XmlValueGetter changes.

	* xsdtest.cs : updated to match 2.0 RTM API.


svn path=/trunk/mcs/; revision=52650
Atsushi Eno 20 سال پیش
والد
کامیت
d7e2e92951

+ 6 - 0
mcs/class/System.XML/Mono.Xml.Schema/ChangeLog

@@ -1,3 +1,9 @@
+2005-11-07  Atsushi Enomoto <[email protected]>
+
+	* XsdValidatingReader.cs, XmlSchemaValidatingReader.cs,
+	  XsdIdentityState.cs :
+	  Dependent changes caused by XmlValueGetter changes.
+
 2005-11-07  Atsushi Enomoto <[email protected]>
 
 	* XsdValidatingReader.cs : XmlReader.ReadTypedValue() does not exist 

+ 1 - 1
mcs/class/System.XML/Mono.Xml.Schema/XmlSchemaValidatingReader.cs

@@ -794,7 +794,7 @@ namespace Mono.Xml.Schema
 				defaultAttributes = (XsAttr [])
 					defaultAttributesCache.ToArray (
 					typeof (XsAttr));
-				v.ValidateEndOfAttributes ();
+				v.ValidateEndOfAttributes (xsinfo);
 				defaultAttributesCache.Clear ();
 
 				if (reader.IsEmptyElement)

+ 3 - 8
mcs/class/System.XML/Mono.Xml.Schema/XsdIdentityState.cs

@@ -106,7 +106,7 @@ namespace Mono.Xml.Schema
 		}
 
 		// if (elementPath) check only elements; else only attributes.
-		internal XsdIdentityPath Matches (bool matchesAttr, object sender, XmlNameTable nameTable, ArrayList qnameStack, string sourceUri, object schemaType, NSResolver nsResolver, IXmlLineInfo lineInfo, int depth, string attrName, string attrNS, string attrValue)
+		internal XsdIdentityPath Matches (bool matchesAttr, object sender, XmlNameTable nameTable, ArrayList qnameStack, string sourceUri, object schemaType, NSResolver nsResolver, IXmlLineInfo lineInfo, int depth, string attrName, string attrNS, object attrValue)
 		{
 			for (int i = 0; i < field.Paths.Length; i++) {
 				XsdIdentityPath path = field.Paths [i];
@@ -174,7 +174,7 @@ namespace Mono.Xml.Schema
 			return null;
 		}
 
-		private void FillAttributeFieldValue (object sender, XmlNameTable nameTable, string sourceUri, object schemaType, NSResolver nsResolver, string value, IXmlLineInfo lineInfo, int depth)
+		private void FillAttributeFieldValue (object sender, XmlNameTable nameTable, string sourceUri, object schemaType, NSResolver nsResolver, object identity, IXmlLineInfo lineInfo, int depth)
 		{
 			if (this.FieldFound)
 				throw new ValException ("The key value was already found."
@@ -186,12 +186,7 @@ namespace Mono.Xml.Schema
 			XmlSchemaSimpleType st = schemaType as XmlSchemaSimpleType;
 			if (dt == null && st != null)
 				dt = st.Datatype;
-			object identity = null;
 			try {
-				if (dt != null)
-					identity = dt.ParseValue (value, nameTable, nsResolver);
-				if (identity == null)
-					identity = value;
 				if (!this.SetIdentityField (identity, false, dt as XsdAnySimpleType, depth, lineInfo))
 					throw new ValException ("Two or more identical field was found.",
 						sender, sourceUri, entry.OwnerSequence.SourceSchemaIdentity, null);
@@ -287,7 +282,7 @@ namespace Mono.Xml.Schema
 
 		// In this method, attributes are ignored.
 		// It might throw Exception.
-		public void ProcessMatch (bool isAttribute, ArrayList qnameStack, object sender, XmlNameTable nameTable, string sourceUri, object schemaType, NSResolver nsResolver, IXmlLineInfo li, int depth, string attrName, string attrNS, string attrValue, bool isXsiNil, ArrayList currentKeyFieldConsumers)
+		public void ProcessMatch (bool isAttribute, ArrayList qnameStack, object sender, XmlNameTable nameTable, string sourceUri, object schemaType, NSResolver nsResolver, IXmlLineInfo li, int depth, string attrName, string attrNS, object attrValue, bool isXsiNil, ArrayList currentKeyFieldConsumers)
 		{
 			for (int i = 0; i < KeyFields.Count; i++) {
 				XsdKeyEntryField keyField = KeyFields [i];

+ 10 - 6
mcs/class/System.XML/Mono.Xml.Schema/XsdValidatingReader.cs

@@ -1120,7 +1120,16 @@ namespace Mono.Xml.Schema
 						case XmlSchema.InstanceNamespace:
 							continue;
 						}
-						entry.ProcessMatch (true, elementQNameStack, this, NameTable, BaseURI, SchemaType, NamespaceManager, readerLineInfo, Depth, LocalName, NamespaceURI, Value, false, CurrentKeyFieldConsumers);
+						XmlSchemaDatatype dt = SchemaType as XmlSchemaDatatype;
+						XmlSchemaSimpleType st = SchemaType as XmlSchemaSimpleType;
+						if (dt == null && st != null)
+							dt = st.Datatype;
+						object identity = null;
+						if (dt != null)
+							identity = dt.ParseValue (Value, NameTable, NamespaceManager);
+						if (identity == null)
+							identity = Value;
+						entry.ProcessMatch (true, elementQNameStack, this, NameTable, BaseURI, SchemaType, NamespaceManager, readerLineInfo, Depth, LocalName, NamespaceURI, identity, false, CurrentKeyFieldConsumers);
 					} while (MoveToNextAttribute ());
 				} finally {
 					MoveToElement ();
@@ -1785,11 +1794,6 @@ namespace Mono.Xml.Schema
 			return null;
 		}
 
-		public object FindID (string name)
-		{
-			return idList [name];
-		}
-
 		public bool HasMissingIDReferences ()
 		{
 			return missingIDReferences != null

+ 6 - 0
mcs/class/System.XML/System.Xml.Schema/ChangeLog

@@ -1,3 +1,9 @@
+2005-11-07  Atsushi Enomoto <[email protected]>
+
+	* XmlValueGetter.cs, XmlSchemaValidator.cs, XmlSchemaException.cs,
+	  XmlSchemaAttribute.cs : Updated API to match 2.0 RTM. Most of the
+	  changes are related to XmlValueGetter change.
+
 2005-11-07  Atsushi Enomoto <[email protected]>
 
 	* XmlSchemaValidator.cs : sealed.

+ 8 - 1
mcs/class/System.XML/System.Xml.Schema/XmlSchemaAttribute.cs

@@ -46,6 +46,7 @@ namespace System.Xml.Schema
 		private string fixedValue;
 		private string validatedDefaultValue;
 		private string validatedFixedValue;
+		private object validatedFixedTypedValue;
 		private XmlSchemaForm form;
 		private string name;
 		private string targetNamespace;
@@ -194,6 +195,12 @@ namespace System.Xml.Schema
 			// FixedValue can be overriden in case of ref.
 			get { return validatedFixedValue; }
 		}
+
+		internal object ValidatedFixedTypedValue
+		{
+			get { return validatedFixedTypedValue; }
+		}
+
 		internal XmlSchemaUse ValidatedUse
 		{
 			get { return validatedUse; }
@@ -427,7 +434,7 @@ namespace System.Xml.Schema
 					try {
 						if (fixedValue != null) {
 							validatedFixedValue = datatype.Normalize (fixedValue);
-							datatype.ParseValue (validatedFixedValue, null, null);
+							validatedFixedTypedValue = datatype.ParseValue (validatedFixedValue, null, null);
 						}
 					} catch (Exception ex) {
 						// FIXME: This is not a good way to handle exception.

+ 0 - 3
mcs/class/System.XML/System.Xml.Schema/XmlSchemaException.cs

@@ -162,12 +162,9 @@ namespace System.Xml.Schema
 			return msg;
 		}
 
-#if NET_2_0
-#else
 		public override string Message {
 			get { return base.Message; }
 		}
-#endif
 
 		// Methods
 

+ 34 - 25
mcs/class/System.XML/System.Xml.Schema/XmlSchemaValidator.cs

@@ -270,12 +270,6 @@ namespace System.Xml.Schema
 			list.AddRange (defaultAttributes);
 		}
 
-		public object FindID (string name)
-		{
-			// It looks returning the element's local name (string)
-			return idManager.FindID (name);
-		}
-
 		// State Controller
 
 		public void AddSchema (XmlSchema schema)
@@ -327,6 +321,17 @@ namespace System.Xml.Schema
 			state.PopContext ();
 		}
 
+		public object ValidateAttribute (
+			string localName,
+			string ns,
+			string attributeValue,
+			XmlSchemaInfo info)
+		{
+			return ValidateAttribute (localName, ns,
+				delegate () { return info.SchemaType.Datatype.ParseValue (attributeValue, nameTable, nsResolver); },
+				info);
+		}
+
 		// I guess this weird XmlValueGetter is for such case that
 		// value might not be required (and thus it improves 
 		// performance in some cases. Doh).
@@ -423,9 +428,9 @@ namespace System.Xml.Schema
 			}
 		}
 
-		public object ValidateEndElement (XmlSchemaInfo schemaInfo)
+		public object ValidateEndElement (XmlSchemaInfo info)
 		{
-			return ValidateEndElement (schemaInfo, null);
+			return ValidateEndElement (info, null);
 		}
 
 		// The return value is typed primitive, if supplied.
@@ -434,13 +439,13 @@ namespace System.Xml.Schema
 		// some kind of object to this method to check the behavior.)
 		// EndTagDeriv
 		[MonoTODO ("Handle 'var' parameter.")]
-		public object ValidateEndElement (XmlSchemaInfo schemaInfo,
+		public object ValidateEndElement (XmlSchemaInfo info,
 			object var)
 		{
 			// If it is going to validate an empty element, then
 			// first validate end of attributes.
 			if (transition == Transition.StartTag)
-				ValidateEndOfAttributes ();
+				ValidateEndOfAttributes (info);
 
 			CheckState (Transition.Content);
 
@@ -457,12 +462,13 @@ namespace System.Xml.Schema
 			if (depth == skipValidationDepth)
 				skipValidationDepth = -1;
 			else if (skipValidationDepth < 0 || depth <= skipValidationDepth)
-				ret = AssessEndElementSchemaValidity (schemaInfo);
+				ret = AssessEndElementSchemaValidity (info);
 			return ret;
 		}
 
 		// StartTagCloseDeriv
-		public void ValidateEndOfAttributes ()
+		// FIXME: fill validity inside this invocation.
+		public void ValidateEndOfAttributes (XmlSchemaInfo info)
 		{
 			try {
 				CheckState (Transition.StartTag);
@@ -470,7 +476,7 @@ namespace System.Xml.Schema
 				if (schemas.Count == 0)
 					return;
 
-				AssessCloseStartElementSchemaValidity ();
+				AssessCloseStartElementSchemaValidity (info);
 			} finally {
 				occuredAtts.Clear ();
 			}
@@ -623,16 +629,16 @@ namespace System.Xml.Schema
 #endregion
 		}
 
-		private void AssessCloseStartElementSchemaValidity ()
+		private void AssessCloseStartElementSchemaValidity (XmlSchemaInfo info)
 		{
 			if (Context.XsiType != null)
-				AssessCloseStartElementLocallyValidType ();
+				AssessCloseStartElementLocallyValidType (info);
 			else if (Context.Element != null) {
 				// element locally valid is checked only when
 				// xsi:type does not exist.
 				AssessElementLocallyValidElement ();
 				if (Context.Element.ElementType != null)
-					AssessCloseStartElementLocallyValidType ();
+					AssessCloseStartElementLocallyValidType (info);
 			}
 
 			if (Context.Element == null) {
@@ -689,7 +695,7 @@ namespace System.Xml.Schema
 		}
 
 		// 3.3.4 Element Locally Valid (Type)
-		private void AssessCloseStartElementLocallyValidType ()
+		private void AssessCloseStartElementLocallyValidType (XmlSchemaInfo info)
 		{
 			object schemaType = Context.ActualType;
 			if (schemaType == null) {	// 1.
@@ -703,12 +709,13 @@ namespace System.Xml.Schema
 				// Attributes are checked in ValidateAttribute().
 			} else if (cType != null) {
 				// 3.2. Also, 2. is checked there.
-				AssessCloseStartElementLocallyValidComplexType (cType);
+				AssessCloseStartElementLocallyValidComplexType (cType, info);
 			}
 		}
 
 		// 3.4.4 Element Locally Valid (Complex Type)
-		private void AssessCloseStartElementLocallyValidComplexType (ComplexType cType)
+		// FIXME: use SchemaInfo for somewhere (? it is passed to ValidateEndOfAttributes() for some reason)
+		private void AssessCloseStartElementLocallyValidComplexType (ComplexType cType, XmlSchemaInfo info)
 		{
 			// 1.
 			if (cType.IsAbstract) {
@@ -752,13 +759,13 @@ namespace System.Xml.Schema
 			XsAttribute attdecl = attMatch as XsAttribute;
 			if (attdecl != null) {
 				AssessAttributeLocallyValidUse (attdecl);
-				return AssessAttributeLocallyValid (attdecl, getter);
+				return AssessAttributeLocallyValid (attdecl, info, getter);
 			} // otherwise anyAttribute or null.
 			return null;
 		}
 
 		// 3.2.4 Attribute Locally Valid and 3.4.4
-		private object AssessAttributeLocallyValid (XsAttribute attr, XmlValueGetter getter)
+		private object AssessAttributeLocallyValid (XsAttribute attr, XmlSchemaInfo info, XmlValueGetter getter)
 		{
 			// 2. - 4.
 			if (attr.AttributeType == null)
@@ -768,16 +775,18 @@ namespace System.Xml.Schema
 				dt = ((SimpleType) attr.AttributeType).Datatype;
 			// It is a bit heavy process, so let's omit as long as possible ;-)
 			if (dt != SimpleType.AnySimpleType || attr.ValidatedFixedValue != null) {
-				string normalized = dt.Normalize (getter ());
 				object parsedValue = null;
 				try {
-					parsedValue = dt.ParseValue (normalized, nameTable, nsResolver);
+					parsedValue = getter ();
 				} catch (Exception ex) { // FIXME: (wishlist) It is bad manner ;-(
 					HandleError ("Attribute value is invalid against its data type " + dt.TokenizedType, ex);
 				}
-				if (attr.ValidatedFixedValue != null && attr.ValidatedFixedValue != normalized) {
+				XmlSchemaType type = info != null ? info.SchemaType : null;
+				if (attr.ValidatedFixedValue != null && 
+					!XmlSchemaUtil.IsSchemaDatatypeEquals (
+					attr.AttributeSchemaType.Datatype as XsdAnySimpleType, attr.ValidatedFixedTypedValue, type != null ? type.Datatype as XsdAnySimpleType : null, parsedValue)) {
 					HandleError ("The value of the attribute " + attr.QualifiedName + " does not match with its fixed value.");
-					parsedValue = dt.ParseValue (attr.ValidatedFixedValue, nameTable, nsResolver);
+					parsedValue = attr.ValidatedFixedTypedValue;
 				}
 #region ID Constraints
 				if (!IgnoreIdentity) {

+ 1 - 1
mcs/class/System.XML/System.Xml.Schema/XmlValueGetter.cs

@@ -25,7 +25,7 @@ namespace System.Xml.Schema
 {
 	/// <summary>
 	/// </summary>
-	public delegate string XmlValueGetter ();
+	public delegate object XmlValueGetter ();
 }
 
 

+ 4 - 0
mcs/class/System.XML/Test/System.Xml.Schema/standalone_tests/ChangeLog

@@ -1,3 +1,7 @@
+2005-11-07  Atsushi Enomoto  <[email protected]>
+
+	* xsdtest.cs : updated to match 2.0 RTM API.
+
 2005-09-30  Atsushi Enomoto  <[email protected]>
 
 	* xsdtest.cs : noResolver option.

+ 2 - 5
mcs/class/System.XML/Test/System.Xml.Schema/standalone_tests/xsdtest.cs

@@ -177,8 +177,6 @@ USAGE: mono xsdtest.exe options target-pattern
 					XmlReaderSettings settings =
 						new XmlReaderSettings ();
 					settings.ValidationType = ValidationType.Schema;
-					settings.ValidationFlags =
-						XmlSchemaValidationFlags.IgnoreValidationWarnings;
 					if (noValidate)
 						settings.ValidationEventHandler +=
 							noValidateHandler;
@@ -186,9 +184,8 @@ USAGE: mono xsdtest.exe options target-pattern
 						settings.Schemas.XmlResolver = null;
 					settings.Schemas.Add (schema);
 					if (noResolver)
-						xvr = XmlReader.Create (ixtr, null, settings);
-					else
-						xvr = XmlReader.Create (ixtr, settings);
+						settings.XmlResolver = null;
+					xvr = XmlReader.Create (ixtr, settings);
 				} else {
 #endif
 					XmlValidatingReader vr = new XmlValidatingReader (ixtr);