2 // System.Configuration.ConfigurationLockCollection.cs
5 // Chris Toshok (toshok@ximian.com)
7 // Permission is hereby granted, free of charge, to any person obtaining
8 // a copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
30 using System.Collections;
32 namespace System.Configuration
35 internal enum ConfigurationLockType
43 public sealed class ConfigurationLockCollection : ICollection, IEnumerable
46 ConfigurationElement element;
47 ConfigurationLockType lockType;
49 Hashtable valid_name_hash;
52 internal ConfigurationLockCollection (ConfigurationElement element,
53 ConfigurationLockType lockType)
55 names = new ArrayList ();
56 this.element = element;
57 this.lockType = lockType;
60 void CheckName (string name)
62 bool isAttribute = (lockType & ConfigurationLockType.Attribute) == ConfigurationLockType.Attribute;
64 if (valid_name_hash == null) {
65 valid_name_hash = new Hashtable ();
66 foreach (ConfigurationProperty prop in element.Properties) {
67 if (isAttribute == prop.IsElement)
69 valid_name_hash.Add (prop.Name, true);
72 /* add the add/remove/clear names of the
73 * default collection if there is one */
75 ConfigurationElementCollection c = element.GetDefaultCollection ();
76 valid_name_hash.Add (c.AddElementName, true);
77 valid_name_hash.Add (c.ClearElementName, true);
78 valid_name_hash.Add (c.RemoveElementName, true);
81 string[] valid_name_array = new string[valid_name_hash.Keys.Count];
82 valid_name_hash.Keys.CopyTo (valid_name_array, 0);
84 valid_names = String.Join (",", valid_name_array);
87 if (valid_name_hash [name] == null)
88 throw new ConfigurationErrorsException (
89 String.Format ("The {2} '{0}' is not valid in the locked list for this section. The following {3} can be locked: '{1}'",
90 name, valid_names, isAttribute ? "attribute" : "element", isAttribute ? "attributes" : "elements"));
93 public void Add (string name)
96 if (!names.Contains (name)) {
108 public bool Contains (string name)
110 return names.Contains (name);
113 public void CopyTo (string[] array, int index)
115 names.CopyTo (array, index);
118 public IEnumerator GetEnumerator()
120 return names.GetEnumerator ();
123 [MonoInternalNote ("we can't possibly *always* return false here...")]
124 public bool IsReadOnly (string name)
126 for (int i = 0; i < names.Count; i ++) {
127 if ((string)names[i] == name) {
128 /* this test used to switch off whether the collection was 'Exclude' or not
129 * (the LockAll*Except collections), but that doesn't seem to be the crux of
130 * it. maybe this returns true if the element/attribute is locked in a parent
131 * element's lock collections? */
136 throw new ConfigurationErrorsException (String.Format ("The entry '{0}' is not in the collection.", name));
139 public void Remove (string name)
145 public void SetFromList (string attributeList)
149 char [] split = {','};
150 string [] attrs = attributeList.Split (split);
151 foreach (string a in attrs) {
156 void ICollection.CopyTo (System.Array array, int index)
158 names.CopyTo (array, index);
161 public string AttributeList {
163 string[] name_arr = new string[names.Count];
164 names.CopyTo (name_arr, 0);
165 return String.Join (",", name_arr);
170 get { return names.Count; }
174 public bool HasParentElements {
175 get { return false; /* XXX */ }
179 public bool IsModified {
180 get { return is_modified; }
181 internal set { is_modified = value; }
185 public bool IsSynchronized {
186 get { return false; /* XXX */ }
190 public object SyncRoot {
191 get { return this; /* XXX */ }