2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.XML / System.Xml.Serialization / TypeTranslator.cs
index e494081a1a960b863ed2a44dbfa13c338aa51394..fc71eeea981f378058c4908567497f5e0da23c23 100644 (file)
 // (C) 2003 Erik Lebel
 //
 
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using System;
 using System.Collections;
+using System.Globalization;
 
 namespace System.Xml.Serialization
 {
@@ -47,7 +69,6 @@ namespace System.Xml.Serialization
                        nameCache.Add (typeof (byte[]), new TypeData (typeof (byte[]), "base64Binary", true));
                        nameCache.Add (typeof (XmlNode), new TypeData (typeof (XmlNode), "XmlNode", false));
                        nameCache.Add (typeof (XmlElement), new TypeData (typeof (XmlElement), "XmlElement", false));
-                       nameCache.Add (typeof (Uri), new TypeData (typeof (Uri), "anyURI", true));
                        nameCache.Add (typeof (TimeSpan), new TypeData (typeof (TimeSpan), "duration", true));
 
                        primitiveTypes = new Hashtable();
@@ -60,29 +81,32 @@ namespace System.Xml.Serialization
                        primitiveTypes.Add ("date", new TypeData (typeof (DateTime), "date", true));    // TODO: timeInstant
                        primitiveTypes.Add ("time", new TypeData (typeof (DateTime), "time", true));
                        primitiveTypes.Add ("timePeriod", new TypeData (typeof (DateTime), "timePeriod", true));
-                       primitiveTypes.Add ("gDay", new TypeData (typeof (DateTime), "gDay", true));
-                       primitiveTypes.Add ("gMonthDay", new TypeData (typeof (DateTime), "gMonthDay", true));
-                       primitiveTypes.Add ("gYear", new TypeData (typeof (DateTime), "gYear", true));
-                       primitiveTypes.Add ("gYearMonth", new TypeData (typeof (DateTime), "gYearMonth", true));
+                       primitiveTypes.Add ("gDay", new TypeData (typeof (string), "gDay", true));
+                       primitiveTypes.Add ("gMonthDay", new TypeData (typeof (string), "gMonthDay", true));
+                       primitiveTypes.Add ("gYear", new TypeData (typeof (string), "gYear", true));
+                       primitiveTypes.Add ("gYearMonth", new TypeData (typeof (string), "gYearMonth", true));
                        primitiveTypes.Add ("month", new TypeData (typeof (DateTime), "month", true));
                        primitiveTypes.Add ("NMTOKEN", new TypeData (typeof (string), "NMTOKEN", true));
-                       primitiveTypes.Add ("NMTOKENS", new TypeData (typeof (string[]), "NMTOKENS", true));
+                       primitiveTypes.Add ("NMTOKENS", new TypeData (typeof (string), "NMTOKENS", true));
                        primitiveTypes.Add ("Name", new TypeData (typeof (string), "Name", true));
                        primitiveTypes.Add ("NCName", new TypeData (typeof (string), "NCName", true));
                        primitiveTypes.Add ("language", new TypeData (typeof (string), "language", true));
-                       primitiveTypes.Add ("integer", new TypeData (typeof (decimal), "integer", true));
-                       primitiveTypes.Add ("positiveInteger", new TypeData (typeof (decimal), "positiveInteger", true));
-                       primitiveTypes.Add ("nonPositiveInteger", new TypeData (typeof (decimal), "nonPositiveInteger", true));
-                       primitiveTypes.Add ("negativeInteger", new TypeData (typeof (decimal), "negativeInteger", true));
-                       primitiveTypes.Add ("nonNegativeInteger", new TypeData (typeof (decimal), "nonNegativeInteger", true));
-                       primitiveTypes.Add ("ENTITIES", new TypeData (typeof (string[]), "ENTITIES", true));
+                       primitiveTypes.Add ("integer", new TypeData (typeof (string), "integer", true));
+                       primitiveTypes.Add ("positiveInteger", new TypeData (typeof (string), "positiveInteger", true));
+                       primitiveTypes.Add ("nonPositiveInteger", new TypeData (typeof (string), "nonPositiveInteger", true));
+                       primitiveTypes.Add ("negativeInteger", new TypeData (typeof (string), "negativeInteger", true));
+                       primitiveTypes.Add ("nonNegativeInteger", new TypeData (typeof (string), "nonNegativeInteger", true));
+                       primitiveTypes.Add ("ENTITIES", new TypeData (typeof (string), "ENTITIES", true));
                        primitiveTypes.Add ("ENTITY", new TypeData (typeof (string), "ENTITY", true));
                        primitiveTypes.Add ("hexBinary", new TypeData (typeof (byte[]), "hexBinary", true));
                        primitiveTypes.Add ("ID", new TypeData (typeof (string), "ID", true));
                        primitiveTypes.Add ("IDREF", new TypeData (typeof (string), "IDREF", true));
-                       primitiveTypes.Add ("IDREFS", new TypeData (typeof (string[]), "IDREFS", true));
+                       primitiveTypes.Add ("IDREFS", new TypeData (typeof (string), "IDREFS", true));
                        primitiveTypes.Add ("NOTATION", new TypeData (typeof (string), "NOTATION", true));
                        primitiveTypes.Add ("token", new TypeData (typeof (string), "token", true));
+                       primitiveTypes.Add ("normalizedString", new TypeData (typeof (string), "normalizedString", true));
+                       primitiveTypes.Add ("anyURI", new TypeData (typeof (string), "anyURI", true));
+                       primitiveTypes.Add ("base64", new TypeData (typeof (byte[]), "base64", true));
                }
 
                public static TypeData GetTypeData (Type type)
@@ -92,7 +116,7 @@ namespace System.Xml.Serialization
 
                public static TypeData GetTypeData (Type type, string xmlDataType)
                {
-                       if (xmlDataType != null) return GetPrimitiveTypeData (xmlDataType);
+                       if ((xmlDataType != null) && (xmlDataType.Length != 0)) return GetPrimitiveTypeData (xmlDataType);
 
                        TypeData typeData = nameCache[type] as TypeData;
                        if (typeData != null) return typeData;
@@ -122,6 +146,11 @@ namespace System.Xml.Serialization
                        return td;
                }
 
+               public static TypeData FindPrimitiveTypeData (string typeName)
+               {
+                       return (TypeData) primitiveTypes[typeName];
+               }
+
                public static TypeData GetDefaultPrimitiveTypeData (TypeData primType)
                {
                        // Returns the TypeData that is mapped by default to the clr type
@@ -148,7 +177,7 @@ namespace System.Xml.Serialization
 
                public static string GetArrayName (string elemName)
                {
-                       return "ArrayOf" + Char.ToUpper (elemName [0]) + elemName.Substring (1);
+                       return "ArrayOf" + Char.ToUpper (elemName [0], CultureInfo.InvariantCulture) + elemName.Substring (1);
                }
                
                public static string GetArrayName (string elemName, int dimensions)