Browse Source

2004-11-22 Atsushi Enomoto <[email protected]>

	* XmlSchemaException.cs : Message is only 1.x (not 2.0).
	* XmlSchemaInference.cs : use more static readonly QName fields.
	  Type merge inference now traverses every base types.
	* XmlSchemaInfo.cs : added new file.



svn path=/trunk/mcs/; revision=36359
Atsushi Eno 21 năm trước cách đây
mục cha
commit
f9451776fa

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

@@ -1,3 +1,10 @@
+2004-11-22  Atsushi Enomoto <[email protected]>
+
+	* XmlSchemaException.cs : Message is only 1.x (not 2.0).
+	* XmlSchemaInference.cs : use more static readonly QName fields.
+	  Type merge inference now traverses every base types.
+	* XmlSchemaInfo.cs : added new file.
+
 2004-11-18  Atsushi Enomoto <[email protected]>
 
 	* XmlSchemaException.cs : added .ctor(string).

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

@@ -163,6 +163,7 @@ namespace System.Xml.Schema
 		}
 
 #if NET_2_0
+#else
 		public override string Message {
 			get { return base.Message; }
 		}

+ 79 - 33
mcs/class/System.XML/System.Xml.Schema/XmlSchemaInference.cs

@@ -117,20 +117,65 @@ namespace System.Xml.Schema
 			return impl.schemas;
 		}
 
-		public const string NamespaceXml = "http://www.w3.org/XML/1998/namespace";
+		public const string NamespaceXml =
+			"http://www.w3.org/XML/1998/namespace";
 
-		public const string NamespaceXmlns = "http://www.w3.org/2000/xmlns/";
+		public const string NamespaceXmlns =
+			"http://www.w3.org/2000/xmlns/";
 
-		public const string XdtNamespace = "http://www.w3.org/2003/11/xpath-datatypes";
+		public const string XdtNamespace =
+			"http://www.w3.org/2003/11/xpath-datatypes";
 
-		static readonly QName QNameString = new QName ("string",
-			XmlSchema.Namespace);
+		static readonly QName QNameString = new QName (
+			"string", XmlSchema.Namespace);
 
-		static readonly QName QNameBoolean = new QName ("boolean",
-			XmlSchema.Namespace);
+		static readonly QName QNameBoolean = new QName (
+			"boolean", XmlSchema.Namespace);
 
-		static readonly QName QNameAnyType = new QName ("anyType",
-			XmlSchema.Namespace);
+		static readonly QName QNameAnyType = new QName (
+			"anyType", XmlSchema.Namespace);
+
+		static readonly QName QNameByte = new QName (
+			"byte", XmlSchema.Namespace);
+
+		static readonly QName QNameUByte = new QName (
+			"unsignedByte", XmlSchema.Namespace);
+
+		static readonly QName QNameShort = new QName (
+			"short", XmlSchema.Namespace);
+
+		static readonly QName QNameUShort = new QName (
+			"unsignedShort", XmlSchema.Namespace);
+
+		static readonly QName QNameInt = new QName (
+			"int", XmlSchema.Namespace);
+
+		static readonly QName QNameUInt = new QName (
+			"unsignedInt", XmlSchema.Namespace);
+
+		static readonly QName QNameLong = new QName (
+			"long", XmlSchema.Namespace);
+
+		static readonly QName QNameULong = new QName (
+			"unsignedLong", XmlSchema.Namespace);
+
+		static readonly QName QNameDecimal = new QName (
+			"decimal", XmlSchema.Namespace);
+
+		static readonly QName QNameUDecimal = new QName (
+			"unsignedDecimal", XmlSchema.Namespace);
+
+		static readonly QName QNameDouble = new QName (
+			"double", XmlSchema.Namespace);
+
+		static readonly QName QNameFloat = new QName (
+			"float", XmlSchema.Namespace);
+
+		static readonly QName QNameDateTime = new QName (
+			"dateTime", XmlSchema.Namespace);
+
+		static readonly QName QNameDuration = new QName (
+			"duration", XmlSchema.Namespace);
 
 		XmlReader source;
 		XmlSchemaSet schemas;
@@ -339,17 +384,18 @@ namespace System.Xml.Schema
 				typeName);
 			if (st == null) // non-primitive type => see above.
 				return QNameString;
-			try {
-				st.Datatype.ParseValue (value,
-					source.NameTable,
-					source as IXmlNamespaceResolver);
-				// the string value was value
-				return typeName;
-			} catch {
-				// The types were incompatible.
-				// FIXME: find the base common type
-				return QNameString;
-			}
+			do {
+				try {
+					st.Datatype.ParseValue (value,
+						source.NameTable,
+						source as IXmlNamespaceResolver);
+					return typeName;
+				} catch {
+					st = st.BaseXmlSchemaType as XmlSchemaSimpleType;
+					typeName = st != null ? st.QualifiedName : QName.Empty;
+				}
+			} while (typeName != QName.Empty);
+			return QNameString;
 		}
 
 		private SOMList GetAttributes (ComplexType ct)
@@ -930,49 +976,49 @@ namespace System.Xml.Schema
 			try {
 				long dec = XmlConvert.ToInt64 (value);
 				if (byte.MinValue <= dec && dec <= byte.MaxValue)
-					return XmlSchemaType.GetBuiltInSimpleType (XmlTypeCode.UnsignedByte).QualifiedName;
+					return QNameUByte;
 				if (sbyte.MinValue <= dec && dec <= sbyte.MaxValue)
-					return XmlSchemaType.GetBuiltInSimpleType (XmlTypeCode.Byte).QualifiedName;
+					return QNameByte;
 				if (ushort.MinValue <= dec && dec <= ushort.MaxValue)
-					return XmlSchemaType.GetBuiltInSimpleType (XmlTypeCode.UnsignedShort).QualifiedName;
+					return QNameUShort;
 				if (short.MinValue <= dec && dec <= short.MaxValue)
-					return XmlSchemaType.GetBuiltInSimpleType (XmlTypeCode.Short).QualifiedName;
+					return QNameShort;
 				if (uint.MinValue <= dec && dec <= uint.MaxValue)
-					return XmlSchemaType.GetBuiltInSimpleType (XmlTypeCode.UnsignedInt).QualifiedName;
+					return QNameUInt;
 				if (int.MinValue <= dec && dec <= int.MaxValue)
-					return XmlSchemaType.GetBuiltInSimpleType (XmlTypeCode.Int).QualifiedName;
-				return XmlSchemaType.GetBuiltInSimpleType (XmlTypeCode.Long).QualifiedName;
+					return QNameInt;
+				return QNameLong;
 			} catch (Exception) {
 			}
 			try {
 				XmlConvert.ToUInt64 (value);
-				return XmlSchemaType.GetBuiltInSimpleType (XmlTypeCode.UnsignedLong).QualifiedName;
+				return QNameULong;
 			} catch (Exception) {
 			}
 			try {
 				XmlConvert.ToDecimal (value);
-				return XmlSchemaType.GetBuiltInSimpleType (XmlTypeCode.Decimal).QualifiedName;
+				return QNameDecimal;
 			} catch (Exception) {
 			}
 			try {
 				double dbl = XmlConvert.ToDouble (value);
 				if (float.MinValue <= dbl &&
 					dbl <= float.MaxValue)
-					return XmlSchemaType.GetBuiltInSimpleType (XmlTypeCode.Float).QualifiedName;
+					return QNameFloat;
 				else
-					return XmlSchemaType.GetBuiltInSimpleType (XmlTypeCode.Double).QualifiedName;
+					return QNameDouble;
 			} catch (Exception) {
 			}
 			try {
 				// FIXME: also try DateTimeSerializationMode
 				// and gYearMonth
 				XmlConvert.ToDateTime (value);
-				return XmlSchemaType.GetBuiltInSimpleType (XmlTypeCode.DateTime).QualifiedName;
+				return QNameDateTime;
 			} catch (Exception) {
 			}
 			try {
 				XmlConvert.ToTimeSpan (value);
-				return XmlSchemaType.GetBuiltInSimpleType (XmlTypeCode.Duration).QualifiedName;
+				return QNameDuration;
 			} catch (Exception) {
 			}
 

+ 88 - 0
mcs/class/System.XML/System.Xml.Schema/XmlSchemaInfo.cs

@@ -0,0 +1,88 @@
+//
+// XmlSchemaInfo.cs
+//
+// Author:
+//	Atsushi Enomoto <[email protected]>
+//
+// (C)2004 Novell, Inc.
+//
+
+//
+// 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.
+//
+
+#if NET_2_0
+namespace System.Xml.Schema
+{
+	[MonoTODO]
+	public class XmlSchemaInfo : IXmlSchemaInfo
+	{
+		bool isDefault;
+		bool isNil;
+		XmlSchemaSimpleType memberType;
+		XmlSchemaAttribute attr;
+		XmlSchemaElement elem;
+		XmlSchemaType type;
+		XmlSchemaValidity validity;
+
+		[MonoTODO]
+		public bool IsDefault {
+			get { return isDefault; }
+			set { isDefault = value; }
+		}
+
+		[MonoTODO]
+		public bool IsNil {
+			get { return isNil; }
+			set { isNil = value; }
+		}
+
+		[MonoTODO]
+		public XmlSchemaSimpleType MemberType {
+			get { return memberType; }
+			set { memberType = value; }
+		}
+
+		[MonoTODO]
+		public XmlSchemaAttribute SchemaAttribute {
+			get { return attr; }
+			set { attr = value; }
+		}
+
+		[MonoTODO]
+		public XmlSchemaElement SchemaElement {
+			get { return elem; }
+			set { elem = value; }
+		}
+
+		[MonoTODO]
+		public XmlSchemaType SchemaType {
+			get { return type; }
+			set { type = value; }
+		}
+
+		[MonoTODO]
+		public XmlSchemaValidity Validity {
+			get { return validity; }
+			set { validity = value; }
+		}
+	}
+}
+#endif