**** Merged from MCS ****
[mono-project.git] / mcs / class / Novell.Directory.Ldap / Novell.Directory.Ldap / LdapSchemaElement.cs
blobda1281ad6a1eb55832990cf60540b515e7dbdd30
1 /******************************************************************************
2 * The MIT License
3 * Copyright (c) 2003 Novell Inc. www.novell.com
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the Software), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *******************************************************************************/
24 // Novell.Directory.Ldap.LdapSchemaElement.cs
26 // Author:
27 // Sunil Kumar (Sunilk@novell.com)
29 // (C) 2003 Novell, Inc (http://www.novell.com)
31 using System;
32 using Novell.Directory.Ldap.Utilclass;
34 namespace Novell.Directory.Ldap
37 /// <summary> The LdapSchemaElement class is the base class representing schema
38 /// elements (definitions) in Ldap.
39 ///
40 /// An LdapSchemaElement is read-only, single-valued LdapAttribute.
41 /// Therefore, it does not support the addValue and removeValue methods from
42 /// LdapAttribute. This class overrides those methods and throws
43 /// <code>UnsupportedOperationException</code> if either of those methods are
44 /// invoked by an application.
45 ///
46 /// </summary>
47 /// <seealso cref="LdapSchema">
48 /// </seealso>
49 /// <seealso cref="LdapConnection.FetchSchema">
50 /// </seealso>
51 public abstract class LdapSchemaElement:LdapAttribute
53 private void InitBlock()
55 hashQualifier = new System.Collections.Hashtable();
57 /// <summary> Returns an array of names for the element, or null if
58 /// none is found.
59 ///
60 /// The getNames method accesses the NAME qualifier (from the BNF
61 /// descriptions of Ldap schema definitions). The array consists of all
62 /// values of the NAME qualifier.
63 ///
64 /// </summary>
65 /// <returns> An array of names for the element, or null if none
66 /// is found.
67 /// </returns>
68 virtual public System.String[] Names
70 get
72 if (names == null)
73 return null;
74 System.String[] generated_var = new System.String[names.Length];
75 names.CopyTo(generated_var, 0);
76 return generated_var;
80 /// <summary> Returns the description of the element.
81 ///
82 /// The getDescription method returns the value of the DESC qualifier
83 /// (from the BNF descriptions of Ldap schema definitions).
84 ///
85 /// </summary>
86 /// <returns> The description of the element.
87 ///
88 /// </returns>
89 virtual public System.String Description
91 get
93 return description;
97 /// <summary> Returns the unique object identifier (OID) of the element.
98 ///
99 /// </summary>
100 /// <returns> The OID of the element.
101 /// </returns>
102 virtual public System.String ID
106 return oid;
110 /// <summary> Returns an enumeration of all qualifiers of the element which are
111 /// vendor specific (begin with "X-").
112 ///
113 /// </summary>
114 /// <returns> An enumeration of all qualifiers of the element.
115 /// </returns>
116 virtual public System.Collections.IEnumerator QualifierNames
120 return new EnumeratedIterator(new SupportClass.SetSupport(hashQualifier.Keys).GetEnumerator());
124 /// <summary> Returns whether the element has the OBSOLETE qualifier
125 /// in its Ldap definition.
126 ///
127 /// </summary>
128 /// <returns> True if the Ldap definition contains the OBSOLETE qualifier;
129 /// false if OBSOLETE qualifier is not present.
130 /// </returns>
131 virtual public bool Obsolete
135 return obsolete;
140 /// <summary> Creates an LdapSchemaElement by setting the name of the LdapAttribute.
141 /// Because this is the only constructor, all extended classes are expected
142 /// to call this constructor. The value of the LdapAttribute must be set
143 /// by the setValue method.
144 /// </summary>
145 /// <param name="attrName"> The attribute name of the schema definition. Valid
146 /// names are one of the following:
147 /// "attributeTypes", "objectClasses", "ldapSyntaxes",
148 /// "nameForms", "dITContentRules", "dITStructureRules",
149 /// "matchingRules", or "matchingRuleUse"
150 /// </param>
151 protected internal LdapSchemaElement(System.String attrName):base(attrName)
153 InitBlock();
155 /// <summary> The names of the schema element.</summary>
156 [CLSCompliantAttribute(false)]
157 protected internal System.String[] names = new System.String[]{""};
159 /// <summary> The OID for the schema element.</summary>
160 protected internal System.String oid = "";
162 /// <summary> The description for the schema element.</summary>
163 [CLSCompliantAttribute(false)]
164 protected internal System.String description = "";
166 /// <summary> If present, indicates that the element is obsolete, no longer in use in
167 /// the directory.
168 /// </summary>
169 [CLSCompliantAttribute(false)]
170 protected internal bool obsolete = false;
172 /// <summary> A string array of optional, or vendor-specific, qualifiers for the
173 /// schema element.
174 ///
175 /// These optional qualifiers begin with "X-"; the Novell eDirectory
176 /// specific qualifiers begin with "X-NDS".
177 /// </summary>
178 protected internal System.String[] qualifier = new System.String[]{""};
180 /// <summary> A hash table that contains the vendor-specific qualifiers (for example,
181 /// the X-NDS flags).
182 /// </summary>
183 protected internal System.Collections.Hashtable hashQualifier;
185 /// <summary> Returns an array of all values of a specified optional or non-
186 /// standard qualifier of the element.
187 ///
188 /// The getQualifier method may be used to access the values of
189 /// vendor-specific qualifiers (which begin with "X-").
190 ///
191 /// </summary>
192 /// <param name="name"> The name of the qualifier, case-sensitive.
193 ///
194 /// </param>
195 /// <returns> An array of values for the specified non-standard qualifier.
196 /// </returns>
197 public virtual System.String[] getQualifier(System.String name)
199 AttributeQualifier attr = (AttributeQualifier) hashQualifier[name];
200 if (attr != null)
202 return attr.Values;
204 return null;
207 /// <summary> Returns a string in a format suitable for directly adding to a directory,
208 /// as a value of the particular schema element.
209 ///
210 /// </summary>
211 /// <returns> A string that can be used to add the element to the directory.
212 /// </returns>
213 public override System.String ToString()
215 return formatString();
218 /// <summary> Implementations of formatString format a schema element into a string
219 /// suitable for using in a modify (ADD) operation to the directory.
220 /// toString uses this method. This method is needed because a call to
221 /// setQualifier requires reconstructing the string value of the schema
222 /// element.
223 /// </summary>
224 abstract protected internal System.String formatString();
226 /// <summary> Sets the values of a specified optional or non-standard qualifier of
227 /// the element.
228 ///
229 /// The setQualifier method is used to set the values of vendor-
230 /// specific qualifiers (which begin with "X-").
231 ///
232 /// </summary>
233 /// <param name="name"> The name of the qualifier, case-sensitive.
234 ///
235 /// </param>
236 /// <param name="values"> The values to set for the qualifier.
237 /// </param>
238 public virtual void setQualifier(System.String name, System.String[] values)
240 AttributeQualifier attrQualifier = new AttributeQualifier(name, values);
241 SupportClass.PutElement(hashQualifier, name, attrQualifier);
244 * This is the only method that modifies the schema element.
245 * We need to reset the attribute value since it has changed.
247 base.Value = formatString();
248 return ;
251 /// <summary> LdapSchemaElement is read-only and this method is over-ridden to
252 /// throw an exception.
253 /// @throws UnsupportedOperationException always thrown since
254 /// LdapSchemaElement is read-only
255 /// </summary>
256 public override void addValue(System.String value_Renamed)
258 throw new System.NotSupportedException("addValue is not supported by LdapSchemaElement");
261 /// <summary> LdapSchemaElement is read-only and this method is over-ridden to
262 /// throw an exception.
263 /// @throws UnsupportedOperationException always thrown since
264 /// LdapSchemaElement is read-only
265 /// </summary>
266 public virtual void addValue(System.Byte[] value_Renamed)
268 throw new System.NotSupportedException("addValue is not supported by LdapSchemaElement");
270 /// <summary> LdapSchemaElement is read-only and this method is over-ridden to
271 /// throw an exception.
272 /// @throws UnsupportedOperationException always thrown since
273 /// LdapSchemaElement is read-only
274 /// </summary>
275 public override void removeValue(System.String value_Renamed)
277 throw new System.NotSupportedException("removeValue is not supported by LdapSchemaElement");
280 /// <summary> LdapSchemaElement is read-only and this method is over-ridden to
281 /// throw an exception.
282 /// @throws UnsupportedOperationException always thrown since
283 /// LdapSchemaElement is read-only
284 /// </summary>
285 public virtual void removeValue(System.Byte[] value_Renamed)
287 throw new System.NotSupportedException("removeValue is not supported by LdapSchemaElement");