فهرست منبع

2005-01-12 Lluis Sanchez Gual <[email protected]>

	* XmlTypeMapElementInfo.cs: Added new IndexOfElement method.
	* XmlSchemaImporter.cs: When importing a base type of a complex type,
	make sure that the base class is always imported as a class and not
	as an array. If it has been imported as array, import it again.
	This fixes bug #70839. Other minor fixes as well.
	* XmlSerializationWriter.cs: Fixed warning.


svn path=/trunk/mcs/; revision=38750
Lluis Sanchez 21 سال پیش
والد
کامیت
4564ef55fd

+ 9 - 0
mcs/class/System.XML/System.Xml.Serialization/ChangeLog

@@ -1,3 +1,12 @@
+2005-01-12  Lluis Sanchez Gual  <[email protected]>
+
+	* XmlTypeMapElementInfo.cs: Added new IndexOfElement method.
+	* XmlSchemaImporter.cs: When importing a base type of a complex type,
+	make sure that the base class is always imported as a class and not
+	as an array. If it has been imported as array, import it again.
+	This fixes bug #70839. Other minor fixes as well.
+	* XmlSerializationWriter.cs: Fixed warning.
+
 2004-12-09  Lluis Sanchez Gual  <[email protected]>
 
 	* SerializationCodeGenerator.cs: Yet another generation fix.

+ 39 - 7
mcs/class/System.XML/System.Xml.Serialization/XmlSchemaImporter.cs

@@ -485,6 +485,14 @@ namespace System.Xml.Serialization
 			return ImportType (name, type, root);
 		}
 
+		XmlTypeMapping ImportClass (XmlQualifiedName name)
+		{
+			XmlTypeMapping map = ImportType (name, null);
+			if (map.TypeData.SchemaType == SchemaTypes.Class) return map;
+			XmlSchemaComplexType stype = schemas.Find (name, typeof (XmlSchemaComplexType)) as XmlSchemaComplexType;
+			return CreateClassMap (name, stype, new XmlQualifiedName (map.ElementName, map.Namespace));
+		}
+		
 		XmlTypeMapping ImportType (XmlQualifiedName name, XmlSchemaType stype, XmlQualifiedName root)
 		{
 			XmlTypeMapping map = GetRegisteredTypeMapping (name);
@@ -509,8 +517,6 @@ namespace System.Xml.Serialization
 
 		XmlTypeMapping ImportClassComplexType (XmlQualifiedName typeQName, XmlSchemaComplexType stype, XmlQualifiedName root)
 		{
-			XmlTypeMapping map;
-
 			// The need for fixups: If the complex type is an array, then to get the type of the
 			// array we need first to get the type of the items of the array.
 			// But if one of the item types or its children has a referece to this type array,
@@ -528,7 +534,7 @@ namespace System.Xml.Serialization
 				ListMap listMap = BuildArrayMap (typeQName, stype, out typeData);
 				if (listMap != null)
 				{
-					map = CreateArrayTypeMapping (typeQName, typeData);
+					XmlTypeMapping map = CreateArrayTypeMapping (typeQName, typeData);
 					map.ObjectMap = listMap;
 					return map;
 				}
@@ -543,7 +549,12 @@ namespace System.Xml.Serialization
 			// Register the map right now but do not build it,
 			// This will avoid loops.
 
-			map = CreateTypeMapping (typeQName, SchemaTypes.Class, root);
+			return CreateClassMap (typeQName, stype, root);
+		}
+		
+		XmlTypeMapping CreateClassMap (XmlQualifiedName typeQName, XmlSchemaComplexType stype, XmlQualifiedName root)
+		{
+			XmlTypeMapping map = CreateTypeMapping (typeQName, SchemaTypes.Class, root);
 			map.Documentation = GetDocumentation (stype);
 			RegisterMapFixup (map, typeQName, stype);
 			return map;
@@ -606,6 +617,8 @@ namespace System.Xml.Serialization
 
 			ImportAttributes (typeQName, cmap, stype.Attributes, stype.AnyAttribute, classIds);
 			ImportExtensionTypes (typeQName);
+
+			if (isMixed) AddTextMember (typeQName, cmap, classIds);
 			
 			AddObjectDerivedMap (map);
 		}
@@ -769,7 +782,12 @@ namespace System.Xml.Serialization
 		void ImportParticleComplexContent (XmlQualifiedName typeQName, ClassMap cmap, XmlSchemaParticle particle, CodeIdentifiers classIds, bool isMixed)
 		{
 			ImportParticleContent (typeQName, cmap, particle, classIds, false, ref isMixed);
-			if (isMixed && cmap.XmlTextCollector == null)
+			if (isMixed) AddTextMember (typeQName, cmap, classIds);
+		}
+		
+		void AddTextMember (XmlQualifiedName typeQName, ClassMap cmap, CodeIdentifiers classIds)
+		{
+			if (cmap.XmlTextCollector == null)
 			{
 				XmlTypeMapMemberFlatList member = new XmlTypeMapMemberFlatList ();
 				member.Name = classIds.AddUnique ("Text", member);
@@ -924,8 +942,22 @@ namespace System.Xml.Serialization
 			bool allEqual = true;
 			Hashtable types = new Hashtable ();
 
-			foreach (XmlTypeMapElementInfo einfo in choices)
+			for (int n = choices.Count - 1; n >= 0; n--)
 			{
+				XmlTypeMapElementInfo einfo = (XmlTypeMapElementInfo) choices [n];
+				
+				// In some complex schemas, we may end up with several options
+				// with the same name. It is better to ignore the extra options
+				// than to crash. It's the best we can do, and btw it works
+				// better than in MS.NET.
+				
+				if (cmap.GetElement (einfo.ElementName, einfo.Namespace) != null ||
+					choices.IndexOfElement (einfo.ElementName, einfo.Namespace) != n)
+				{
+					choices.RemoveAt (n);
+					continue;
+				}
+					
 				if (types.ContainsKey (einfo.TypeData)) twoEqual = true;
 				else types.Add (einfo.TypeData, einfo);
 
@@ -1139,7 +1171,7 @@ namespace System.Xml.Serialization
 			
 			// Add base map members to this map
 
-			XmlTypeMapping baseMap = ImportType (qname, null);
+			XmlTypeMapping baseMap = ImportClass (qname);
 			BuildPendingMap (baseMap);
 			ClassMap baseClassMap = (ClassMap)baseMap.ObjectMap;
 

+ 0 - 2
mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriter.cs

@@ -748,8 +748,6 @@ namespace System.Xml.Serialization
 					serializedObjects [o] = o;
 			}
 			
-			WriteState oldState = Writer.WriteState;
-			
 			string prefix = null;
 			
 			if (topLevelElement && ns != null && ns.Length != 0)

+ 9 - 0
mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapElementInfo.cs

@@ -172,6 +172,15 @@ namespace System.Xml.Serialization
 
 	class XmlTypeMapElementInfoList: ArrayList
 	{
+		public int IndexOfElement (string name, string namspace)
+		{
+			for (int n=0; n<Count; n++) {
+				XmlTypeMapElementInfo info = (XmlTypeMapElementInfo) base [n];
+				if (info.ElementName == name && info.Namespace == namspace)
+					return n;
+			}
+			return -1;
+		}
 	}
 }