1 /******************************************************************************
3 * Copyright (c) 2003 Novell Inc. www.novell.com
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
22 *******************************************************************************/
24 // Novell.Directory.Ldap.LdapAttributeSchema.cs
27 // Sunil Kumar (Sunilk@novell.com)
29 // (C) 2003 Novell, Inc (http://www.novell.com)
32 using Novell.Directory.Ldap.Utilclass;
34 namespace Novell.Directory.Ldap
37 /// <summary> The definition of an attribute type in the schema.
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.
49 /// <seealso cref="LdapSchema">
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.
61 /// <returns> The object identifer of the attribute's syntax.
63 virtual public System.String SyntaxString
71 /// <summary> Returns the name of the attribute type which this attribute derives
72 /// from, or null if there is no superior attribute.
75 /// <returns> The attribute's superior attribute, or null if there is none.
77 virtual public System.String Superior
85 /// <summary> Returns true if the attribute is single-valued.
88 /// <returns> True if the attribute is single-valued; false if the attribute
91 virtual public bool SingleValued
99 /// <summary> Returns the matching rule for this attribute.
102 /// <returns> The attribute's equality matching rule; null if it has no equality
105 virtual public System.String EqualityMatchingRule
113 /// <summary> Returns the ordering matching rule for this attribute.
116 /// <returns> The attribute's ordering matching rule; null if it has no ordering
119 virtual public System.String OrderingMatchingRule
127 /// <summary> Returns the substring matching rule for this attribute.
130 /// <returns> The attribute's substring matching rule; null if it has no substring
133 virtual public System.String SubstringMatchingRule
141 /// <summary> Returns true if the attribute is a collective attribute.
144 /// <returns> True if the attribute is a collective; false if the attribute
145 /// is not a collective attribute.
147 virtual public bool Collective
155 /// <summary> Returns false if the attribute is read-only.
158 /// <returns> False if the attribute is read-only; true if the attribute
161 virtual public bool UserModifiable
169 /// <summary> Returns the usage of the attribute.
172 /// <returns> One of the following values: USER_APPLICATIONS,
173 /// DIRECTORY_OPERATION, DISTRIBUTED_OPERATION or
176 virtual public int 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;
195 /// <summary> Indicates that the attribute usage is for ordinary application
198 public const int USER_APPLICATIONS = 0;
199 /// <summary> Indicates that the attribute usage is for directory operations.
200 /// Values are vendor specific.
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.
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.
211 public const int DSA_OPERATION = 3;
213 /// <summary> Constructs an attribute definition for adding to or deleting from a
214 /// directory's schema.
217 /// <param name="names">Names of the attribute.
220 /// <param name="oid"> Object identifer of the attribute, in
221 /// dotted numerical format.
224 /// <param name="description"> Optional description of the attribute.
227 /// <param name="syntaxString"> Object identifer of the syntax of the
228 /// attribute, in dotted numerical format.
231 /// <param name="single"> True if the attribute is to be single-valued.
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.
239 /// <param name="obsolete"> True if the attribute is obsolete.
242 /// <param name="equality"> Optional matching rule name; null if there is not
243 /// an equality matching rule for this attribute.
246 /// <param name="ordering">Optional matching rule name; null if there is not
247 /// an ordering matching rule for this attribute.
250 /// <param name="substring"> Optional matching rule name; null if there is not
251 /// a substring matching rule for this attribute.
254 /// <param name="collective"> True of this attribute is a collective attribute
257 /// <param name="isUserModifiable"> False if this attribute is a read-only attribute
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
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])
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;
280 base.Value = formatString();
286 /// <summary> Constructs an attribute definition from the raw string value returned
287 /// on a directory query for "attributetypes".
290 /// <param name="raw"> The raw string value returned on a directory
291 /// query for "attributetypes".
293 public LdapAttributeSchema(System.String raw):base(LdapSchema.schemaTypeNames[LdapSchema.ATTRIBUTE])
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());
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.
332 /// <returns> A string representation of the attribute's definition.
334 protected internal override System.String formatString()
337 System.Text.StringBuilder valueBuffer = new System.Text.StringBuilder("( ");
339 System.String[] strArray;
341 if ((System.Object) (token = ID) != null)
343 valueBuffer.Append(token);
346 if (strArray != null)
348 valueBuffer.Append(" NAME ");
349 if (strArray.Length == 1)
351 valueBuffer.Append("'" + strArray[0] + "'");
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 + "'");
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);
400 valueBuffer.Append(" SINGLE-VALUE");
404 valueBuffer.Append(" COLLECTIVE");
406 if (UserModifiable == false)
408 valueBuffer.Append(" NO-USER-MODIFICATION");
411 if ((useType = Usage) != USER_APPLICATIONS)
416 case DIRECTORY_OPERATION:
417 valueBuffer.Append(" USAGE directoryOperation");
420 case DISTRIBUTED_OPERATION:
421 valueBuffer.Append(" USAGE distributedOperation");
425 valueBuffer.Append(" USAGE dSAOperation");
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();