Author: antonello
Date: 2007-04-01 16:20:59 -0400 (Sun, 01 Apr 2007)
New Revision: 75270
Added:
trunk/olive/class/System.Data.Linq/System.Data.Linq/DataShape.cs
trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlAssociationMapping.cs
trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlColumnMapping.cs
trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlDatabaseMapping.cs
trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlMappingSource.cs
trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlMemberMapping.cs
trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlTableMapping.cs
trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlTypeMapping.cs
Modified:
trunk/olive/class/System.Data.Linq/System.Data.Linq/ChangeLog
Log:
XmlMappingSource implementations.
Modified: trunk/olive/class/System.Data.Linq/System.Data.Linq/ChangeLog
===================================================================
--- trunk/olive/class/System.Data.Linq/System.Data.Linq/ChangeLog
2007-04-01 20:07:34 UTC (rev 75269)
+++ trunk/olive/class/System.Data.Linq/System.Data.Linq/ChangeLog
2007-04-01 20:20:59 UTC (rev 75270)
@@ -1,3 +1,9 @@
+2007-03-29 Antonello Provenzano <[EMAIL PROTECTED]>
+
+ * DataContext.cs: implementations
+ * DataShape.cs: New file
+ * IDataServices.cs: New file
+
2007-03-24 Antonello Provenzano <[EMAIL PROTECTED]>
* Initial commit
\ No newline at end of file
Added: trunk/olive/class/System.Data.Linq/System.Data.Linq/DataShape.cs
===================================================================
--- trunk/olive/class/System.Data.Linq/System.Data.Linq/DataShape.cs
2007-04-01 20:07:34 UTC (rev 75269)
+++ trunk/olive/class/System.Data.Linq/System.Data.Linq/DataShape.cs
2007-04-01 20:20:59 UTC (rev 75270)
@@ -0,0 +1,28 @@
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+//
+// Authors:
+// Antonello Provenzano <[EMAIL PROTECTED]>
+//
+
+namespace System.Data.Linq
+{
+ public sealed class DataShape
+ {
+ }
+}
\ No newline at end of file
Added:
trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlAssociationMapping.cs
===================================================================
---
trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlAssociationMapping.cs
2007-04-01 20:07:34 UTC (rev 75269)
+++
trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlAssociationMapping.cs
2007-04-01 20:20:59 UTC (rev 75270)
@@ -0,0 +1,59 @@
+namespace System.Data.Linq
+{
+ class XmlAssociationMapping : XmlMemberMapping
+ {
+ #region .ctor
+ public XmlAssociationMapping(string member)
+ : base(member)
+ {
+ }
+ #endregion
+
+ #region Fields
+ private string deleteRule;
+ private bool foreignKey;
+ private bool unique;
+ private string otherKey;
+ private string otherTableName;
+ private string thisKey;
+ #endregion
+
+ #region Properties
+ public string DeleteRule
+ {
+ get { return deleteRule; }
+ set { deleteRule = value; }
+ }
+
+ public bool IsForeignKey
+ {
+ get { return foreignKey; }
+ set { foreignKey = value; }
+ }
+
+ public bool IsUnique
+ {
+ get { return unique; }
+ set { unique = value; }
+ }
+
+ public string OtherKey
+ {
+ get { return otherKey; }
+ set { otherKey = value; }
+ }
+
+ public string OtherTableName
+ {
+ get { return otherTableName; }
+ set { otherTableName = value; }
+ }
+
+ public string ThisKey
+ {
+ get { return thisKey; }
+ set { thisKey = value; }
+ }
+ #endregion
+ }
+}
\ No newline at end of file
Added: trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlColumnMapping.cs
===================================================================
--- trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlColumnMapping.cs
2007-04-01 20:07:34 UTC (rev 75269)
+++ trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlColumnMapping.cs
2007-04-01 20:20:59 UTC (rev 75270)
@@ -0,0 +1,24 @@
+namespace System.Data.Linq
+{
+ class XmlColumnMapping : XmlMemberMapping
+ {
+ #region .ctor
+ public XmlColumnMapping(string member)
+ : base(member)
+ {
+ }
+ #endregion
+
+ #region Fields
+ private AutoSync autoSync;
+ private bool? canBeNull;
+ private string dbType;
+ private string expression;
+ private bool dBGenerated;
+ private bool discriminator;
+ private bool primaryKey;
+ private bool version;
+ private UpdateCheck updateCheck;
+ #endregion
+ }
+}
\ No newline at end of file
Added: trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlDatabaseMapping.cs
===================================================================
--- trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlDatabaseMapping.cs
2007-04-01 20:07:34 UTC (rev 75269)
+++ trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlDatabaseMapping.cs
2007-04-01 20:20:59 UTC (rev 75270)
@@ -0,0 +1,64 @@
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+//
+// Authors:
+// Antonello Provenzano <[EMAIL PROTECTED]>
+//
+
+using System.Collections.Generic;
+
+namespace System.Data.Linq
+{
+ /// <summary>
+ /// A class that represents the element "Database" in the
+ /// XML schema of a map to a database.
+ /// </summary>
+ class XmlDatabaseMapping
+ {
+ #region .ctor
+ public XmlDatabaseMapping(string name, string providerType)
+ {
+ this.name = name;
+ this.providerType = providerType;
+ }
+ #endregion
+
+ #region Fields
+ private string name;
+ private string providerType;
+ private List<XmlTableMapping> tables;
+ #endregion
+
+ #region Properties
+ public string Name
+ {
+ get { return name; }
+ }
+
+ public string ProviderType
+ {
+ get { return providerType; }
+ }
+
+ public List<XmlTableMapping> Tables
+ {
+ get { return tables; }
+ }
+ #endregion
+ }
+}
\ No newline at end of file
Added: trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlMappingSource.cs
===================================================================
--- trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlMappingSource.cs
2007-04-01 20:07:34 UTC (rev 75269)
+++ trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlMappingSource.cs
2007-04-01 20:20:59 UTC (rev 75270)
@@ -0,0 +1,221 @@
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+//
+// Authors:
+// Antonello Provenzano <[EMAIL PROTECTED]>
+//
+
+using System.Collections.Generic;
+using System.Data.Linq.Provider;
+using System.IO;
+using System.Xml;
+
+namespace System.Data.Linq
+{
+ /// <summary>
+ /// A source that maps against an XML serialization of the
+ /// DLINQ Mapping Schema.
+ /// </summary>
+ public sealed class XmlMappingSource : MappingSource
+ {
+ #region .ctor
+ private XmlMappingSource(XmlDatabaseMapping dbMapping)
+ {
+ this.dbMapping = dbMapping;
+ }
+ #endregion
+
+ #region Fields
+ private XmlDatabaseMapping dbMapping;
+ private Dictionary<Type, MetaModel> models = new
Dictionary<Type,MetaModel>();
+ #endregion
+
+ #region Private Static Methods
+ private static XmlDatabaseMapping ReadDatabaseMapping(XmlReader reader)
+ {
+ XmlDocument doc = new XmlDocument();
+ doc.Load(reader);
+
+ XmlElement dbElement = doc.DocumentElement;
+ if (dbElement.LocalName != "Database")
+ throw new InvalidOperationException();
+
+ string name = dbElement.GetAttribute("Name");
+ if (name == null)
+ throw new InvalidOperationException();
+
+ string providerType = dbElement.GetAttribute("ProviderType");
+
+ XmlDatabaseMapping dbMapping = new XmlDatabaseMapping(name,
providerType);
+
+ try
+ {
+ dbMapping = new XmlDatabaseMapping(name, providerType);
+
+ XmlNodeList childNodes = dbElement.ChildNodes;
+
+ for (int i = 0; i < childNodes.Count; i++)
+ {
+ XmlElement child = childNodes[i] as XmlElement;
+ switch (child.LocalName)
+ {
+ case "Table":
+ dbMapping.Tables.Add(ReadTableElement(child));
+ break;
+ case "StoredProcedure":
+ break;
+ case "UserDefinedFunction":
+ break;
+ case "TableValuedFunction":
+ break;
+ }
+ }
+ }
+ catch
+ {
+ dbMapping = null;
+ throw;
+ }
+
+ return dbMapping;
+ }
+
+ private static XmlTableMapping ReadTableElement(XmlElement element)
+ {
+ string name = element.GetAttribute("name");
+ if (name == null || name.Length == 0)
+ throw new InvalidOperationException();
+
+ XmlTableMapping tableMapping = new XmlTableMapping(name);
+
+ XmlNodeList childNodes = element.ChildNodes;
+ for (int i = 0; i < childNodes.Count; i++)
+ {
+ XmlElement child = childNodes[i] as XmlElement;
+ if (child.LocalName != "Type") //ISSUE: should we ignore the
case?
+ throw new InvalidOperationException();
+
+ if (tableMapping.RowType != null)
+ throw new InvalidOperationException();
+
+ tableMapping.RowType = ReadTypeElement(child);
+ }
+
+ return tableMapping;
+ }
+
+ private static XmlTypeMapping ReadTypeElement(XmlElement element)
+ {
+ string name = element.GetAttribute("Name");
+ if (name == null || name.Length == 0)
+ throw new InvalidOperationException();
+
+ XmlTypeMapping typeMapping = new XmlTypeMapping(name);
+
+ typeMapping.InheritanceCode =
element.GetAttribute("InheritanceCode");
+
+ string inheritanceDefault =
element.GetAttribute("IsInheritanceDefault");
+ if (inheritanceDefault == null)
+ {
+ typeMapping.IsInheritanceDefault = false;
+ }
+ else
+ {
+ try
+ {
+ typeMapping.IsInheritanceDefault =
Boolean.Parse(inheritanceDefault);
+ }
+ catch (FormatException)
+ {
+ throw new InvalidOperationException();
+ }
+ }
+
+ XmlNodeList childNodes = element.ChildNodes;
+ for (int i = 0; i < childNodes.Count; i++)
+ {
+ XmlElement child = childNodes[i] as XmlElement;
+ switch (child.LocalName)
+ {
+ case "Type":
+ typeMapping.Derived.Add(ReadTypeElement(child));
+ break;
+ case "Association":
+ break;
+ case "Column":
+ break;
+ default:
+ throw new InvalidOperationException();
+ }
+ }
+
+ return typeMapping;
+ }
+ #endregion
+
+ #region Protected Methods
+ protected internal override MetaModel CreateModel(Type contextType)
+ {
+ if (contextType == null)
+ throw new ArgumentNullException("contextType");
+
+ MetaModel model = models[contextType];
+ if (model == null)
+ {
+ //TODO: we have to create it and add it to the dictionary...
+ }
+
+ return model;
+ }
+ #endregion
+
+ #region Public Static Methods
+ public static XmlMappingSource FromStream(Stream stream)
+ {
+ if (stream == null)
+ throw new ArgumentNullException("stream");
+
+ return FromReader(new XmlTextReader(stream));
+ }
+
+ public static XmlMappingSource FromReader(XmlReader reader)
+ {
+ if (reader == null)
+ throw new ArgumentNullException("reader");
+
+ return new XmlMappingSource(ReadDatabaseMapping(reader));
+ }
+
+ public static XmlMappingSource FromUrl(string url)
+ {
+ if (url == null)
+ throw new ArgumentNullException("url");
+
+ return FromReader(new XmlTextReader(url));
+ }
+
+ public static XmlMappingSource FromXml(string xml)
+ {
+ if (xml == null)
+ throw new ArgumentNullException("xml");
+
+ return FromReader(new XmlTextReader(new StringReader(xml)));
+ }
+ #endregion
+ }
+}
\ No newline at end of file
Added: trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlMemberMapping.cs
===================================================================
--- trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlMemberMapping.cs
2007-04-01 20:07:34 UTC (rev 75269)
+++ trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlMemberMapping.cs
2007-04-01 20:20:59 UTC (rev 75270)
@@ -0,0 +1,37 @@
+namespace System.Data.Linq
+{
+ class XmlMemberMapping
+ {
+ #region .ctor
+ protected XmlMemberMapping(string member)
+ {
+ this.member = member;
+ }
+ #endregion
+
+ #region Fields
+ private string member;
+ private string name;
+ private string storage;
+ #endregion
+
+ #region Properties
+ public string MemberName
+ {
+ get { return member; }
+ }
+
+ public string Name
+ {
+ get { return name; }
+ set { name = value; }
+ }
+
+ public string Storage
+ {
+ get { return storage; }
+ set { storage = value; }
+ }
+ #endregion
+ }
+}
\ No newline at end of file
Added: trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlTableMapping.cs
===================================================================
--- trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlTableMapping.cs
2007-04-01 20:07:34 UTC (rev 75269)
+++ trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlTableMapping.cs
2007-04-01 20:20:59 UTC (rev 75270)
@@ -0,0 +1,30 @@
+namespace System.Data.Linq
+{
+ class XmlTableMapping
+ {
+ #region .ctor
+ public XmlTableMapping(string name)
+ {
+ this.name = name;
+ }
+ #endregion
+
+ #region Fields
+ private string name;
+ private XmlTypeMapping rowType;
+ #endregion
+
+ #region Properties
+ public string Name
+ {
+ get { return name; }
+ }
+
+ public XmlTypeMapping RowType
+ {
+ get { return rowType; }
+ set { rowType = value; }
+ }
+ #endregion
+ }
+}
\ No newline at end of file
Added: trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlTypeMapping.cs
===================================================================
--- trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlTypeMapping.cs
2007-04-01 20:07:34 UTC (rev 75269)
+++ trunk/olive/class/System.Data.Linq/System.Data.Linq/XmlTypeMapping.cs
2007-04-01 20:20:59 UTC (rev 75270)
@@ -0,0 +1,46 @@
+using System.Collections.Generic;
+
+namespace System.Data.Linq
+{
+ class XmlTypeMapping
+ {
+ #region .ctor
+ public XmlTypeMapping(string name)
+ {
+ this.name = name;
+ }
+ #endregion
+
+ #region Fields
+ private string name;
+ private string inheritanceCode;
+ private bool inheritanceDefault;
+ private List<XmlTypeMapping> derived = new List<XmlTypeMapping>();
+ private List<XmlMemberMapping> members = new List<XmlMemberMapping>();
+ #endregion
+
+ #region Properties
+ public string TypeName
+ {
+ get { return name; }
+ }
+
+ public string InheritanceCode
+ {
+ get { return inheritanceCode; }
+ set { inheritanceCode = value; }
+ }
+
+ public bool IsInheritanceDefault
+ {
+ get { return inheritanceDefault; }
+ set { inheritanceDefault = value; }
+ }
+
+ public List<XmlTypeMapping> Derived
+ {
+ get { return derived; }
+ }
+ #endregion
+ }
+}
\ No newline at end of file
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches