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)
32 using System.Collections;
34 namespace System.Configuration
37 internal enum ConfigurationLockType
45 public sealed class ConfigurationLockCollection : ICollection, IEnumerable
48 ConfigurationElement element;
49 ConfigurationLockType lockType;
51 Hashtable valid_name_hash;
54 internal ConfigurationLockCollection (ConfigurationElement element,
55 ConfigurationLockType lockType)
57 names = new ArrayList ();
58 this.element = element;
59 this.lockType = lockType;
62 void CheckName (string name)
64 bool isAttribute = (lockType & ConfigurationLockType.Attribute) == ConfigurationLockType.Attribute;
66 if (valid_name_hash == null) {
67 valid_name_hash = new Hashtable ();
68 foreach (ConfigurationProperty prop in element.Properties) {
69 if (isAttribute == prop.IsElement)
71 valid_name_hash.Add (prop.Name, true);
74 /* add the add/remove/clear names of the
75 * default collection if there is one */
77 ConfigurationElementCollection c = element.GetDefaultCollection ();
78 valid_name_hash.Add (c.AddElementName, true);
79 valid_name_hash.Add (c.ClearElementName, true);
80 valid_name_hash.Add (c.RemoveElementName, true);
83 string[] valid_name_array = new string[valid_name_hash.Keys.Count];
84 valid_name_hash.Keys.CopyTo (valid_name_array, 0);
86 valid_names = String.Join (",", valid_name_array);
89 if (valid_name_hash [name] == null)
90 throw new ConfigurationErrorsException (
91 String.Format ("The {2} '{0}' is not valid in the locked list for this section. The following {3} can be locked: '{1}'",
92 name, valid_names, isAttribute ? "attribute" : "element", isAttribute ? "attributes" : "elements"));
95 public void Add (string name)
98 if (!names.Contains (name)) {
110 public bool Contains (string name)
112 return names.Contains (name);
115 public void CopyTo (string[] array, int index)
117 names.CopyTo (array, index);
120 public IEnumerator GetEnumerator()
122 return names.GetEnumerator ();
125 [MonoTODO ("we can't possibly *always* return false here...")]
126 public bool IsReadOnly (string name)
128 for (int i = 0; i < names.Count; i ++) {
129 if ((string)names[i] == name) {
130 /* this test used to switch off whether the collection was 'Exclude' or not
131 * (the LockAll*Except collections), but that doesn't seem to be the crux of
132 * it. maybe this returns true if the element/attribute is locked in a parent
133 * element's lock collections? */
138 throw new ConfigurationErrorsException (String.Format ("The entry '{0}' is not in the collection.", name));
141 public void Remove (string name)
147 public void SetFromList (string attributeList)
151 char [] split = {','};
152 string [] attrs = attributeList.Split (split);
153 foreach (string a in attrs) {
158 void ICollection.CopyTo (System.Array array, int index)
160 names.CopyTo (array, index);
163 public string AttributeList {
165 string[] name_arr = new string[names.Count];
166 names.CopyTo (name_arr, 0);
167 return String.Join (",", name_arr);
172 get { return names.Count; }
176 public bool HasParentElements {
177 get { return false; /* XXX */ }
181 public bool IsModified {
182 get { return is_modified; }
183 internal set { is_modified = value; }
187 public bool IsSynchronized {
188 get { return false; /* XXX */ }
192 public object SyncRoot {
193 get { return this; /* XXX */ }