Author: atsushi
Date: 2007-11-01 06:38:14 -0500 (Thu, 01 Nov 2007)
New Revision: 88636

Modified:
   trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
   trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSchemaImporter.cs
   trunk/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog
   
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSchemaImporterTests.cs
Log:
2007-11-01  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * XmlSchemaImporter.cs : simpleType is allowed to be imported.
          (Part of #336739 fix.)

        * XmlSchemaImporterTests.cs : test for importing simple-typed
          top-level element.



Modified: trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog       
2007-11-01 10:51:50 UTC (rev 88635)
+++ trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog       
2007-11-01 11:38:14 UTC (rev 88636)
@@ -1,3 +1,8 @@
+2007-11-01  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * XmlSchemaImporter.cs : simpleType is allowed to be imported.
+         (Part of #336739 fix.)
+
 2007-10-30  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * XmlCustomFormatter.cs : use RoundtripKind when converting to and

Modified: 
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSchemaImporter.cs
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSchemaImporter.cs    
2007-11-01 10:51:50 UTC (rev 88635)
+++ trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSchemaImporter.cs    
2007-11-01 11:38:14 UTC (rev 88636)
@@ -467,6 +467,9 @@
                        XmlTypeMapping map = GetRegisteredTypeMapping (qname);
                        if (map != null) return map;
                        
+                       if (stype is XmlSchemaSimpleType)
+                               return ImportClassSimpleType 
(stype.QualifiedName, (XmlSchemaSimpleType) stype, name);
+                       
                        map = CreateTypeMapping (qname, SchemaTypes.Class, 
name);
                        map.Documentation = GetDocumentation (stype);
                        map.IsNullable = elem.IsNillable;
@@ -522,7 +525,7 @@
                                        throw new InvalidOperationException 
("Cannot import schema for type '" + elem.SchemaTypeName.Name + "' from 
namespace '" + elem.SchemaTypeName.Namespace + "'. Redefine not supported");
                        }
 
-                       if (stype is XmlSchemaSimpleType) return false;
+                       //if (stype is XmlSchemaSimpleType) return false;
                        return true;
                }
 
@@ -1319,7 +1322,7 @@
                                // Create an enum map
 
                                CodeIdentifiers codeIdents = new 
CodeIdentifiers ();
-                               XmlTypeMapping enumMap = CreateTypeMapping 
(typeQName, SchemaTypes.Enum, null);
+                               XmlTypeMapping enumMap = CreateTypeMapping 
(typeQName, SchemaTypes.Enum, root);
                                enumMap.Documentation = GetDocumentation 
(stype);
                                
                                bool isFlags = false;

Modified: trunk/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog  
2007-11-01 10:51:50 UTC (rev 88635)
+++ trunk/mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog  
2007-11-01 11:38:14 UTC (rev 88636)
@@ -1,3 +1,8 @@
+2007-11-01  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * XmlSchemaImporterTests.cs : test for importing simple-typed
+         top-level element.
+
 2007-10-30  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * XmlSchemaExporterTests.cs : without Infoset(), those tests randomly

Modified: 
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSchemaImporterTests.cs
===================================================================
--- 
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSchemaImporterTests.cs
  2007-11-01 10:51:50 UTC (rev 88635)
+++ 
trunk/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSchemaImporterTests.cs
  2007-11-01 11:38:14 UTC (rev 88636)
@@ -6,7 +6,7 @@
 //   Atsushi Enomoto ([EMAIL PROTECTED])
 //
 // (C) 2005 Gert Driesen
-// Copyright (C) 2006 Novell, Inc.
+// Copyright (C) 2006-2007 Novell, Inc.
 // 
 
 //
@@ -1178,12 +1178,38 @@
     <xs:attribute name='Foo' type='xs:string' />
   </xs:complexType>
 </xs:schema>";
-                       XmlSchemas xss = new XmlSchemas ();
-                       xss.Add (XmlSchema.Read (new XmlTextReader (new 
StringReader (xsd)), null));
-                       XmlSchemaImporter imp = new XmlSchemaImporter (xss);
+                       XmlSchemaImporter imp = CreateImporter (xsd);
                        CodeNamespace cns = new CodeNamespace ();
                        XmlCodeExporter exp = new XmlCodeExporter (cns);
                        exp.ExportTypeMapping (imp.ImportTypeMapping (new 
XmlQualifiedName ("Root")));
                }
+
+               [Test]
+               public void ImportSimpleSchemaType ()
+               {
+                       string xsd = @"
+<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
+  <xs:element name='a' type='b' />
+  <xs:simpleType name='b'>
+    <xs:restriction base='xs:string'>
+      <xs:enumeration value='v1'/>
+      <xs:enumeration value='v2'/>
+      <xs:enumeration value='v3'/>
+    </xs:restriction>
+  </xs:simpleType>
+</xs:schema>";
+                       XmlSchemaImporter imp = CreateImporter (xsd);
+                       XmlTypeMapping tm = imp.ImportTypeMapping (new 
XmlQualifiedName ("a"));
+                       Assert.AreEqual ("a", tm.ElementName, "#1");
+                       Assert.AreEqual ("b", tm.TypeName, "#2");
+               }
+
+               XmlSchemaImporter CreateImporter (params string [] 
schemaXmlStrings)
+               {
+                       XmlSchemas xss = new XmlSchemas ();
+                       foreach (string xsd in schemaXmlStrings)
+                               xss.Add (XmlSchema.Read (new XmlTextReader (new 
StringReader (xsd)), null));
+                       return new XmlSchemaImporter (xss);
+               }
        }
 }

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

Reply via email to