2008-12-06 Ivan N. Zlatev <contact@i-nz.net>
[mono.git] / mcs / class / System.Configuration / System.Configuration / SectionGroupInfo.cs
index 58fa2612bf52364e1c31d19c194bc2e0f2bb6924..5332ef9bc9bb7a51dcfbf215d2dfb755bf2a1e88 100644 (file)
@@ -136,7 +136,7 @@ namespace System.Configuration
                        return false;
                }
                
-               public override void ReadConfig (Configuration cfg, string streamName, XmlTextReader reader)
+               public override void ReadConfig (Configuration cfg, string streamName, XmlReader reader)
                {
                        StreamName = streamName;
                        ConfigHost = cfg.ConfigHost;
@@ -245,13 +245,13 @@ namespace System.Configuration
                        writer.WriteEndElement ();
                }
 
-               private void ReadRemoveSection (XmlTextReader reader)
+               private void ReadRemoveSection (XmlReader reader)
                {
                        if (!reader.MoveToNextAttribute () || reader.Name != "name")
                                ThrowException ("Unrecognized attribute.", reader);
 
                        string removeValue = reader.Value;
-                       if (removeValue == null || removeValue.Length == 0)
+                       if (String.IsNullOrEmpty (removeValue))
                                ThrowException ("Empty name to remove", reader);
 
                        reader.MoveToElement ();
@@ -263,28 +263,28 @@ namespace System.Configuration
                        reader.Skip ();
                }
 
-               public void ReadRootData (XmlTextReader reader, Configuration config, bool overrideAllowed)
+               public void ReadRootData (XmlReader reader, Configuration config, bool overrideAllowed)
                {
                        reader.MoveToContent ();
                        ReadContent (reader, config, overrideAllowed, true);
                }
                
-               public override void ReadData (Configuration config, XmlTextReader reader, bool overrideAllowed)
+               public override void ReadData (Configuration config, XmlReader reader, bool overrideAllowed)
                {
                        reader.MoveToContent ();
-                       reader.ReadStartElement ();
-                       ReadContent (reader, config, overrideAllowed, false);
-                       reader.MoveToContent ();
-                       reader.ReadEndElement ();
+                       if (!reader.IsEmptyElement) {
+                               reader.ReadStartElement ();
+                               ReadContent (reader, config, overrideAllowed, false);
+                               reader.MoveToContent ();
+                               reader.ReadEndElement ();
+                       } else
+                               reader.Read ();
                }
                
-               void ReadContent (XmlTextReader reader, Configuration config, bool overrideAllowed, bool root)
+               void ReadContent (XmlReader reader, Configuration config, bool overrideAllowed, bool root)
                {
-                       StringBuilder spacing = new StringBuilder ();
-                       while (reader.NodeType != XmlNodeType.EndElement) {
+                       while (reader.NodeType != XmlNodeType.EndElement && reader.NodeType != XmlNodeType.None) {
                                if (reader.NodeType != XmlNodeType.Element) {
-                                       if (reader.NodeType == XmlNodeType.Whitespace)
-                                               spacing.Append (reader.Value);
                                        reader.Skip ();
                                        continue;
                                }
@@ -304,8 +304,13 @@ namespace System.Configuration
                                        if (path != null && path.Length > 0) {
                                                string xml = reader.ReadOuterXml ();
                                                string[] pathList = path.Split (',');
+                                               string tpath;
                                                foreach (string p in pathList) {
-                                                       ConfigurationLocation loc = new ConfigurationLocation (p.Trim (), xml, config, allowOverride);
+                                                       tpath = p.Trim ();
+                                                       if (config.Locations.Find (tpath) != null)
+                                                               ThrowException ("Sections must only appear once per config file.", reader);
+                                                       
+                                                       ConfigurationLocation loc = new ConfigurationLocation (tpath, xml, config, allowOverride);
                                                        config.Locations.Add (loc);
                                                }
                                        } else {
@@ -313,10 +318,8 @@ namespace System.Configuration
                                        }
                                        continue;
                                }
-
-                               
+                       
                                ConfigInfo data = GetConfigInfo (reader, this);
-
                                if (data != null)
                                        data.ReadData (config, reader, overrideAllowed);
                                else
@@ -331,7 +334,7 @@ namespace System.Configuration
                                data = current.sections [reader.LocalName];
                        if (data != null)
                                return data;
-                       if (current.groups != null) 
+                       if (current.groups != null)
                                data = current.groups [reader.LocalName];
                        if (data != null)
                                return data;
@@ -343,6 +346,7 @@ namespace System.Configuration
                                if (data != null)
                                        return data;
                        }
+                       
                        // It might be in the root section group
                        return null;
                }
@@ -361,7 +365,7 @@ namespace System.Configuration
                                        sections.Add (key, data.sections[key]);
                                }
                        
-                       if (data.groups != null && data.sections.Count > 0)
+                       if (data.groups != null && data.sections != null && data.sections.Count > 0)
                                foreach (string key in data.groups.AllKeys) {
                                        actInfo = groups[key];
                                        if (actInfo != null)
@@ -396,6 +400,11 @@ namespace System.Configuration
        
        internal class ConfigInfoCollection : NameObjectCollectionBase
        {
+               public ConfigInfoCollection ()
+                       : base (StringComparer.Ordinal)
+               {
+               }
+
                public ICollection AllKeys
                {
                        get { return Keys; }