Author: lluis
Date: 2005-04-12 12:34:24 -0400 (Tue, 12 Apr 2005)
New Revision: 42841

Modified:
   trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
   
trunk/mcs/class/System.XML/System.Xml.Serialization/SerializationCodeGenerator.cs
   trunk/mcs/class/System.XML/System.Xml.Serialization/SoapCodeExporter.cs
   trunk/mcs/class/System.XML/System.Xml.Serialization/XmlCodeExporter.cs
   trunk/mcs/class/System.XML/System.Xml.Serialization/XmlMapping.cs
   trunk/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs
   trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSchemaExporter.cs
   trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReader.cs
   
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReaderInterpreter.cs
   
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapMemberAttribute.cs
   trunk/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapping.cs
Log:
2005-04-12  Lluis Sanchez Gual  <[EMAIL PROTECTED]>
        * XmlTypeMapping.cs: Added new XmlSerializableMapping class.
        * XmlSchemaExporter.cs: When exporting an IXmlSerializable type,
        export the schema that it defines. In ImportNamespace, removed
        check for default namespace, since it may be included from a non
        default namespace.
        * XmlReflectionImporter.cs: Create a special map for IXmlSerializable
        types. All this based on a patch by Andrew Skiba.
        
        * SerializationCodeGenerator.cs:
        * XmlMapping.cs:
        * XmlSerializationReaderInterpreter.cs:
        * SoapCodeExporter.cs:
        * XmlTypeMapMemberAttribute.cs:
        * XmlSerializationReader.cs:
        * XmlCodeExporter.cs: Fixed some warnings.

2005-04-10  Andrew Skiba  <[EMAIL PROTECTED]>

2005-04-03  Andrew Skiba  <[EMAIL PROTECTED]>


Modified: trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog       
2005-04-12 16:26:56 UTC (rev 42840)
+++ trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog       
2005-04-12 16:34:24 UTC (rev 42841)
@@ -1,8 +1,26 @@
-2004-04-10  Andrew Skiba  <[EMAIL PROTECTED]>
+2005-04-12  Lluis Sanchez Gual  <[EMAIL PROTECTED]>
 
+       * XmlTypeMapping.cs: Added new XmlSerializableMapping class.
+       * XmlSchemaExporter.cs: When exporting an IXmlSerializable type,
+       export the schema that it defines. In ImportNamespace, removed
+       check for default namespace, since it may be included from a non
+       default namespace.
+       * XmlReflectionImporter.cs: Create a special map for IXmlSerializable
+       types. All this based on a patch by Andrew Skiba.
+       
+       * SerializationCodeGenerator.cs:
+       * XmlMapping.cs:
+       * XmlSerializationReaderInterpreter.cs:
+       * SoapCodeExporter.cs:
+       * XmlTypeMapMemberAttribute.cs:
+       * XmlSerializationReader.cs:
+       * XmlCodeExporter.cs: Fixed some warnings.
+
+2005-04-10  Andrew Skiba  <[EMAIL PROTECTED]>
+
        * XmlSerializer.cs: fixed a typo - wrong TARGET_JVM condition.
 
-2004-04-03  Andrew Skiba  <[EMAIL PROTECTED]>
+2005-04-03  Andrew Skiba  <[EMAIL PROTECTED]>
 
        * XmlSerializer.cs: added TARGET_JVM that does not support on-the-fly
        code generation.

Modified: 
trunk/mcs/class/System.XML/System.Xml.Serialization/SerializationCodeGenerator.cs
===================================================================
--- 
trunk/mcs/class/System.XML/System.Xml.Serialization/SerializationCodeGenerator.cs
   2005-04-12 16:26:56 UTC (rev 42840)
+++ 
trunk/mcs/class/System.XML/System.Xml.Serialization/SerializationCodeGenerator.cs
   2005-04-12 16:34:24 UTC (rev 42841)
@@ -1912,12 +1912,6 @@
                        GenerateSetMemberValue (member, ob, value, isValueList);
                }
 
-               object GenerateGetMemberValue (XmlTypeMapMember member, object 
ob, bool isValueList)
-               {
-                       if (isValueList) return ob + "[" + member.Index + "]";
-                       else return ob + ".@" + member.Name;
-               }
-
                string GenerateReadObjectElement (XmlTypeMapElementInfo elem)
                {
                        switch (elem.TypeData.SchemaType)
@@ -2288,7 +2282,6 @@
                //
                
                ArrayList _listsToFill = new ArrayList ();
-               Hashtable _hooks;
                Hashtable _hookVariables;
                Stack _hookContexts;
                Stack _hookOpenHooks;
@@ -2305,7 +2298,6 @@
                        _hookContexts = new Stack ();
                        _hookOpenHooks = new Stack ();
                        _hookVariables = new Hashtable ();
-                       _hooks = new Hashtable ();
                }
                
                void PushHookContext ()
@@ -2529,11 +2521,6 @@
                        return "typeof(" + td.FullName.Replace ('+','.') + ")";
                }
                
-               string GetString (string str)
-               {
-                       return "\"" + str + "\"";
-               }
-               
                string GetLiteral (object ob)
                {
                        if (ob == null) return "null";
@@ -2592,11 +2579,6 @@
                        WriteLine (method + " (" + Params (pars) + ");");
                }
                
-               void Indent ()
-               {
-                       _indent++;
-               }
-
                void Unindent ()
                {
                        _indent--;

Modified: 
trunk/mcs/class/System.XML/System.Xml.Serialization/SoapCodeExporter.cs
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.Serialization/SoapCodeExporter.cs     
2005-04-12 16:26:56 UTC (rev 42840)
+++ trunk/mcs/class/System.XML/System.Xml.Serialization/SoapCodeExporter.cs     
2005-04-12 16:34:24 UTC (rev 42841)
@@ -42,8 +42,6 @@
        {
                #region Fields
 
-               CodeNamespace codeNamespace;
-               CodeCompileUnit codeCompileUnit;
 #if !NET_2_0
                SoapMapCodeGenerator codeGenerator;
 #endif
@@ -58,9 +56,6 @@
 
                public SoapCodeExporter (CodeNamespace codeNamespace, 
CodeCompileUnit codeCompileUnit)
                {
-                       this.codeCompileUnit = codeCompileUnit;
-                       this.codeNamespace = codeNamespace;
-                       
                        codeGenerator = new SoapMapCodeGenerator 
(codeNamespace, codeCompileUnit);
                }
 
@@ -89,9 +84,6 @@
                                                                
CodeGenerationOptions options, 
                                                                Hashtable 
mappings)
                {
-                       this.codeCompileUnit = codeCompileUnit;
-                       this.codeNamespace = codeNamespace;
-                       
                        codeGenerator = new SoapMapCodeGenerator 
(codeNamespace, codeCompileUnit, codeGen, options, mappings);
                }
 

Modified: trunk/mcs/class/System.XML/System.Xml.Serialization/XmlCodeExporter.cs
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.Serialization/XmlCodeExporter.cs      
2005-04-12 16:26:56 UTC (rev 42840)
+++ trunk/mcs/class/System.XML/System.Xml.Serialization/XmlCodeExporter.cs      
2005-04-12 16:34:24 UTC (rev 42841)
@@ -44,17 +44,12 @@
        {
                #region Fields
 
-               CodeNamespace codeNamespace;
-               CodeCompileUnit codeCompileUnit;
-
 #if NET_2_0
                CodeGenerationOptions options;
 #else
                XmlMapCodeGenerator codeGenerator;
 #endif
 
-               Hashtable exportedMaps = new Hashtable ();
-
                #endregion
 
                #region Constructors
@@ -65,9 +60,6 @@
 
                public XmlCodeExporter (CodeNamespace codeNamespace, 
CodeCompileUnit codeCompileUnit)
                {
-                       this.codeCompileUnit = codeCompileUnit;
-                       this.codeNamespace = codeNamespace;
-                       
                        codeGenerator = new XmlMapCodeGenerator (codeNamespace, 
codeCompileUnit);
                }
 
@@ -96,9 +88,6 @@
                                                                
CodeGenerationOptions options, 
                                                                Hashtable 
mappings)
                {
-                       this.codeCompileUnit = codeCompileUnit;
-                       this.codeNamespace = codeNamespace;
-                       
                        codeGenerator = new XmlMapCodeGenerator (codeNamespace, 
codeCompileUnit, codeGen, options, mappings);
                }
                

Modified: trunk/mcs/class/System.XML/System.Xml.Serialization/XmlMapping.cs
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.Serialization/XmlMapping.cs   
2005-04-12 16:26:56 UTC (rev 42840)
+++ trunk/mcs/class/System.XML/System.Xml.Serialization/XmlMapping.cs   
2005-04-12 16:34:24 UTC (rev 42841)
@@ -40,12 +40,13 @@
                ArrayList relatedMaps;
                SerializationFormat format;
                SerializationSource source;
-               string key;
                
                internal string _elementName;
                internal string _namespace;
                
 #if NET_2_0
+               string key;
+               
                internal XmlMapping ()
                {
                }

Modified: 
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs
===================================================================
--- 
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs    
    2005-04-12 16:26:56 UTC (rev 42840)
+++ 
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs    
    2005-04-12 16:34:24 UTC (rev 42841)
@@ -83,11 +83,12 @@
                                this.attributeOverrides = attributeOverrides;
                }
 
-               void Reset ()
+/*             void Reset ()
                {
                        helper = new ReflectionHelper();
                        arrayChoiceCount = 1;
                }
+*/
                
                internal bool AllowPrivateTypes
                {
@@ -242,7 +243,12 @@
                        if (rootNamespace == null) rootNamespace = "";
                        if (typeNamespace == null || typeNamespace.Length == 0) 
typeNamespace = rootNamespace;
                        
-                       XmlTypeMapping map = new XmlTypeMapping (elementName, 
rootNamespace, typeData, defaultXmlType, typeNamespace);
+                       XmlTypeMapping map;
+                       if (typeData.SchemaType == SchemaTypes.XmlSerializable)
+                               map = new XmlSerializableMapping (elementName, 
rootNamespace, typeData, defaultXmlType, typeNamespace);
+                       else
+                               map = new XmlTypeMapping (elementName, 
rootNamespace, typeData, defaultXmlType, typeNamespace);
+                               
                        map.IncludeInSchema = includeInSchema;
                        map.IsNullable = nullable;
                        relatedMaps.Add (map);

Modified: 
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSchemaExporter.cs
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSchemaExporter.cs    
2005-04-12 16:26:56 UTC (rev 42840)
+++ trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSchemaExporter.cs    
2005-04-12 16:34:24 UTC (rev 42841)
@@ -214,6 +214,26 @@
                        CompileSchemas ();
                }
 
+               void ExportXmlSerializableSchema (XmlSchema currentSchema, 
XmlSerializableMapping map)
+               {
+               if (IsMapExported (map)) return;
+               SetMapExported (map);
+               
+               if (map.Schema == null) return;
+
+                       string targetNs = map.Schema.TargetNamespace;
+               XmlSchema existingSchema = schemas [targetNs];
+               if (existingSchema == null)
+               {
+                               schemas.Add (map.Schema);
+                               ImportNamespace (currentSchema, targetNs);
+               }
+               else if (existingSchema != map.Schema)
+               {
+                               throw new InvalidOperationException("The 
namespace '" + targetNs +"' defined by the class '" + map.TypeFullName + "' is 
a duplicate.");
+               }
+               }
+
                void ExportClassSchema (XmlTypeMapping map)
                {
                        if (IsMapExported (map)) return;
@@ -468,7 +488,8 @@
                                                break;
 
                                        case SchemaTypes.XmlSerializable:
-                                               selem.SchemaType = 
GetSchemaXmlSerializableType ();
+                                               selem.SchemaType = 
GetSchemaXmlSerializableType (einfo.MappedType as XmlSerializableMapping);
+                                               ExportXmlSerializableSchema 
(currentSchema, einfo.MappedType as XmlSerializableMapping);
                                                break;
 
                                        case SchemaTypes.Enum:
@@ -513,7 +534,7 @@
 
                void ImportNamespace (XmlSchema schema, string ns)
                {
-                       if (ns == "" || ns == schema.TargetNamespace || ns == 
XmlSchema.Namespace) return;
+                       if (ns == schema.TargetNamespace || ns == 
XmlSchema.Namespace) return;
 
                        foreach (XmlSchemaObject sob in schema.Includes)
                                if ((sob is XmlSchemaImport) && 
((XmlSchemaImport)sob).Namespace == ns) return;
@@ -543,14 +564,20 @@
                        return stype;
                }
 
-               XmlSchemaType GetSchemaXmlSerializableType ()
+               XmlSchemaType GetSchemaXmlSerializableType 
(XmlSerializableMapping map)
                {
                        XmlSchemaComplexType stype = new XmlSchemaComplexType 
();
                        XmlSchemaSequence seq = new XmlSchemaSequence ();
-                       XmlSchemaElement selem = new XmlSchemaElement ();
-                       selem.RefName = new XmlQualifiedName 
("schema",XmlSchema.Namespace);
-                       seq.Items.Add (selem);
-                       seq.Items.Add (new XmlSchemaAny ());
+                       if (map.Schema == null) {
+                               XmlSchemaElement selem = new XmlSchemaElement 
();
+                               selem.RefName = new XmlQualifiedName 
("schema",XmlSchema.Namespace);
+                               seq.Items.Add (selem);
+                               seq.Items.Add (new XmlSchemaAny ());
+                       } else {
+                               XmlSchemaAny any = new XmlSchemaAny ();
+                               any.Namespace = map.Schema.TargetNamespace;
+                               seq.Items.Add (any);
+                       }
                        stype.Particle = seq;
                        return stype;
                }

Modified: 
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReader.cs
===================================================================
--- 
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReader.cs   
    2005-04-12 16:26:56 UTC (rev 42840)
+++ 
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReader.cs   
    2005-04-12 16:34:24 UTC (rev 42841)
@@ -61,43 +61,33 @@
                int delayedFixupId = 0;
 
                string w3SchemaNS;
-               string w3SchemaNS2000;
-               string w3SchemaNS1999;
                string w3InstanceNS;
                string w3InstanceNS2000;
                string w3InstanceNS1999;
                string soapNS;
-               string schema;
                string wsdlNS;
-               string wsdlArrayType;
                string nullX;
                string nil;
                string typeX;
                string arrayType;
-               string anyType;
                XmlQualifiedName arrayQName;
                #endregion
 
                internal void Initialize (XmlReader reader, XmlSerializer 
eventSource)
                {
                        w3SchemaNS = reader.NameTable.Add (XmlSchema.Namespace);
-                       w3SchemaNS2000 = reader.NameTable.Add 
("http://www.w3.org/2000/10/XMLSchema";);
-                       w3SchemaNS1999 = reader.NameTable.Add 
("http://www.w3.org/1999/XMLSchema";);
                        w3InstanceNS = reader.NameTable.Add 
(XmlSchema.InstanceNamespace);
                        w3InstanceNS2000 = reader.NameTable.Add 
("http://www.w3.org/2000/10/XMLSchema-instance";);
                        w3InstanceNS1999 = reader.NameTable.Add 
("http://www.w3.org/1999/XMLSchema-instance";);
                        soapNS = reader.NameTable.Add 
(XmlSerializer.EncodingNamespace);
-                       schema = reader.NameTable.Add ("schema");
                        wsdlNS = reader.NameTable.Add 
(XmlSerializer.WsdlNamespace);
-                       wsdlArrayType = reader.NameTable.Add ("arrayType");
                        nullX = reader.NameTable.Add ("null");
                        nil = reader.NameTable.Add ("nil");
                        typeX = reader.NameTable.Add ("type");
                        arrayType = reader.NameTable.Add ("arrayType");
-                       anyType = reader.NameTable.Add ("anyType");
                        this.reader = reader;
                        this.eventSource = eventSource;
-                       arrayQName = new XmlQualifiedName ("Array", 
XmlSerializer.EncodingNamespace);
+                       arrayQName = new XmlQualifiedName ("Array", soapNS);
                        InitIDs ();
                }
                        
@@ -333,12 +323,12 @@
 
                protected XmlQualifiedName GetXsiType ()
                {
-                       string typeName = Reader.GetAttribute ("type", 
XmlSchema.InstanceNamespace);
+                       string typeName = Reader.GetAttribute (typeX, 
XmlSchema.InstanceNamespace);
                        
                        if (typeName == string.Empty || typeName == null) {
-                               typeName = Reader.GetAttribute ("type", 
w3InstanceNS1999);
+                               typeName = Reader.GetAttribute (typeX, 
w3InstanceNS1999);
                                if (typeName == string.Empty || typeName == 
null) {
-                                       typeName = Reader.GetAttribute ("type", 
w3InstanceNS2000);
+                                       typeName = Reader.GetAttribute (typeX, 
w3InstanceNS2000);
                                        if (typeName == string.Empty || 
typeName == null)
                                                return null;
                                }
@@ -371,7 +361,7 @@
 
                protected void ParseWsdlArrayType (XmlAttribute attr)
                {
-                       if (attr.NamespaceURI == XmlSerializer.WsdlNamespace && 
attr.LocalName == "arrayType")
+                       if (attr.NamespaceURI == wsdlNS && attr.LocalName == 
arrayType)
                        {
                                string ns = "", type, dimensions;
                                TypeTranslator.ParseArrayType (attr.Value, out 
type, out ns, out dimensions);
@@ -516,10 +506,10 @@
 
                bool ReadList (out object resultList)
                {
-                       string arrayType = Reader.GetAttribute ("arrayType", 
XmlSerializer.EncodingNamespace);
-                       if (arrayType == null) arrayType = Reader.GetAttribute 
("arrayType", XmlSerializer.WsdlNamespace);
+                       string arrayTypeAttr = Reader.GetAttribute (arrayType, 
soapNS);
+                       if (arrayTypeAttr == null) arrayTypeAttr = 
Reader.GetAttribute (arrayType, wsdlNS);
                        
-                       XmlQualifiedName qn = ToXmlQualifiedName (arrayType);
+                       XmlQualifiedName qn = ToXmlQualifiedName 
(arrayTypeAttr);
                        int i = qn.Name.LastIndexOf ('[');
                        string dim = qn.Name.Substring (i);
                        string itemType = qn.Name.Substring (0,i);
@@ -531,7 +521,7 @@
                        string baseType = itemType.Substring (0,i);
                        string arrayTypeName;
 
-                       if (qn.Namespace == XmlSchema.Namespace)
+                       if (qn.Namespace == w3SchemaNS)
                                arrayTypeName = 
TypeTranslator.GetPrimitiveTypeData (baseType).Type.FullName + 
itemType.Substring (i);
                        else
                        {
@@ -639,9 +629,9 @@
 
                                XmlQualifiedName qname = GetXsiType ();
                                if (qname == null) qname = new XmlQualifiedName 
(name, ns);
-                               string arrayType = Reader.GetAttribute 
("arrayType", XmlSerializer.EncodingNamespace);
+                               string arrayTypeAttr = Reader.GetAttribute 
(arrayType, soapNS);
 
-                               if (qname == arrayQName || arrayType != null)
+                               if (qname == arrayQName || arrayTypeAttr != 
null)
                                {
                                        delayedListFixups = EnsureHashtable 
(delayedListFixups);
                                        fixupReference = "__<" + 
(delayedFixupId++) + ">";

Modified: 
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReaderInterpreter.cs
===================================================================
--- 
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReaderInterpreter.cs
    2005-04-12 16:26:56 UTC (rev 42840)
+++ 
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReaderInterpreter.cs
    2005-04-12 16:34:24 UTC (rev 42841)
@@ -681,14 +681,6 @@
                        }
                }
 
-               int GetListCount (TypeData listType, object ob)
-               {
-                       if (listType.Type.IsArray)
-                               return ((Array)ob).Length;
-                       else
-                               return (int) listType.Type.GetProperty 
("Count").GetValue(ob,null);
-               }
-
                object ReadXmlNodeElement (XmlTypeMapping typeMap, bool 
isNullable)
                {
                        return ReadXmlNode (typeMap.TypeData, false);

Modified: 
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapMemberAttribute.cs
===================================================================
--- 
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapMemberAttribute.cs
    2005-04-12 16:26:56 UTC (rev 42840)
+++ 
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapMemberAttribute.cs
    2005-04-12 16:34:24 UTC (rev 42841)
@@ -39,7 +39,6 @@
        internal class XmlTypeMapMemberAttribute: XmlTypeMapMember
        {
                string _attributeName;
-               string _dataType;
                string _namespace = "";
                XmlSchemaForm _form;
                XmlTypeMapping _mappedType;

Modified: trunk/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapping.cs
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapping.cs       
2005-04-12 16:26:56 UTC (rev 42840)
+++ trunk/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapping.cs       
2005-04-12 16:34:24 UTC (rev 42841)
@@ -32,7 +32,8 @@
 using System.Xml;
 using System;
 using System.Collections;
-using System.Globalization;
+using System.Globalization;
+using System.Xml.Schema;
 
 namespace System.Xml.Serialization
 {
@@ -169,6 +170,31 @@
                }
        }
 
+ 
+       // Mapping info for XmlSerializable
+       internal class XmlSerializableMapping : XmlTypeMapping
+       {
+               XmlSchema _schema;
+
+               internal XmlSerializableMapping(string elementName, string ns, 
TypeData typeData, string xmlType, string xmlTypeNamespace)
+                       : base(elementName, ns, typeData, xmlType, 
xmlTypeNamespace)
+               {
+                       IXmlSerializable serializable = 
(IXmlSerializable)Activator.CreateInstance(typeData.Type);
+                       _schema = serializable.GetSchema();
+                       if (_schema != null) 
+                       {
+                               if (_schema.Id == null || _schema.Id.Length == 
0) 
+                                       throw new 
InvalidOperationException("Schema Id is missing. The schema returned from " + 
typeData.Type.FullName + ".GetSchema() must have an Id.");
+                       }
+               }
+
+               internal XmlSchema Schema
+               {
+                       get { return _schema; }
+               }
+       }
+ 
+
        // Mapping info for classes and structs
 
        internal class ClassMap: ObjectMap

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to