diff options
author | Atsushi Eno <atsushieno@gmail.com> | 2004-08-06 06:00:25 +0400 |
---|---|---|
committer | Atsushi Eno <atsushieno@gmail.com> | 2004-08-06 06:00:25 +0400 |
commit | a865c14e9c4245cfc687568ba13e605181d539e7 (patch) | |
tree | 5abd8e0a8a1c948475cac1d5ed08e237d553b946 | |
parent | a35153b3963e4d5aa5094456fbb3f69f51d31111 (diff) |
2004-08-06 Atsushi Enomoto <atsushi@ximian.com>
* DataSet.cs : DataSet's ExtendedProperties were not XmlConverted.
2004-08-05 Atsushi Enomoto <atsushi@ximian.com>
* XmlConstants.cs : Added constants for "msprop" support.
* DataSet.cs : ExtendedProperties should be written in the schema.
This fixes bug #61233.
svn path=/branches/mono-1-0/mcs/; revision=31968
-rw-r--r-- | mcs/class/System.Data/System.Data/ChangeLog | 10 | ||||
-rw-r--r-- | mcs/class/System.Data/System.Data/DataSet.cs | 71 | ||||
-rwxr-xr-x | mcs/class/System.Data/System.Data/XmlConstants.cs | 2 |
3 files changed, 72 insertions, 11 deletions
diff --git a/mcs/class/System.Data/System.Data/ChangeLog b/mcs/class/System.Data/System.Data/ChangeLog index 19a97068767..78cc45ac101 100644 --- a/mcs/class/System.Data/System.Data/ChangeLog +++ b/mcs/class/System.Data/System.Data/ChangeLog @@ -1,3 +1,13 @@ +2004-08-06 Atsushi Enomoto <atsushi@ximian.com> + + * DataSet.cs : DataSet's ExtendedProperties were not XmlConverted. + +2004-08-05 Atsushi Enomoto <atsushi@ximian.com> + + * XmlConstants.cs : Added constants for "msprop" support. + * DataSet.cs : ExtendedProperties should be written in the schema. + This fixes bug #61233. + 2004-07-27 Atsushi Enomoto <atsushi@ximian.com> * DataSet.cs : on serialization to XmlWriter, XmlConvert should be diff --git a/mcs/class/System.Data/System.Data/DataSet.cs b/mcs/class/System.Data/System.Data/DataSet.cs index 49ae0f024f9..8ac4d34836b 100644 --- a/mcs/class/System.Data/System.Data/DataSet.cs +++ b/mcs/class/System.Data/System.Data/DataSet.cs @@ -1390,6 +1390,8 @@ namespace System.Data { nsmgr.AddNamespace (XmlConstants.TnsPrefix, Namespace); nsmgr.AddNamespace (String.Empty, Namespace); } + if (CheckExtendedPropertyExists ()) + nsmgr.AddNamespace (XmlConstants.MspropPrefix, XmlConstants.MspropNamespace); if (atts.Count > 0) schema.UnhandledAttributes = atts.ToArray (typeof (XmlAttribute)) as XmlAttribute []; @@ -1416,6 +1418,8 @@ namespace System.Data { elem.UnhandledAttributes = atts.ToArray (typeof (XmlAttribute)) as XmlAttribute []; + AddExtendedPropertyAttributes (elem, ExtendedProperties, doc); + XmlSchemaComplexType complex = new XmlSchemaComplexType (); elem.SchemaType = complex; @@ -1446,7 +1450,7 @@ namespace System.Data { schema.Items.Add (elem); - AddConstraintsToSchema (elem, constraintPrefix, tables, relations); + AddConstraintsToSchema (elem, constraintPrefix, tables, relations, doc); foreach (string prefix in nsmgr) { string ns = nsmgr.LookupNamespace (nsmgr.NameTable.Get (prefix)); if (prefix != "xmlns" && prefix != "xml" && ns != null && ns != String.Empty) @@ -1455,29 +1459,48 @@ namespace System.Data { return schema; } + private bool CheckExtendedPropertyExists () + { + if (ExtendedProperties.Count > 0) + return true; + foreach (DataTable dt in Tables) { + if (dt.ExtendedProperties.Count > 0) + return true; + foreach (DataColumn col in dt.Columns) + if (col.ExtendedProperties.Count > 0) + return true; + foreach (Constraint c in dt.Constraints) + if (c.ExtendedProperties.Count > 0) + return true; + } + foreach (DataRelation rel in Relations) + if (rel.ExtendedProperties.Count > 0) + return true; + return false; + } + // Add all constraints in all tables to the schema. - private void AddConstraintsToSchema (XmlSchemaElement elem, string constraintPrefix, DataTableCollection tables, DataRelationCollection relations) + private void AddConstraintsToSchema (XmlSchemaElement elem, string constraintPrefix, DataTableCollection tables, DataRelationCollection relations, XmlDocument doc) { // first add all unique constraints. - Hashtable uniqueNames = AddUniqueConstraints (elem, constraintPrefix, tables); + Hashtable uniqueNames = AddUniqueConstraints (elem, constraintPrefix, tables, doc); // Add all foriegn key constraints. - AddForeignKeys (uniqueNames, elem, constraintPrefix, relations); + AddForeignKeys (uniqueNames, elem, constraintPrefix, relations, doc); } // Add unique constaraints to the schema. // return hashtable with the names of all XmlSchemaUnique elements we created. - private Hashtable AddUniqueConstraints (XmlSchemaElement elem, string constraintPrefix, DataTableCollection tables) + private Hashtable AddUniqueConstraints (XmlSchemaElement elem, string constraintPrefix, DataTableCollection tables, XmlDocument doc) { - XmlDocument doc = new XmlDocument(); Hashtable uniqueNames = new Hashtable(); foreach (DataTable table in tables) { - foreach (Constraint constaint in table.Constraints) { + foreach (Constraint constraint in table.Constraints) { - if (constaint is UniqueConstraint) { + if (constraint is UniqueConstraint) { ArrayList attrs = new ArrayList (); XmlAttribute attrib; - UniqueConstraint uqConst = (UniqueConstraint)constaint; + UniqueConstraint uqConst = (UniqueConstraint) constraint; XmlSchemaUnique uniq = new XmlSchemaUnique (); // if column of the constraint is hidden do not write the constraint. @@ -1520,6 +1543,8 @@ namespace System.Data { uniq.Fields.Add(field); } + AddExtendedPropertyAttributes (uniq, constraint.ExtendedProperties, doc); + elem.Constraints.Add (uniq); uniqueNames.Add (uniq.Name, null); } @@ -1529,11 +1554,10 @@ namespace System.Data { } // Add the foriegn keys to the schema. - private void AddForeignKeys (Hashtable uniqueNames, XmlSchemaElement elem, string constraintPrefix, DataRelationCollection relations) + private void AddForeignKeys (Hashtable uniqueNames, XmlSchemaElement elem, string constraintPrefix, DataRelationCollection relations, XmlDocument doc) { if (relations == null) return; - XmlDocument doc = new XmlDocument(); foreach (DataRelation rel in relations) { if (rel.ParentKeyConstraint == null || rel.ChildKeyConstraint == null) @@ -1585,7 +1609,10 @@ namespace System.Data { field.XPath = constraintPrefix+column.ColumnName; keyRef.Fields.Add(field); } + keyRef.UnhandledAttributes = (XmlAttribute[])attrs.ToArray (typeof (XmlAttribute)); + AddExtendedPropertyAttributes (keyRef, rel.ExtendedProperties, doc); + elem.Constraints.Add (keyRef); } } @@ -1687,6 +1714,7 @@ namespace System.Data { } colElem.UnhandledAttributes = (XmlAttribute[])xattrs.ToArray(typeof (XmlAttribute)); + AddExtendedPropertyAttributes (colElem, col.ExtendedProperties, doc); seq.Items.Add (colElem); } @@ -1726,12 +1754,33 @@ namespace System.Data { schemaToAdd.Namespaces.Add (prefix, col.Namespace); } att.SchemaTypeName = MapType (col.DataType); + // FIXME: what happens if extended properties are set on attribute columns?? schemaAttributes.Add (att); } + AddExtendedPropertyAttributes (elem, table.ExtendedProperties, doc); + return elem; } + private void AddExtendedPropertyAttributes (XmlSchemaAnnotated xsobj, PropertyCollection props, XmlDocument doc) + { + ArrayList attList = new ArrayList (); + XmlAttribute xmlAttr; + + if (xsobj.UnhandledAttributes != null) + attList.AddRange (xsobj.UnhandledAttributes); + + // add extended properties to xs:element + foreach (DictionaryEntry de in props) { + xmlAttr = doc.CreateAttribute (XmlConstants.MspropPrefix, XmlConvert.EncodeName (de.Key.ToString ()), XmlConstants.MspropNamespace); + xmlAttr.Value = de.Value != null ? WriteObjectXml (de.Value) : String.Empty; + attList.Add (xmlAttr); + } + if (attList.Count > 0) + xsobj.UnhandledAttributes = attList.ToArray (typeof (XmlAttribute)) as XmlAttribute []; + } + private string SafeNS (string ns) { return ns != null ? ns : String.Empty; diff --git a/mcs/class/System.Data/System.Data/XmlConstants.cs b/mcs/class/System.Data/System.Data/XmlConstants.cs index b50a80bc6d5..1d459157606 100755 --- a/mcs/class/System.Data/System.Data/XmlConstants.cs +++ b/mcs/class/System.Data/System.Data/XmlConstants.cs @@ -83,6 +83,8 @@ internal class XmlConstants //ms schema objects public const string MsdataPrefix = "msdata"; public const string MsdataNamespace = "urn:schemas-microsoft-com:xml-msdata"; + public const string MspropPrefix = "msprop"; + public const string MspropNamespace = "urn:schemas-microsoft-com:xml-msprop"; public const string DiffgrPrefix = "diffgr"; public const string DiffgrNamespace = "urn:schemas-microsoft-com:xml-diffgram-v1"; public const string TnsPrefix = "mstns"; |