2004-02-19 Jean-Marc Andre <jeanmarc.andre@cpe.fr>
authorJean-Marc Andre <jeanmarc@mono-cvs.ximian.com>
Thu, 19 Feb 2004 18:23:00 +0000 (18:23 -0000)
committerJean-Marc Andre <jeanmarc@mono-cvs.ximian.com>
Thu, 19 Feb 2004 18:23:00 +0000 (18:23 -0000)
Multiple bug fixed concerning internationalization and xml attributes.
see the ChangeLog

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

mcs/class/System.Runtime.Serialization.Formatters.Soap/ChangeLog
mcs/class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/SoapCommon.cs
mcs/class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/SoapFormatter.cs
mcs/class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/SoapWriter.cs
mcs/class/System.Runtime.Serialization.Formatters.Soap/Test/SoapFormatterTest.cs

index e489632f5c61922b907f41b0c0454c0ea763bf2b..007356e61c534862af4a30077a2c4c8ca1c42198 100644 (file)
@@ -1,3 +1,13 @@
+2004-02-19  Jean-Marc Andre <jeanmarc.andre@cpe.fr>
+       * SoapFormatter.cs:
+               Forced the utilisation of CultureInfo("en-US") during
+               the serialization and deserialization because I got problems
+               with numeral and date format.
+
+       * SoapWriter.cs, SoapCommon.cs:
+               Bug fixed: XmlTextWriter.WriteAttributeString() was used
+               with its "namespace" parameter set to null whereas it shouldn't.
+
 2003-12-22  Jean-Marc Andre <jeanmarc.andre@cpe.fr>
        * SoapFormatterTest.cs:
                Added unit test for the SerializationBinder property
index 3ea4b6bffc18ea142002d42155c50ccf0cb179cb..e1efeed5b4e564e4ec5cde09431fc136e2d9e546 100644 (file)
@@ -71,11 +71,20 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                public string prefix;\r
                public string attributeName;\r
                public string attributeValue;\r
+               public string nameSpace;\r
                \r
                public SoapAttributeStruct(string prefix, string attributeName, string attributeValue) {\r
                        this.prefix = prefix;\r
                        this.attributeName = attributeName;\r
                        this.attributeValue = attributeValue;\r
+                       this.nameSpace = null;\r
+               }\r
+\r
+               public SoapAttributeStruct(string prefix, string nameSpace, string attributeName, string attributeValue) {\r
+                       this.prefix = prefix;\r
+                       this.attributeName = attributeName;\r
+                       this.attributeValue = attributeValue;\r
+                       this.nameSpace = nameSpace;\r
                }\r
        }\r
        \r
index 99043516fe2fe0376d5d35e6fc910050be9127d6..7614870dd4f6d111d36984e48d15a7507391b5f6 100755 (executable)
@@ -13,6 +13,8 @@ using System.Runtime.Remoting;
 using System.Runtime.Serialization;\r
 using System.Runtime.Remoting.Messaging;\r
 using System.Xml.Serialization;\r
+using System.Threading;\r
+using System.Globalization;\r
 \r
 \r
 namespace System.Runtime.Serialization.Formatters.Soap {\r
@@ -51,15 +53,26 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                }\r
                \r
                public object Deserialize(Stream serializationStream, HeaderHandler handler) {\r
+                       object objReturn = null;\r
                        SoapParser parser = new SoapParser(serializationStream);\r
                        SoapReader soapReader = new SoapReader(parser);\r
                        soapReader.Binder = _binder;\r
                        \r
-                       \r
                        if(_topObject != null) soapReader.TopObject = _topObject;\r
                        ObjectReader reader = new ObjectReader(_selector, _context, soapReader);\r
-                       parser.Run();\r
-                       object objReturn = reader.TopObject;\r
+                       // Use the english numeral and date format during the serialization\r
+                       // and the deserialization.\r
+                       // The original CultureInfo is restored when the operation\r
+                       // is done\r
+                       CultureInfo savedCi = CultureInfo.CurrentCulture;\r
+                       try {\r
+                               Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");\r
+                               parser.Run();\r
+                               objReturn = reader.TopObject;\r
+                       }\r
+                       finally {\r
+                               Thread.CurrentThread.CurrentCulture = savedCi;\r
+                       }\r
                        return objReturn;\r
                }\r
                \r
@@ -77,7 +90,19 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                        _soapWriter = new SoapWriter(serializationStream);\r
                        _objWriter = new ObjectWriter((ISoapWriter) _soapWriter, _selector,  new StreamingContext(StreamingContextStates.File));\r
                        _soapWriter.Writer = _objWriter;\r
-                       _objWriter.Serialize(graph);\r
+\r
+                       // Use the english numeral and date format during the serialization\r
+                       // and the deserialization.\r
+                       // The original CultureInfo is restored when the operation\r
+                       // is done\r
+                       CultureInfo savedCi = CultureInfo.CurrentCulture;\r
+                       try {\r
+                               Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");\r
+                               _objWriter.Serialize(graph);\r
+                       }\r
+                       finally {\r
+                               Thread.CurrentThread.CurrentCulture = savedCi;\r
+                       }\r
                        \r
                }\r
                \r
index a55df234f2159bd26193a1c97286debdf2d9c412..9a0da53ff5a67e9d1b0dc4ccad7da791f8bd37b6 100755 (executable)
@@ -118,13 +118,13 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                        // If the type of the element needs to be specified, do it there\r
                        if(entry.SpecifyEncoding) {\r
                                needNamespace = GetPrefix(entry.elementNamespace, out prefix);\r
-                               attributeList.Add(new SoapAttributeStruct("xsi", "type", prefix+":"+ entry.elementName));\r
+                               attributeList.Add(new SoapAttributeStruct("xsi", XmlSchema.InstanceNamespace, "type", prefix+":"+ entry.elementName));\r
                                if(needNamespace) attributeList.Add(new SoapAttributeStruct("xmlns", prefix, entry.elementNamespace));\r
                        }\r
                        \r
                        switch(entry.elementType) {\r
                                case ElementType.Null:\r
-                                       attributeList.Add(new SoapAttributeStruct("xsi", "null", "1"));\r
+                                       attributeList.Add(new SoapAttributeStruct("xsi", XmlSchema.InstanceNamespace, "null", "1"));\r
                                        return attributeList;\r
                                        //break;\r
                                case ElementType.Id:\r
@@ -148,7 +148,7 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                                rank = rank.Substring(0,rank.Length - 1);\r
                                rank += "]";\r
                                needNamespace = GetPrefix(elementMapping.TypeNamespace, out prefix);\r
-                               attributeList.Add(new SoapAttributeStruct("SOAP-ENC", "arrayType",prefix+":"+elementMapping.TypeName+rank));\r
+                               attributeList.Add(new SoapAttributeStruct("SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/", "arrayType", prefix+":"+elementMapping.TypeName+rank));\r
                                if(needNamespace) attributeList.Add(new SoapAttributeStruct("xmlns", prefix, elementMapping.TypeNamespace));\r
                                \r
                        }\r
@@ -232,7 +232,7 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                        _xmlWriter.WriteStartElement(entry.prefix, XmlConvert.EncodeNmToken(entry.elementName), entry.elementNamespace);\r
                        \r
                        if (entry.elementAttributes != null) foreach(SoapAttributeStruct attr in entry.elementAttributes){\r
-                               _xmlWriter.WriteAttributeString(attr.prefix, attr.attributeName, null, attr.attributeValue);\r
+                               _xmlWriter.WriteAttributeString(attr.prefix, attr.attributeName, attr.nameSpace, attr.attributeValue);\r
                        }\r
                        if(entry.CanBeValue && entry.elementValue != null && !entry.getIntoFields){\r
                                _xmlWriter.WriteString(String.Format(_format, "{0}", entry.elementValue));\r
index cb3b61670df09a1a32a05e3991b4a14c1631b24c..0d2f6a87d7b18b0af683210874c77728a6db4de2 100644 (file)
@@ -22,6 +22,7 @@ namespace MonoTests.System.Runtime.Serialization.Formatters.Soap {
        public class MoreComplexObject {\r
                public event TrucDlg TrucEvent;\r
                private string _string;\r
+               private string[] _strings = new string[]{};\r
                private Queue _queue = new Queue();\r
                public Hashtable _table = new Hashtable();\r
 \r
@@ -167,6 +168,15 @@ namespace MonoTests.System.Runtime.Serialization.Formatters.Soap {
                private SoapFormatter _soapFormatter;\r
                private SoapFormatter _soapFormatterDeserializer;\r
                private RemotingSurrogateSelector _surrogate;\r
+\r
+#if DEBUG\r
+               private void Out(MemoryStream stream, object objGraph) {\r
+                       Console.WriteLine("\n---------------------\n{0}\n", objGraph.ToString());\r
+                       stream.Position = 0;\r
+                       StreamReader r = new StreamReader(stream);\r
+                       Console.WriteLine(r.ReadToEnd());\r
+               }                       \r
+#endif\r
                \r
                private object Serialize(object objGraph) {\r
                        MemoryStream stream = new MemoryStream();\r
@@ -175,9 +185,9 @@ namespace MonoTests.System.Runtime.Serialization.Formatters.Soap {
                        _soapFormatter.SurrogateSelector = _surrogate;\r
                        _soapFormatter.Serialize(stream, objGraph);\r
                        \r
-//                     stream.Position = 0;\r
-//                     StreamReader r = new StreamReader(stream);\r
-//                     Console.WriteLine(r.ReadToEnd());\r
+#if DEBUG\r
+                       Out(stream, objGraph);\r
+#endif\r
                        stream.Position = 0;\r
                        \r
                        object objReturn = _soapFormatterDeserializer.Deserialize(stream);\r
@@ -186,10 +196,8 @@ namespace MonoTests.System.Runtime.Serialization.Formatters.Soap {
                        stream = new MemoryStream();\r
                        _soapFormatter.Serialize(stream, objReturn);\r
                        stream.Position = 0;\r
-//                     StreamReader r = new StreamReader(stream);\r
-//                     Console.WriteLine(r.ReadToEnd());\r
-                       \r
                        return objReturn;\r
+                       \r
                }\r
                \r
                [SetUp]\r
@@ -283,6 +291,9 @@ namespace MonoTests.System.Runtime.Serialization.Formatters.Soap {
                        objTest = new int[,]{{0, 1}, {2, 3}, {123, 4}};\r
                        objReturn = Serialize(objTest);\r
                        CheckArray(objTest, objReturn);\r
+                       objTest = new string[]{};\r
+                       objReturn = Serialize(objTest);\r
+                       CheckArray(objTest, objReturn);\r
                        object[,,] objArray = new object[3,2,1];\r
                        objArray[0,0,0] = 1;\r
                        objArray[2,1,0] = "end";\r