Bladeren bron

2002-09-13 Gonzalo Paniagua Javier <[email protected]>

	* CodeIdentifiers.cs:
	* XmlSchemaExporter.cs:
	* XmlSchemaImporter.cs:
	* XmlSchemas.cs:
	* XmlSerializationWriteCallback.cs:
	* XmlSerializationWriter.cs:
	* XmlSerializer.cs:
	* XmlSerializerNamespaces.cs: some class status based fixed and
	implemented a couple of methods.

svn path=/trunk/mcs/; revision=7442
Gonzalo Paniagua Javier 23 jaren geleden
bovenliggende
commit
0bfa6eba80

+ 12 - 0
mcs/class/System.XML/System.Xml.Serialization/ChangeLog

@@ -1,3 +1,15 @@
+2002-09-13  Gonzalo Paniagua Javier <[email protected]>
+
+	* CodeIdentifiers.cs:
+	* XmlSchemaExporter.cs:
+	* XmlSchemaImporter.cs:
+	* XmlSchemas.cs:
+	* XmlSerializationWriteCallback.cs:
+	* XmlSerializationWriter.cs:
+	* XmlSerializer.cs:
+	* XmlSerializerNamespaces.cs: some class status based fixed and
+	implemented a couple of methods.
+
 2002-08-24  Tim Coleman <[email protected]>
 	* SoapCodeExporter.cs:
 		Fix return value of ExportTypeMapping.

+ 12 - 10
mcs/class/System.XML/System.Xml.Serialization/CodeIdentifiers.cs

@@ -16,7 +16,8 @@ namespace System.Xml.Serialization {
 		#region Fields
 
 		bool useCamelCasing;
-		static Hashtable table = new Hashtable ();
+		Hashtable table = new Hashtable ();
+		Hashtable reserved = new Hashtable ();
 
 		#endregion
 
@@ -44,15 +45,16 @@ namespace System.Xml.Serialization {
 			table.Add (identifier, value);
 		}
 
-		[MonoTODO ("What does this do?")]
 		public void AddReserved (string identifier)
 		{
-			throw new NotImplementedException ();
+			reserved.Add (identifier, identifier);
 		}
 
-		public void AddUnique (string identifier, object value)
+		public string AddUnique (string identifier, object value)
 		{
-			Add (MakeUnique (identifier), value);
+			string unique = MakeUnique (identifier);
+			Add (unique, value);
+			return unique;
 		}
 
 		public void Clear ()
@@ -62,7 +64,7 @@ namespace System.Xml.Serialization {
 
 		public bool IsInUse (string identifier)
 		{
-			return (table.ContainsKey (identifier));
+			return (table.ContainsKey (identifier) || reserved.ContainsKey (identifier));
 		}
 
 		public string MakeRightCase (string identifier)
@@ -91,16 +93,16 @@ namespace System.Xml.Serialization {
 			table.Remove (identifier);
 		}
 
-		[MonoTODO ("What does this do?")]
 		public void RemoveReserved (string identifier)
 		{
-			throw new NotImplementedException ();
+			reserved.Remove (identifier);
 		}
 
-		[MonoTODO ("Need to determine how to do the conversion.")]
 		public object ToArray (Type type)
 		{
-			throw new NotImplementedException ();
+			Array list = Array.CreateInstance (type, table.Count);
+			table.CopyTo (list, 0);
+			return list;
 		}
 
 		#endregion // Methods

+ 1 - 1
mcs/class/System.XML/System.Xml.Serialization/XmlSchemaExporter.cs

@@ -48,7 +48,7 @@ namespace System.Xml.Serialization {
 		}
 
 		[MonoTODO]
-		public XmlQualifiedName ExportTypeMapping (XmlTypeMapping xmlTypeMapping)
+		public void ExportTypeMapping (XmlTypeMapping xmlTypeMapping)
 		{
 			throw new NotImplementedException ();
 		}

+ 8 - 0
mcs/class/System.XML/System.Xml.Serialization/XmlSchemaImporter.cs

@@ -54,6 +54,14 @@ namespace System.Xml.Serialization {
 			throw new NotImplementedException ();
 		}
 
+		[MonoTODO]
+		public XmlTypeMapping ImportDerivedTypeMapping (XmlQualifiedName name,
+								Type baseType,
+								bool baseTypeCanBeIndirect)
+		{
+			throw new NotImplementedException ();
+		}
+
 		[MonoTODO]
 		public XmlMembersMapping ImportMembersMapping (XmlQualifiedName name)
 		{

+ 34 - 1
mcs/class/System.XML/System.Xml.Serialization/XmlSchemas.cs

@@ -15,7 +15,7 @@ namespace System.Xml.Serialization {
 
 		#region Fields
 
-		static Hashtable table = new Hashtable ();
+		Hashtable table = new Hashtable ();
 
 		#endregion
 
@@ -69,6 +69,39 @@ namespace System.Xml.Serialization {
 			List.CopyTo (array, index);
 		}
 
+		public object Find (XmlQualifiedName name, Type type)
+		{
+			XmlSchema schema = table [name.Namespace] as XmlSchema;
+			if (schema == null)
+				return null;
+
+			if (!schema.IsCompiled) {
+				try {
+					schema.Compile (null);
+				} catch {
+					throw new InvalidOperationException ("Error compiling XmlSchema " + 
+									     name.Namespace);
+				}
+			}
+
+			XmlSchemaObjectTable tbl = null;
+
+			if (type == typeof (XmlSchemaSimpleType) || type == typeof (XmlSchemaComplexType))
+				tbl = schema.SchemaTypes;
+			else if (type == typeof (XmlSchemaAttribute))
+				tbl = schema.Attributes;
+			else if (type == typeof (XmlSchemaAttributeGroup))
+				tbl = schema.AttributeGroups;
+			else if (type == typeof (XmlSchemaElement))
+				tbl = schema.Elements;
+			else if (type == typeof (XmlSchemaGroup))
+				tbl = schema.Groups;
+			else if (type == typeof (XmlSchemaNotation))
+				tbl = schema.Notations;
+
+			return (tbl != null) ? tbl [name] : null;
+		}
+
 		public int IndexOf (XmlSchema schema)
 		{
 			return List.IndexOf (schema);

+ 1 - 1
mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriteCallback.cs

@@ -12,6 +12,6 @@ using System;
 namespace System.Xml.Serialization {
 	
 	[Serializable]
-	public delegate object XmlSerializationWriteCallback (object o);
+	public delegate void XmlSerializationWriteCallback (object o);
 }
 

+ 14 - 0
mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriter.cs

@@ -358,6 +358,20 @@ namespace System.Xml.Serialization {
 			WriteAttribute ("id", GetId (o, true));
 		}
 
+		protected void WriteNamespaceDeclarations (XmlSerializerNamespaces ns)
+		{
+			if (ns == null)
+				return;
+
+			Hashtable tbl = ns.Namespaces;
+			foreach (string key in tbl.Keys) {
+				string val = tbl [key] as string;
+				if (val == null)
+					val = String.Empty;
+				WriteAttribute ("xmlns", key, null, val);
+			}
+		}
+
 		[MonoTODO ("Implement")]
 		protected void WriteNullableQualifiedNameEncoded (string name, string ns, XmlQualifiedName value, XmlQualifiedName xsiType)
 		{

+ 13 - 5
mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs

@@ -107,20 +107,16 @@ namespace System.Xml.Serialization {
 
 		#region Events
 
-		[MonoTODO]
 		public event XmlAttributeEventHandler UnknownAttribute;
-		[MonoTODO]
 		public event XmlElementEventHandler UnknownElement;
-		[MonoTODO]
 		public event XmlNodeEventHandler UnknownNode;
-		[MonoTODO]
 		public event UnreferencedObjectEventHandler UnreferencedObject;
 
 		#endregion // Events
 
 		#region Properties
 
-		public bool UseOrder {
+		internal bool UseOrder {
 			get { return useOrder; }
 			set { useOrder = value; }
 		}
@@ -169,6 +165,18 @@ namespace System.Xml.Serialization {
 			throw new NotImplementedException ();
 		}
 
+		[MonoTODO]
+		public static XmlSerializer [] FromMappings (XmlMapping [] mappings)
+		{
+			throw new NotImplementedException ();
+		}
+
+		[MonoTODO]
+		public static XmlSerializer [] FromTypes (Type [] mappings)
+		{
+			throw new NotImplementedException ();
+		}
+
 		[MonoTODO]
 		protected virtual void Serialize (object o, XmlSerializationWriter writer)
 		{

+ 7 - 1
mcs/class/System.XML/System.Xml.Serialization/XmlSerializerNamespaces.cs

@@ -65,6 +65,12 @@ namespace System.Xml.Serialization
 			}
 			return null;
 		}
-	
+
+		internal Hashtable Namespaces
+		{
+			get {
+				return namespaces;
+			}
+		}
 	}
 }