diff options
Diffstat (limited to 'mcs/class/System.XML/System.Xml.Serialization')
68 files changed, 6416 insertions, 0 deletions
diff --git a/mcs/class/System.XML/System.Xml.Serialization/AssemblyInfo.cs b/mcs/class/System.XML/System.Xml.Serialization/AssemblyInfo.cs new file mode 100644 index 00000000000..177a4f0e70a --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/AssemblyInfo.cs @@ -0,0 +1,58 @@ +using System.Reflection;
+using System.Runtime.CompilerServices;
+
+//
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+//
+[assembly: AssemblyTitle("")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+//
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+
+[assembly: AssemblyVersion("1.0.*")]
+
+//
+// In order to sign your assembly you must specify a key to use. Refer to the
+// Microsoft .NET Framework documentation for more information on assembly signing.
+//
+// Use the attributes below to control which key is used for signing.
+//
+// Notes:
+// (*) If no key is specified, the assembly is not signed.
+// (*) KeyName refers to a key that has been installed in the Crypto Service
+// Provider (CSP) on your machine. KeyFile refers to a file which contains
+// a key.
+// (*) If the KeyFile and the KeyName values are both specified, the
+// following processing occurs:
+// (1) If the KeyName can be found in the CSP, that key is used.
+// (2) If the KeyName does not exist and the KeyFile does exist, the key
+// in the KeyFile is installed into the CSP and used.
+// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
+// When specifying the KeyFile, the location of the KeyFile should be
+// relative to the project output directory which is
+// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
+// located in the project directory, you would specify the AssemblyKeyFile
+// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
+// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
+// documentation for more information on this.
+//
+[assembly: AssemblyDelaySign(false)]
+[assembly: AssemblyKeyFile("")]
+[assembly: AssemblyKeyName("")]
diff --git a/mcs/class/System.XML/System.Xml.Serialization/ChangeLog b/mcs/class/System.XML/System.Xml.Serialization/ChangeLog new file mode 100755 index 00000000000..3b1d98de2dd --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/ChangeLog @@ -0,0 +1,143 @@ +2003-01-16 Ajay kumar Dwivedi <adwiv@yahoo.com> + * XmlSerializer.cs: Array serialization for 1D arrays works + * TypeTranslator: Added for translations` + +2002-09-19 Gonzalo Paniagua Javier <gonzalo@ximian.com> + + * XmlCustomFormatter.cs: finished. + * XmlSerializationReader.cs: implemented some more methods. + +2002-09-18 Gonzalo Paniagua Javier <gonzalo@ximian.com> + + * XmlSerializationReader.cs: implemented a few methods. + + * XmlAnyElementAttribute.cs: + * XmlArrayAttribute.cs: + * XmlChoiceIdentifierAttribute.cs: + * XmlElementAttribute.cs: + * XmlMemberMapping.cs: + * XmlMembersMapping.cs: class status based fixes. + +2002-09-13 Gonzalo Paniagua Javier <gonzalo@ximian.com> + + * 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. + + * SoapSchemaExporter.cs: stubbed out. + +2002-08-24 Tim Coleman <tim@timcoleman.com> + * SoapCodeExporter.cs: + Fix return value of ExportTypeMapping. + * XmlCustomFormatter.cs: + Change methods to be internal instead of public. + * XmlSerializationWriter.cs: + Modify GetPrimitiveTypeName to build on linux. + Modify GetQualifiedName to return an incrementing prefix + instead of the same one all the time (still need to manage + conflicts) + Modify WriteElementString to only do special stuff is XsiType + is not defined. + Modify WriteTypedPrimitive to use FromXmlQualifiedName if it's + an XmlQualifiedName. + +2002-08-22 Tim Coleman <tim@timcoleman.com> + * XmlSerializationReader.cs: + Some implementation + * XmlSerializationWriter.cs: + More implementation + * XmlCustomFormatter.cs: + Implemented this class. + +2002-08-20 Tim Coleman <tim@timcoleman.com> + * XmlSerializationWriter.cs: + Some implementation. + +2002-08-19 Tim Coleman <tim@timcoleman.com> + * XmlSerializer.cs: + New stubs added. + * XmlSerializationWriter.cs: + New stubs added. + +2002-08-14 Tim Coleman <tim@timcoleman.com> + * XmlSerializer.cs: + More reformatting of source code so I can + better understand what it does. + +2002-08-06 Tim Coleman <tim@timcoleman.com> + * XmlSerializer.cs: + Some reformatting of code for readability. + Modify to correctly serialize ICollection objects + such as the BindingCollection of a ServiceDescription + for example. + +2002-08-03 Tim Coleman <tim@timcoleman.com> + * XmlSerializer.cs: + Changed Implements() to check based on name rather + than FullName. FullName was never working correctly. + +2002-07-26 Tim Coleman <tim@timcoleman.com> + * XmlSerializer.cs: + The constructor now looks for an XmlRootAttribute attribute + if one is not passed in. Various changes to make it emit + proper XML, such as handling an element without a namespace + prefix, and using WriteEndDocument where it should be. + +2002-07-24 Tim Coleman <tim@timcoleman.com> + * CodeIdentifier.cs: + * IXmlSerializable.cs: + * XmlSerializationCollectionFixupCallback.cs: + * XmlSerializationFixupCallback.cs: + * XmlSerializationReadCallback.cs: + * XmlSerializationReader.cs: + * XmlSerializationWriteCallback.cs: + Add new classes. + * XmlSchemas.cs + * CodeIdentifiers.cs: + Implement some of these classes + * XmlCodeExporter.cs: + Fix return type of a function + +2002-07-24 Tim Coleman <tim@timcoleman.com> + * SoapReflectionImporter.cs: + New class added to build + System.Web.Services.Description.ServiceDescription.cs + +2002-07-22 Tim Coleman <tim@timcoleman.com> + * CodeIdentifiers.cs: + * SoapCodeExporter.cs: + * SoapSchemaExporter.cs: + * XmlCodeExporter.cs: + * XmlMemberMapping.cs: + * XmlMembersMapping.cs: + * XmlReflectionImporter.cs: + * XmlReflectionMember.cs: + * XmlSchemaExporter.cs: + * XmlSchemaImporter.cs: + * XmlSchemas.cs: + New stubbs added to aid in the linux build of + System.Web.Services. + +2002-07-05 Ajay kumar Dwivedi <adwiv@yahoo.com> + + * XmlSeriailizer: Serialize method can serialize XmlSchema perfectly. + + * XmlSerializerNamespaces: Reverted to use of a single Hashtable. + +2002-07-02 Ajay kumar Dwivedi <adwiv@yahoo.com> + + * XmlSeriailizer: Updated Serialize() method. + +2002-06-27 Ajay kumar Dwivedi <adwiv@yahoo.com> + * XmlSerializer: Serialize() method Partially Implemented. + +2002-06-20 Ajay kumar Dwivedi <adwiv@yahoo.com> + + * Soap & XmlOverrides: Implemented using TypeMember as key with + suggestions from Rafael. diff --git a/mcs/class/System.XML/System.Xml.Serialization/CodeIdentifier.cs b/mcs/class/System.XML/System.Xml.Serialization/CodeIdentifier.cs new file mode 100644 index 00000000000..94a532b402b --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/CodeIdentifier.cs @@ -0,0 +1,50 @@ +// +// System.Xml.Serialization.CodeIdentifier.cs +// +// Author: +// Tim Coleman (tim@timcoleman.com) +// +// Copyright (C) Tim Coleman, 2002 +// + +using System; + +namespace System.Xml.Serialization { + public class CodeIdentifier { + + public CodeIdentifier () + { + } + + public static string MakeCamel (string identifier) + { + string validIdentifier = MakeValid (identifier); + return (Char.ToLower (validIdentifier[0]) + validIdentifier.Substring (1)); + } + + public static string MakePascal (string identifier) + { + string validIdentifier = MakeValid (identifier); + return (Char.ToUpper (validIdentifier[0]) + validIdentifier.Substring (1)); + } + + public static string MakeValid (string identifier) + { + if (identifier == null) + throw new NullReferenceException (); + if (identifier.Length == 0) + return identifier; + + string output = ""; + + if (Char.IsNumber (identifier[0])) + output = "Item"; + + foreach (char c in identifier) + if (Char.IsLetterOrDigit (c) || c == '_') + output += c; + + return output; + } + } +} diff --git a/mcs/class/System.XML/System.Xml.Serialization/CodeIdentifiers.cs b/mcs/class/System.XML/System.Xml.Serialization/CodeIdentifiers.cs new file mode 100644 index 00000000000..0cd713946c8 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/CodeIdentifiers.cs @@ -0,0 +1,110 @@ +//
+// System.Xml.Serialization.CodeIdentifiers
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2002
+//
+
+using System;
+using System.Collections;
+
+namespace System.Xml.Serialization {
+ public class CodeIdentifiers {
+
+ #region Fields
+
+ bool useCamelCasing;
+ Hashtable table = new Hashtable ();
+ Hashtable reserved = new Hashtable ();
+
+ #endregion
+
+ #region Constructors
+
+ public CodeIdentifiers ()
+ {
+ }
+
+ #endregion // Constructors
+
+ #region Properties
+
+ public bool UseCamelCasing {
+ get { return useCamelCasing; }
+ set { useCamelCasing = value; }
+ }
+
+ #endregion // Properties
+
+ #region Methods
+
+ public void Add (string identifier, object value)
+ {
+ table.Add (identifier, value);
+ }
+
+ public void AddReserved (string identifier)
+ {
+ reserved.Add (identifier, identifier);
+ }
+
+ public string AddUnique (string identifier, object value)
+ {
+ string unique = MakeUnique (identifier);
+ Add (unique, value);
+ return unique;
+ }
+
+ public void Clear ()
+ {
+ table.Clear ();
+ }
+
+ public bool IsInUse (string identifier)
+ {
+ return (table.ContainsKey (identifier) || reserved.ContainsKey (identifier));
+ }
+
+ public string MakeRightCase (string identifier)
+ {
+ if (UseCamelCasing)
+ return CodeIdentifier.MakeCamel (identifier);
+ else
+ return CodeIdentifier.MakePascal (identifier);
+ }
+
+ public string MakeUnique (string identifier)
+ {
+ string uniqueIdentifier = identifier;
+ int i = 1;
+
+ while (IsInUse (uniqueIdentifier)) {
+ uniqueIdentifier = String.Format ("{0}{1}", identifier, i.ToString ());
+ i += 1;
+ }
+
+ return uniqueIdentifier;
+ }
+
+ public void Remove (string identifier)
+ {
+ table.Remove (identifier);
+ }
+
+ public void RemoveReserved (string identifier)
+ {
+ reserved.Remove (identifier);
+ }
+
+ public object ToArray (Type type)
+ {
+ Array list = Array.CreateInstance (type, table.Count);
+ table.CopyTo (list, 0);
+ return list;
+ }
+
+ #endregion // Methods
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/IXmlSerializable.cs b/mcs/class/System.XML/System.Xml.Serialization/IXmlSerializable.cs new file mode 100644 index 00000000000..3aa7f785e69 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/IXmlSerializable.cs @@ -0,0 +1,19 @@ +// +// System.Xml.Serialization.IXmlSerializable.cs +// +// Author: +// Tim Coleman (tim@timcoleman.com) +// +// Copyright (C) Tim Coleman, 2002 +// + +using System.Xml.Schema; + +namespace System.Xml.Serialization { + public interface IXmlSerializable { + + XmlSchema GetSchema (); + void ReadXml (XmlReader reader); + void WriteXml (XmlWriter writer); + } +} diff --git a/mcs/class/System.XML/System.Xml.Serialization/SchemaTypes.cs b/mcs/class/System.XML/System.Xml.Serialization/SchemaTypes.cs new file mode 100644 index 00000000000..5110eb15910 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/SchemaTypes.cs @@ -0,0 +1,23 @@ +// +// System.Xml.Serialization.SchemaTypes +// +// Authors: +// Gonzalo Paniagua Javier (gonzalo@ximian.com) +// +// (C) 2002 Ximian, Inc (http://www.ximian.com) +// + +namespace System.Xml.Serialization +{ + internal enum SchemaTypes { + NotSet = 0, + Primitive, + Enum, + Array, + Class, + DataSet, + XmlNode, + Void + } +} + diff --git a/mcs/class/System.XML/System.Xml.Serialization/SoapAttributeAttribute.cs b/mcs/class/System.XML/System.Xml.Serialization/SoapAttributeAttribute.cs new file mode 100644 index 00000000000..71311673741 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/SoapAttributeAttribute.cs @@ -0,0 +1,61 @@ +// +// SoapAttributeAttribute.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for SoapAttributeAttribute.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field
+ | AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
+ public class SoapAttributeAttribute : Attribute
+ {
+ private string attrName;
+ private string dataType;
+ private string ns;
+
+ public SoapAttributeAttribute ()
+ {
+ }
+
+ public SoapAttributeAttribute (string attrName)
+ {
+ AttributeName = attrName;
+ }
+
+ public string AttributeName {
+ get {
+ return attrName;
+ }
+ set {
+ attrName = value;
+ }
+ }
+
+ public string DataType {
+ get {
+ return dataType;
+ }
+ set {
+ dataType = value;
+ }
+ }
+
+ public string Namespace {
+ get {
+ return ns;
+ }
+ set {
+ ns = value;
+ }
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/SoapAttributeOverrides.cs b/mcs/class/System.XML/System.Xml.Serialization/SoapAttributeOverrides.cs new file mode 100644 index 00000000000..dcbbca6bcb7 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/SoapAttributeOverrides.cs @@ -0,0 +1,72 @@ +// +// SoapAttributeOverrides.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System;
+using System.Collections;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ ///
+ /// </summary>
+ public class SoapAttributeOverrides
+ {
+ /// <summary>
+ /// This class requires to store SoapAttrributes indexed by a key containg
+ /// both Type and Member Name. There are 3 approaches to this IMO.
+ /// 1. Make the key as "FullTypeName..MemberName", with ".." seperating Type and Member.
+ /// 2. Use a jagged 2D hashtable. The main hashtable is indexed by Type and each value
+ /// contains another hashtable which is indexed by member names. (Too many hashtables)
+ /// 3. Use a new class which emcompasses the Type and MemberName. An implementation is there
+ /// in TypeMember class in this namespace. (Too many instantiations of the class needed)
+ ///
+ /// Method 1 is the most elegent, but I am not sure if the seperator is language insensitive.
+ /// What if someone writes a language which allows . in the member names.
+ /// </summary>
+ ///
+ private Hashtable overrides;
+
+ public SoapAttributeOverrides ()
+ {
+ overrides = new Hashtable();
+ }
+
+ public SoapAttributes this [Type type]
+ {
+ get { return this [type, string.Empty]; }
+ }
+
+ public SoapAttributes this [Type type, string member]
+ {
+ get
+ {
+ return (SoapAttributes) overrides[GetKey(type,member)];
+ }
+ }
+
+ public void Add (Type type, SoapAttributes attributes)
+ {
+ Add(type, string.Empty, attributes);
+ }
+
+ public void Add (Type type, string member, SoapAttributes attributes)
+ {
+ if(overrides[GetKey(type, member)] != null)
+ throw new Exception("The attributes for the given type and Member already exist in the collection");
+
+ overrides.Add(GetKey(type,member), attributes);
+ }
+
+ private TypeMember GetKey(Type type, string member)
+ {
+ return new TypeMember(type, member);
+ }
+
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/SoapAttributes.cs b/mcs/class/System.XML/System.Xml.Serialization/SoapAttributes.cs new file mode 100644 index 00000000000..786ca2921f3 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/SoapAttributes.cs @@ -0,0 +1,88 @@ +// +// SoapAttributes.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System.Reflection;
+using System;
+using System.ComponentModel;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for SoapAttributes.
+ /// </summary>
+ public class SoapAttributes
+ {
+ private SoapAttributeAttribute soapAttribute;
+ private object soapDefaultValue;
+ private SoapElementAttribute soapElement;
+ private SoapEnumAttribute soapEnum;
+ private bool soapIgnore;
+ private SoapTypeAttribute soapType;
+
+ public SoapAttributes ()
+ {
+ }
+
+ public SoapAttributes (ICustomAttributeProvider provider)
+ {
+ object[] attributes = provider.GetCustomAttributes(false);
+ foreach(object obj in attributes)
+ {
+ if(obj is SoapAttributeAttribute)
+ soapAttribute = (SoapAttributeAttribute) obj;
+ else if(obj is DefaultValueAttribute)
+ soapDefaultValue = obj;
+ else if(obj is SoapElementAttribute)
+ soapElement = (SoapElementAttribute) obj;
+ else if(obj is SoapEnumAttribute)
+ soapEnum = (SoapEnumAttribute) obj;
+ else if(obj is SoapIgnoreAttribute)
+ soapIgnore = true;
+ else if(obj is SoapTypeAttribute)
+ soapType = (SoapTypeAttribute) obj;
+ }
+ }
+
+ public SoapAttributeAttribute SoapAttribute
+ {
+ get { return soapAttribute; }
+ set { soapAttribute = value; }
+ }
+
+ public object SoapDefaultValue
+ {
+ get { return soapDefaultValue; }
+ set { soapDefaultValue = value; }
+ }
+
+ public SoapElementAttribute SoapElement
+ {
+ get { return soapElement; }
+ set { soapElement = value; }
+ }
+
+ public SoapEnumAttribute SoapEnum
+ {
+ get { return soapEnum; }
+ set { soapEnum = value; }
+ }
+
+ public bool SoapIgnore
+ {
+ get { return soapIgnore; }
+ set { soapIgnore = value; }
+ }
+
+ public SoapTypeAttribute SoapType
+ {
+ get { return soapType; }
+ set { soapType = value; }
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/SoapCodeExporter.cs b/mcs/class/System.XML/System.Xml.Serialization/SoapCodeExporter.cs new file mode 100644 index 00000000000..6c25de9e392 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/SoapCodeExporter.cs @@ -0,0 +1,75 @@ +//
+// System.Xml.Serialization.SoapCodeExporter
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2002
+//
+
+using System.CodeDom;
+
+namespace System.Xml.Serialization {
+ public class SoapCodeExporter {
+
+ #region Fields
+
+ CodeNamespace codeNamespace;
+ CodeCompileUnit codeCompileUnit;
+ CodeAttributeDeclarationCollection includeMetadata;
+
+ #endregion
+
+ #region Constructors
+
+ public SoapCodeExporter (CodeNamespace codeNamespace)
+ {
+ includeMetadata = new CodeAttributeDeclarationCollection ();
+ this.codeNamespace = codeNamespace;
+ }
+
+ public SoapCodeExporter (CodeNamespace codeNamespace, CodeCompileUnit codeCompileUnit)
+ : this (codeNamespace)
+ {
+ this.codeCompileUnit = codeCompileUnit;
+ }
+
+ #endregion // Constructors
+
+ #region Properties
+
+ public CodeAttributeDeclarationCollection IncludeMetadata {
+ get { return includeMetadata; }
+ }
+
+ #endregion // Properties
+
+ #region Methods
+
+ [MonoTODO]
+ public void AddMappingMetadata (CodeAttributeDeclarationCollection metadata, XmlMemberMapping member)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public void AddMappingMetadata (CodeAttributeDeclarationCollection metadata, XmlMemberMapping member, bool forceUseMemberName)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public void ExportMembersMapping (XmlMembersMapping xmlMembersMapping)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public void ExportTypeMapping (XmlTypeMapping xmlTypeMapping)
+ {
+ throw new NotImplementedException ();
+ }
+
+ #endregion // Methods
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/SoapElementAttribute.cs b/mcs/class/System.XML/System.Xml.Serialization/SoapElementAttribute.cs new file mode 100644 index 00000000000..fbb6527e821 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/SoapElementAttribute.cs @@ -0,0 +1,60 @@ +// +// SoapElementAttribute.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for SoapElementAttribute.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field
+ | AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
+ public class SoapElementAttribute : Attribute
+ {
+ private string dataType;
+ private string elementName;
+ private bool isNullable;
+
+ public SoapElementAttribute ()
+ {
+ }
+ public SoapElementAttribute (string elementName)
+ {
+ ElementName = elementName;
+ }
+
+ public string DataType {
+ get {
+ return dataType;
+ }
+ set {
+ dataType = value;
+ }
+ }
+
+ public string ElementName {
+ get {
+ return elementName;
+ }
+ set {
+ elementName = value;
+ }
+ }
+
+ public bool IsNullable {
+ get {
+ return isNullable;
+ }
+ set {
+ isNullable = value;
+ }
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/SoapEnumAttribute.cs b/mcs/class/System.XML/System.Xml.Serialization/SoapEnumAttribute.cs new file mode 100644 index 00000000000..fba4f311126 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/SoapEnumAttribute.cs @@ -0,0 +1,40 @@ +// +// SoapEnumAttribute.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for SoapEnumAttribute.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Field)]
+ public class SoapEnumAttribute : Attribute
+ {
+ private string name;
+
+ public SoapEnumAttribute ()
+ {
+ }
+
+ public SoapEnumAttribute (string name)
+ {
+ Name = name;
+ }
+
+ public string Name {
+ get {
+ return name;
+ }
+ set {
+ name = value;
+ }
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/SoapIgnoreAttribute.cs b/mcs/class/System.XML/System.Xml.Serialization/SoapIgnoreAttribute.cs new file mode 100644 index 00000000000..52798f1dd30 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/SoapIgnoreAttribute.cs @@ -0,0 +1,25 @@ +// +// SoapIgnoreAttribute.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for SoapIgnoreAttribute.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field
+ | AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
+ public class SoapIgnoreAttribute : Attribute
+ {
+ public SoapIgnoreAttribute ()
+ {
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/SoapIncludeAttribute.cs b/mcs/class/System.XML/System.Xml.Serialization/SoapIncludeAttribute.cs new file mode 100644 index 00000000000..aaf3e29d03c --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/SoapIncludeAttribute.cs @@ -0,0 +1,38 @@ +// +// SoapIncludeAttribute.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for SoapIncludeAttribute.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct |
+ AttributeTargets.Method)]
+ public class SoapIncludeAttribute : Attribute
+ {
+ private Type type;
+
+ public SoapIncludeAttribute( Type type)
+ {
+ Type = type;
+ }
+
+ public Type Type
+ {
+ get {
+ return type;
+ }
+ set {
+ type = value;
+ }
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/SoapReflectionImporter.cs b/mcs/class/System.XML/System.Xml.Serialization/SoapReflectionImporter.cs new file mode 100644 index 00000000000..11c2b5926c2 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/SoapReflectionImporter.cs @@ -0,0 +1,90 @@ +//
+// System.Xml.Serialization.SoapReflectionImporter
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2002
+//
+
+using System.Reflection;
+using System.Xml;
+
+namespace System.Xml.Serialization {
+ public class SoapReflectionImporter {
+
+ #region Constructors
+
+ [MonoTODO]
+ public SoapReflectionImporter ()
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public SoapReflectionImporter (SoapAttributeOverrides attributeOverrides)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public SoapReflectionImporter (string defaultNamespace)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public SoapReflectionImporter (SoapAttributeOverrides attributeOverrides, string defaultNamespace)
+ {
+ throw new NotImplementedException ();
+ }
+
+ #endregion // Constructors
+
+ #region Methods
+
+ [MonoTODO]
+ public XmlMembersMapping ImportMembersMapping (string elementName, string ns, XmlReflectionMember[] members)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public XmlMembersMapping ImportMembersMapping (string elementName, string ns, XmlReflectionMember[] members, bool hasWrapperElement, bool writeAccessors)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public XmlMembersMapping ImportMembersMapping (string elementName, string ns, XmlReflectionMember[] members, bool hasWrapperElement, bool writeAccessors, bool validate)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public XmlTypeMapping ImportTypeMapping (Type type)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public XmlTypeMapping ImportTypeMapping (Type type, string defaultNamespace)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public void IncludeType (Type type)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public void IncludeTypes (ICustomAttributeProvider provider)
+ {
+ throw new NotImplementedException ();
+ }
+
+ #endregion // Methods
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/SoapSchemaExporter.cs b/mcs/class/System.XML/System.Xml.Serialization/SoapSchemaExporter.cs new file mode 100644 index 00000000000..f11cbe45d47 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/SoapSchemaExporter.cs @@ -0,0 +1,42 @@ +// +// System.Xml.Serialization.SoapSchemaExporter +// +// Authors: +// Gonzalo Paniagua Javier (gonzalo@ximian.com) +// +// (c) 2002 Ximian, Inc. (http://www.ximian.com) +// + +using System; + +namespace System.Xml.Serialization +{ + public class SoapSchemaExporter + { + [MonoTODO] + public SoapSchemaExporter (XmlSchemas schemas) + { + throw new NotImplementedException (); + } + + [MonoTODO] + public void ExportMembersMapping (XmlMembersMapping xmlMembersMapping) + { + throw new NotImplementedException (); + } + + [MonoTODO] + public void ExportMembersMapping (XmlMembersMapping xmlMembersMapping, + bool exportEnclosingType) + { + throw new NotImplementedException (); + } + + [MonoTODO] + public void ExportTypeMapping (XmlTypeMapping xmlTypeMapping) + { + throw new NotImplementedException (); + } + } +} + diff --git a/mcs/class/System.XML/System.Xml.Serialization/SoapSchemaImporter.cs b/mcs/class/System.XML/System.Xml.Serialization/SoapSchemaImporter.cs new file mode 100644 index 00000000000..baafb07716d --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/SoapSchemaImporter.cs @@ -0,0 +1,71 @@ +//
+// System.Xml.Serialization.SoapSchemaImporter
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2002
+//
+
+using System.Xml;
+
+namespace System.Xml.Serialization {
+ public class SoapSchemaImporter {
+
+ #region Fields
+
+ XmlSchemas schemas;
+ CodeIdentifiers typeIdentifiers;
+
+ #endregion
+
+ #region Constructors
+
+ public SoapSchemaImporter (XmlSchemas schemas)
+ {
+ this.schemas = schemas;
+ }
+
+ public SoapSchemaImporter (XmlSchemas schemas, CodeIdentifiers typeIdentifiers)
+ : this (schemas)
+ {
+ this.typeIdentifiers = typeIdentifiers;
+ }
+
+ #endregion // Constructors
+
+ #region Methods
+
+ [MonoTODO]
+ public XmlTypeMapping ImportDerivedTypeMapping (XmlQualifiedName name, Type baseType, bool baseTypeCanBeIndirect)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public XmlMembersMapping ImportMembersMapping (string name, string ns, SoapSchemaMember member)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public XmlMembersMapping ImportMembersMapping (string name, string ns, SoapSchemaMember[] members)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public XmlMembersMapping ImportMembersMapping (string name, string ns, SoapSchemaMember[] members, bool hasWrapperElement)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public XmlMembersMapping ImportMembersMapping (string name, string ns, SoapSchemaMember[] members, bool hasWrapperElement, Type baseType, bool baseTypeCanBeIndirect)
+ {
+ throw new NotImplementedException ();
+ }
+
+ #endregion // Methods
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/SoapSchemaMember.cs b/mcs/class/System.XML/System.Xml.Serialization/SoapSchemaMember.cs new file mode 100644 index 00000000000..733d59c57e8 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/SoapSchemaMember.cs @@ -0,0 +1,44 @@ +//
+// System.Xml.Serialization.SoapSchemaMember
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2002
+//
+
+using System.Xml;
+
+namespace System.Xml.Serialization {
+ public class SoapSchemaMember {
+
+ #region Fields
+
+ string memberName;
+ XmlQualifiedName memberType;
+
+ #endregion
+
+ #region Constructors
+
+ public SoapSchemaMember ()
+ {
+ }
+
+ #endregion // Constructors
+
+ #region Properties
+
+ public string MemberName {
+ get { return memberName; }
+ set { memberName = value; }
+ }
+
+ public XmlQualifiedName MemberType {
+ get { return memberType; }
+ set { memberType = value; }
+ }
+
+ #endregion // Properties
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/SoapTypeAttribute.cs b/mcs/class/System.XML/System.Xml.Serialization/SoapTypeAttribute.cs new file mode 100644 index 00000000000..d6e68934cc6 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/SoapTypeAttribute.cs @@ -0,0 +1,59 @@ +// +// SoapTypeAttribute.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for SoapTypeAttribute.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct |
+ AttributeTargets.Enum | AttributeTargets.Interface)]
+ public class SoapTypeAttribute : Attribute
+ {
+ private string ns;
+ private string typeName;
+ private bool includeInSchema = true;
+
+ public SoapTypeAttribute ()
+ {
+ }
+ public SoapTypeAttribute (string typeName)
+ {
+ TypeName = typeName;
+ }
+ public SoapTypeAttribute (string typeName, string ns)
+ {
+ TypeName = typeName;
+ Namespace = ns;
+ }
+
+ public bool IncludeInSchema
+ {
+ get { return includeInSchema; }
+ set { includeInSchema = value; }
+ }
+
+ public string Namespace {
+ get { return ns; + }
+ set { ns = value; + }
+ }
+ public string TypeName {
+ get { return typeName; + }
+ set { typeName = value; + }
+ }
+
+
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/TypeData.cs b/mcs/class/System.XML/System.Xml.Serialization/TypeData.cs new file mode 100644 index 00000000000..ee9223b0b59 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/TypeData.cs @@ -0,0 +1,82 @@ +// +// System.Xml.Serialization.TypeData +// +// Authors: +// Gonzalo Paniagua Javier (gonzalo@ximian.com) +// +// (C) 2002 Ximian, Inc (http://www.ximian.com) +// + +using System; + +namespace System.Xml.Serialization +{ + internal class TypeData + { + Type type; + string elementName; + SchemaTypes sType; + + public TypeData (Type type, string elementName, bool isPrimitive) + { + this.type = type; + this.elementName = elementName; + if (isPrimitive) + sType = SchemaTypes.Primitive; + else + sType = SchemaTypes.NotSet; + } + + private SchemaTypes GetSchemaType () + { + if (type.IsEnum) + return SchemaTypes.Enum; + else if (type.IsArray) + return SchemaTypes.Array; + /*else if (type == typeof (System.Data.DataSet)) + return SchemaTypes.DataSet;*/ + else if (type == typeof (System.Xml.XmlNode)) + return SchemaTypes.XmlNode; + return SchemaTypes.Class; + } + + public string ElementName + { + get { + return elementName; + } + } + + public string TypeName + { + get { + return type.Name; + } + } + + public Type Type + { + get { + return type; + } + } + + public string FullTypeName + { + get { + return type.FullName.Replace ('+', '.'); + } + } + + public SchemaTypes SchemaType + { + get { + if (sType == SchemaTypes.NotSet) + sType = GetSchemaType (); + + return sType; + } + } + } +} + diff --git a/mcs/class/System.XML/System.Xml.Serialization/TypeMember.cs b/mcs/class/System.XML/System.Xml.Serialization/TypeMember.cs new file mode 100755 index 00000000000..854e31cb511 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/TypeMember.cs @@ -0,0 +1,54 @@ +using System;
+using System.Collections;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// TypeMember is immutable class which is used as a key in a Hashtable.
+ /// </summary>
+
+ internal sealed class TypeMember
+ {
+ Type type;
+ string member;
+ internal TypeMember(Type type, string member)
+ {
+ this.type = type;
+ this.member = member;
+ }
+
+ public override int GetHashCode()
+ {
+ return unchecked (type.GetHashCode() + member.GetHashCode());
+ }
+
+ public override bool Equals(object obj)
+ {
+ if(obj is TypeMember)
+ return TypeMember.Equals(this,(TypeMember)obj);
+
+ return false;
+ }
+
+ public static bool Equals(TypeMember tm1, TypeMember tm2)
+ {
+ if(Object.ReferenceEquals(tm1,tm2))
+ return true;
+ if(Object.ReferenceEquals(tm1,null) || Object.ReferenceEquals(tm2,null))
+ return false;
+ if(tm1.type == tm2.type && tm1.member == tm2.member)
+ return true;
+ return false;
+ }
+
+ public static bool operator==(TypeMember tm1, TypeMember tm2)
+ {
+ return TypeMember.Equals(tm1,tm2);
+ }
+
+ public static bool operator!=(TypeMember tm1, TypeMember tm2)
+ {
+ return !TypeMember.Equals(tm1,tm2);
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/TypeTranslator.cs b/mcs/class/System.XML/System.Xml.Serialization/TypeTranslator.cs new file mode 100644 index 00000000000..7988b342e50 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/TypeTranslator.cs @@ -0,0 +1,53 @@ +// +// System.Xml.Serialization.TypeTranslator +// +// Authors: +// Gonzalo Paniagua Javier (gonzalo@ximian.com) +// +// (C) 2002 Ximian, Inc (http://www.ximian.com) +// + +using System; +using System.Collections; + +namespace System.Xml.Serialization +{ + internal class TypeTranslator + { + static Hashtable primitives; + + static TypeTranslator () + { + primitives = new Hashtable (); + primitives.Add (typeof (bool), "boolean"); + primitives.Add (typeof (short), "short"); + primitives.Add (typeof (ushort), "unsignedShort"); + primitives.Add (typeof (int), "int"); + primitives.Add (typeof (uint), "unsignedInt"); + primitives.Add (typeof (long), "long"); + primitives.Add (typeof (ulong), "unsignedLong"); + primitives.Add (typeof (float), "float"); + primitives.Add (typeof (double), "double"); + primitives.Add (typeof (DateTime), "dateTime"); // TODO: timeInstant, Xml date, xml time + primitives.Add (typeof (Guid), "guid"); + primitives.Add (typeof (Decimal), "decimal"); + primitives.Add (typeof (XmlQualifiedName), "QName"); + primitives.Add (typeof (string), "string"); + primitives.Add (typeof (byte), "unsignedByte"); + primitives.Add (typeof (sbyte), "byte"); + primitives.Add (typeof (char), "char"); + primitives.Add (typeof (object), "anyType"); + } + + private TypeTranslator () + { + } + + static public TypeData GetTypeData (Type type) + { + string name = primitives [type] as string; + return new TypeData (type, (name == null) ? type.Name : name, name != null); + } + } +} + diff --git a/mcs/class/System.XML/System.Xml.Serialization/UnreferencedObjectEventArgs.cs b/mcs/class/System.XML/System.Xml.Serialization/UnreferencedObjectEventArgs.cs new file mode 100644 index 00000000000..b501cb5fea0 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/UnreferencedObjectEventArgs.cs @@ -0,0 +1,35 @@ +// +// UnreferencedObjectEventArgs.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for UnreferencedObjectEventArgs.
+ /// </summary>
+ public class UnreferencedObjectEventArgs : EventArgs
+ {
+ private object unreferencedObject;
+ private string unreferencedId;
+
+ public UnreferencedObjectEventArgs(object o, string id)
+ {
+ unreferencedObject = o;
+ unreferencedId = id;
+ }
+
+ public string UnreferencedId {
+ get{ return unreferencedId; }
+ }
+ public object UnreferencedObject {
+ get{ return unreferencedObject; }
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/UnreferencedObjectEventHandler.cs b/mcs/class/System.XML/System.Xml.Serialization/UnreferencedObjectEventHandler.cs new file mode 100755 index 00000000000..5344f05a746 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/UnreferencedObjectEventHandler.cs @@ -0,0 +1,16 @@ +// +// UnreferencedObjectEventHandler.cs: +// +// Author: +// Miguel de Icaza (miguel@ximian.com) +// +// (C) 2002 Ximian, Inc. +// +using System; + +namespace System.Xml.Serialization { + + [Serializable] + public delegate void UnreferencedObjectEventHandler (object sender, UnreferencedObjectEventArgs e); +} + diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlAnyAttributeAttribute.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlAnyAttributeAttribute.cs new file mode 100644 index 00000000000..c34e70448d6 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlAnyAttributeAttribute.cs @@ -0,0 +1,28 @@ +// +// XmlAnyAttribute.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlAnyAttributeAttribute.
+ /// </summary>
+ ///
+ [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field
+ | AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
+ public class XmlAnyAttributeAttribute : Attribute
+ {
+
+ public XmlAnyAttributeAttribute()
+ {
+
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlAnyElementAttribute.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlAnyElementAttribute.cs new file mode 100644 index 00000000000..255be7ea96c --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlAnyElementAttribute.cs @@ -0,0 +1,66 @@ +// +// filename.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlAnyElementAttribute.
+ /// </summary>
+ ///
+ [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field
+ | AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
+ public class XmlAnyElementAttribute : Attribute
+ {
+ private string elementName;
+ private string ns;
+ private int order;
+
+ public XmlAnyElementAttribute ()
+ {
+ }
+
+ public XmlAnyElementAttribute (string name)
+ {
+ elementName = name;
+ }
+
+ public XmlAnyElementAttribute (string name, string ns)
+ {
+ elementName = name;
+ Namespace = ns;
+ }
+
+ public string Name {
+ get { + return elementName; + }
+ set { + elementName = value; + }
+ }
+ public string Namespace {
+ get { + return ns; + }
+ set { + ns = value; + }
+ }
+ /// <summary>
+ /// Specifies Order in which Memberswill be serialized as Elements.
+ /// </summary>
+ internal int Order
+ {
+ get{ return order; }
+ set{ order = value; }
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlAnyElementAttributes.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlAnyElementAttributes.cs new file mode 100644 index 00000000000..86242fe7097 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlAnyElementAttributes.cs @@ -0,0 +1,66 @@ +// +// XmlAnyElementAttributes.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System.Xml;
+using System.Xml.Serialization;
+using System.Collections;
+using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlAnyElementAttributes.
+ /// </summary>
+ public class XmlAnyElementAttributes : CollectionBase
+ {
+
+ public XmlAnyElementAttribute this[int index]
+ {
+ get
+ {
+ return (XmlAnyElementAttribute)List[index];
+ }
+ set
+ {
+ List[index] = value;
+ }
+ }
+
+ public int Add(XmlAnyElementAttribute attribute)
+ {
+ return List.Add(attribute);
+ }
+
+ public bool Contains(XmlAnyElementAttribute attribute)
+ {
+ return List.Contains(attribute);
+ }
+
+ public int IndexOf(XmlAnyElementAttribute attribute)
+ {
+ return List.IndexOf(attribute);
+ }
+
+ public void Insert(int index, XmlAnyElementAttribute attribute)
+ {
+ List.Insert(index, attribute);
+ }
+
+ public void Remove(XmlAnyElementAttribute attribute)
+ {
+ List.Remove(attribute);
+ }
+
+ public void CopyTo(XmlAnyElementAttribute[] array,int index)
+ {
+ List.CopyTo(array, index);
+ }
+ }
+
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlArrayAttribute.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlArrayAttribute.cs new file mode 100644 index 00000000000..d0b67ab636d --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlArrayAttribute.cs @@ -0,0 +1,90 @@ +// +// XmlArrayAttribute.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System.Xml.Schema;
+using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlArrayAttribute.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field
+ | AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
+ public class XmlArrayAttribute : Attribute
+ {
+ private string elementName;
+ private XmlSchemaForm form;
+ private bool isNullable;
+ private string ns;
+ private int order;
+
+ public XmlArrayAttribute()
+ {
+ }
+
+ public XmlArrayAttribute(string elementName)
+ {
+ ElementName = elementName;
+ }
+
+ public string ElementName
+ {
+ get
+ {
+ return elementName;
+ }
+ set
+ {
+ elementName = value;
+ }
+ }
+ public XmlSchemaForm Form
+ {
+ get
+ {
+ return form;
+ }
+ set
+ {
+ form = value;
+ }
+ }
+ public bool IsNullable
+ {
+ get
+ {
+ return isNullable;
+ }
+ set
+ {
+ isNullable = value;
+ }
+ }
+ public string Namespace
+ {
+ get
+ {
+ return ns;
+ }
+ set
+ {
+ ns = value;
+ }
+ }
+ /// <summary>
+ /// Specifies Order in which Memberswill be serialized as Elements.
+ /// </summary>
+ internal int Order
+ {
+ get{ return order; }
+ set{ order = value; }
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlArrayItemAttribute.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlArrayItemAttribute.cs new file mode 100644 index 00000000000..354af362b76 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlArrayItemAttribute.cs @@ -0,0 +1,85 @@ +// +// XmlArrayItemAttribute.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System.Xml.Schema;
+using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlArrayItemAttribute.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field
+ | AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
+ public class XmlArrayItemAttribute : Attribute
+ {
+ private string dataType;
+ private string elementName;
+ private XmlSchemaForm form;
+ private string ns;
+ private bool isNullable;
+ private int nestingLevel;
+ private Type type;
+ private int order;
+
+ public XmlArrayItemAttribute ()
+ {
+ }
+ public XmlArrayItemAttribute (string elementName)
+ {
+ ElementName = elementName;
+ }
+ public XmlArrayItemAttribute (Type type)
+ {
+ Type = type;
+ }
+ public XmlArrayItemAttribute (string elementName, Type type)
+ {
+ ElementName = elementName;
+ Type = type;
+ }
+
+ public string DataType {
+ get { return dataType; }
+ set { dataType = value; }
+ }
+ public string ElementName {
+ get { return elementName; }
+ set { elementName = value; }
+ }
+ public XmlSchemaForm Form {
+ get { return form; }
+ set { form = value; }
+ }
+ public string Namespace {
+ get { return ns; }
+ set { ns = value; }
+ }
+ public bool IsNullable {
+ get { return isNullable; }
+ set { isNullable = value; }
+ }
+ public Type Type {
+ get { return type; }
+ set { type = value; }
+ }
+ public int NestingLevel {
+ get { return nestingLevel; }
+ set { nestingLevel = value; }
+ }
+ /// <summary>
+ /// Specifies Order in which Memberswill be serialized as Elements.
+ /// </summary>
+ public int Order
+ {
+ get{ return order; }
+ set{ order = value; }
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlArrayItemAttributes.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlArrayItemAttributes.cs new file mode 100644 index 00000000000..51528209a41 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlArrayItemAttributes.cs @@ -0,0 +1,61 @@ +// +// XmlArrayItemAttributes.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System.Xml.Serialization;
+using System.Collections;
+using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlArrayItemAttributes.
+ /// </summary>
+ public class XmlArrayItemAttributes : CollectionBase
+ {
+
+ public XmlArrayItemAttribute this [int index] {
+ get {
+ return (XmlArrayItemAttribute)List [index];
+ }
+ set {
+ List [index] = value;
+ }
+ }
+
+ public int Add (XmlArrayItemAttribute attribute)
+ {
+ return List.Add(attribute);
+ }
+
+ public bool Contains(XmlArrayItemAttribute attribute)
+ {
+ return List.Contains(attribute);
+ }
+
+ public void CopyTo(XmlArrayItemAttribute[] array, int index)
+ {
+ List.CopyTo(array, index);
+ }
+
+ public int IndexOf(XmlArrayItemAttribute attribute)
+ {
+ return List.IndexOf(attribute);
+ }
+
+ public void Insert(int index, XmlArrayItemAttribute attribute)
+ {
+ List.Insert(index, attribute);
+ }
+
+ public void Remove(XmlArrayItemAttribute attribute)
+ {
+ List.Remove(attribute);
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlAttributeAttribute.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlAttributeAttribute.cs new file mode 100644 index 00000000000..e23ff75890c --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlAttributeAttribute.cs @@ -0,0 +1,95 @@ +// +// XmlAttributeAttribute.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System.Xml.Schema;
+using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlAttributeAttribute.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field
+ | AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
+ public class XmlAttributeAttribute : Attribute
+ {
+ private string attributeName;
+ private string dataType;
+ private Type type;
+ private XmlSchemaForm form;
+ private string ns;
+
+ public XmlAttributeAttribute ()
+ {
+ }
+
+ public XmlAttributeAttribute (string attributeName)
+ {
+ AttributeName = attributeName;
+ }
+
+ public XmlAttributeAttribute (Type type)
+ {
+ Type = type;
+ }
+
+ public XmlAttributeAttribute (string attributeName, Type type)
+ {
+ AttributeName = attributeName;
+ Type = type;
+ }
+
+ public string AttributeName {
+ get { + return attributeName; + }
+ set { + attributeName = value; + }
+ }
+ public string DataType {
+ get { + return dataType; + }
+ set { + dataType = value; + }
+ }
+ public XmlSchemaForm Form {
+ get { + return form; + }
+ set { + if(Namespace != null) + form = value; + }
+ }
+ public string Namespace {
+ get { + return ns; + }
+ set { + ns = value; + }
+ }
+
+ public Type Type
+ {
+ get
+ { + return type; + }
+ set
+ { + type = value; + }
+ }
+
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlAttributeEventArgs.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlAttributeEventArgs.cs new file mode 100644 index 00000000000..e39c6811573 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlAttributeEventArgs.cs @@ -0,0 +1,49 @@ +// +// XmlAttributeEventArgs.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System.Xml;
+using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlAttributeEventArgs.
+ /// </summary>
+ public class XmlAttributeEventArgs : EventArgs
+ {
+ private XmlAttribute attr;
+ private int lineNumber;
+ private int linePosition;
+ private object obj;
+
+ internal XmlAttributeEventArgs(XmlAttribute attr, int lineNum, int linePos, object source)
+ {
+ this.attr = attr;
+ this.lineNumber = lineNum;
+ this.linePosition = linePos;
+ this.obj = source;
+ }
+
+ public XmlAttribute Attr {
+ get { return attr; }
+ }
+
+ public int LineNumber {
+ get { return lineNumber; }
+ }
+
+ public int LinePosition {
+ get { return linePosition; }
+ }
+
+ public object ObjectBeingDeserialized {
+ get{ return obj; }
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlAttributeEventHandler.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlAttributeEventHandler.cs new file mode 100755 index 00000000000..35a0f2d5474 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlAttributeEventHandler.cs @@ -0,0 +1,16 @@ +// +// XmlAttributeEventHandler.cs: +// +// Author: +// Miguel de Icaza (miguel@ximian.com) +// +// (C) 2002 Ximian, Inc. +// +using System; + +namespace System.Xml.Serialization { + + [Serializable] + public delegate void XmlAttributeEventHandler (object sender, XmlAttributeEventArgs e); +} + diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlAttributeOverrides.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlAttributeOverrides.cs new file mode 100644 index 00000000000..75c6112c794 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlAttributeOverrides.cs @@ -0,0 +1,60 @@ +// +// XmlAttributeOverrides.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System;
+using System.Collections;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlAttributeOverrides.
+ /// </summary>
+ public class XmlAttributeOverrides
+ {
+
+ private Hashtable overrides;
+
+ public XmlAttributeOverrides ()
+ {
+ overrides = new Hashtable();
+ }
+
+ public XmlAttributes this [Type type]
+ {
+ get { return this [type, string.Empty]; }
+ }
+
+ public XmlAttributes this [Type type, string member]
+ {
+ get
+ {
+ return (XmlAttributes) overrides[GetKey(type,member)];
+ }
+ }
+
+ public void Add (Type type, XmlAttributes attributes)
+ {
+ Add(type, string.Empty, attributes);
+ }
+
+ public void Add (Type type, string member, XmlAttributes attributes)
+ {
+ if(overrides[GetKey(type, member)] != null)
+ throw new Exception("The attributes for the given type and Member already exist in the collection");
+
+ overrides.Add(GetKey(type,member), attributes);
+ }
+
+ private TypeMember GetKey(Type type, string member)
+ {
+ return new TypeMember(type, member);
+ }
+
+ }
+}
\ No newline at end of file diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlAttributes.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlAttributes.cs new file mode 100644 index 00000000000..a9f22b5c0b9 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlAttributes.cs @@ -0,0 +1,439 @@ +// +// XmlAttributes.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System.Reflection; +using System;
+using System.ComponentModel;
+using System.Collections;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlAttributes.
+ /// </summary>
+ public class XmlAttributes
+ {
+ private XmlAnyAttributeAttribute xmlAnyAttribute;
+ private XmlAnyElementAttributes xmlAnyElements;
+ private XmlArrayAttribute xmlArray;
+ private XmlArrayItemAttributes xmlArrayItems;
+ private XmlAttributeAttribute xmlAttribute;
+ private XmlChoiceIdentifierAttribute xmlChoiceIdentifier;
+ private object xmlDefaultValue;
+ private XmlElementAttributes xmlElements;
+ private XmlEnumAttribute xmlEnum;
+ private bool xmlIgnore;
+ private bool xmlns;
+ private XmlRootAttribute xmlRoot;
+ private XmlTextAttribute xmlText;
+ private XmlTypeAttribute xmlType;
+
+ private MemberInfo minfo;
+ private FieldInfo finfo;
+ private PropertyInfo pinfo;
+ internal ArrayList XmlIncludes;
+ //internal string ElementName;
+
+ //The element Order in serialization.
+ internal int order;
+ internal bool isAttribute;
+ internal static XmlAttributes.XmlAttributesComparer attrComparer;
+
+ //Sorting Order of Elements: XmlNs, XmlAttributes, XmlElement
+ internal class XmlAttributesComparer : IComparer
+ {
+ public int Compare(object x,object y)
+ {
+ if(x is XmlAttributes && y is XmlAttributes)
+ {
+ XmlAttributes attx = (XmlAttributes)x;
+ XmlAttributes atty = (XmlAttributes)y;
+ if(attx.xmlns)
+ return -1;
+ if(atty.xmlns)
+ return 1;
+ if(attx.isAttribute)
+ return -1;
+ if(atty.isAttribute)
+ return 1;
+ int diff = attx.order - atty.order;
+ if(diff == 0)
+ return 0;
+ if(diff > 0)
+ return 1;
+ if(diff < 0)
+ return -1;
+ }
+ if(x == null)
+ return -1;
+ if(y == null)
+ return 1;
+ throw new Exception("Should never occur. XmlAttributesComparer.Compare");
+ }
+ }
+
+ public XmlAttributes ()
+ {
+ xmlAnyElements = new XmlAnyElementAttributes ();
+ xmlArrayItems = new XmlArrayItemAttributes ();
+ xmlElements = new XmlElementAttributes ();
+ XmlIncludes = new ArrayList();
+ }
+
+ static XmlAttributes ()
+ {
+ attrComparer = new XmlAttributes.XmlAttributesComparer();
+ }
+
+ public XmlAttributes (ICustomAttributeProvider provider)
+ {
+ object[] attributes = provider.GetCustomAttributes(false);
+ foreach(object obj in attributes)
+ {
+ if(obj is XmlAnyAttributeAttribute)
+ xmlAnyAttribute = (XmlAnyAttributeAttribute) obj;
+ else if(obj is XmlAnyElementAttribute)
+ xmlAnyElements.Add((XmlAnyElementAttribute) obj);
+ else if(obj is XmlArrayAttribute)
+ xmlArray = (XmlArrayAttribute) obj;
+ else if(obj is XmlArrayItemAttribute)
+ xmlArrayItems.Add((XmlArrayItemAttribute) obj);
+ else if(obj is XmlAttributeAttribute)
+ xmlAttribute = (XmlAttributeAttribute) obj;
+ else if(obj is XmlChoiceIdentifierAttribute)
+ xmlChoiceIdentifier = (XmlChoiceIdentifierAttribute) obj;
+ else if(obj is DefaultValueAttribute)
+ xmlDefaultValue = obj;
+ else if(obj is XmlElementAttribute )
+ xmlElements.Add((XmlElementAttribute ) obj);
+ else if(obj is XmlEnumAttribute)
+ xmlEnum = (XmlEnumAttribute) obj;
+ else if(obj is XmlIgnoreAttribute)
+ xmlIgnore = true;
+ else if(obj is XmlNamespaceDeclarationsAttribute)
+ xmlns = true;
+ else if(obj is XmlRootAttribute)
+ xmlRoot = (XmlRootAttribute) obj;
+ else if(obj is XmlTextAttribute)
+ xmlText = (XmlTextAttribute) obj;
+ else if(obj is XmlTypeAttribute)
+ xmlType = (XmlTypeAttribute) obj;
+ }
+ }
+
+ #region public properties
+ public XmlAnyAttributeAttribute XmlAnyAttribute
+ {
+ get
+ { + return xmlAnyAttribute; + }
+ set
+ { + xmlAnyAttribute = value; + }
+ }
+ public XmlAnyElementAttributes XmlAnyElements
+ {
+ get
+ { + return xmlAnyElements; + }
+ }
+ public XmlArrayAttribute XmlArray
+ {
+ get
+ { + return xmlArray; + }
+ set
+ { + xmlArray = value; + }
+ }
+ public XmlArrayItemAttributes XmlArrayItems
+ {
+ get
+ { + return xmlArrayItems; + }
+ }
+ public XmlAttributeAttribute XmlAttribute
+ {
+ get
+ { + return xmlAttribute; + }
+ set
+ { + xmlAttribute = value; + }
+ }
+ public XmlChoiceIdentifierAttribute XmlChoiceIdentifier
+ {
+ get
+ { + return xmlChoiceIdentifier; + }
+ }
+ public object XmlDefaultValue
+ {
+ get
+ { + return xmlDefaultValue; + }
+ set
+ { + xmlDefaultValue = value; + }
+ }
+ public XmlElementAttributes XmlElements
+ {
+ get
+ { + return xmlElements; + }
+ }
+ public XmlEnumAttribute XmlEnum
+ {
+ get
+ { + return xmlEnum; + }
+ set
+ { + xmlEnum = value; + }
+ }
+ public bool XmlIgnore
+ {
+ get
+ { + return xmlIgnore; + }
+ set
+ { + xmlIgnore = value; + }
+ }
+ public bool Xmlns
+ {
+ get
+ { + return xmlns; + }
+ set
+ { + xmlns = value; + }
+ }
+ public XmlRootAttribute XmlRoot
+ {
+ get
+ { + return xmlRoot;}
+ set
+ { + xmlRoot = value; + }
+ }
+ public XmlTextAttribute XmlText
+ {
+ get
+ { + return xmlText; + }
+ set
+ { + xmlText = value; + }
+ }
+ public XmlTypeAttribute XmlType
+ {
+ get
+ { + return xmlType; + }
+ set
+ { + xmlType = value; + }
+ }
+ #endregion
+
+ #region internal properties
+ internal MemberInfo MemberInfo
+ {
+ get { return minfo; }
+ set { minfo = value; }
+ }
+
+ internal FieldInfo FieldInfo
+ {
+ get { return finfo; }
+ set { finfo = value; }
+ }
+
+ internal PropertyInfo PropertyInfo
+ {
+ get { return pinfo; }
+ set { pinfo = value; }
+ }
+ #endregion
+
+ //Only permissible attributes for a class type are: XmlRoot and XmlInclude
+ internal static XmlAttributes FromClass(Type classType)
+ {
+ XmlAttributes XmlAttr = new XmlAttributes();
+ object[] attributes = classType.GetCustomAttributes(false);
+ foreach(object obj in attributes)
+ {
+ if(obj is XmlRootAttribute)
+ XmlAttr.xmlRoot = (XmlRootAttribute) obj;
+ else if(obj is XmlIncludeAttribute)
+ XmlAttr.XmlIncludes.Add(obj);
+ }
+ return XmlAttr;
+ }
+
+ internal static XmlAttributes FromField(MemberInfo member, FieldInfo finfo)
+ {
+ XmlAttributes XmlAttr = new XmlAttributes();
+ object[] attributes = member.GetCustomAttributes(false);
+ XmlAttr.AddMemberAttributes(attributes);
+
+ XmlAttr.minfo = member;
+ XmlAttr.finfo = finfo;
+
+ return XmlAttr;
+ }
+
+
+ internal static XmlAttributes FromProperty(MemberInfo member, PropertyInfo pinfo)
+ {
+
+ XmlAttributes XmlAttr = new XmlAttributes();
+ object[] attributes = member.GetCustomAttributes(false);
+ XmlAttr.AddMemberAttributes(attributes);
+
+ XmlAttr.minfo = member;
+ XmlAttr.pinfo = pinfo;
+ return XmlAttr;
+ }
+
+ internal void AddMemberAttributes(object[] attributes)
+ {
+ foreach(object obj in attributes)
+ {
+ if(obj is XmlAnyAttributeAttribute)
+ {
+ xmlAnyAttribute = (XmlAnyAttributeAttribute) obj;
+ isAttribute = true;
+ }
+ else if(obj is XmlAttributeAttribute)
+ {
+ xmlAttribute = (XmlAttributeAttribute) obj;
+ isAttribute = true;
+ }
+ else if(obj is XmlNamespaceDeclarationsAttribute)
+ {
+ xmlns = true;
+ isAttribute = true;
+ }
+ else if(obj is XmlAnyElementAttribute)
+ {
+ xmlAnyElements.Add((XmlAnyElementAttribute) obj);
+ order = ((XmlAnyElementAttribute) obj).Order;
+ }
+ else if(obj is XmlArrayAttribute)
+ {
+ xmlArray = (XmlArrayAttribute) obj;
+ order = ((XmlArrayAttribute) obj).Order;
+ }
+ else if(obj is XmlArrayItemAttribute)
+ {
+ xmlArrayItems.Add((XmlArrayItemAttribute) obj);
+ order = ((XmlArrayItemAttribute) obj).Order;
+ }
+ else if(obj is XmlChoiceIdentifierAttribute)
+ {
+ xmlChoiceIdentifier = (XmlChoiceIdentifierAttribute) obj;
+ order = ((XmlChoiceIdentifierAttribute) obj).Order;
+ }
+ else if(obj is XmlTextAttribute)
+ {
+ xmlText = (XmlTextAttribute) obj;
+ order = ((XmlTextAttribute) obj).Order;
+ }
+ else if(obj is XmlElementAttribute )
+ {
+ xmlElements.Add((XmlElementAttribute ) obj);
+ order = ((XmlElementAttribute ) obj).Order;
+ }
+ else if(obj is DefaultValueAttribute)
+ {
+ xmlDefaultValue = ((DefaultValueAttribute ) obj).Value;
+ }
+ else if(obj is XmlEnumAttribute)
+ {
+ xmlEnum = (XmlEnumAttribute) obj;
+ }
+ else if(obj is XmlIgnoreAttribute)
+ {
+ xmlIgnore = true;
+ }
+ else if(obj is XmlRootAttribute)
+ {
+ throw new Exception("should never happen. XmlRoot on a member");
+ }
+ else if(obj is XmlTypeAttribute)
+ {
+ xmlType = (XmlTypeAttribute) obj;
+ }
+ }
+ }
+
+ internal string GetAttributeName(Type type, string defaultName)
+ {
+ if(XmlAttribute != null && XmlAttribute.AttributeName != null && XmlAttribute.AttributeName != "")
+ return XmlAttribute.AttributeName;
+ return defaultName;
+ }
+
+ internal string GetElementName(Type type, string defaultName)
+ {
+ foreach(XmlElementAttribute elem in XmlElements)
+ {
+ if(elem.Type == type && elem.ElementName != null && elem.ElementName != "")
+ return elem.ElementName;
+ else if(elem.Type == null && elem.ElementName != null && elem.ElementName != "")
+ return elem.ElementName;
+ }
+ return defaultName;
+ }
+
+ internal string GetAttributeNamespace(Type type)
+ {
+ if(XmlAttribute != null)
+ return XmlAttribute.Namespace;
+ return null;
+ }
+ internal string GetElementNamespace(Type type)
+ {
+ foreach(XmlElementAttribute elem in XmlElements)
+ {
+ if(elem.Type == type )
+ return elem.Namespace;
+ else if(elem.Type == null)
+ return elem.Namespace;
+ }
+ return null;
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlChoiceIdentifierAttribute.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlChoiceIdentifierAttribute.cs new file mode 100644 index 00000000000..6b84f761e02 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlChoiceIdentifierAttribute.cs @@ -0,0 +1,51 @@ +// +// XmlChoiceIdentifierAttribute.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlChoiceIdentifierAttribute.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field
+ | AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
+ public class XmlChoiceIdentifierAttribute : Attribute
+ {
+ private string memberName;
+ private int order;
+
+ public XmlChoiceIdentifierAttribute ()
+ {
+ }
+ public XmlChoiceIdentifierAttribute (string name)
+ {
+ MemberName = name;
+ }
+
+ public string MemberName {
+ get { + return memberName; + }
+ set { + memberName = value; + }
+ }
+
+ /// <summary>
+ /// Specifies Order in which Memberswill be serialized as Elements.
+ /// </summary>
+ internal int Order
+ {
+ get{ return order; }
+ set{ order = value; }
+ }
+
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlCodeExporter.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlCodeExporter.cs new file mode 100644 index 00000000000..d6ead00212f --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlCodeExporter.cs @@ -0,0 +1,81 @@ +//
+// System.Xml.Serialization.XmlCodeExporter
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2002
+//
+
+using System.CodeDom;
+
+namespace System.Xml.Serialization {
+ public class XmlCodeExporter {
+
+ #region Fields
+
+ CodeNamespace codeNamespace;
+ CodeCompileUnit codeCompileUnit;
+ CodeAttributeDeclarationCollection includeMetadata;
+
+ #endregion
+
+ #region Constructors
+
+ public XmlCodeExporter (CodeNamespace codeNamespace)
+ {
+ includeMetadata = new CodeAttributeDeclarationCollection ();
+ this.codeNamespace = codeNamespace;
+ }
+
+ public XmlCodeExporter (CodeNamespace codeNamespace, CodeCompileUnit codeCompileUnit)
+ : this (codeNamespace)
+ {
+ this.codeCompileUnit = codeCompileUnit;
+ }
+
+ #endregion // Constructors
+
+ #region Properties
+
+ public CodeAttributeDeclarationCollection IncludeMetadata {
+ get { return includeMetadata; }
+ }
+
+ #endregion Properties
+
+ #region Methods
+
+ [MonoTODO]
+ public void AddMappingMetadata (CodeAttributeDeclarationCollection metadata, XmlMemberMapping member, string ns)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public void AddMappingMetadata (CodeAttributeDeclarationCollection metadata, XmlTypeMapping member, string ns)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public void AddMappingMetadata (CodeAttributeDeclarationCollection metadata, XmlMemberMapping member, string ns, bool forceUseMemberName)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public void ExportMembersMapping (XmlMembersMapping xmlMembersMapping)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public void ExportTypeMapping (XmlTypeMapping xmlTypeMapping)
+ {
+ throw new NotImplementedException ();
+ }
+
+ #endregion // Methods
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlCustomFormatter.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlCustomFormatter.cs new file mode 100644 index 00000000000..90f710fac73 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlCustomFormatter.cs @@ -0,0 +1,133 @@ +// +// System.Xml.Serialization.XmlCustomFormatter.cs +// +// Author: +// Tim Coleman (tim@timcoleman.com) +// +// Copyright (C) Tim Coleman, 2002 +// + +using System; +using System.Text; +using System.Xml; + +namespace System.Xml.Serialization { + internal class XmlCustomFormatter { + + #region Methods + + [MonoTODO] + internal static byte[] FromByteArrayBase64 (byte[] value) + { + throw new NotImplementedException (); + } + + internal static string FromByteArrayHex (byte[] value) + { + StringBuilder output = new StringBuilder (); + foreach (byte val in value) + output.Append (val.ToString ("X2")); + return output.ToString (); + } + + internal static string FromChar (char value) + { + return ((int) value).ToString (); + } + + internal static string FromDate (DateTime value) + { + return XmlConvert.ToString (value, "yyyy-MM-dd"); + } + + internal static string FromDateTime (DateTime value) + { + return XmlConvert.ToString (value, "yyyy-MM-ddTHH:mm:ss.fffffffzzz"); + } + + internal static string FromTime (DateTime value) + { + return XmlConvert.ToString (value, "HH:mm:ss.fffffffzzz"); + } + + internal static string FromEnum (long value, string[] values, long[] ids) + { + int length = ids.Length; + + for (int i = 0; i < length; i ++) { + if (ids[i] == value) + if (i >= values.Length) + return String.Empty; + else + return values[i].ToString (); + } + return value.ToString (); + } + + internal static string FromXmlName (string name) + { + return XmlConvert.EncodeName (name); + } + + internal static string FromXmlNCName (string ncName) + { + return XmlConvert.EncodeLocalName (ncName); + } + + internal static string FromXmlNmToken (string nmToken) + { + return XmlConvert.EncodeNmToken (nmToken); + } + + internal static string FromXmlNmTokens (string nmTokens) + { + StringBuilder output = new StringBuilder (); + string [] tokens = nmTokens.Split (' '); + foreach (string token in tokens) + output.Append (FromXmlNmToken (token)); + return output.ToString (); + } + + internal static char ToChar (string value) + { + return (char) XmlConvert.ToUInt16 (value); + } + + internal static DateTime ToDate (string value) + { + return ToDateTime (value); + } + + internal static DateTime ToDateTime (string value) + { + return XmlConvert.ToDateTime (value); + } + + internal static DateTime ToTime (string value) + { + return ToDateTime (value); + } + + internal static string ToXmlName (string value) + { + return XmlConvert.DecodeName (value); + } + + internal static string ToXmlNCName (string value) + { + return ToXmlName (value); + } + + internal static string ToXmlNmToken (string value) + { + return ToXmlName (value); + } + + internal static string ToXmlNmTokens (string value) + { + return ToXmlName (value); + } + + #endregion // Methods + } +} diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlElementAttribute.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlElementAttribute.cs new file mode 100644 index 00000000000..f72e43bc347 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlElementAttribute.cs @@ -0,0 +1,104 @@ +// +// XmlElementAttribute.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System.Xml.Schema;
+using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlElementAttribute.
+ /// </summary
+ [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field
+ | AttributeTargets.Parameter | AttributeTargets.ReturnValue, AllowMultiple=true)]
+ public class XmlElementAttribute : Attribute
+ {
+ private string dataType;
+ private string elementName;
+ private XmlSchemaForm form;
+ private string ns;
+ private bool isNullable;
+ private Type type;
+ private int order;
+
+ public XmlElementAttribute ()
+ {
+ }
+ public XmlElementAttribute (string elementName)
+ {
+ ElementName = elementName;
+ }
+ public XmlElementAttribute (Type type)
+ {
+ Type = type;
+ }
+ public XmlElementAttribute (string elementName, Type type)
+ {
+ ElementName = elementName;
+ Type = type;
+ }
+
+ public string DataType {
+ get { + return dataType; + }
+ set { + dataType = value; + }
+ }
+ public string ElementName {
+ get { + return elementName; + }
+ set { + elementName = value; + }
+ }
+ public XmlSchemaForm Form {
+ get { + return form; + }
+ set { + form = value; + }
+ }
+ public string Namespace {
+ get { + return ns; + }
+ set { + ns = value; + }
+ }
+ public bool IsNullable {
+ get { + return isNullable; + }
+ set { + isNullable = value; + }
+ }
+ public Type Type {
+ get { + return type; + }
+ set { + type = value; + }
+ }
+ /// <summary>
+ /// Specifies Order in which Memberswill be serialized as Elements.
+ /// </summary>
+ internal int Order
+ {
+ get{ return order; }
+ set{ order = value; }
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlElementAttributes.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlElementAttributes.cs new file mode 100644 index 00000000000..b2a75c1d50c --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlElementAttributes.cs @@ -0,0 +1,59 @@ +// +// XmlElementAttributes.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System.Collections;
+using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlElementAttributes.
+ /// </summary>
+ public class XmlElementAttributes : CollectionBase
+ {
+ public XmlElementAttribute this [int index] {
+ get {
+ return (XmlElementAttribute)List [index];
+ }
+ set {
+ List [index] = value;
+ }
+ }
+
+ public int Add (XmlElementAttribute attribute)
+ {
+ return List.Add (attribute);
+ }
+
+ public bool Contains(XmlElementAttribute attribute)
+ {
+ return List.Contains(attribute);
+ }
+
+ public int IndexOf(XmlElementAttribute attribute)
+ {
+ return List.IndexOf(attribute);
+ }
+
+ public void Insert(int index, XmlElementAttribute attribute)
+ {
+ List.Insert(index, attribute);
+ }
+
+ public void Remove(XmlElementAttribute attribute)
+ {
+ List.Remove(attribute);
+ }
+
+ public void CopyTo(XmlElementAttribute[] array,int index)
+ {
+ List.CopyTo(array, index);
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlElementEventArgs.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlElementEventArgs.cs new file mode 100644 index 00000000000..94655c0bb0c --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlElementEventArgs.cs @@ -0,0 +1,53 @@ +// +// XmlElementEventArgs.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System.Xml;
+using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlElementEventArgs.
+ /// </summary>
+ public class XmlElementEventArgs : EventArgs
+ {
+ private XmlElement attr;
+ private int lineNumber;
+ private int linePosition;
+ private object obj;
+
+ internal XmlElementEventArgs(XmlElement attr, int lineNum, int linePos, object source)
+ {
+ this.attr = attr;
+ this.lineNumber = lineNum;
+ this.linePosition = linePos;
+ this.obj = source;
+ }
+
+ public XmlElement Element
+ {
+ get { return attr; }
+ }
+
+ public int LineNumber
+ {
+ get { return lineNumber; }
+ }
+
+ public int LinePosition
+ {
+ get { return linePosition; }
+ }
+
+ public object ObjectBeingDeserialized
+ {
+ get{ return obj; }
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlElementEventHandler.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlElementEventHandler.cs new file mode 100755 index 00000000000..be4dda7428a --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlElementEventHandler.cs @@ -0,0 +1,16 @@ +// +// XmlElementEventHandler.cs: +// +// Author: +// Miguel de Icaza (miguel@ximian.com) +// +// (C) 2002 Ximian, Inc. +// +using System; + +namespace System.Xml.Serialization { + + [Serializable] + public delegate void XmlElementEventHandler (object sender, XmlElementEventArgs e); +} + diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlEnumAttribute.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlEnumAttribute.cs new file mode 100644 index 00000000000..e95087c09fb --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlEnumAttribute.cs @@ -0,0 +1,41 @@ +// +// XmlEnumAttribute.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlEnumAttribute.
+ /// </summary>\
+ [AttributeUsage(AttributeTargets.Field)]
+ public class XmlEnumAttribute : Attribute
+ {
+ private string name;
+
+ public XmlEnumAttribute ()
+ {
+ }
+
+ public XmlEnumAttribute (string name)
+ {
+ Name = name;
+ }
+
+ public string Name {
+ get {
+ return name;
+ }
+ set {
+ name = value;
+ }
+ }
+
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlIgnoreAttribute.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlIgnoreAttribute.cs new file mode 100644 index 00000000000..cb0fe82ba33 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlIgnoreAttribute.cs @@ -0,0 +1,26 @@ +// +// XmlIgnoreAttribute.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlIgnoreAttribute.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field
+ | AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
+ public class XmlIgnoreAttribute : Attribute
+ {
+ public XmlIgnoreAttribute ()
+ {
+
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlIncludeAttribute.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlIncludeAttribute.cs new file mode 100644 index 00000000000..e7eafcdf4cc --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlIncludeAttribute.cs @@ -0,0 +1,37 @@ +// +// XmlIncludeAttribute.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlIncludeAttribute.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct |
+ AttributeTargets.Method)]
+ public class XmlIncludeAttribute : Attribute
+ {
+ private Type type;
+
+ public XmlIncludeAttribute (Type type)
+ {
+ Type = type;
+ }
+
+ public Type Type {
+ get {
+ return type;
+ }
+ set {
+ type = value;
+ }
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlMapping.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlMapping.cs new file mode 100644 index 00000000000..a989e674218 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlMapping.cs @@ -0,0 +1,23 @@ +// +// XmlMapping.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlMapping.
+ /// </summary>
+ public abstract class XmlMapping
+ {
+ internal XmlMapping () + { + } + }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlMemberMapping.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlMemberMapping.cs new file mode 100644 index 00000000000..8c222aa8b82 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlMemberMapping.cs @@ -0,0 +1,56 @@ +//
+// System.Xml.Serialization.XmlMemberMapping
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2002
+//
+
+namespace System.Xml.Serialization {
+ public class XmlMemberMapping {
+
+ internal XmlMemberMapping ()
+ {
+ }
+
+ #region Properties
+
+ public bool Any {
+ [MonoTODO]
+ get { throw new NotImplementedException (); }
+ }
+
+ public string ElementName {
+ [MonoTODO]
+ get { throw new NotImplementedException (); }
+ }
+
+ public string MemberName {
+ [MonoTODO]
+ get { throw new NotImplementedException (); }
+ }
+
+ public string Namespace {
+ [MonoTODO]
+ get { throw new NotImplementedException (); }
+ }
+
+ public string TypeFullName {
+ [MonoTODO]
+ get { throw new NotImplementedException (); }
+ }
+
+ public string TypeName {
+ [MonoTODO]
+ get { throw new NotImplementedException (); }
+ }
+
+ public string TypeNamespace {
+ [MonoTODO]
+ get { throw new NotImplementedException (); }
+ }
+
+ #endregion // Properties
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlMembersMapping.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlMembersMapping.cs new file mode 100644 index 00000000000..ebd9b6bc60d --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlMembersMapping.cs @@ -0,0 +1,53 @@ +//
+// System.Xml.Serialization.XmlMembersMapping
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2002
+//
+
+using System.Reflection;
+
+namespace System.Xml.Serialization {
+ public class XmlMembersMapping : XmlMapping {
+
+ internal XmlMembersMapping ()
+ {
+ }
+
+ #region Properties
+
+ public int Count {
+ [MonoTODO]
+ get { throw new NotImplementedException (); }
+ }
+
+ public string ElementName {
+ [MonoTODO]
+ get { throw new NotImplementedException (); }
+ }
+
+ public XmlMemberMapping this [int index] {
+ [MonoTODO]
+ get { throw new NotImplementedException (); }
+ }
+
+ public string Namespace {
+ [MonoTODO]
+ get { throw new NotImplementedException (); }
+ }
+
+ public string TypeName {
+ [MonoTODO]
+ get { throw new NotImplementedException (); }
+ }
+
+ public string TypeNamespace {
+ [MonoTODO]
+ get { throw new NotImplementedException (); }
+ }
+
+ #endregion // Properties
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlNamespaceDeclarationsAttribute.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlNamespaceDeclarationsAttribute.cs new file mode 100644 index 00000000000..4cc59b3cf00 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlNamespaceDeclarationsAttribute.cs @@ -0,0 +1,26 @@ +// +// XmlNamespaceDeclarationsAttribute.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlNamespaceDeclarationsAttribute.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field
+ | AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
+ public class XmlNamespaceDeclarationsAttribute : Attribute
+ {
+ public XmlNamespaceDeclarationsAttribute ()
+ {
+
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlNodeEventArgs.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlNodeEventArgs.cs new file mode 100644 index 00000000000..8064d6855f2 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlNodeEventArgs.cs @@ -0,0 +1,82 @@ +// +// XmlNodeEventArgs.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System.Xml;
+using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlNodeEventArgs.
+ /// </summary>
+ public class XmlNodeEventArgs : EventArgs
+ {
+ private int linenumber;
+ private int lineposition ;
+ private string localname;
+ private string name;
+ private string nsuri;
+ private XmlNodeType nodetype;
+ private object source;
+ private string text;
+
+ internal XmlNodeEventArgs(int linenumber, int lineposition, string localname, string name, string nsuri,
+ XmlNodeType nodetype, object source, string text)
+ {
+ this.linenumber = linenumber;
+ this.lineposition = lineposition;
+ this.localname = localname;
+ this.name = name;
+ this.nsuri = nsuri;
+ this.nodetype = nodetype;
+ this.source = source;
+ this.text = text;
+ }
+
+ public int LineNumber + {
+ get { return linenumber; }
+ } +
+ public int LinePosition + {
+ get { return lineposition; }
+ }
+
+ public string LocalName + {
+ get { return localname; }
+ }
+
+ public string Name + {
+ get { return name; }
+ }
+
+ public string NamespaceURI + {
+ get { return nsuri; }
+ }
+
+ public XmlNodeType NodeType + {
+ get { return nodetype; }
+ }
+
+ public object ObjectBeingDeserialized + {
+ get { return source; }
+ }
+
+ public string Text + {
+ get { return text; }
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlNodeEventHandler.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlNodeEventHandler.cs new file mode 100755 index 00000000000..4c1fdb5c92b --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlNodeEventHandler.cs @@ -0,0 +1,16 @@ +// +// XmlNodeEventHandler.cs: +// +// Author: +// Miguel de Icaza (miguel@ximian.com) +// +// (C) 2002 Ximian, Inc. +// +using System; + +namespace System.Xml.Serialization { + + [Serializable] + public delegate void XmlNodeEventHandler (object sender, XmlNodeEventArgs e); +} + diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs new file mode 100644 index 00000000000..108a50b2929 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs @@ -0,0 +1,128 @@ +//
+// System.Xml.Serialization.XmlReflectionImporter
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2002
+//
+
+using System.Reflection;
+
+namespace System.Xml.Serialization {
+ public class XmlReflectionImporter {
+
+ string defaultNamespace;
+ XmlAttributeOverrides attributeOverrides;
+
+ #region Constructors
+
+ public XmlReflectionImporter ()
+ : this (null, null)
+ {
+ }
+
+ public XmlReflectionImporter (string defaultNamespace)
+ : this (null, defaultNamespace)
+ {
+ }
+
+ public XmlReflectionImporter (XmlAttributeOverrides attributeOverrides)
+ : this (attributeOverrides, null)
+ {
+ }
+
+ public XmlReflectionImporter (XmlAttributeOverrides attributeOverrides, string defaultNamespace)
+ {
+ if (defaultNamespace == null)
+ this.defaultNamespace = String.Empty;
+ else
+ this.defaultNamespace = defaultNamespace;
+
+ if (attributeOverrides == null)
+ this.attributeOverrides = new XmlAttributeOverrides();
+ else
+ this.attributeOverrides = attributeOverrides;
+ }
+
+ #endregion // Constructors
+
+ #region Methods
+
+ [MonoTODO]
+ public XmlMembersMapping ImportMembersMapping (string elementName,
+ string ns,
+ XmlReflectionMember [] members,
+ bool hasWrapperElement)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public XmlTypeMapping ImportTypeMapping (Type type)
+ {
+ return ImportTypeMapping (type, null, null);
+ }
+
+ public XmlTypeMapping ImportTypeMapping (Type type, string defaultNamespace)
+ {
+ return ImportTypeMapping (type, null, defaultNamespace);
+ }
+
+ public XmlTypeMapping ImportTypeMapping (Type type, XmlRootAttribute group)
+ {
+ return ImportTypeMapping (type, group, null);
+ }
+
+ public XmlTypeMapping ImportTypeMapping (Type type, XmlRootAttribute group, string defaultNamespace)
+ {
+ if (type == null)
+ throw new ArgumentNullException ("type");
+
+ if (type == typeof (void))
+ throw new InvalidOperationException ("Type " + type.Name +
+ " may not be serialized.");
+
+ XmlAttributes atts = new XmlAttributes (type);
+ TypeData data = TypeTranslator.GetTypeData (type);
+ string elementName = data.ElementName;
+ string typeName = data.TypeName;
+ string typeFullName = data.FullTypeName;
+ string nameSpc = (defaultNamespace != null) ? defaultNamespace : this.defaultNamespace;
+ return new XmlTypeMapping (elementName, nameSpc, typeFullName, typeName);
+ }
+
+ private void ImportTypeMapping (TypeData data, string ns)
+ {
+ ImportTypeMapping (data.Type, null, ns);
+ }
+
+ public void IncludeType (Type type)
+ {
+ if (type == null)
+ throw new ArgumentNullException ("type");
+
+ TypeData data = TypeTranslator.GetTypeData (type);
+ ImportTypeMapping (data, defaultNamespace);
+ }
+
+ public void IncludeTypes (ICustomAttributeProvider provider)
+ {
+ if (provider == null)
+ throw new ArgumentNullException ("provider");
+
+ Type ixml = typeof (IXmlSerializable);
+ object [] customAttrs = provider.GetCustomAttributes (typeof (XmlIncludeAttribute), false);
+ foreach (XmlIncludeAttribute att in customAttrs) {
+ Type type = att.Type;
+ if (ixml.IsAssignableFrom (type)) {
+ string fmt = "Type {0} is derived from {1} and therefore cannot " +
+ "be used with attribute XmlInclude";
+ throw new InvalidOperationException (String.Format (fmt, type, ixml));
+ }
+ IncludeType (type);
+ }
+ }
+
+ #endregion // Methods
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionMember.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionMember.cs new file mode 100644 index 00000000000..43ba1a82e9b --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionMember.cs @@ -0,0 +1,66 @@ +//
+// System.Xml.Serialization.XmlReflectionMember
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2002
+//
+
+namespace System.Xml.Serialization {
+ public class XmlReflectionMember {
+
+ #region Fields
+
+ bool isReturnValue;
+ string memberName;
+ Type memberType;
+ bool overrideIsNullable;
+ SoapAttributes soapAttributes;
+ XmlAttributes xmlAttributes;
+
+ #endregion
+
+ #region Constructors
+
+ public XmlReflectionMember ()
+ {
+ }
+
+ #endregion // Constructors
+
+ #region Properties
+
+ public bool IsReturnValue {
+ get { return isReturnValue; }
+ set { isReturnValue = value; }
+ }
+
+ public string MemberName {
+ get { return memberName; }
+ set { memberName = value; }
+ }
+
+ public Type MemberType {
+ get { return memberType; }
+ set { memberType = value; }
+ }
+
+ public bool OverrideIsNullable {
+ get { return overrideIsNullable; }
+ set { overrideIsNullable = value; }
+ }
+
+ public SoapAttributes SoapAttributes {
+ get { return soapAttributes; }
+ set { soapAttributes = value; }
+ }
+
+ public XmlAttributes XmlAttributes {
+ get { return xmlAttributes; }
+ set { xmlAttributes = value; }
+ }
+
+ #endregion // Properties
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlRootAttribute.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlRootAttribute.cs new file mode 100644 index 00000000000..cc3a83c1b9f --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlRootAttribute.cs @@ -0,0 +1,73 @@ +// +// XmlRootAttribute.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlRootAttribute.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct |
+ AttributeTargets.Enum | AttributeTargets.Interface |
+ AttributeTargets.ReturnValue)]
+ public class XmlRootAttribute : Attribute
+ {
+ private string dataType;
+ private string elementName;
+ private bool isNullable;
+ private string ns;
+
+ public XmlRootAttribute ()
+ {
+
+ }
+ public XmlRootAttribute (string elementName)
+ {
+ ElementName = elementName;
+ }
+
+ public string DataType
+ {
+ get {
+ return dataType;
+ }
+ set {
+ dataType = value;
+ }
+ }
+ public string ElementName
+ {
+ get {
+ return elementName;
+ }
+ set {
+ elementName = value;
+ }
+ }
+ public bool IsNullable
+ {
+ get {
+ return isNullable;
+ }
+ set {
+ isNullable = value;
+ }
+ }
+ public string Namespace
+ {
+ get {
+ return ns;
+ }
+ set {
+ ns = value;
+ }
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlSchemaExporter.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlSchemaExporter.cs new file mode 100644 index 00000000000..991bbce1b3e --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlSchemaExporter.cs @@ -0,0 +1,58 @@ +//
+// System.Xml.Serialization.XmlSchemaExporter
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2002
+//
+
+using System.Xml;
+
+namespace System.Xml.Serialization {
+ public class XmlSchemaExporter {
+
+ #region Fields
+
+ XmlSchemas schemas;
+
+ #endregion
+
+ #region Constructors
+
+ public XmlSchemaExporter (XmlSchemas schemas)
+ {
+ this.schemas = schemas;
+ }
+
+ #endregion // Constructors
+
+ #region Methods
+
+ [MonoTODO]
+ public string ExportAnyType (string ns)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public void ExportMembersMapping (XmlMembersMapping xmlMembersMapping)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public XmlQualifiedName ExportTypeMapping (XmlMembersMapping xmlMembersMapping)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public void ExportTypeMapping (XmlTypeMapping xmlTypeMapping)
+ {
+ throw new NotImplementedException ();
+ }
+
+ #endregion // Methods
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlSchemaImporter.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlSchemaImporter.cs new file mode 100644 index 00000000000..fd0df8faadc --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlSchemaImporter.cs @@ -0,0 +1,91 @@ +//
+// System.Xml.Serialization.XmlSchemaImporter
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2002
+//
+
+using System.Xml;
+
+namespace System.Xml.Serialization {
+ public class XmlSchemaImporter {
+
+ #region Fields
+
+ XmlSchemas schemas;
+ CodeIdentifiers typeIdentifiers;
+
+ #endregion
+
+ #region Constructors
+
+ public XmlSchemaImporter (XmlSchemas schemas)
+ {
+ this.schemas = schemas;
+ }
+
+ public XmlSchemaImporter (XmlSchemas schemas, CodeIdentifiers typeIdentifiers)
+ : this (schemas)
+ {
+ this.typeIdentifiers = typeIdentifiers;
+ }
+
+ #endregion // Constructors
+
+ #region Methods
+
+ [MonoTODO]
+ public XmlMembersMapping ImportAnyType (XmlQualifiedName typeName, string elementName)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public XmlTypeMapping ImportDerivedTypeMapping (XmlQualifiedName name, Type baseType)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public XmlTypeMapping ImportDerivedTypeMapping (XmlQualifiedName name, bool baseTypeCanBeIndirect)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public XmlTypeMapping ImportDerivedTypeMapping (XmlQualifiedName name,
+ Type baseType,
+ bool baseTypeCanBeIndirect)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public XmlMembersMapping ImportMembersMapping (XmlQualifiedName name)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public XmlMembersMapping ImportMembersMapping (XmlQualifiedName[] names)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public XmlMembersMapping ImportMembersMapping (XmlQualifiedName[] names, Type baseType, bool baseTypeCanBeIndirect)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ public XmlTypeMapping ImportTypeMapping (XmlQualifiedName name)
+ {
+ throw new NotImplementedException ();
+ }
+
+ #endregion // Methods
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlSchemas.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlSchemas.cs new file mode 100644 index 00000000000..0918f928489 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlSchemas.cs @@ -0,0 +1,148 @@ +//
+// System.Xml.Serialization.XmlSchemas
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2002
+//
+
+using System.Collections;
+using System.Xml.Schema;
+
+namespace System.Xml.Serialization {
+ public class XmlSchemas : CollectionBase {
+
+ #region Fields
+
+ Hashtable table = new Hashtable ();
+
+ #endregion
+
+ #region Constructors
+
+ public XmlSchemas ()
+ {
+ }
+
+ #endregion // Constructors
+
+ #region Properties
+
+ public XmlSchema this [int index] {
+ get {
+ if (index < 0 || index > Count)
+ throw new ArgumentOutOfRangeException ();
+
+ return (XmlSchema) List [index];
+ }
+ set { List [index] = value; }
+ }
+
+ public XmlSchema this [string ns] {
+ get { return (XmlSchema) table[ns]; }
+ }
+
+ #endregion // Properties
+
+ #region Methods
+
+ public int Add (XmlSchema schema)
+ {
+ Insert (Count, schema);
+ return (Count - 1);
+ }
+
+ public void Add (XmlSchemas schemas)
+ {
+ foreach (XmlSchema schema in schemas)
+ Add (schema);
+ }
+
+ public bool Contains (XmlSchema schema)
+ {
+ return List.Contains (schema);
+ }
+
+ public void CopyTo (XmlSchema[] array, int index)
+ {
+ 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);
+ }
+
+ public void Insert (int index, XmlSchema schema)
+ {
+ List.Insert (index, schema);
+ }
+
+ [MonoTODO]
+ public static bool IsDataSet (XmlSchema schema)
+ {
+ throw new NotImplementedException ();
+ }
+
+ protected override void OnClear ()
+ {
+ table.Clear ();
+ }
+
+ protected override void OnInsert (int index, object value)
+ {
+ table [((XmlSchema) value).TargetNamespace] = value;
+ }
+
+ protected override void OnRemove (int index, object value)
+ {
+ table.Remove (value);
+ }
+
+ protected override void OnSet (int index, object oldValue, object newValue)
+ {
+ table [((XmlSchema) oldValue).TargetNamespace] = newValue;
+ }
+
+ public void Remove (XmlSchema schema)
+ {
+ List.Remove (schema);
+ }
+
+ #endregion // Methods
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationCollectionFixupCallback.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationCollectionFixupCallback.cs new file mode 100644 index 00000000000..2fd79643126 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationCollectionFixupCallback.cs @@ -0,0 +1,17 @@ +// +// System.Xml.Serialization.XmlSerializationCollectionFixupCallback.cs: +// +// Author: +// Tim Coleman (tim@timcoleman.com) +// +// Copyright (C) Tim Coleman, 2002 +// + +using System; + +namespace System.Xml.Serialization { + + [Serializable] + public delegate void XmlSerializationCollectionFixupCallback (object collection, object collectionItems); +} + diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationFixupCallback.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationFixupCallback.cs new file mode 100644 index 00000000000..e1bf47a4fa5 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationFixupCallback.cs @@ -0,0 +1,17 @@ +// +// System.Xml.Serialization.XmlSerializationFixupCallback.cs: +// +// Author: +// Tim Coleman (tim@timcoleman.com) +// +// Copyright (C) Tim Coleman, 2002 +// + +using System; + +namespace System.Xml.Serialization { + + [Serializable] + public delegate void XmlSerializationFixupCallback (object fixup); +} + diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReadCallback.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReadCallback.cs new file mode 100644 index 00000000000..bd426ff0415 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReadCallback.cs @@ -0,0 +1,17 @@ +// +// System.Xml.Serialization.XmlSerializationReadCallback.cs: +// +// Author: +// Tim Coleman (tim@timcoleman.com) +// +// Copyright (C) Tim Coleman, 2002 +// + +using System; + +namespace System.Xml.Serialization { + + [Serializable] + public delegate object XmlSerializationReadCallback (); +} + diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReader.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReader.cs new file mode 100644 index 00000000000..1ffff04a79b --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReader.cs @@ -0,0 +1,634 @@ +// +// System.Xml.Serialization.XmlSerializationReader.cs +// +// Authors: +// Tim Coleman (tim@timcoleman.com) +// Gonzalo Paniagua Javier (gonzalo@ximian.com) +// +// Copyright (C) Tim Coleman, 2002 +// (c) 2002 Ximian, Inc. (http://www.ximian.com) +// + +using System; +using System.Collections; +using System.Xml; + +namespace System.Xml.Serialization { + public abstract class XmlSerializationReader { + + #region Fields + + XmlDocument document; + XmlReader reader; + ArrayList fixups; + ArrayList collFixups; + Hashtable readCallbacks; + Hashtable typesCallbacks; + ArrayList noIDTargets; + Hashtable targets; + + 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; + #endregion + + private void Initialize () + { + w3SchemaNS = reader.NameTable.Add ("http://www.w3.org/2001/XMLSchema"); + 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 ("http://www.w3.org/2001/XMLSchema-instance"); + 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 ("http://schemas.xmlsoap.org/soap/encoding/"); + schema = reader.NameTable.Add ("schema"); + wsdlNS = reader.NameTable.Add ("http://schemas.xmlsoap.org/wsdl/"); + 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"); + InitIDs (); + } + + private ArrayList EnsureArrayList (ArrayList list) + { + if (list == null) + list = new ArrayList (); + return list; + } + + private Hashtable EnsureHashtable (Hashtable hash) + { + if (hash == null) + hash = new Hashtable (); + return hash; + } + + protected XmlSerializationReader () + { + } + + protected XmlDocument Document + { + get { + if (document == null) + document = new XmlDocument (reader.NameTable); + + return document; + } + } + + protected XmlReader Reader { + get { return reader; } + } + + #region Methods + + protected void AddFixup (CollectionFixup fixup) + { + collFixups = EnsureArrayList (collFixups); + collFixups.Add(fixup); + } + + protected void AddFixup (Fixup fixup) + { + fixups = EnsureArrayList (fixups); + fixups.Add(fixup); + } + + protected void AddReadCallback (string name, string ns, Type type, XmlSerializationReadCallback read) + { + XmlNameTable nt = reader.NameTable; + XmlQualifiedName xqn = new XmlQualifiedName (nt.Add (name), nt.Add (ns)); + readCallbacks = EnsureHashtable (readCallbacks); + readCallbacks.Add (xqn, read); + typesCallbacks = EnsureHashtable (typesCallbacks); + typesCallbacks.Add (xqn, type); + } + + protected void AddTarget (string id, object o) + { + if (id != null) { + targets = EnsureHashtable (targets); + if (targets [id] == null) + targets.Add (id, o); + } else { + if (o != null) + return; + noIDTargets = EnsureArrayList (noIDTargets); + noIDTargets.Add (o); + } + } + + private string CurrentTag () + { + switch (reader.NodeType) { + case XmlNodeType.None: + return String.Format ("<{0} xmlns='{1}'>", reader.LocalName, + reader.NamespaceURI); + case XmlNodeType.Attribute: + return reader.Value; + case XmlNodeType.Text: + return "CDATA"; + case XmlNodeType.ProcessingInstruction: + return "<--"; + case XmlNodeType.Entity: + return "<?"; + case XmlNodeType.EndElement: + return ">"; + default: + return "(unknown)"; + } + } + + protected Exception CreateAbstractTypeException (string name, string ns) + { + string message = "Error at " + name + " " + ns + ":" + CurrentTag (); + return new InvalidOperationException (message); + } + + protected Exception CreateInvalidCastException (Type type, object value) + { + string message = String.Format ("Cannot assign object of type {0} to an object of " + + "type {1}.", value.GetType (), type); + return new InvalidCastException (message); + } + + protected Exception CreateReadOnlyCollectionException (string name) + { + string message = String.Format ("Could not serialize {0}. Default constructors are " + + "required for collections and enumerators.", name); + return new InvalidOperationException (message); + } + + protected Exception CreateUnknownConstantException (string value, Type enumType) + { + string message = String.Format ("'{0}' is not a valid value for {1}.", value, enumType); + return new InvalidOperationException (message); + } + + protected Exception CreateUnknownNodeException () + { + string message = "Unknown xml node -> " + CurrentTag (); + return new InvalidOperationException (message); + } + + protected Exception CreateUnknownTypeException (XmlQualifiedName type) + { + string message = "Unknown type " + type.Namespace + ":" + type.Name + " " + CurrentTag (); + return new InvalidOperationException (message); + } + + protected Array EnsureArrayIndex (Array a, int index, Type elementType) + { + if (a != null && index < a.Length) + return a; + + int size; + if (a == null) { + size = 32; + } else { + size = a.Length * 2; + } + + Array result = Array.CreateInstance (elementType, size); + if (a != null) + Array.Copy (a, result, index); + + return result; + } + + [MonoTODO ("Implement")] + protected void FixupArrayRefs (object fixup) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected int GetArrayLength (string name, string ns) + { + throw new NotImplementedException (); + } + + protected bool GetNullAttr () + { + string na = reader.GetAttribute (nullX, w3InstanceNS); + if (na == null) { + na = reader.GetAttribute (nil, w3InstanceNS); + if (na == null) { + na = reader.GetAttribute (nullX, w3InstanceNS2000); + if (na == null) + na = reader.GetAttribute (nullX, w3InstanceNS1999); + } + } + return (na != null); + } + + [MonoTODO ("Implement")] + protected object GetTarget (string id) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected XmlQualifiedName GetXsiType () + { + throw new NotImplementedException (); + } + + protected abstract void InitCallbacks (); + protected abstract void InitIDs (); + + protected bool IsXmlnsAttribute (string name) + { + int length = name.Length; + if (length < 5) + return false; + + if (length == 5) + return (name == "xmlns"); + + return name.StartsWith ("xmlns:"); + } + + [MonoTODO ("Implement")] + protected void ParseWsdlArrayType (XmlAttribute attr) + { + throw new NotImplementedException (); + } + + protected XmlQualifiedName ReadElementQualifiedName () + { + if (reader.IsEmptyElement) { + reader.Skip(); + return ToXmlQualifiedName (String.Empty); + } + + XmlQualifiedName xqn = ToXmlQualifiedName(reader.ReadString ()); + reader.ReadEndElement (); + return xqn; + } + + protected void ReadEndElement () + { + while (reader.NodeType == XmlNodeType.Whitespace) + reader.Skip (); + + if (reader.NodeType != XmlNodeType.None) { + reader.ReadEndElement (); + } else { + reader.Skip (); + } + } + + protected bool ReadNull () + { + if (!GetNullAttr ()) + return false; + + if (reader.IsEmptyElement) { + reader.Skip(); + return true; + } + + reader.ReadStartElement(); + while (reader.NodeType != XmlNodeType.EndElement) + UnknownNode (null); + ReadEndElement (); + return true; + } + + protected XmlQualifiedName ReadNullableQualifiedName () + { + if (ReadNull ()) + return null; + + return ReadElementQualifiedName (); + } + + protected string ReadNullableString () + { + if (ReadNull ()) + return null; + + return reader.ReadElementString (); + } + + protected bool ReadReference (out string fixupReference) + { + string href = reader.GetAttribute ("href"); + if (href == null) { + fixupReference = null; + return false; + } + + if (href [0] != '#') + throw new InvalidOperationException("href not found: " + href); + + fixupReference = href.Substring (1); + if (!reader.IsEmptyElement) { + reader.ReadStartElement (); + ReadEndElement (); + } else { + reader.Skip (); + } + return true; + } + + protected object ReadReferencedElement () + { + return ReadReferencedElement (null, null); + } + + protected object ReadReferencedElement (string name, string ns) + { + string unused; + return ReadReferencingElement (name, ns, false, out unused); + } + + protected void ReadReferencedElements () + { + string unused; + + reader.MoveToContent(); + XmlNodeType nt = reader.NodeType; + while (nt != XmlNodeType.EndElement && nt != XmlNodeType.None) { + ReadReferencingElement (null, null, true, out unused); + reader.MoveToContent (); + nt = reader.NodeType; + } + } + + [MonoTODO ("Implement")] + protected object ReadReferencingElement (out string fixupReference) + { + return ReadReferencingElement (null, null, false, out fixupReference); + } + + protected object ReadReferencingElement (string name, string ns, out string fixupReference) + { + return ReadReferencingElement (name, ns, false, out fixupReference); + } + + [MonoTODO] + protected object ReadReferencingElement (string name, + string ns, + bool elementCanBeType, + out string fixupReference) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected IXmlSerializable ReadSerializable (IXmlSerializable serializable) + { + throw new NotImplementedException (); + } + + protected string ReadString (string value) + { + if (value == null || value == String.Empty) + return reader.ReadString (); + + return (value + reader.ReadString ()); + } + + [MonoTODO ("Implement")] + protected object ReadTypedPrimitive (XmlQualifiedName type) + { + throw new NotImplementedException (); + } + + protected XmlNode ReadXmlNode (bool wrapped) + { + return document.ReadNode (reader); + } + + [MonoTODO ("Implement")] + protected void Referenced (object o) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected Array ShrinkArray (Array a, int length, Type elementType, bool isNullable) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected byte[] ToByteArrayBase64 (bool isNull) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected static byte[] ToByteArrayBase64 (string value) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected byte[] ToByteArrayHex (bool isNull) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected static byte[] ToByteArrayHex (string value) + { + throw new NotImplementedException (); + } + + protected static char ToChar (string value) + { + return XmlCustomFormatter.ToChar (value); + } + + protected static DateTime ToDate (string value) + { + return XmlCustomFormatter.ToDate (value); + } + + protected static DateTime ToDateTime (string value) + { + return XmlCustomFormatter.ToDateTime (value); + } + + [MonoTODO ("Implement")] + protected static long ToEnum (string value, Hashtable h, string typeName) + { + throw new NotImplementedException (); + } + + protected static DateTime ToTime (string value) + { + return XmlCustomFormatter.ToTime (value); + } + + protected static string ToXmlName (string value) + { + return XmlCustomFormatter.ToXmlName (value); + } + + protected static string ToXmlNCName (string value) + { + return XmlCustomFormatter.ToXmlNCName (value); + } + + protected static string ToXmlNmToken (string value) + { + return XmlCustomFormatter.ToXmlNmToken (value); + } + + protected static string ToXmlNmTokens (string value) + { + return XmlCustomFormatter.ToXmlNmTokens (value); + } + + protected XmlQualifiedName ToXmlQualifiedName (string value) + { + string name; + string ns; + int lastColon = value.LastIndexOf (':'); + string decodedValue = XmlConvert.DecodeName (value); + if (lastColon < 0) { + name = reader.NameTable.Add (decodedValue); + ns = reader.LookupNamespace (String.Empty); + } else { + string prefix = value.Substring (0, lastColon); + ns = reader.LookupNamespace (prefix); + if (ns == null) + throw new InvalidOperationException ("namespace " + prefix + "not defined"); + + name = reader.NameTable.Add (value.Substring (lastColon + 1)); + } + + return new XmlQualifiedName (name, ns); + } + + [MonoTODO ("Implement")] + protected void UnknownAttribute (object o, XmlAttribute attr) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected void UnknownElement (object o, XmlElement elem) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected void UnknownNode (object o) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected void UnreferencedObject (string id, object o) + { + throw new NotImplementedException (); + } + + #endregion // Methods + + protected class CollectionFixup { + + #region Fields + + XmlSerializationCollectionFixupCallback callback; + object collection; + object collectionItems; + + #endregion // Fields + + #region Constructors + + [MonoTODO] + public CollectionFixup (object collection, XmlSerializationCollectionFixupCallback callback, object collectionItems) + { + this.callback = callback; + this.collection = collection; + this.collectionItems = collectionItems; + } + + #endregion // Constructors + + #region Properties + + public XmlSerializationCollectionFixupCallback Callback { + get { return callback; } + } + + public object Collection { + get { return collection; } + } + + public object CollectionItems { + get { return collectionItems; } + } + + #endregion // Properties + } + + protected class Fixup { + + #region Fields + + object source; + string[] ids; + XmlSerializationFixupCallback callback; + + #endregion // Fields + + #region Constructors + + [MonoTODO] + public Fixup (object o, XmlSerializationFixupCallback callback, int count) + { + this.callback = callback; + } + + [MonoTODO] + public Fixup (object o, XmlSerializationFixupCallback callback, string[] ids) + { + this.callback = callback; + } + + #endregion // Constructors + + #region Properties + + public XmlSerializationFixupCallback Callback { + get { return callback; } + } + + public string[] Ids { + get { return ids; } + } + + public object Source { + get { return source; } + set { source = value; } + } + + #endregion // Properties + } + } +} + diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriteCallback.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriteCallback.cs new file mode 100644 index 00000000000..8da2224c979 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriteCallback.cs @@ -0,0 +1,17 @@ +// +// System.Xml.Serialization.XmlSerializationWriteCallback.cs: +// +// Author: +// Tim Coleman (tim@timcoleman.com) +// +// Copyright (C) Tim Coleman, 2002 +// + +using System; + +namespace System.Xml.Serialization { + + [Serializable] + public delegate void XmlSerializationWriteCallback (object o); +} + diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriter.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriter.cs new file mode 100644 index 00000000000..6dc637b70ed --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriter.cs @@ -0,0 +1,571 @@ +// +// System.Xml.Serialization.XmlSerializationWriter.cs +// +// Author: +// Tim Coleman (tim@timcoleman.com) +// +// Copyright (C) Tim Coleman, 2002 +// + +using System; +using System.Collections; +using System.Text; +using System.Xml; +using System.Xml.Schema; + +namespace System.Xml.Serialization { + public abstract class XmlSerializationWriter { + + #region Fields + + Hashtable references; + int referenceCount; + int qnameCount; + + ArrayList namespaces; + XmlWriter writer; + + #endregion // Fields + + #region Constructors + + [MonoTODO] + protected XmlSerializationWriter () + { + qnameCount = 0; + references = new Hashtable (); + referenceCount = 0; + } + + #endregion // Constructors + + #region Properties + + protected ArrayList Namespaces { + get { return namespaces; } + set { namespaces = value; } + } + + protected XmlWriter Writer { + get { return writer; } + set { writer = value; } + } + + #endregion // Properties + + #region Methods + + [MonoTODO ("Implement")] + protected void AddWriteCallback (Type type, string typeName, string typeNs, XmlSerializationWriteCallback callback) + { + throw new NotImplementedException (); + } + + protected Exception CreateMismatchChoiceException (string value, string elementName, string enumValue) + { + string message = String.Format ("Value of {0} mismatches the type of {1}, you need to set it to {2}.", elementName, value, enumValue); + return new InvalidOperationException (message); + } + + protected Exception CreateUnknownAnyElementException (string name, string ns) + { + string message = String.Format ("The XML element named '{0}' from namespace '{1}' was not expected. The XML element name and namespace must match those provided via XmlAnyElementAttribute(s).", name, ns); + return new InvalidOperationException (message); + } + + protected Exception CreateUnknownTypeException (object o) + { + return CreateUnknownTypeException (o.GetType ()); + } + + protected Exception CreateUnknownTypeException (Type type) + { + string message = String.Format ("The type {0} may not be used in this context.", type); + return new InvalidOperationException (message); + } + + protected static byte[] FromByteArrayBase64 (byte[] value) + { + return XmlCustomFormatter.FromByteArrayBase64 (value); + } + + protected static string FromByteArrayHex (byte[] value) + { + return XmlCustomFormatter.FromByteArrayHex (value); + } + + protected static string FromChar (char value) + { + return XmlCustomFormatter.FromChar (value); + } + + protected static string FromDate (DateTime value) + { + return XmlCustomFormatter.FromDate (value); + } + + protected static string FromDateTime (DateTime value) + { + return XmlCustomFormatter.FromDateTime (value); + } + + protected static string FromEnum (long value, string[] values, long[] ids) + { + return XmlCustomFormatter.FromEnum (value, values, ids); + } + + protected static string FromTime (DateTime value) + { + return XmlCustomFormatter.FromTime (value); + } + + protected static string FromXmlName (string name) + { + return XmlCustomFormatter.FromXmlName (name); + } + + protected static string FromXmlNCName (string ncName) + { + return XmlCustomFormatter.FromXmlNCName (ncName); + } + + protected static string FromXmlNmToken (string nmToken) + { + return XmlCustomFormatter.FromXmlNmToken (nmToken); + } + + protected static string FromXmlNmTokens (string nmTokens) + { + return XmlCustomFormatter.FromXmlNmTokens (nmTokens); + } + + [MonoTODO ("Implement")] + protected string FromXmlQualifiedName (XmlQualifiedName xmlQualifiedName) + { + return GetQualifiedName (xmlQualifiedName.Name, xmlQualifiedName.Namespace); + } + + private string GetId (object o, bool addToReferencesList) + { + referenceCount += 1; + string id = String.Format ("id{0}", referenceCount); + if (addToReferencesList) + references[o] = id; + return id; + } + + [MonoTODO ("Complete this list.")] + private string GetPrimitiveTypeName (Type type) + { + if (type == typeof (string)) + return "string"; + if (type == typeof (bool)) + return "Boolean"; + if (type == typeof (float)) + return "float"; + if (type == typeof (double)) + return "double"; + if (type == typeof (XmlQualifiedName)) + return "QName"; + + return String.Empty; + } + + [MonoTODO ("Need to check for namespace conflicts before blindly allocating qN")] + private string GetQualifiedName (string name, string ns) + { + qnameCount += 1; + string prefix = String.Format ("q{0}", qnameCount); + + WriteAttribute ("xmlns", prefix, null, ns); + return String.Format ("{0}:{1}", prefix, name); + } + + protected abstract void InitCallbacks (); + + [MonoTODO ("Implement")] + protected void TopLevelElement () + { + throw new NotImplementedException (); + } + + protected void WriteAttribute (string localName, byte[] value) + { + WriteAttribute (localName, String.Empty, value); + } + + protected void WriteAttribute (string localName, string value) + { + WriteAttribute (String.Empty, localName, String.Empty, value); + } + + protected void WriteAttribute (string localName, string ns, byte[] value) + { + Writer.WriteStartAttribute (localName, ns); + WriteValue (value); + Writer.WriteEndAttribute (); + } + + protected void WriteAttribute (string localName, string ns, string value) + { + WriteAttribute (String.Empty, localName, ns, value); + } + + protected void WriteAttribute (string prefix, string localName, string ns, string value) + { + Writer.WriteStartAttribute (prefix, localName, ns); + WriteValue (value); + Writer.WriteEndAttribute (); + } + + [MonoTODO ("Implement")] + protected void WriteElementEncoded (XmlNode node, string name, string ns, bool isNullable, bool any) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected void WriteElementLiteral (XmlNode node, string name, string ns, bool isNullable, bool any) + { + WriteStartElement (name, ns); + node.WriteTo (Writer); + WriteEndElement (); + } + + protected void WriteElementQualifiedName (string localName, XmlQualifiedName value) + { + WriteElementQualifiedName (localName, String.Empty, value, null); + } + + protected void WriteElementQualifiedName (string localName, string ns, XmlQualifiedName value) + { + WriteElementQualifiedName (localName, ns, value, null); + } + + protected void WriteElementQualifiedName (string localName, XmlQualifiedName value, XmlQualifiedName xsiType) + { + WriteElementQualifiedName (localName, String.Empty, value, xsiType); + } + + protected void WriteElementQualifiedName (string localName, string ns, XmlQualifiedName value, XmlQualifiedName xsiType) + { + WriteStartElement (localName, ns); + Writer.WriteString (FromXmlQualifiedName (value)); + WriteEndElement (); + } + + protected void WriteElementString (string localName, string value) + { + WriteElementString (localName, String.Empty, value, null); + } + + protected void WriteElementString (string localName, string ns, string value) + { + WriteElementString (localName, ns, value, null); + } + + protected void WriteElementString (string localName, string value, XmlQualifiedName xsiType) + { + WriteElementString (localName, String.Empty, value, xsiType); + } + + [MonoTODO ("Implement")] + protected void WriteElementString (string localName, string ns, string value, XmlQualifiedName xsiType) + { + if (xsiType != null) { + WriteStartElement (localName, ns); + WriteXsiType (xsiType.Name, xsiType.Namespace); + Writer.WriteString (value); + WriteEndElement (); + } + else + Writer.WriteElementString (localName, ns, value); + } + + protected void WriteElementStringRaw (string localName, byte[] value) + { + WriteElementStringRaw (localName, String.Empty, value, null); + } + + protected void WriteElementStringRaw (string localName, string value) + { + WriteElementStringRaw (localName, String.Empty, value, null); + } + + protected void WriteElementStringRaw (string localName, byte[] value, XmlQualifiedName xsiType) + { + WriteElementStringRaw (localName, String.Empty, value, xsiType); + } + + protected void WriteElementStringRaw (string localName, string ns, byte[] value) + { + WriteElementStringRaw (localName, ns, value, null); + } + + protected void WriteElementStringRaw (string localName, string ns, string value) + { + WriteElementStringRaw (localName, ns, value, null); + } + + protected void WriteElementStringRaw (string localName, string value, XmlQualifiedName xsiType) + { + WriteElementStringRaw (localName, String.Empty, value, null); + } + + [MonoTODO ("Implement")] + protected void WriteElementStringRaw (string localName, string ns, byte[] value, XmlQualifiedName xsiType) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected void WriteElementStringRaw (string localName, string ns, string value, XmlQualifiedName xsiType) + { + WriteStartElement (localName, ns); + + if (xsiType != null) + WriteXsiType (xsiType.Name, xsiType.Namespace); + + Writer.WriteRaw (value); + WriteEndElement (); + } + + protected void WriteEmptyTag (string name) + { + WriteEmptyTag (name, String.Empty); + } + + [MonoTODO ("Verify")] + protected void WriteEmptyTag (string name, string ns) + { + Writer.WriteStartElement (name, ns); + Writer.WriteEndElement (); + } + + protected void WriteEndElement () + { + WriteEndElement (null); + } + + [MonoTODO ("Implement")] + protected void WriteEndElement (object o) + { + Writer.WriteEndElement (); + } + + protected void WriteId (object o) + { + 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) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected void WriteNullableQualifiedNameLiteral (string name, string ns, XmlQualifiedName value) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected void WriteNullableStringEncoded (string name, string ns, string value, XmlQualifiedName xsiType) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected void WriteNullableStringEncodedRaw (string name, string ns, byte[] value, XmlQualifiedName xsiType) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected void WriteNullableStringEncodedRaw (string name, string ns, string value, XmlQualifiedName xsiType) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected void WriteNullableStringLiteral (string name, string ns, string value) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected void WriteNullableStringLiteralRaw (string name, string ns, byte[] value) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected void WriteNullableStringLiteralRaw (string name, string ns, string value) + { + throw new NotImplementedException (); + } + + protected void WriteNullTagEncoded (string name) + { + WriteNullTagEncoded (name, String.Empty); + } + + [MonoTODO ("Implement")] + protected void WriteNullTagEncoded (string name, string ns) + { + throw new NotImplementedException (); + } + + protected void WriteNullTagLiteral (string name) + { + WriteNullTagLiteral (name, String.Empty); + } + + [MonoTODO ("Implement")] + protected void WriteNullTagLiteral (string name, string ns) + { + throw new NotImplementedException (); + } + + protected void WritePotentiallyReferencingElement (string n, string ns, object o) + { + WritePotentiallyReferencingElement (n, ns, o, null, false, false); + } + + protected void WritePotentiallyReferencingElement (string n, string ns, object o, Type ambientType) + { + WritePotentiallyReferencingElement (n, ns, o, ambientType, false, false); + } + + protected void WritePotentiallyReferencingElement (string n, string ns, object o, Type ambientType, bool suppressReference) + { + WritePotentiallyReferencingElement (n, ns, o, ambientType, suppressReference, false); + } + + [MonoTODO ("Implement")] + protected void WritePotentiallyReferencingElement (string n, string ns, object o, Type ambientType, bool suppressReference, bool isNullable) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected void WriteReferencedElements () + { + throw new NotImplementedException (); + } + + protected void WriteReferencingElement (string n, string ns, object o) + { + WriteReferencingElement (n, ns, o, false); + } + + [MonoTODO ("Implement")] + protected void WriteReferencingElement (string n, string ns, object o, bool isNullable) + { + throw new NotImplementedException (); + } + + [MonoTODO ("Implement")] + protected void WriteSerializable (IXmlSerializable serializable, string name, string ns, bool isNullable) + { + throw new NotImplementedException (); + } + + protected void WriteStartDocument () + { + Writer.WriteStartDocument (); + } + + protected void WriteStartElement (string name) + { + WriteStartElement (name, String.Empty, null, false); + } + + protected void WriteStartElement (string name, string ns) + { + WriteStartElement (name, ns, null, false); + } + + protected void WriteStartElement (string name, string ns, bool writePrefixed) + { + WriteStartElement (name, ns, null, writePrefixed); + } + + protected void WriteStartElement (string name, string ns, object o) + { + WriteStartElement (name, ns, o, false); + } + + [MonoTODO] + protected void WriteStartElement (string name, string ns, object o, bool writePrefixed) + { + if (writePrefixed) + Writer.WriteStartElement (String.Empty, name, ns); + else + Writer.WriteStartElement (name, ns); + } + + protected void WriteTypedPrimitive (string name, string ns, object o, bool xsiType) + { + string value; + + WriteStartElement (name, ns); + + if (o is XmlQualifiedName) + value = FromXmlQualifiedName ((XmlQualifiedName) o); + else + value = o.ToString (); + + if (xsiType) + WriteXsiType (GetPrimitiveTypeName (o.GetType ()), XmlSchema.Namespace); + + WriteValue (value); + WriteEndElement (); + } + + protected void WriteValue (byte[] value) + { + Writer.WriteBase64 (value, 0, value.Length); + } + + protected void WriteValue (string value) + { + Writer.WriteString (value); + } + + protected void WriteXmlAttribute (XmlNode node) + { + WriteXmlAttribute (node, null); + } + + [MonoTODO ("Implement")] + protected void WriteXmlAttribute (XmlNode node, object container) + { + if (!(node is XmlAttribute)) + throw new InvalidOperationException ("The node must be either type XmlAttribute or a derived type."); + throw new NotImplementedException (); + } + + protected void WriteXsiType (string name, string ns) + { + WriteAttribute ("type", XmlSchema.InstanceNamespace, GetQualifiedName (name, ns)); + } + + #endregion + } +} diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs new file mode 100644 index 00000000000..3a5ba0fd1e6 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs @@ -0,0 +1,1012 @@ +// +// Mono Class Libraries +// System.Xml.Serialization.XmlSerializer +// +// Authors: +// John Donagher (john@webmeta.com) +// Ajay kumar Dwivedi (adwiv@yahoo.com) +// Tim Coleman (tim@timcoleman.com) +// +// (C) 2002 John Donagher, Ajay kumar Dwivedi +// Copyright (C) Tim Coleman, 2002 +// + +using System; +using System.Collections; +using System.IO; +using System.Reflection; +using System.Xml; +using System.Xml.Schema; + +namespace System.Xml.Serialization { + /// <summary> + /// Summary description for XmlSerializer. + /// </summary> + public class XmlSerializer { + + #region Fields + + Type xsertype; + XmlAttributeOverrides overrides; + Type[] extraTypes; + XmlRootAttribute rootAttribute; + string defaultNamespace; + Hashtable typeTable; + bool useOrder; + bool isNullable; + Hashtable typeMappings = new Hashtable (); + + #endregion // Fields + + #region Constructors + + protected XmlSerializer () + { + } + + public XmlSerializer (Type type) + : this (type, null, null, null, null) + { + } + + public XmlSerializer (XmlTypeMapping xmlTypeMapping) + { + typeMappings.Add (xmlTypeMapping.TypeFullName, xmlTypeMapping); + } + + public XmlSerializer (Type type, string defaultNamespace) + : this (type, null, null, null, defaultNamespace) + { + } + + public XmlSerializer (Type type, Type[] extraTypes) + : this (type, null, extraTypes, null, null) + { + } + + public XmlSerializer (Type type, XmlAttributeOverrides overrides) + : this (type, overrides, null, null, null) + { + } + + public XmlSerializer (Type type, XmlRootAttribute root) + : this (type, null, null, root, null) + { + } + + internal XmlSerializer (Hashtable typeTable) + { + this.typeTable = typeTable; + } + + public XmlSerializer (Type type, + XmlAttributeOverrides overrides, + Type [] extraTypes, + XmlRootAttribute root, + string defaultNamespace) + { + if (type == null) + throw new ArgumentNullException ("type"); + + XmlReflectionImporter ri = new XmlReflectionImporter (overrides, defaultNamespace); + TypeData td = TypeTranslator.GetTypeData (type); + typeMappings.Add (td.FullTypeName, ri.ImportTypeMapping (type, root, defaultNamespace)); + ri.IncludeTypes (type); + + if (extraTypes != null) { + foreach (Type t in extraTypes) { + td = TypeTranslator.GetTypeData (t); + string n = td.FullTypeName; + typeMappings.Add (n, ri.ImportTypeMapping (type, root, defaultNamespace)); + ri.IncludeTypes (t); + } + } + + this.xsertype = type; + this.overrides = overrides; + this.extraTypes = (extraTypes == null ? new Type[0] : extraTypes); + + if (root != null) + this.rootAttribute = root; + else { + object[] attributes = type.GetCustomAttributes (typeof (XmlRootAttribute), false); + if (attributes.Length > 0) + this.rootAttribute = (XmlRootAttribute) attributes[0]; + } + + this.defaultNamespace = defaultNamespace; + + if (typeTable == null) + typeTable = new Hashtable (); + + FillTypeTable (type); + } + + #endregion // Constructors + + #region Events + + public event XmlAttributeEventHandler UnknownAttribute; + public event XmlElementEventHandler UnknownElement; + public event XmlNodeEventHandler UnknownNode; + public event UnreferencedObjectEventHandler UnreferencedObject; + + #endregion // Events + + #region Properties + + internal bool UseOrder { + get { return useOrder; } + set { useOrder = value; } + } + + #endregion // Properties + + #region Methods + + [MonoTODO] + public virtual bool CanDeserialize (XmlReader xmlReader) + { + throw new NotImplementedException (); + } + + protected virtual XmlSerializationReader CreateReader () + { + // This is what MS does!!! + throw new NotImplementedException (); + } + + protected virtual XmlSerializationWriter CreateWriter () + { + // This is what MS does!!! + throw new NotImplementedException (); + } + + [MonoTODO] + public object Deserialize (Stream stream) + { + throw new NotImplementedException (); + } + [MonoTODO] + public object Deserialize (TextReader textReader) + { + throw new NotImplementedException (); + } + [MonoTODO] + public object Deserialize (XmlReader xmlReader) + { + throw new NotImplementedException (); + } + + protected virtual object Deserialize (XmlSerializationReader reader) + { + // This is what MS does!!! + 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) + { + throw new NotImplementedException (); + } + + public void Serialize (Stream stream, object o) + { + XmlTextWriter xmlWriter = new XmlTextWriter (stream, System.Text.Encoding.Default); + xmlWriter.Formatting = Formatting.Indented; + Serialize (xmlWriter, o, null); + } + + public void Serialize (TextWriter textWriter, object o) + { + XmlTextWriter xmlWriter = new XmlTextWriter (textWriter); + xmlWriter.Formatting = Formatting.Indented; + Serialize (xmlWriter, o, null); + } + + public void Serialize (XmlWriter xmlWriter, object o) + { + Serialize (xmlWriter, o, null); + } + + public void Serialize (Stream stream, object o, XmlSerializerNamespaces namespaces) + { + XmlTextWriter xmlWriter = new XmlTextWriter (stream, System.Text.Encoding.Default); + xmlWriter.Formatting = Formatting.Indented; + Serialize (xmlWriter, o, namespaces); + } + + public void Serialize (TextWriter textWriter, object o, XmlSerializerNamespaces namespaces) + { + XmlTextWriter xmlWriter = new XmlTextWriter (textWriter); + xmlWriter.Formatting = Formatting.Indented; + Serialize (xmlWriter, o, namespaces); + } + + public void Serialize (XmlWriter writer, object o, XmlSerializerNamespaces namespaces) + { + Type objType = xsertype;//o.GetType (); + + if (IsInbuiltType(objType))
+ { + writer.WriteStartDocument (); + SerializeBuiltIn (writer, o); + writer.WriteEndDocument(); + return; + } + + string rootName = objType.Name; + string rootNs = String.Empty; + string rootPrefix = String.Empty; + + if (namespaces == null) + namespaces = new XmlSerializerNamespaces (); + + if (namespaces.Count == 0) { + namespaces.Add ("xsd", XmlSchema.Namespace); + namespaces.Add ("xsi", XmlSchema.InstanceNamespace); + } + + XmlSerializerNamespaces nss = new XmlSerializerNamespaces (); + XmlQualifiedName[] qnames; + + writer.WriteStartDocument (); + object [] memberObj = (object []) typeTable [objType]; + if (memberObj == null) + throw new Exception ("Unknown Type " + objType + + " encountered during Serialization"); + + Hashtable memberTable = (Hashtable) memberObj [0]; + XmlAttributes xmlAttributes = (XmlAttributes) memberTable [""]; + + //If we have been passed an XmlRoot, set it on the base class + if (rootAttribute != null) + xmlAttributes.XmlRoot = rootAttribute; + + if (xmlAttributes.XmlRoot != null) { + isNullable = xmlAttributes.XmlRoot.IsNullable; + if (xmlAttributes.XmlRoot.ElementName != null) + rootName = xmlAttributes.XmlRoot.ElementName; + rootNs = xmlAttributes.XmlRoot.Namespace; + } + + if (namespaces != null && namespaces.GetPrefix (rootNs) != null) + rootPrefix = namespaces.GetPrefix (rootNs); + + //XMLNS attributes in the Root + XmlAttributes XnsAttrs = (XmlAttributes) ((object[]) typeTable[objType])[1]; + + if (XnsAttrs != null) { + MemberInfo member = XnsAttrs.MemberInfo; + FieldInfo fieldInfo = member as FieldInfo; + PropertyInfo propertyInfo = member as PropertyInfo; + XmlSerializerNamespaces xns; + + if (fieldInfo != null) + xns = (XmlSerializerNamespaces) fieldInfo.GetValue (o); + else + xns = (XmlSerializerNamespaces) propertyInfo.GetValue (o, null); + + qnames = xns.ToArray (); + + foreach (XmlQualifiedName qname in qnames) + nss.Add (qname.Name, qname.Namespace); + } + + //XmlNs from the namespaces passed + qnames = namespaces.ToArray (); + foreach (XmlQualifiedName qname in qnames) + if (writer.LookupPrefix (qname.Namespace) != qname.Name) + nss.Add (qname.Name, qname.Namespace); + + writer.WriteStartElement (rootPrefix, rootName, rootNs); + + qnames = nss.ToArray(); + foreach (XmlQualifiedName qname in qnames) + if (writer.LookupPrefix (qname.Namespace) != qname.Name) + writer.WriteAttributeString ("xmlns", qname.Name, null, qname.Namespace); + + if (rootPrefix == String.Empty && rootNs != String.Empty && rootNs != null) + writer.WriteAttributeString (String.Empty, "xmlns", null, rootNs); + + SerializeMembers (writer, o, true);//, namespaces); + + writer.WriteEndDocument (); + } + + private void SerializeBuiltIn (XmlWriter writer, object o) + { + TypeData td = TypeTranslator.GetTypeData (o.GetType ()); + writer.WriteStartElement (td.ElementName); + WriteBuiltinValue(writer,o); + writer.WriteEndElement(); + } + + private void WriteNilAttribute(XmlWriter writer) + { + writer.WriteAttributeString("nil",XmlSchema.InstanceNamespace, "true"); + } + + private void WriteBuiltinValue(XmlWriter writer, object o) + { + if(o == null) + WriteNilAttribute(writer); + else + writer.WriteString (GetXmlValue(o)); + } + + private void SerializeMembers (XmlWriter writer, object o, bool isRoot) + { + if(o == null) + { + WriteNilAttribute(writer); + return; + } + + Type objType = o.GetType (); + + if (IsInbuiltType(objType))
+ { + SerializeBuiltIn (writer, o); + return; + } + + XmlAttributes nsAttributes = (XmlAttributes) ((object[]) typeTable [objType])[1]; + ArrayList attributes = (ArrayList) ((object[]) typeTable [objType])[2]; + ArrayList elements = (ArrayList) ((object[]) typeTable [objType])[3]; + + if (!isRoot && nsAttributes != null) { + MemberInfo member = nsAttributes.MemberInfo; + FieldInfo fieldInfo = member as FieldInfo; + PropertyInfo propertyInfo = member as PropertyInfo; + + XmlSerializerNamespaces xns; + + if (fieldInfo != null) + xns = (XmlSerializerNamespaces) fieldInfo.GetValue (o); + else + xns = (XmlSerializerNamespaces) propertyInfo.GetValue (o, null); + + XmlQualifiedName[] qnames = xns.ToArray (); + foreach (XmlQualifiedName qname in qnames) + if (writer.LookupPrefix (qname.Namespace) != qname.Name) + writer.WriteAttributeString ("xmlns", qname.Name, null, qname.Namespace); + } + + //Serialize the Attributes. + foreach (XmlAttributes xmlAttributes in attributes) { + MemberInfo member = xmlAttributes.MemberInfo; + FieldInfo fieldInfo = member as FieldInfo; + PropertyInfo propertyInfo = member as PropertyInfo; + + Type attributeType; + object attributeValue; + string attributeValueString; + string attributeName; + string attributeNs; + + if (fieldInfo != null) { + attributeType = fieldInfo.FieldType; + attributeValue = fieldInfo.GetValue (o); + } + else { + attributeType = propertyInfo.PropertyType; + attributeValue = propertyInfo.GetValue (o, null); + } + + attributeName = xmlAttributes.GetAttributeName (attributeType, member.Name); + attributeNs = xmlAttributes.GetAttributeNamespace (attributeType); + + if (attributeValue is XmlQualifiedName) { + XmlQualifiedName qname = (XmlQualifiedName) attributeValue; + + if (qname.IsEmpty) + continue; + + writer.WriteStartAttribute (attributeName, attributeNs); + writer.WriteQualifiedName (qname.Name, qname.Namespace); + writer.WriteEndAttribute (); + continue; + } + else if (attributeValue is XmlQualifiedName[]) { + XmlQualifiedName[] qnames = (XmlQualifiedName[]) attributeValue; + writer.WriteStartAttribute (attributeName, attributeNs); + int count = 0; + foreach (XmlQualifiedName qname in qnames) { + if (qname.IsEmpty) + continue; + if (count++ > 0) + writer.WriteWhitespace (" "); + writer.WriteQualifiedName (qname.Name, qname.Namespace); + } + writer.WriteEndAttribute (); + continue; + } + else if (attributeValue is XmlAttribute[]) { + XmlAttribute[] xmlattrs = (XmlAttribute[]) attributeValue; + foreach (XmlAttribute xmlattr in xmlattrs) + xmlattr.WriteTo(writer); + continue; + } + + attributeValueString = GetXmlValue (attributeValue); + if (attributeValueString != GetXmlValue (xmlAttributes.XmlDefaultValue)) + writer.WriteAttributeString (attributeName, attributeNs, attributeValueString); + } + + // Serialize Elements + foreach (XmlAttributes xmlElements in elements) { + MemberInfo member = xmlElements.MemberInfo; + FieldInfo fieldInfo = member as FieldInfo; + PropertyInfo propertyInfo = member as PropertyInfo; + + Type elementType; + object elementValue; + string elementName; + string elementNs; + + if (fieldInfo != null) { + elementType = fieldInfo.FieldType; + elementValue = fieldInfo.GetValue (o); + } + else { + elementType = propertyInfo.PropertyType; + elementValue = propertyInfo.GetValue (o, null); + } + + elementName = xmlElements.GetElementName (elementType, member.Name); + elementNs = xmlElements.GetElementNamespace (elementType); + WriteElement (writer, xmlElements, elementName, elementNs, elementType, elementValue); + } + } + + [MonoTODO ("Remove FIXMEs")] + private void WriteElement (XmlWriter writer, XmlAttributes attrs, string name, string ns, Type type, Object value) + { + //IF the element has XmlText Attribute, the name of the member is not serialized; + if (attrs.XmlText != null && value != null)
+ { + if (type == typeof (object[]))
+ { + foreach(object obj in (object[]) value) + writer.WriteRaw(""+obj); + } + else if (type == typeof (string[]))
+ { + foreach(string str in (string[]) value) + writer.WriteRaw(str); + } + else if (type == typeof (XmlNode))
+ { + ((XmlNode) value).WriteTo (writer); + } + else if (type == typeof (XmlNode[]))
+ { + XmlNode[] nodes = (XmlNode[]) value; + foreach (XmlNode node in nodes) + node.WriteTo (writer); + } + return; + } + + //If not text, serialize as an element + + //Start the element tag + writer.WriteStartElement (name, ns); +
+ if (IsInbuiltType (type))
+ { + WriteBuiltinValue(writer,value); + } + else if (type.IsArray && value != null)
+ { + SerializeArray (writer, value); + } + else if (value is ICollection)
+ { + BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; + + //Find a non indexer Count Property with return type of int + PropertyInfo countInfo = type.GetProperty ("Count", flags, null, typeof (int), new Type[0], null); + PropertyInfo itemInfo = type.GetProperty ("Item", flags, null, null, new Type[1] {typeof (int)}, null); + int count = (int) countInfo.GetValue (value, null); + + if (count > 0) + for (int i = 0; i < count; i++)
+ { + object itemValue = itemInfo.GetValue (value, new object[1] {i}); + Type itemType = itemInfo.PropertyType; + + if (itemValue != null)
+ { + string itemName = attrs.GetElementName (itemValue.GetType (), TypeTranslator.GetTypeData(itemType).ElementName); + string itemNs = attrs.GetElementNamespace (itemValue.GetType ()); + + writer.WriteStartElement (itemName, itemNs); + SerializeMembers (writer, itemValue, false); + writer.WriteEndElement (); + } + } + } + else if (value is IEnumerable)
+ { + // FIXME + } + else if (type.IsEnum)
+ { + // FIXME + } + else
+ { //Complex Type + SerializeMembers (writer, value, false); + } + + // Close the Element + writer.WriteEndElement(); + } + + //Does not take care of any array specific Xml Attributes + [MonoTODO] + private void SerializeArray (XmlWriter writer, object o) + { + Array arr = (o as Array); + if(arr == null || arr.Rank != 1) + throw new ApplicationException("Expected a single dimension Array, Got "+ o); + + Type arrayType = arr.GetType().GetElementType(); + string arrayTypeName = TypeTranslator.GetTypeData(arrayType).ElementName; + + TypeData td = TypeTranslator.GetTypeData (arrayType); + writer.WriteStartElement (td.ElementName); + Console.WriteLine(td.ElementName); + //Special Treatment for Byte array + if(arrayType.Equals(typeof(byte))) + { + WriteBuiltinValue(writer,o); + } + else + { + for(int i=0; i< arr.Length; i++) + { + object value = arr.GetValue(i); + if (IsInbuiltType (arrayType))
+ { + WriteBuiltinValue(writer, value); + } + else + { + SerializeMembers(writer, value, false); + } + } + } + writer.WriteEndElement(); + } + + /// <summary> + /// If the type is a string, valuetype or primitive type we do not populate the TypeTable. + /// If the type is an array, we populate the TypeTable with Element type of the array. + /// If the type implements ICollection, it is handled differently. We do not care for its members. + /// If the type implements IEnumberable, we check that it implements Add(). Don't care for members. + /// </summary> + [MonoTODO ("Remove FIXMEs")] + private void FillTypeTable (Type type) + { + if (typeTable.Contains (type)) + return; + + //For value types and strings we don't need the members. + //FIXME: We will need the enum types probably. + if (IsInbuiltType (type)) + return; + + //Array, ICollection and IEnumberable are treated differenty + if (type.IsArray) { + FillArrayType (type); + return; + } + else if (type.IsEnum) { + FillEnum (type); + return; + } + else { + //There must be a public constructor + if (!HasDefaultConstructor (type)) + throw new Exception ("Can't Serialize Type " + type.Name + " since it does not have default Constructor"); + + if (type.GetInterface ("ICollection") == typeof (System.Collections.ICollection)) { + FillICollectionType (type); + return; + } + if (type.GetInterface ("IEnumerable") == typeof (System.Collections.IEnumerable)) { + //FillIEnumerableType(type); + //return; + } + } + + + //Add the Class to the hashtable. + //Each value of the hashtable has two objects, one is the hashtable with key of membername (for deserialization) + //Other is an Array of XmlSerializernames, Array of XmlAttributes & Array of XmlElements. + Object[] memberObj = new Object[4]; + typeTable.Add (type,memberObj); + + Hashtable memberTable = new Hashtable (); + memberObj[0] = memberTable; + memberTable.Add ("", XmlAttributes.FromClass (type)); + + memberObj[1] = null; + + ArrayList attributes = new ArrayList (); + memberObj[2] = attributes; + + ArrayList elements = new ArrayList (); + memberObj[3] = elements; + + //Get the graph of the members. Graph is nothing but the order + //in which MS implementation serializes the members. + MemberInfo[] minfo = GetGraph (type); + + foreach (MemberInfo member in minfo) { + FieldInfo fieldInfo = (member as FieldInfo); + PropertyInfo propertyInfo = (member as PropertyInfo); + + if (fieldInfo != null) { + //If field is readOnly or const, do not serialize it. + if (fieldInfo.IsLiteral || fieldInfo.IsInitOnly) + continue; + + XmlAttributes xmlAttributes = XmlAttributes.FromField (member, fieldInfo); + + //If XmlAttributes have XmlIgnore, ignore this member + + if (xmlAttributes.XmlIgnore) + continue; + + //If this member is a XmlNs type, set the XmlNs object. + if (xmlAttributes.Xmlns) { + memberObj[1] = xmlAttributes; + continue; + } + + //If the member is a attribute Type, Add to attribute list + if (xmlAttributes.isAttribute) + attributes.Add (xmlAttributes); + else //Add to elements + elements.Add (xmlAttributes); + + //Add in the Hashtable. + memberTable.Add (member.Name, xmlAttributes); + + if (xmlAttributes.XmlAnyAttribute != null || xmlAttributes.XmlText != null) + continue; + + if (xmlAttributes.XmlElements.Count > 0) { + foreach (XmlElementAttribute elem in xmlAttributes.XmlElements) { + if (elem.Type != null) + FillTypeTable (elem.Type); + else + FillTypeTable (fieldInfo.FieldType); + } + continue; + } + + if (!IsInbuiltType (fieldInfo.FieldType)) + FillTypeTable (fieldInfo.FieldType); + } + else if (propertyInfo != null) { + //If property is readonly or writeonly, do not serialize it. + //Exceptions are properties whose return type is array, ICollection or IEnumerable + //Indexers are not serialized unless the class Implements ICollection. + if (!(propertyInfo.PropertyType.IsArray || Implements (propertyInfo.PropertyType, typeof (ICollection)) || + (propertyInfo.PropertyType != typeof (string) && Implements (propertyInfo.PropertyType, typeof (IEnumerable))))) { + if(!(propertyInfo.CanRead && propertyInfo.CanWrite) || propertyInfo.GetIndexParameters ().Length != 0) + continue; + } + + XmlAttributes xmlAttributes = XmlAttributes.FromProperty (member, propertyInfo); + + // If XmlAttributes have XmlIgnore, ignore this member + if (xmlAttributes.XmlIgnore) + continue; + + // If this member is a XmlNs type, set the XmlNs object. + if (xmlAttributes.Xmlns) { + memberObj[1] = xmlAttributes; + continue; + } + // If the member is a attribute Type, Add to attribute list + if (xmlAttributes.isAttribute) + attributes.Add (xmlAttributes); + else //Add to elements + elements.Add (xmlAttributes); + + // OtherWise add in the Hashtable. + memberTable.Add (member.Name, xmlAttributes); + + if (xmlAttributes.XmlAnyAttribute != null || xmlAttributes.XmlText != null) + continue; + + if (xmlAttributes.XmlElements.Count > 0) { + foreach (XmlElementAttribute elem in xmlAttributes.XmlElements) { + if (elem.Type != null) + FillTypeTable (elem.Type); + else + FillTypeTable (propertyInfo.PropertyType); + } + continue; + } + + if (!IsInbuiltType (propertyInfo.PropertyType)) + FillTypeTable (propertyInfo.PropertyType); + } + } + + // Sort the attributes for the members according to their Order + // This is an extension to MS's Implementation and will be useful + // if our reflection does not return the same order of elements + // as MS .NET impl + if (useOrder) + BubbleSort (elements, XmlAttributes.attrComparer); + } + + private void FillArrayType (Type type) + { + if (type.GetArrayRank () != 1) + throw new Exception ("MultiDimensional Arrays are not Supported"); + + Type arrayType = type.GetElementType (); + + if (arrayType.IsArray) + FillArrayType (arrayType); + else if (!IsInbuiltType (arrayType)) + FillTypeTable (arrayType); + } + + private void FillICollectionType (Type type) + { + //Must have an public Indexer that takes an integer and + //a public Count Property which returns an int. + + BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; + + //Find a non indexer Count Property with return type of int + PropertyInfo countProp = type.GetProperty ("Count", flags, null, typeof (int), new Type[0], null); + if (countProp == null || !countProp.CanRead) + throw new Exception ("Cannot Serialize " + type + " because it implements ICollectoion, but does not implement public Count property"); + //Find a indexer Item Property which takes an int + PropertyInfo itemProp = type.GetProperty ("Item", flags, null, null, new Type[1] {typeof (int)}, null); + if (itemProp == null || !itemProp.CanRead || !itemProp.CanWrite) + throw new Exception ("Cannot Serialize " + type + " because it does not have a read/write indexer property that takes an int as argument"); + FillTypeTable (itemProp.PropertyType); + } + + [MonoTODO] + private void FillIEnumerableType (Type type) + { + //Must implement a public Add method that takes a single parameter. + //The Add method's parameter must be of the same type as is returned from + //the Current property on the value returned from GetEnumerator, or one of that type's bases. + + // We currently ignore enumerable types anyway, so this method was junked. + // The code did not do what the documentation above says (if that is even possible!) + return; + } + + private void FillEnum (Type type) + { + Hashtable memberTable = new Hashtable (); + BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; + typeTable.Add (type, memberTable); + string[] names = Enum.GetNames (type); + + foreach (string name in names) { + MemberInfo[] members = type.GetMember (name); + if (members.Length != 1) + throw new Exception("Should never happen. Enum member not present or more than one. " + name); + XmlAttributes xmlAttributes = new XmlAttributes (members[0]); + + if (xmlAttributes.XmlIgnore) + continue; + + if (xmlAttributes.XmlEnum != null) + memberTable.Add (members[0].Name, xmlAttributes.XmlEnum.Name); + else + memberTable.Add (members[0].Name, members[0].Name); + } + } + + private bool HasDefaultConstructor (Type type) + { + ConstructorInfo defaultConstructor = type.GetConstructor (new Type[0]); + if (defaultConstructor == null || defaultConstructor.IsAbstract || defaultConstructor.IsStatic || !defaultConstructor.IsPublic) + return false; + + return true; + } + + private bool IsInbuiltType (Type type) + { + if (type.IsEnum) + return false; + if (type.IsValueType || type == typeof (string) || type.IsPrimitive) + return true; + if (type == typeof (DateTime) || type == typeof (XmlNode)) + return true; + + return false; + } + + private static MemberInfo[] GetGraph(Type type) + { + ArrayList typeGraph = new ArrayList (); + GetGraph (type, typeGraph); + return (MemberInfo[]) typeGraph.ToArray (typeof (MemberInfo)); + } + + private static void GetGraph (Type type, ArrayList typeGraph) + { + BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly; + if (type.BaseType == null) + return; + GetGraph (type.BaseType, typeGraph); + + typeGraph.AddRange (type.GetFields (flags)); + typeGraph.AddRange (type.GetProperties (flags)); + } + + private string GetXmlValue (object value) + { + if (value == null) + return null; + #region enum type + if (value is Enum)
+ { + Type type = value.GetType (); + + if (typeTable.ContainsKey (type)) { + Hashtable memberTable = (Hashtable) (typeTable[type]); + if (type.IsDefined (typeof (FlagsAttribute), false)) { + //If value is exactly a single enum member + if (memberTable.Contains (value.ToString ())) + return (string) memberTable[value.ToString ()]; + + string retval = ""; + int enumval = (int) value; + string[] names = Enum.GetNames (type); + + foreach (string key in names) { + if (!memberTable.ContainsKey (key)) + continue; + + //Otherwise multiple values. + int val = (int) Enum.Parse (type, key); + if (val != 0 && (enumval & val) == val) + retval += " " + (string) memberTable[Enum.GetName (type, val)]; + } + + retval = retval.Trim (); + + if (retval.Length == 0) + return null; + + return retval; + } + else if (memberTable.ContainsKey (value.ToString ())) + return (string) memberTable[value.ToString()]; + else + return null; + } + else + throw new Exception ("Unknown Enumeration"); + } + #endregion + if (value is byte[]) + return XmlCustomFormatter.FromByteArrayHex((byte[])value); + if (value is Guid) + return XmlConvert.ToString((Guid)value); + if(value is DateTime) + return XmlConvert.ToString((DateTime)value); + if(value is TimeSpan) + return XmlConvert.ToString((TimeSpan)value); + if(value is bool) + return XmlConvert.ToString((bool)value); + if(value is byte) + return XmlConvert.ToString((byte)value); + if(value is char) + return XmlCustomFormatter.FromChar((char)value); + if(value is decimal) + return XmlConvert.ToString((decimal)value); + if(value is double) + return XmlConvert.ToString((double)value); + if(value is short) + return XmlConvert.ToString((short)value); + if(value is int) + return XmlConvert.ToString((int)value); + if(value is long) + return XmlConvert.ToString((long)value); + if(value is sbyte) + return XmlConvert.ToString((sbyte)value); + if(value is float) + return XmlConvert.ToString((float)value); + if(value is ushort) + return XmlConvert.ToString((ushort)value); + if(value is uint) + return XmlConvert.ToString((uint)value); + if(value is ulong) + return XmlConvert.ToString((ulong)value); + if (value is XmlQualifiedName) { + if (((XmlQualifiedName) value).IsEmpty) + return null; + } + return (value == null) ? null : value.ToString (); + } + + [MonoTODO ("Remove FIXMEs")] + private static void ProcessAttributes (XmlAttributes attrs, Hashtable memberTable) + { + if (attrs.XmlAnyAttribute != null) { + // FIXME + } + foreach (XmlAnyElementAttribute anyelem in attrs.XmlAnyElements) + memberTable.Add (new XmlQualifiedName (anyelem.Name, anyelem.Namespace), attrs); + + if (attrs.XmlArray != null) { + // FIXME + } + + foreach (XmlArrayItemAttribute item in attrs.XmlArrayItems) + memberTable.Add (new XmlQualifiedName (item.ElementName, item.Namespace), attrs); + + if (attrs.XmlAttribute != null) + memberTable.Add (new XmlQualifiedName (attrs.XmlAttribute.AttributeName,attrs.XmlAttribute.Namespace), attrs); + + if (attrs.XmlChoiceIdentifier != null) { + // FIXME + } + + foreach (XmlElementAttribute elem in attrs.XmlElements) + memberTable.Add (new XmlQualifiedName (elem.ElementName, elem.Namespace), attrs); + + if (attrs.XmlEnum != null) { + // FIXME + } + + if (attrs.XmlType != null) + memberTable.Add (new XmlQualifiedName (attrs.XmlType.TypeName, attrs.XmlType.Namespace), attrs); + } + + private bool Implements (Type type, Type interfaceType) + { + return (type.GetInterface (interfaceType.Name) == interfaceType); + } + + private static void BubbleSort (ArrayList array, IComparer comparer) + { + int len = array.Count; + object obj1, obj2; + for (int i=0; i < len; i++) { + for (int j=0; j < len -i -1; j++) { + obj1 = array[j]; + obj2 = array[j+1]; + if (comparer.Compare (obj2 , obj1 ) < 0) { + array[j] = obj2; + array[j+1] = obj1; + } + } + } + } + #endregion // Methods + } +} diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlSerializerNamespaces.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializerNamespaces.cs new file mode 100644 index 00000000000..744026ae201 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializerNamespaces.cs @@ -0,0 +1,76 @@ +// +// XmlSerializerNamespaces.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System;
+using System.Xml;
+using System.Collections;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlSerializerNamespaces.
+ /// </summary>
+ public class XmlSerializerNamespaces
+ {
+ private Hashtable namespaces;
+
+ public XmlSerializerNamespaces ()
+ {
+ namespaces = new Hashtable ();
+ }
+
+ public XmlSerializerNamespaces(XmlQualifiedName[] namespaces)
+ : this()
+ {
+ foreach(XmlQualifiedName qname in namespaces)
+ {
+ this.namespaces[qname.Name] = qname;
+ }
+ }
+
+ public XmlSerializerNamespaces(XmlSerializerNamespaces namespaces)
+ : this(namespaces.ToArray())
+ {}
+
+ public void Add (string prefix, string ns)
+ {
+ XmlQualifiedName qname = new XmlQualifiedName(prefix,ns);
+ namespaces[qname.Name] = qname;
+ }
+
+ public XmlQualifiedName[] ToArray ()
+ {
+ XmlQualifiedName[] array = new XmlQualifiedName[namespaces.Count];
+ namespaces.Values.CopyTo(array,0);
+ return array;
+ }
+
+ public int Count
+ {
+ get{ return namespaces.Count; }
+ }
+
+ internal string GetPrefix(string Ns)
+ {
+ foreach(string prefix in namespaces.Keys)
+ {
+ if(Ns == ((XmlQualifiedName)namespaces[prefix]).Namespace)
+ return prefix;
+ }
+ return null;
+ }
+ + internal Hashtable Namespaces + { + get { + return namespaces; + } + } + }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlTextAttribute.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlTextAttribute.cs new file mode 100644 index 00000000000..c45c61cc2c6 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlTextAttribute.cs @@ -0,0 +1,61 @@ +// +// XmlTextAttribute.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlTextAttribute.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field
+ | AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
+ public class XmlTextAttribute : Attribute
+ {
+ private string dataType;
+ private Type type;
+ private int order;
+
+ public XmlTextAttribute ()
+ {
+ }
+
+ public XmlTextAttribute (Type type)
+ {
+ Type = type;
+ }
+
+ public string DataType {
+ get {
+ return dataType;
+ }
+ set {
+ dataType = value;
+ }
+ }
+ public Type Type
+ {
+ get {
+ return type;
+ }
+ set {
+ type = value;
+ }
+ }
+ /// <summary>
+ /// Specifies Order in which Memberswill be serialized as Elements.
+ /// </summary>
+ internal int Order
+ {
+ get{ return order; }
+ set{ order = value; }
+ }
+
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlTypeAttribute.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlTypeAttribute.cs new file mode 100644 index 00000000000..dd8ebacb162 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlTypeAttribute.cs @@ -0,0 +1,60 @@ +// +// XmlTypeAttribute.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlTypeAttribute.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct |
+ AttributeTargets.Enum | AttributeTargets.Interface)]
+ public class XmlTypeAttribute : Attribute
+ {
+ private bool includeInSchema;
+ private string ns;
+ private string typeName;
+
+ public XmlTypeAttribute ()
+ {
+ }
+
+ public XmlTypeAttribute (string typeName)
+ {
+ TypeName = typeName;
+ }
+
+ public bool IncludeInSchema {
+ get {
+ return includeInSchema;
+ }
+ set {
+ includeInSchema = value;
+ }
+ }
+
+ public string Namespace {
+ get {
+ return ns;
+ }
+ set {
+ ns = value;
+ }
+ }
+ public string TypeName {
+ get {
+ return typeName;
+ }
+ set {
+ typeName = value;
+ }
+ }
+ }
+}
diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapping.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapping.cs new file mode 100644 index 00000000000..ff9c9b7b4f0 --- /dev/null +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapping.cs @@ -0,0 +1,50 @@ +// +// XmlTypeMapping.cs: +// +// Author: +// John Donagher (john@webmeta.com) +// +// (C) 2002 John Donagher +// + +using System.Xml;
+using System;
+
+namespace System.Xml.Serialization
+{
+ /// <summary>
+ /// Summary description for XmlTypeMapping.
+ /// </summary>
+ public class XmlTypeMapping : XmlMapping
+ {
+ private string elementName;
+ private string ns;
+ private string typeFullName;
+ private string typeName;
+
+ internal XmlTypeMapping(string elementName, string ns, string typeFullName, string typeName)
+ {
+ this.elementName = elementName;
+ this.ns = ns;
+ this.typeFullName = typeFullName;
+ this.typeName = typeName;
+ }
+
+ public string ElementName
+ {
+ get { return elementName; }
+ }
+ public string Namespace
+ {
+ get { return ns; }
+ }
+ public string TypeFullName
+ {
+ get { return typeFullName; }
+ }
+ public string TypeName
+ {
+ get { return typeName; }
+ }
+ }
+}
|