فهرست منبع

2004-07-13 Atsushi Enomoto <[email protected]>

	* XmlSchemaBuiltInType.cs, XmlSchemaValidity.cs, XmlTypeCode.cs
	  : fixed annoying enum errors.
	* XmlSchemaCollection.cs : completely delegate to XmlSchemaSet.
	* XmlSchemaSet.cs : sealed classes. Use ListDictionary (avoid annoying
	  order preservation matter). NameTable null check for .ctor().
	  Fill GlobalAttributes, GlobalElements, GlobalTypes correctly.
	  Add(string, XmlReader) checks namespace conflicts, while
	  Add(XmlSchema) does not. Fixed Schemas() return type.

svn path=/trunk/mcs/; revision=31079
Atsushi Eno 21 سال پیش
والد
کامیت
c396b3e156

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

@@ -1,3 +1,14 @@
+2004-07-13  Atsushi Enomoto <[email protected]>
+
+	* XmlSchemaBuiltInType.cs, XmlSchemaValidity.cs, XmlTypeCode.cs
+	  : fixed annoying enum errors.
+	* XmlSchemaCollection.cs : completely delegate to XmlSchemaSet.
+	* XmlSchemaSet.cs : sealed classes. Use ListDictionary (avoid annoying
+	  order preservation matter). NameTable null check for .ctor().
+	  Fill GlobalAttributes, GlobalElements, GlobalTypes correctly.
+	  Add(string, XmlReader) checks namespace conflicts, while
+	  Add(XmlSchema) does not. Fixed Schemas() return type.
+
 2004-07-11  Atsushi Enomoto <[email protected]>
 
 	* XmlSchemaDatatypeVariety.cs : Fixed class name typo.

+ 12 - 12
mcs/class/System.XML/System.Xml.Schema/XmlSchemaBuiltInType.cs

@@ -31,26 +31,28 @@ namespace System.Xml.Schema
 {
 	public enum XmlSchemaBuiltInType
 	{
-		AnySimpleType,
+		None,
 		AnyType,
+		AnySimpleType,
+		String,
+		Boolean,
+		Float,
+		Double,
+		Decimal,
+		Duration,
 		AnyUri,
 		Base64Binary,
-		Boolean,
 		Byte,
 		Date,
 		DateTime,
-		Decimal,
-		Double,
-		Duration,
-		Entities,
-		Entity,
-		Float,
 		GDay,
 		GMonth,
 		GMonthDay,
 		GYear,
 		GYearMonth,
 		HexBinary,
+		Entities,
+		Entity,
 		Id,
 		Idref,
 		Idrefs,
@@ -63,21 +65,19 @@ namespace System.Xml.Schema
 		NegativeInteger,
 		NmToken,
 		NmTokens,
-		None,
 		NonNegativeInteger,
 		NonPositiveInteger,
-		Normalizedstring,
+		NormalizedString,
 		Notation,
 		PositiveInteger,
 		QName,
 		Short,
-		String,
 		Time,
 		Token,
 		UnsignedByte,
 		UnsignedInt,
 		UnsignedLong,
-		UnsignedShort
+		UnsignedShort,
 	}
 }
 #endif

+ 9 - 0
mcs/class/System.XML/System.Xml.Schema/XmlSchemaCollection.cs

@@ -35,6 +35,10 @@ namespace System.Xml.Schema
 {
 	/// <summary>
 	/// Summary description for XmlSchemaCollection.
+	///
+	/// It is just a wrapper for XmlSchemaSet (unlike MS.NET, our 
+	/// XmlSchemaCollection is originally designed to be conformant to 
+	/// W3C specification).
 	/// </summary>
 	public sealed class XmlSchemaCollection : ICollection, IEnumerable
 	{
@@ -135,6 +139,7 @@ namespace System.Xml.Schema
 			if (schema == null)
 				throw new ArgumentNullException ("schema");
 
+			/*
 			foreach (XmlSchema s in schema) {
 				string ns = GetSafeNs (s.TargetNamespace);
 				lock (schemaSet) {
@@ -143,6 +148,10 @@ namespace System.Xml.Schema
 					schemaSet.Add (s);
 				}
 			}
+			*/
+			lock (schemaSet) {
+				schemaSet.Add (schema.schemaSet);
+			}
 		}
 
 		public bool Contains (string ns)

+ 63 - 23
mcs/class/System.XML/System.Xml.Schema/XmlSchemaSet.cs

@@ -40,35 +40,38 @@ using System.Xml.XPath;
 namespace System.Xml.Schema
 {
 #if NET_2_0
-	public class XmlSchemaSet
+	public sealed class XmlSchemaSet
 #else
-	internal class XmlSchemaSet
+	internal sealed class XmlSchemaSet
 #endif
 	{
 		XmlNameTable nameTable;
 		XmlResolver xmlResolver;
 
-		Hashtable schemas;
+		ListDictionary schemas;
 		XmlSchemaObjectTable attributes;
 		XmlSchemaObjectTable elements;
 		XmlSchemaObjectTable types;
 		XmlSchemaCollection col;
+		ValidationEventHandler handler;
 
 		bool isCompiled;
 
 		internal Guid CompilationId;
 
-		public XmlSchemaSet () : this (new NameTable ())
+		public XmlSchemaSet ()
+			: this (new NameTable ())
 		{
+			handler = new ValidationEventHandler (this.OnValidationError);
 		}
 
 		public XmlSchemaSet (XmlNameTable nameTable)
 		{
+			if (nameTable == null)
+				throw new ArgumentNullException ("nameTable");
+
 			this.nameTable = nameTable;
-			schemas = new Hashtable ();
-			attributes = new XmlSchemaObjectTable ();
-			elements = new XmlSchemaObjectTable ();
-			types = new XmlSchemaObjectTable ();
+			schemas = new ListDictionary ();
 			CompilationId = Guid.NewGuid ();
 		}
 
@@ -79,15 +82,45 @@ namespace System.Xml.Schema
 		}
 
 		public XmlSchemaObjectTable GlobalAttributes {
-			get { return attributes; }
+			get {
+				if (attributes == null) {
+					lock (this) {
+						attributes = new XmlSchemaObjectTable ();
+						foreach (XmlSchema s in schemas.Values)
+							foreach (XmlSchemaAttribute a in s.Attributes.Values)
+								attributes.Add (a.QualifiedName, a);
+					}
+				}
+				return attributes;
+			}
 		}
 
 		public XmlSchemaObjectTable GlobalElements {
-			get { return elements; }
+			get {
+				if (elements == null) {
+					lock (this) {
+						elements = new XmlSchemaObjectTable ();
+						foreach (XmlSchema s in schemas.Values)
+							foreach (XmlSchemaElement e in s.Elements.Values)
+								elements.Add (e.QualifiedName, e);
+					}
+				}
+				return elements;
+			}
 		}
 
 		public XmlSchemaObjectTable GlobalTypes { 
-			get { return types; }
+			get {
+				if (types == null) {
+					lock (this) {
+						types = new XmlSchemaObjectTable ();
+						foreach (XmlSchema s in schemas.Values)
+							foreach (XmlSchemaType t in s.SchemaTypes.Values)
+								types.Add (t.QualifiedName, t);
+					}
+				}
+				return types;
+			}
 		}
 
 		public bool IsCompiled { 
@@ -120,38 +153,45 @@ namespace System.Xml.Schema
 			}
 		}
 
-		[MonoTODO ("Check how targetNamespace is used")]
+		// LAMESPEC? MS.NET allows multiple chameleon schema addition,
+		// while rejects namespace-targeted schema.
 		public XmlSchema Add (string targetNamespace, XmlReader reader)
 		{
-			return Add (XmlSchema.Read (reader, null));
+			XmlSchema schema = XmlSchema.Read (reader, handler);
+			if (targetNamespace != null)
+				schema.TargetNamespace = targetNamespace;
+			XmlSchema existing = schemas [GetSafeNs (schema.TargetNamespace)] as XmlSchema;
+			if (existing != null)
+				throw new ArgumentException (String.Format ("Item has been already added. Target namespace is \"{0}\"", schema.TargetNamespace));
+			return Add (schema);
 		}
 
 		[MonoTODO ("Check the exact behavior when namespaces are in conflict")]
 		public void Add (XmlSchemaSet schemaSet)
 		{
 			foreach (XmlSchema schema in schemaSet.schemas)
-				schemas.Add (schema.TargetNamespace, schema);
+				Add (schema);
 		}
 
-		[MonoTODO ("Check the exact behavior when namespaces are in conflict")]
+		[MonoTODO ("Currently no way to identify if the argument schema is error-prone or not.")]
 		public XmlSchema Add (XmlSchema schema)
 		{
-			XmlSchema existing = schemas [GetSafeNs (schema.TargetNamespace)] as XmlSchema;
-			if (existing != null)
-				return existing;
-			schemas.Add (GetSafeNs (schema.TargetNamespace), schema);
+			schemas [GetSafeNs (schema.TargetNamespace)] = schema;
 			return schema;
 		}
 
 		[MonoTODO]
 		public void Compile ()
 		{
-			throw new NotImplementedException ();
+			foreach (XmlSchema schema in schemas.Values)
+				schema.Compile (handler, col, xmlResolver);
+			isCompiled = true;
+			attributes = elements = types = null;
 		}
 
 		public bool Contains (string targetNamespace)
 		{
-			return schemas.ContainsKey (targetNamespace);
+			return schemas.Contains (targetNamespace);
 		}
 
 		public bool Contains (XmlSchema targetNamespace)
@@ -213,13 +253,13 @@ namespace System.Xml.Schema
 			throw new NotImplementedException ();
 		}
 
-		public ArrayList Schemas ()
+		public ICollection Schemas ()
 		{
 			return new ArrayList (schemas.Values);
 		}
 
 		[MonoTODO]
-		public ArrayList Schemas (string targetNamespace)
+		public ICollection Schemas (string targetNamespace)
 		{
 			throw new NotImplementedException ();
 		}

+ 2 - 2
mcs/class/System.XML/System.Xml.Schema/XmlSchemaValidity.cs

@@ -31,9 +31,9 @@ namespace System.Xml.Schema
 {
 	public enum XmlSchemaValidity
 	{
-		Invalid,
 		NotKnown,
-		Valid
+		Valid,
+		Invalid,
 	}
 }
 

+ 40 - 44
mcs/class/System.XML/System.Xml.Schema/XmlTypeCode.cs

@@ -35,65 +35,61 @@ namespace System.Xml.Schema
 {
 	public enum XmlTypeCode
 	{
-		AnyAtomicType, // xdt
-		AnyItem, // xpath misc
-		AnyNode, // node
-		AnySimpleType,
-		AnyType,
-		AnyUri,
+		None,
+		Item,
+		Node,
+		Document, // node
+		Element, // node
 		Attribute, // node
-		Base64Binary,
-		Boolean,
-		Byte,
+		Namespace, // node
+		ProcessingInstruction, // node
 		Comment, // node
-		Date,
-		DateTime,
-		DayTimeDuration, // xdt
+		Text,	// node
+		AnyAtomicType, // xdt
+		UntypedAtomic, // xdt
+		String,
+		Boolean,
 		Decimal,
-		Document, // node
+		Float,
 		Double,
 		Duration,
-		Element, // node
-		// Entities is not primitive
-		Entity,
-		Float,
+		DateTime,
+		Time,
+		Date,
+		GYearMonth,
+		GYear,
+		GMonthDay,
 		GDay,
 		GMonth,
-		GMonthDay,
-		GYear,
-		GYearMonth,
 		HexBinary,
-		Id,
-		Idref,
-		// Idrefs is not primitive
-		Int,
-		Integer,
+		Base64Binary,
+		AnyUri,
+		QName,
+		Notation,
+		NormalizedString,
+		Token,
 		Language,
-		Long,
+		NmToken, // NmTokens is not primitive
 		Name,
 		NCName,
-		NegativeInteger,
-		NmToken,
-		// NmTokens is not primitive
-		None,
-		NonNegativeInteger,
+		Id,
+		Idref, // Idrefs is not primitive
+		Entity, // Entities is not primitive
+		Integer,
 		NonPositiveInteger,
-		Normalizedstring,
-		Notation,
-		// there seems "ocument" enumeration in MS.NET, but it must be a bug
-		PositiveInteger,
-		ProcessingInstruction, // node
-		QName,
+		NegativeInteger,
+		Long,
+		Int,
 		Short,
-		String,
-		Time,
-		Token,
-		UnsignedByte,
-		UnsignedInt,
+		Byte,
+		NonNegativeInteger,
 		UnsignedLong,
+		UnsignedInt,
 		UnsignedShort,
-		UntypedAtomic, // xdt
-		YearMonthDuration // xdt
+		UnsignedByte,
+		PositiveInteger,
+		YearMonthDuration, // xdt
+		DayTimeDuration, // xdt
 	}
 }
 #endif