**** Merged from MCS ****
[mono-project.git] / mcs / class / Novell.Directory.Ldap / Novell.Directory.Ldap / LdapAttributeSchema.cs
blob5e1cb867c46785cf97da8cf75adc38474c9d8880
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.LdapAttributeSchema.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 definition of an attribute type in the schema.
38 ///
39 /// LdapAttributeSchema is used to discover an attribute's
40 /// syntax, and add or delete an attribute definition.
41 /// RFC 2252, "Lightweight Directory Access Protocol (v3):
42 /// Attribute Syntax Definitions" contains a description
43 /// of the information on the Ldap representation of schema.
44 /// draft-sermerseim-nds-ldap-schema-02, "Ldap Schema for NDS"
45 /// defines the schema descriptions and non-standard syntaxes
46 /// used by Novell eDirectory.
47 ///
48 /// </summary>
49 /// <seealso cref="LdapSchema">
50 /// </seealso>
51 public class LdapAttributeSchema:LdapSchemaElement
53 private void InitBlock()
55 usage = USER_APPLICATIONS;
57 /// <summary> Returns the object identifer of the syntax of the attribute, in
58 /// dotted numerical format.
59 ///
60 /// </summary>
61 /// <returns> The object identifer of the attribute's syntax.
62 /// </returns>
63 virtual public System.String SyntaxString
65 get
67 return syntaxString;
71 /// <summary> Returns the name of the attribute type which this attribute derives
72 /// from, or null if there is no superior attribute.
73 ///
74 /// </summary>
75 /// <returns> The attribute's superior attribute, or null if there is none.
76 /// </returns>
77 virtual public System.String Superior
79 get
81 return superior;
85 /// <summary> Returns true if the attribute is single-valued.
86 ///
87 /// </summary>
88 /// <returns> True if the attribute is single-valued; false if the attribute
89 /// is multi-valued.
90 /// </returns>
91 virtual public bool SingleValued
93 get
95 return single;
99 /// <summary> Returns the matching rule for this attribute.
100 ///
101 /// </summary>
102 /// <returns> The attribute's equality matching rule; null if it has no equality
103 /// matching rule.
104 /// </returns>
105 virtual public System.String EqualityMatchingRule
109 return equality;
113 /// <summary> Returns the ordering matching rule for this attribute.
114 ///
115 /// </summary>
116 /// <returns> The attribute's ordering matching rule; null if it has no ordering
117 /// matching rule.
118 /// </returns>
119 virtual public System.String OrderingMatchingRule
123 return ordering;
127 /// <summary> Returns the substring matching rule for this attribute.
128 ///
129 /// </summary>
130 /// <returns> The attribute's substring matching rule; null if it has no substring
131 /// matching rule.
132 /// </returns>
133 virtual public System.String SubstringMatchingRule
137 return substring;
141 /// <summary> Returns true if the attribute is a collective attribute.
142 ///
143 /// </summary>
144 /// <returns> True if the attribute is a collective; false if the attribute
145 /// is not a collective attribute.
146 /// </returns>
147 virtual public bool Collective
151 return collective;
155 /// <summary> Returns false if the attribute is read-only.
156 ///
157 /// </summary>
158 /// <returns> False if the attribute is read-only; true if the attribute
159 /// is read-write.
160 /// </returns>
161 virtual public bool UserModifiable
165 return userMod;
169 /// <summary> Returns the usage of the attribute.
170 ///
171 /// </summary>
172 /// <returns> One of the following values: USER_APPLICATIONS,
173 /// DIRECTORY_OPERATION, DISTRIBUTED_OPERATION or
174 /// DSA_OPERATION.
175 /// </returns>
176 virtual public int Usage
180 return usage;
185 private System.String syntaxString;
186 private bool single = false;
187 private System.String superior;
188 private System.String equality;
189 private System.String ordering;
190 private System.String substring;
191 private bool collective = false;
192 private bool userMod = true;
193 private int usage;
195 /// <summary> Indicates that the attribute usage is for ordinary application
196 /// or user data.
197 /// </summary>
198 public const int USER_APPLICATIONS = 0;
199 /// <summary> Indicates that the attribute usage is for directory operations.
200 /// Values are vendor specific.
201 /// </summary>
202 public const int DIRECTORY_OPERATION = 1;
203 /// <summary> Indicates that the attribute usage is for distributed operational
204 /// attributes. These hold server (DSA) information that is shared among
205 /// servers holding replicas of the entry.
206 /// </summary>
207 public const int DISTRIBUTED_OPERATION = 2;
208 /// <summary> Indicates that the attribute usage is for local operational attributes.
209 /// These hold server (DSA) information that is local to a server.
210 /// </summary>
211 public const int DSA_OPERATION = 3;
213 /// <summary> Constructs an attribute definition for adding to or deleting from a
214 /// directory's schema.
215 ///
216 /// </summary>
217 /// <param name="names">Names of the attribute.
218 ///
219 /// </param>
220 /// <param name="oid"> Object identifer of the attribute, in
221 /// dotted numerical format.
222 ///
223 /// </param>
224 /// <param name="description"> Optional description of the attribute.
225 ///
226 /// </param>
227 /// <param name="syntaxString"> Object identifer of the syntax of the
228 /// attribute, in dotted numerical format.
229 ///
230 /// </param>
231 /// <param name="single"> True if the attribute is to be single-valued.
232 ///
233 /// </param>
234 /// <param name="superior"> Optional name of the attribute type which this
235 /// attribute type derives from; null if there is no
236 /// superior attribute type.
237 ///
238 /// </param>
239 /// <param name="obsolete"> True if the attribute is obsolete.
240 ///
241 /// </param>
242 /// <param name="equality"> Optional matching rule name; null if there is not
243 /// an equality matching rule for this attribute.
244 ///
245 /// </param>
246 /// <param name="ordering">Optional matching rule name; null if there is not
247 /// an ordering matching rule for this attribute.
248 ///
249 /// </param>
250 /// <param name="substring"> Optional matching rule name; null if there is not
251 /// a substring matching rule for this attribute.
252 ///
253 /// </param>
254 /// <param name="collective"> True of this attribute is a collective attribute
255 ///
256 /// </param>
257 /// <param name="isUserModifiable"> False if this attribute is a read-only attribute
258 ///
259 /// </param>
260 /// <param name="usage"> Describes what the attribute is used for. Must be
261 /// one of the following: USER_APPLICATIONS,
262 /// DIRECTORY_OPERATION, DISTRIBUTED_OPERATION or
263 /// DSA_OPERATION.
264 /// </param>
265 public LdapAttributeSchema(System.String[] names, System.String oid, System.String description, System.String syntaxString, bool single, System.String superior, bool obsolete, System.String equality, System.String ordering, System.String substring, bool collective, bool isUserModifiable, int usage):base(LdapSchema.schemaTypeNames[LdapSchema.ATTRIBUTE])
267 InitBlock();
268 base.names = names;
269 base.oid = oid;
270 base.description = description;
271 base.obsolete = obsolete;
272 this.syntaxString = syntaxString;
273 this.single = single;
274 this.equality = equality;
275 this.ordering = ordering;
276 this.substring = substring;
277 this.collective = collective;
278 this.userMod = isUserModifiable;
279 this.usage = usage;
280 base.Value = formatString();
281 return ;
286 /// <summary> Constructs an attribute definition from the raw string value returned
287 /// on a directory query for "attributetypes".
288 ///
289 /// </summary>
290 /// <param name="raw"> The raw string value returned on a directory
291 /// query for "attributetypes".
292 /// </param>
293 public LdapAttributeSchema(System.String raw):base(LdapSchema.schemaTypeNames[LdapSchema.ATTRIBUTE])
295 InitBlock();
298 SchemaParser parser = new SchemaParser(raw);
300 if (parser.Names != null)
301 base.names = parser.Names;
302 if ((System.Object) parser.ID != null)
303 base.oid = parser.ID;
304 if ((System.Object) parser.Description != null)
305 base.description = parser.Description;
306 if ((System.Object) parser.Syntax != null)
307 syntaxString = parser.Syntax;
308 if ((System.Object) parser.Superior != null)
309 syntaxString = parser.Superior;
310 single = parser.Single;
311 base.obsolete = parser.Obsolete;
312 System.Collections.IEnumerator qualifiers = parser.Qualifiers;
313 AttributeQualifier attrQualifier;
314 while (qualifiers.MoveNext())
316 attrQualifier = (AttributeQualifier) qualifiers.Current;
317 setQualifier(attrQualifier.Name, attrQualifier.Values);
319 base.Value = formatString();
321 catch (System.IO.IOException e)
323 throw new System.SystemException(e.ToString());
325 return ;
328 /// <summary> Returns a string in a format suitable for directly adding to a
329 /// directory, as a value of the particular schema element attribute.
330 ///
331 /// </summary>
332 /// <returns> A string representation of the attribute's definition.
333 /// </returns>
334 protected internal override System.String formatString()
337 System.Text.StringBuilder valueBuffer = new System.Text.StringBuilder("( ");
338 System.String token;
339 System.String[] strArray;
341 if ((System.Object) (token = ID) != null)
343 valueBuffer.Append(token);
345 strArray = Names;
346 if (strArray != null)
348 valueBuffer.Append(" NAME ");
349 if (strArray.Length == 1)
351 valueBuffer.Append("'" + strArray[0] + "'");
353 else
355 valueBuffer.Append("( ");
357 for (int i = 0; i < strArray.Length; i++)
359 valueBuffer.Append(" '" + strArray[i] + "'");
361 valueBuffer.Append(" )");
364 if ((System.Object) (token = Description) != null)
366 valueBuffer.Append(" DESC ");
367 valueBuffer.Append("'" + token + "'");
369 if (Obsolete)
371 valueBuffer.Append(" OBSOLETE");
373 if ((System.Object) (token = Superior) != null)
375 valueBuffer.Append(" SUP ");
376 valueBuffer.Append("'" + token + "'");
378 if ((System.Object) (token = EqualityMatchingRule) != null)
380 valueBuffer.Append(" EQUALITY ");
381 valueBuffer.Append("'" + token + "'");
383 if ((System.Object) (token = OrderingMatchingRule) != null)
385 valueBuffer.Append(" ORDERING ");
386 valueBuffer.Append("'" + token + "'");
388 if ((System.Object) (token = SubstringMatchingRule) != null)
390 valueBuffer.Append(" SUBSTR ");
391 valueBuffer.Append("'" + token + "'");
393 if ((System.Object) (token = SyntaxString) != null)
395 valueBuffer.Append(" SYNTAX ");
396 valueBuffer.Append(token);
398 if (SingleValued)
400 valueBuffer.Append(" SINGLE-VALUE");
402 if (Collective)
404 valueBuffer.Append(" COLLECTIVE");
406 if (UserModifiable == false)
408 valueBuffer.Append(" NO-USER-MODIFICATION");
410 int useType;
411 if ((useType = Usage) != USER_APPLICATIONS)
413 switch (useType)
416 case DIRECTORY_OPERATION:
417 valueBuffer.Append(" USAGE directoryOperation");
418 break;
420 case DISTRIBUTED_OPERATION:
421 valueBuffer.Append(" USAGE distributedOperation");
422 break;
424 case DSA_OPERATION:
425 valueBuffer.Append(" USAGE dSAOperation");
426 break;
428 default:
429 break;
433 System.Collections.IEnumerator en = QualifierNames;
435 while (en.MoveNext())
437 token = ((System.String) en.Current);
438 if (((System.Object) token != null))
440 valueBuffer.Append(" " + token);
441 strArray = getQualifier(token);
442 if (strArray != null)
444 if (strArray.Length > 1)
445 valueBuffer.Append("(");
446 for (int i = 0; i < strArray.Length; i++)
448 valueBuffer.Append(" '" + strArray[i] + "'");
450 if (strArray.Length > 1)
451 valueBuffer.Append(" )");
455 valueBuffer.Append(" )");
456 return valueBuffer.ToString();