Преглед на файлове

* XmlSerializationReader.cs: Support schamea instance namespaces other than
the 2001 one when reading the xsi type.
* MapCodeGenerator.cs: Take into account that the root namespace and element
name may have changed from one export to another of the same type. In
this case the class attributes need to be regenerated.
* SoapCodeExporter.cs, XmlCodeExporter.cs: Take the enum name from XmlType,
not ElementName. Idem for namespace.
* XmlReflectionImporter.cs: Set nullable property of XmlTypeMapping.
* XmlRootAttribute.cs: Default value for nullable is true.
* XmlSchemaImporter.cs: The root name for a class may change in some
scenarios (for example, when the type is initially exported as part of
another type and later exported as a root type).
* XmlSerializationReader.cs: In GetXsiType(), if the type attribute is not
found using the standard namespace, try getting the type using
the 2000/10 and 1999 namespaces.
* XmlTypeMapping.cs: Added IsNullable property. Updated SetRoot method.

svn path=/trunk/mcs/; revision=28711

Lluis Sanchez преди 21 години
родител
ревизия
285cd2dcc8

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

@@ -1,3 +1,22 @@
+2004-06-02  Lluis Sanchez Gual <[email protected]>
+
+	* XmlSerializationReader.cs: Support schamea instance namespaces other than
+	  the 2001 one when reading the xsi type.
+	* MapCodeGenerator.cs: Take into account that the root namespace and element
+	  name may have changed from one export to another of the same type. In
+	  this case the class attributes need to be regenerated.
+	* SoapCodeExporter.cs, XmlCodeExporter.cs: Take the enum name from XmlType,
+	  not ElementName. Idem for namespace.
+	* XmlReflectionImporter.cs: Set nullable property of XmlTypeMapping.
+	* XmlRootAttribute.cs: Default value for nullable is true.
+	* XmlSchemaImporter.cs: The root name for a class may change in some
+	  scenarios (for example, when the type is initially exported as part of
+	  another type and later exported as a root type).
+	* XmlSerializationReader.cs: In GetXsiType(), if the type attribute is not
+	  found using the standard namespace, try getting the type using
+	  the 2000/10 and 1999 namespaces.
+	* XmlTypeMapping.cs: Added IsNullable property. Updated SetRoot method ;-)
+
 2004-05-26  Lluis Sanchez Gual <[email protected]>
 
 	* SerializationCodeGenerator.cs, XmlSerializationReaderInterpreter.cs:

+ 29 - 10
mcs/class/System.XML/System.Xml.Serialization/MapCodeGenerator.cs

@@ -85,16 +85,29 @@ namespace System.Xml.Serialization {
 
 		void ExportClassCode (XmlTypeMapping map)
 		{
-			if (IsMapExported (map)) return;
-			SetMapExported (map);
+			CodeTypeDeclaration codeClass;
+			
+			if (IsMapExported (map)) {
+				// Regenerate attributes, since things may have changed
+				codeClass = GetMapDeclaration (map);
+				if (codeClass != null) {
+					codeClass.CustomAttributes = null;
+					GenerateClass (map, codeClass);
+					ExportDerivedTypes (map, codeClass, true);
+				}
+				return;
+			}
 
 			if (map.TypeData.Type == typeof(object))
 			{
 				exportedAnyType = map;
+				SetMapExported (map, null);
 				return;
 			}
 			
-			CodeTypeDeclaration codeClass = new CodeTypeDeclaration (map.TypeData.TypeName);
+			codeClass = new CodeTypeDeclaration (map.TypeData.TypeName);
+			SetMapExported (map, codeClass);
+			
 			AddCodeType (codeClass, map.Documentation);
 			codeClass.Attributes = MemberAttributes.Public;
 
@@ -109,10 +122,10 @@ namespace System.Xml.Serialization {
 				ExportMapCode (map.BaseMap);
 			}
 
-			ExportDerivedTypes (map, codeClass);
+			ExportDerivedTypes (map, codeClass, false);
 		}
 		
-		void ExportDerivedTypes (XmlTypeMapping map, CodeTypeDeclaration codeClass)
+		void ExportDerivedTypes (XmlTypeMapping map, CodeTypeDeclaration codeClass, bool onlyIncludes)
 		{
 			foreach (XmlTypeMapping tm in map.DerivedTypes)
 			{
@@ -120,8 +133,8 @@ namespace System.Xml.Serialization {
 					codeClass.CustomAttributes = new CodeAttributeDeclarationCollection ();
 
 				GenerateClassInclude (codeClass.CustomAttributes, tm);
-				ExportMapCode (tm);
-				ExportDerivedTypes (tm, codeClass);
+				if (!onlyIncludes) ExportMapCode (tm);
+				ExportDerivedTypes (tm, codeClass, onlyIncludes);
 			}
 		}
 
@@ -352,9 +365,10 @@ namespace System.Xml.Serialization {
 		void ExportEnumCode (XmlTypeMapping map)
 		{
 			if (IsMapExported (map)) return;
-			SetMapExported (map);
 
 			CodeTypeDeclaration codeEnum = new CodeTypeDeclaration (map.TypeData.TypeName);
+			SetMapExported (map, codeEnum);
+			
 			codeEnum.Attributes = MemberAttributes.Public;
 			codeEnum.IsEnum = true;
 			AddCodeType (codeEnum, map.Documentation);
@@ -392,9 +406,14 @@ namespace System.Xml.Serialization {
 			return false;
 		}
 
-		void SetMapExported (XmlTypeMapping map)
+		void SetMapExported (XmlTypeMapping map, CodeTypeDeclaration declaration)
+		{
+			exportedMaps.Add (map.TypeData.FullTypeName, declaration);
+		}
+
+		CodeTypeDeclaration GetMapDeclaration (XmlTypeMapping map)
 		{
-			exportedMaps.Add (map.TypeData.FullTypeName, map);
+			return exportedMaps [map.TypeData.FullTypeName] as CodeTypeDeclaration;
 		}
 
 		public static void AddCustomAttribute (CodeTypeMember ctm, CodeAttributeDeclaration att, bool addIfNoParams)

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

@@ -123,8 +123,8 @@ namespace System.Xml.Serialization {
 		protected override void GenerateEnum (XmlTypeMapping map, CodeTypeDeclaration codeEnum)
 		{
 			CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.SoapType");
-			if (map.ElementName != map.TypeData.TypeName) att.Arguments.Add (GetArg (map.ElementName));
-			if (map.Namespace != "") att.Arguments.Add (GetArg ("Namespace", map.Namespace));
+			if (map.XmlType != map.TypeData.TypeName) att.Arguments.Add (GetArg (map.XmlType));
+			if (map.XmlTypeNamespace != "") att.Arguments.Add (GetArg ("Namespace", map.XmlTypeNamespace));
 			AddCustomAttribute (codeEnum, att, false);
 		}		
 		

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

@@ -225,8 +225,8 @@ namespace System.Xml.Serialization {
 		protected override void GenerateEnum (XmlTypeMapping map, CodeTypeDeclaration codeEnum)
 		{
 			CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlTypeAttribute");
-			if (map.ElementName != map.TypeData.TypeName) att.Arguments.Add (GetArg ("TypeName", map.ElementName));
-			if (map.Namespace != "") att.Arguments.Add (GetArg ("Namespace", map.Namespace));
+			if (map.XmlType != map.TypeData.TypeName) att.Arguments.Add (GetArg ("TypeName", map.XmlType));
+			if (map.XmlTypeNamespace != "") att.Arguments.Add (GetArg ("Namespace", map.XmlTypeNamespace));
 			AddCustomAttribute (codeEnum, att, false);
 		}		
 		

+ 3 - 1
mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs

@@ -149,10 +149,11 @@ namespace System.Xml.Serialization {
 		{
 			string rootNamespace = defaultNamespace;
 			string typeNamespace = null;
-			
 			string elementName;
 			bool includeInSchema = true;
 			XmlAttributes atts = null;
+			bool nullable = true;
+
 			if (defaultXmlType == null) defaultXmlType = typeData.XmlType;
 
 			if (!typeData.IsListType)
@@ -189,6 +190,7 @@ namespace System.Xml.Serialization {
 					elementName = root.ElementName;
 				if (root.Namespace != null && root.Namespace != String.Empty)
 					rootNamespace = root.Namespace;
+				nullable = root.IsNullable;
 			}
 
 			if (rootNamespace == null) rootNamespace = "";

+ 1 - 1
mcs/class/System.XML/System.Xml.Serialization/XmlRootAttribute.cs

@@ -21,7 +21,7 @@ namespace System.Xml.Serialization
 	{
 		private string dataType;
 		private string elementName;
-		private bool isNullable;
+		private bool isNullable = true;
 		private string ns;
 
 		public XmlRootAttribute ()

+ 12 - 8
mcs/class/System.XML/System.Xml.Serialization/XmlSchemaImporter.cs

@@ -132,7 +132,7 @@ namespace System.Xml.Serialization {
 				// has the requested base type
 				
 				SetMapBaseType (map, baseType);
-				map.SetRoot (name);
+				map.UpdateRoot (name);
 				return map;
 			}
 			
@@ -235,7 +235,7 @@ namespace System.Xml.Serialization {
 				
 				XmlQualifiedName typeQName = new XmlQualifiedName ("Message", names[n].Namespace);
 				XmlTypeMapping tmap;
-				TypeData td = GetElementTypeData (typeQName, elem, out tmap);
+				TypeData td = GetElementTypeData (typeQName, elem, names[n], out tmap);
 				
 				mapping[n] = ImportMemberMapping (elem.Name, typeQName.Namespace, elem.IsNillable, td, tmap);
 			}
@@ -364,7 +364,10 @@ namespace System.Xml.Serialization {
 		XmlTypeMapping ImportType (XmlQualifiedName name, XmlQualifiedName root)
 		{
 			XmlTypeMapping map = GetRegisteredTypeMapping (name);
-			if (map != null) return map;
+			if (map != null) {
+				map.UpdateRoot (root);
+				return map;
+			}
 
 			XmlSchemaType type = (XmlSchemaType) schemas.Find (name, typeof (XmlSchemaComplexType));
 			if (type == null) type = (XmlSchemaType) schemas.Find (name, typeof (XmlSchemaSimpleType));
@@ -385,8 +388,10 @@ namespace System.Xml.Serialization {
 			XmlTypeMapping map = GetRegisteredTypeMapping (name);
 			if (map != null) {
 				XmlSchemaComplexType ct = stype as XmlSchemaComplexType;
-				if (map.TypeData.SchemaType != SchemaTypes.Class || ct == null || !CanBeArray (name, ct))
+				if (map.TypeData.SchemaType != SchemaTypes.Class || ct == null || !CanBeArray (name, ct)) {
+					map.UpdateRoot (root);
 					return map;
+				}
 					
 				// The map was initially imported as a class, but it turns out that it is an
 				// array. It has to be imported now as array.
@@ -705,7 +710,7 @@ namespace System.Xml.Serialization {
 					string ns;
 					XmlSchemaElement elem = (XmlSchemaElement) item;
 					XmlTypeMapping emap;
-					TypeData typeData = GetElementTypeData (typeQName, elem, out emap);
+					TypeData typeData = GetElementTypeData (typeQName, elem, null, out emap);
 					XmlSchemaElement refElem = GetRefElement (typeQName, elem, out ns);
 
 					if (elem.MaxOccurs == 1 && !multiValue)
@@ -891,7 +896,7 @@ namespace System.Xml.Serialization {
 					string ns;
 					XmlSchemaElement elem = (XmlSchemaElement) item;
 					XmlTypeMapping emap;
-					TypeData typeData = GetElementTypeData (typeQName, elem, out emap);
+					TypeData typeData = GetElementTypeData (typeQName, elem, null, out emap);
 					XmlSchemaElement refElem = GetRefElement (typeQName, elem, out ns);
 					choices.Add (CreateElementInfo (ns, member, refElem.Name, typeData, refElem.IsNillable, refElem.Form, emap));
 					if (elem.MaxOccurs > 1) multiValue = true;
@@ -1392,10 +1397,9 @@ namespace System.Xml.Serialization {
 			}
 		}
 
-		TypeData GetElementTypeData (XmlQualifiedName typeQName, XmlSchemaElement elem, out XmlTypeMapping map)
+		TypeData GetElementTypeData (XmlQualifiedName typeQName, XmlSchemaElement elem, XmlQualifiedName root, out XmlTypeMapping map)
 		{
 			bool sharedAnnType = false;
-			XmlQualifiedName root = null;
 			map = null;
 			
 			if (!elem.RefName.IsEmpty) {

+ 10 - 1
mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReader.cs

@@ -274,7 +274,16 @@ namespace System.Xml.Serialization {
 		protected XmlQualifiedName GetXsiType ()
 		{
 			string typeName = Reader.GetAttribute ("type", XmlSchema.InstanceNamespace);
-			if (typeName == string.Empty || typeName == null) return null;
+			
+			if (typeName == string.Empty || typeName == null) {
+				typeName = Reader.GetAttribute ("type", w3InstanceNS1999);
+				if (typeName == string.Empty || typeName == null) {
+					typeName = Reader.GetAttribute ("type", w3InstanceNS2000);
+					if (typeName == string.Empty || typeName == null)
+						return null;
+				}
+			}
+			
 			int i = typeName.IndexOf (":");
 			if (i == -1) return new XmlQualifiedName (typeName, Reader.NamespaceURI);
 			else 

+ 12 - 3
mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapping.cs

@@ -26,6 +26,7 @@ namespace System.Xml.Serialization
 		bool isSimpleType;
 		string documentation;
 		bool includeInSchema;
+		bool isNullable = true;
 
 		ArrayList _derivedTypes = new ArrayList();
 
@@ -108,6 +109,12 @@ namespace System.Xml.Serialization
 			get { return includeInSchema; }
 			set { includeInSchema = value; }
 		}
+		
+		internal bool IsNullable
+		{
+			get { return isNullable; }
+			set { isNullable = value; }
+		}
 
 		internal XmlTypeMapping GetRealTypeMap (string objectFullTypeName)
 		{
@@ -132,10 +139,12 @@ namespace System.Xml.Serialization
 			return null;
 		}
 		
-		internal void SetRoot (XmlQualifiedName qname)
+		internal void UpdateRoot (XmlQualifiedName qname)
 		{
-			this.elementName = qname.Name;
-			this.ns = qname.Namespace;
+			if (qname != null) {
+				this.elementName = qname.Name;
+				this.ns = qname.Namespace;
+			}
 		}
 	}