* XmlSerializationReader.cs: Support schamea instance namespaces other than
authorLluis Sanchez <lluis@novell.com>
Wed, 2 Jun 2004 18:16:39 +0000 (18:16 -0000)
committerLluis Sanchez <lluis@novell.com>
Wed, 2 Jun 2004 18:16:39 +0000 (18:16 -0000)
  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

mcs/class/System.XML/System.Xml.Serialization/ChangeLog
mcs/class/System.XML/System.Xml.Serialization/MapCodeGenerator.cs
mcs/class/System.XML/System.Xml.Serialization/SoapCodeExporter.cs
mcs/class/System.XML/System.Xml.Serialization/XmlCodeExporter.cs
mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs
mcs/class/System.XML/System.Xml.Serialization/XmlRootAttribute.cs
mcs/class/System.XML/System.Xml.Serialization/XmlSchemaImporter.cs
mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReader.cs
mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapping.cs

index b3b38c1820ff5638f9179b93c4a5e7df19e48ac2..b57f1872e3a94085309542d35e6df3bae6c25747 100755 (executable)
@@ -1,3 +1,22 @@
+2004-06-02  Lluis Sanchez Gual <lluis@ximian.com>
+
+       * 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 <lluis@ximian.com>
 
        * SerializationCodeGenerator.cs, XmlSerializationReaderInterpreter.cs:
index f7f5dcc8da1389cdc7672697095c8f97ccaf6c0e..866542dd25f952511bd0a8ac13c1c1f3d82ea711 100644 (file)
@@ -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)
index af91d43bccfe177388926eb009c512c9ce469254..7a514fec9cc072987aca68773f24a1acbc646c62 100644 (file)
@@ -123,8 +123,8 @@ namespace System.Xml.Serialization {
                protected override void GenerateEnum (XmlTypeMapping map, CodeTypeDeclaration codeEnum)\r
                {\r
                        CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.SoapType");\r
-                       if (map.ElementName != map.TypeData.TypeName) att.Arguments.Add (GetArg (map.ElementName));\r
-                       if (map.Namespace != "") att.Arguments.Add (GetArg ("Namespace", map.Namespace));\r
+                       if (map.XmlType != map.TypeData.TypeName) att.Arguments.Add (GetArg (map.XmlType));\r
+                       if (map.XmlTypeNamespace != "") att.Arguments.Add (GetArg ("Namespace", map.XmlTypeNamespace));\r
                        AddCustomAttribute (codeEnum, att, false);\r
                }               \r
                \r
index 5c0889a4dac19db75515020bcfc3725df0a0b54b..d464415c7e75acd0f430fab17b2febcdf6a95a46 100644 (file)
@@ -225,8 +225,8 @@ namespace System.Xml.Serialization {
                protected override void GenerateEnum (XmlTypeMapping map, CodeTypeDeclaration codeEnum)\r
                {\r
                        CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlTypeAttribute");\r
-                       if (map.ElementName != map.TypeData.TypeName) att.Arguments.Add (GetArg ("TypeName", map.ElementName));\r
-                       if (map.Namespace != "") att.Arguments.Add (GetArg ("Namespace", map.Namespace));\r
+                       if (map.XmlType != map.TypeData.TypeName) att.Arguments.Add (GetArg ("TypeName", map.XmlType));\r
+                       if (map.XmlTypeNamespace != "") att.Arguments.Add (GetArg ("Namespace", map.XmlTypeNamespace));\r
                        AddCustomAttribute (codeEnum, att, false);\r
                }               \r
                \r
index 498e4bba7a3266d831a667d4453bee71e31b75ab..1976267a972899a6085c30afa45ca4ac096d33c1 100644 (file)
@@ -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 = "";
index dbf5de5b269b45d02389a4bb7c46cfecb233f4df..b9355dab396bf9bb79002314dc532627d673cd0b 100644 (file)
@@ -21,7 +21,7 @@ namespace System.Xml.Serialization
        {\r
                private string dataType;\r
                private string elementName;\r
-               private bool isNullable;\r
+               private bool isNullable = true;\r
                private string ns;\r
 \r
                public XmlRootAttribute ()\r
index c7c21b3c9ec105a9776e0f288643c07be1b66880..2ed70a2b123510d62a948f905e01cdfc0d835bbd 100644 (file)
@@ -132,7 +132,7 @@ namespace System.Xml.Serialization {
                                // has the requested base type\r
                                \r
                                SetMapBaseType (map, baseType);\r
-                               map.SetRoot (name);\r
+                               map.UpdateRoot (name);\r
                                return map;\r
                        }\r
                        \r
@@ -235,7 +235,7 @@ namespace System.Xml.Serialization {
                                \r
                                XmlQualifiedName typeQName = new XmlQualifiedName ("Message", names[n].Namespace);\r
                                XmlTypeMapping tmap;\r
-                               TypeData td = GetElementTypeData (typeQName, elem, out tmap);\r
+                               TypeData td = GetElementTypeData (typeQName, elem, names[n], out tmap);\r
                                \r
                                mapping[n] = ImportMemberMapping (elem.Name, typeQName.Namespace, elem.IsNillable, td, tmap);\r
                        }\r
@@ -364,7 +364,10 @@ namespace System.Xml.Serialization {
                XmlTypeMapping ImportType (XmlQualifiedName name, XmlQualifiedName root)\r
                {\r
                        XmlTypeMapping map = GetRegisteredTypeMapping (name);\r
-                       if (map != null) return map;\r
+                       if (map != null) {\r
+                               map.UpdateRoot (root);\r
+                               return map;\r
+                       }\r
 \r
                        XmlSchemaType type = (XmlSchemaType) schemas.Find (name, typeof (XmlSchemaComplexType));\r
                        if (type == null) type = (XmlSchemaType) schemas.Find (name, typeof (XmlSchemaSimpleType));\r
@@ -385,8 +388,10 @@ namespace System.Xml.Serialization {
                        XmlTypeMapping map = GetRegisteredTypeMapping (name);\r
                        if (map != null) {\r
                                XmlSchemaComplexType ct = stype as XmlSchemaComplexType;\r
-                               if (map.TypeData.SchemaType != SchemaTypes.Class || ct == null || !CanBeArray (name, ct))\r
+                               if (map.TypeData.SchemaType != SchemaTypes.Class || ct == null || !CanBeArray (name, ct)) {\r
+                                       map.UpdateRoot (root);\r
                                        return map;\r
+                               }\r
                                        \r
                                // The map was initially imported as a class, but it turns out that it is an\r
                                // array. It has to be imported now as array.\r
@@ -705,7 +710,7 @@ namespace System.Xml.Serialization {
                                        string ns;\r
                                        XmlSchemaElement elem = (XmlSchemaElement) item;\r
                                        XmlTypeMapping emap;\r
-                                       TypeData typeData = GetElementTypeData (typeQName, elem, out emap);\r
+                                       TypeData typeData = GetElementTypeData (typeQName, elem, null, out emap);\r
                                        XmlSchemaElement refElem = GetRefElement (typeQName, elem, out ns);\r
 \r
                                        if (elem.MaxOccurs == 1 && !multiValue)\r
@@ -891,7 +896,7 @@ namespace System.Xml.Serialization {
                                        string ns;\r
                                        XmlSchemaElement elem = (XmlSchemaElement) item;\r
                                        XmlTypeMapping emap;\r
-                                       TypeData typeData = GetElementTypeData (typeQName, elem, out emap);\r
+                                       TypeData typeData = GetElementTypeData (typeQName, elem, null, out emap);\r
                                        XmlSchemaElement refElem = GetRefElement (typeQName, elem, out ns);\r
                                        choices.Add (CreateElementInfo (ns, member, refElem.Name, typeData, refElem.IsNillable, refElem.Form, emap));\r
                                        if (elem.MaxOccurs > 1) multiValue = true;\r
@@ -1392,10 +1397,9 @@ namespace System.Xml.Serialization {
                        }\r
                }\r
 \r
-               TypeData GetElementTypeData (XmlQualifiedName typeQName, XmlSchemaElement elem, out XmlTypeMapping map)\r
+               TypeData GetElementTypeData (XmlQualifiedName typeQName, XmlSchemaElement elem, XmlQualifiedName root, out XmlTypeMapping map)\r
                {\r
                        bool sharedAnnType = false;\r
-                       XmlQualifiedName root = null;\r
                        map = null;\r
                        \r
                        if (!elem.RefName.IsEmpty) {\r
index d8bdf0ad9520e17e6d91ed8fc53d6e8540acb699..9a57eb35571f22eeafa6705a74419f8546537ea6 100644 (file)
@@ -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 
index bccc348286425b2873b23a4d607df15bdc60732d..f96d1d58a17750c938ab4be7e6effc9090411a95 100644 (file)
@@ -26,6 +26,7 @@ namespace System.Xml.Serialization
                bool isSimpleType;\r
                string documentation;\r
                bool includeInSchema;\r
+               bool isNullable = true;\r
 \r
                ArrayList _derivedTypes = new ArrayList();\r
 \r
@@ -108,6 +109,12 @@ namespace System.Xml.Serialization
                        get { return includeInSchema; }\r
                        set { includeInSchema = value; }\r
                }\r
+               \r
+               internal bool IsNullable\r
+               {\r
+                       get { return isNullable; }\r
+                       set { isNullable = value; }\r
+               }\r
 \r
                internal XmlTypeMapping GetRealTypeMap (string objectFullTypeName)\r
                {\r
@@ -132,10 +139,12 @@ namespace System.Xml.Serialization
                        return null;\r
                }\r
                \r
-               internal void SetRoot (XmlQualifiedName qname)\r
+               internal void UpdateRoot (XmlQualifiedName qname)\r
                {\r
-                       this.elementName = qname.Name;\r
-                       this.ns = qname.Namespace;\r
+                       if (qname != null) {\r
+                               this.elementName = qname.Name;\r
+                               this.ns = qname.Namespace;\r
+                       }\r
                }\r
        }\r
 \r