[sgen] Untag the vtable during concurrent mark
[mono.git] / mcs / class / System.XML / System.Xml.Serialization / XmlReflectionImporter.cs
index 53a88a46a41f45d7fbffbb2e78b8a2a1886d5365..0c4e131b87d993693f86e80fab46b45468e4464a 100644 (file)
@@ -109,10 +109,8 @@ namespace System.Xml.Serialization {
                        return ImportMembersMapping (elementName, ns, members, hasWrapperElement, true);
                }
 
-#if NET_2_0
                [MonoTODO]
                public
-#endif
                XmlMembersMapping ImportMembersMapping (string elementName, 
                        string ns, 
                        XmlReflectionMember[] members, 
@@ -122,10 +120,8 @@ namespace System.Xml.Serialization {
                        return ImportMembersMapping (elementName, ns, members, hasWrapperElement, rpc, true);
                }
 
-#if NET_2_0
                [MonoTODO]
                public
-#endif
                XmlMembersMapping ImportMembersMapping (string elementName, 
                        string ns, 
                        XmlReflectionMember[] members, 
@@ -136,10 +132,8 @@ namespace System.Xml.Serialization {
                        return ImportMembersMapping (elementName, ns, members, hasWrapperElement, rpc, openModel, XmlMappingAccess.Read | XmlMappingAccess.Write);
                }
 
-#if NET_2_0
                [MonoTODO] // FIXME: handle writeAccessors, validate, and mapping access
                public
-#endif
                XmlMembersMapping ImportMembersMapping (string elementName, 
                        string ns, 
                        XmlReflectionMember[] members, 
@@ -163,7 +157,7 @@ namespace System.Xml.Serialization {
                        mps.RelatedMaps = relatedMaps;
                        mps.Format = SerializationFormat.Literal;
                        Type[] extraTypes = includedTypes != null ? (Type[])includedTypes.ToArray(typeof(Type)) : null;
-#if !NET_2_1
+#if !MOBILE
                        mps.Source = new MembersSerializationSource (elementName, hasWrapperElement, members, false, true, ns, extraTypes);
                        if (allowPrivateTypes) mps.Source.CanBeGenerated = false;
 #endif
@@ -227,14 +221,12 @@ namespace System.Xml.Serialization {
                                        default: throw new NotSupportedException ("Type " + typeData.Type.FullName + " not supported for XML stialization");
                                }
 
-#if NET_2_0
                                // bug #372780
                                map.SetKey (typeData.Type.ToString ());
-#endif
                                map.RelatedMaps = relatedMaps;
                                map.Format = SerializationFormat.Literal;
                                Type[] extraTypes = includedTypes != null ? (Type[]) includedTypes.ToArray (typeof (Type)) : null;
-#if !NET_2_1
+#if !MOBILE
                                map.Source = new XmlTypeSerializationSource (typeData.Type, root, attributeOverrides, defaultNamespace, extraTypes);
                                if (allowPrivateTypes) map.Source.CanBeGenerated = false;
 #endif
@@ -326,21 +318,21 @@ namespace System.Xml.Serialization {
                        return map;
                }
 
-               XmlTypeMapping ImportClassMapping (Type type, XmlRootAttribute root, string defaultNamespace)
+               XmlTypeMapping ImportClassMapping (Type type, XmlRootAttribute root, string defaultNamespace, bool isBaseType = false)
                {
                        TypeData typeData = TypeTranslator.GetTypeData (type);
-                       return ImportClassMapping (typeData, root, defaultNamespace);
+                       return ImportClassMapping (typeData, root, defaultNamespace, isBaseType);
                }
 
-               XmlTypeMapping ImportClassMapping (TypeData typeData, XmlRootAttribute root, string defaultNamespace)
+               XmlTypeMapping ImportClassMapping (TypeData typeData, XmlRootAttribute root, string defaultNamespace, bool isBaseType = false)
                {
                        Type type = typeData.Type;
 
+                       if (!allowPrivateTypes && !isBaseType)
+                               ReflectionHelper.CheckSerializableType (type, false);
+
                        XmlTypeMapping map = helper.GetRegisteredClrType (type, GetTypeNamespace (typeData, root, defaultNamespace));
                        if (map != null) return map;
-
-                       if (!allowPrivateTypes)
-                               ReflectionHelper.CheckSerializableType (type, false);
                        
                        map = CreateTypeMapping (typeData, root, null, defaultNamespace);
                        helper.RegisterClrType (map, type, map.XmlTypeNamespace);
@@ -372,7 +364,7 @@ namespace System.Xml.Serialization {
                                string ns = map.XmlTypeNamespace;
                                if (rmember.XmlAttributes.XmlIgnore) continue;
                                if (rmember.DeclaringType != null && rmember.DeclaringType != type) {
-                                       XmlTypeMapping bmap = ImportClassMapping (rmember.DeclaringType, root, defaultNamespace);
+                                       XmlTypeMapping bmap = ImportClassMapping (rmember.DeclaringType, root, defaultNamespace, true);
                                        if (bmap.HasXmlTypeNamespace)
                                                ns = bmap.XmlTypeNamespace;
                                }
@@ -400,7 +392,7 @@ namespace System.Xml.Serialization {
 
                        if (type.BaseType != null)
                        {
-                               XmlTypeMapping bmap = ImportClassMapping (type.BaseType, root, defaultNamespace);
+                               XmlTypeMapping bmap = ImportClassMapping (type.BaseType, root, defaultNamespace, true);
                                ClassMap cbmap = bmap.ObjectMap as ClassMap;
                                
                                if (type.BaseType != typeof (object)) {
@@ -516,7 +508,7 @@ namespace System.Xml.Serialization {
                                elem.Form = att.Form;
                                if (att.Form == XmlSchemaForm.Unqualified)
                                        elem.Namespace = string.Empty;
-                               elem.IsNullable = att.IsNullable && CanBeNull (elem.TypeData);
+                               elem.IsNullable = (!att.IsNullableSpecified || att.IsNullable) && CanBeNull (elem.TypeData);
                                elem.NestingLevel = att.NestingLevel;
 
                                if (isMultiArray) {
@@ -709,16 +701,6 @@ namespace System.Xml.Serialization {
                        // Read all Fields via reflection.
                        ArrayList fieldList = new ArrayList();
                        FieldInfo[] tfields = type.GetFields (BindingFlags.Instance | BindingFlags.Public);
-#if TARGET_JVM
-                       // This statement ensures fields are ordered starting from the base type.
-                       for (int ti=0; ti<typeList.Count; ti++) {
-                               for (int i=0; i<tfields.Length; i++) {
-                                       FieldInfo field = tfields[i];
-                                       if (field.DeclaringType == typeList[ti])
-                                               fieldList.Add (field);
-                               }
-                       }
-#else
                        currentType = null;
                        int currentIndex = 0;
                        foreach (FieldInfo field in tfields)
@@ -731,22 +713,9 @@ namespace System.Xml.Serialization {
                                }
                                fieldList.Insert(currentIndex++, field);
                        }
-#endif
                        // Read all Properties via reflection.
                        ArrayList propList = new ArrayList();
                        PropertyInfo[] tprops = type.GetProperties (BindingFlags.Instance | BindingFlags.Public);
-#if TARGET_JVM
-                       // This statement ensures properties are ordered starting from the base type.
-                       for (int ti=0; ti<typeList.Count; ti++) {
-                               for (int i=0; i<tprops.Length; i++) {
-                                       PropertyInfo prop = tprops[i];
-                                       if (!prop.CanRead) continue;
-                                       if (prop.GetIndexParameters().Length > 0) continue;
-                                       if (prop.DeclaringType == typeList[ti])
-                                               propList.Add (prop);
-                               }
-                       }
-#else
                        currentType = null;
                        currentIndex = 0;
                        foreach (PropertyInfo prop in tprops)
@@ -761,7 +730,6 @@ namespace System.Xml.Serialization {
                                if (prop.GetIndexParameters().Length > 0) continue;
                                propList.Insert(currentIndex++, prop);
                        }
-#endif
                        var members = new List<XmlReflectionMember>();
                        int fieldIndex=0;
                        int propIndex=0;
@@ -798,6 +766,7 @@ namespace System.Xml.Serialization {
                                                if (atts == null) atts = new XmlAttributes (prop);
                                                if (atts.XmlIgnore) continue;
                                                if (!prop.CanWrite) {
+                                                       if (prop.PropertyType.IsInterface && typeof (IEnumerable).IsAssignableFrom (prop.PropertyType)) continue;
                                                        if (prop.PropertyType.IsGenericType && TypeData.GetGenericListItemType (prop.PropertyType) == null) continue; // check this before calling GetTypeData() which raises error for missing Add(). See bug #704813.
                                                        if (TypeTranslator.GetTypeData (prop.PropertyType).SchemaType != SchemaTypes.Array || prop.PropertyType.IsArray) continue;
                                                }
@@ -862,7 +831,7 @@ namespace System.Xml.Serialization {
                                else 
                                        mapAttribute.AttributeName = atts.XmlAttribute.AttributeName;
 
-                               mapAttribute.AttributeName = XmlConvert.EncodeLocalName (mapAttribute.AttributeName);
+                               mapAttribute.AttributeName = XmlConvert.EncodeName (mapAttribute.AttributeName);
 
                                if (typeData.IsComplexType)
                                        mapAttribute.MappedType = ImportTypeMapping (typeData.Type, null, defaultNamespace);
@@ -1040,6 +1009,9 @@ namespace System.Xml.Serialization {
 
                                if (choiceEnumMap != null) {
                                        string cname = choiceEnumMap.GetEnumName (choiceEnumType.FullName, elem.ElementName);
+                                       if (cname == null && elem.Namespace != null)
+                                               cname = choiceEnumMap.GetEnumName (choiceEnumType.FullName,
+                                                       elem.Namespace.ToString () + ":" + elem.ElementName);
                                        if (cname == null)
                                                throw new InvalidOperationException (string.Format (
                                                        CultureInfo.InvariantCulture, "Type {0} is missing"
@@ -1114,10 +1086,6 @@ namespace System.Xml.Serialization {
                
                bool CanBeNull (TypeData type)
                {
-#if !NET_2_0   // idiotic compatibility
-                       if (type.Type == typeof (XmlQualifiedName))
-                               return false;
-#endif
                        return !type.Type.IsValueType || type.IsNullable;
                }