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)
33 using SchemaParser = Novell.Directory.Ldap.Utilclass.SchemaParser;
34 using AttributeQualifier = Novell.Directory.Ldap.Utilclass.AttributeQualifier;
36 namespace Novell.Directory.Ldap
39 /// <summary> A specific a name form in the directory schema.
41 /// The LdapNameFormSchema class represents the definition of a Name Form. It
42 /// is used to discover or modify the allowed naming attributes for a particular
46 /// <seealso cref="LdapSchemaElement">
48 /// <seealso cref="LdapSchema">
51 public class LdapNameFormSchema:LdapSchemaElement
53 /// <summary> Returns the name of the object class which this name form applies to.
56 /// <returns> The name of the object class.
58 virtual public System.String ObjectClass
66 /// <summary> Returns the list of required naming attributes for an entry
67 /// controlled by this name form.
70 /// <returns> The list of required naming attributes.
72 virtual public System.String[] RequiredNamingAttributes
80 /// <summary> Returns the list of optional naming attributes for an entry
81 /// controlled by this content rule.
84 /// <returns> The list of the optional naming attributes.
86 virtual public System.String[] OptionalNamingAttributes
94 private System.String objectClass;
95 private System.String[] required;
96 private System.String[] optional;
98 /// <summary> Constructs a name form for adding to or deleting from the schema.
101 /// <param name="names"> The name(s) of the name form.
104 /// <param name="oid"> The unique object identifier of the name form - in
105 /// dotted numerical format.
108 /// <param name="description">An optional description of the name form.
111 /// <param name="obsolete"> True if the name form is obsolete.
114 /// <param name="objectClass">The object to which this name form applies.
115 /// This may be specified by either name or
119 /// <param name="required"> A list of the attributes that must be present
120 /// in the RDN of an entry that this name form
121 /// controls. These attributes may be specified by
122 /// either name or numeric oid.
125 /// <param name="optional"> A list of the attributes that may be present
126 /// in the RDN of an entry that this name form
127 /// controls. These attributes may be specified by
128 /// either name or numeric oid.
130 public LdapNameFormSchema(System.String[] names, System.String oid, System.String description, bool obsolete, System.String objectClass, System.String[] required, System.String[] optional):base(LdapSchema.schemaTypeNames[LdapSchema.NAME_FORM])
132 base.names = new System.String[names.Length];
133 names.CopyTo(base.names, 0);
135 base.description = description;
136 base.obsolete = obsolete;
137 this.objectClass = objectClass;
138 this.required = new System.String[required.Length];
139 required.CopyTo(this.required, 0);
140 this.optional = new System.String[optional.Length];
141 optional.CopyTo(this.optional, 0);
142 base.Value = formatString();
150 * Constructs a Name Form from the raw string value returned on a
151 * schema query for nameForms.
153 * @param raw The raw string value returned on a schema
154 * query for nameForms.
156 public LdapNameFormSchema(System.String raw):base(LdapSchema.schemaTypeNames[LdapSchema.NAME_FORM])
158 base.obsolete = false;
161 SchemaParser parser = new SchemaParser(raw);
163 if (parser.Names != null)
165 base.names = new System.String[parser.Names.Length];
166 parser.Names.CopyTo(base.names, 0);
168 if ((System.Object) parser.ID != null)
169 base.oid = new System.Text.StringBuilder(parser.ID).ToString();
170 if ((System.Object) parser.Description != null)
171 base.description = new System.Text.StringBuilder(parser.Description).ToString();
172 if (parser.Required != null)
174 required = new System.String[parser.Required.Length];
175 parser.Required.CopyTo(required, 0);
177 if (parser.Optional != null)
179 optional = new System.String[parser.Optional.Length];
180 parser.Optional.CopyTo(optional, 0);
182 if ((System.Object) parser.ObjectClass != null)
183 objectClass = parser.ObjectClass;
184 base.obsolete = parser.Obsolete;
185 System.Collections.IEnumerator qualifiers = parser.Qualifiers;
186 AttributeQualifier attrQualifier;
187 while (qualifiers.MoveNext())
189 attrQualifier = (AttributeQualifier) qualifiers.Current;
190 setQualifier(attrQualifier.Name, attrQualifier.Values);
192 base.Value = formatString();
194 catch (System.IO.IOException e)
200 /// <summary> Returns a string in a format suitable for directly adding to a
201 /// directory, as a value of the particular schema element class.
204 /// <returns> A string representation of the class' definition.
206 protected internal override System.String formatString()
208 System.Text.StringBuilder valueBuffer = new System.Text.StringBuilder("( ");
210 System.String[] strArray;
212 if ((System.Object) (token = ID) != null)
214 valueBuffer.Append(token);
217 if (strArray != null)
219 valueBuffer.Append(" NAME ");
220 if (strArray.Length == 1)
222 valueBuffer.Append("'" + strArray[0] + "'");
226 valueBuffer.Append("( ");
228 for (int i = 0; i < strArray.Length; i++)
230 valueBuffer.Append(" '" + strArray[i] + "'");
232 valueBuffer.Append(" )");
235 if ((System.Object) (token = Description) != null)
237 valueBuffer.Append(" DESC ");
238 valueBuffer.Append("'" + token + "'");
242 valueBuffer.Append(" OBSOLETE");
244 if ((System.Object) (token = ObjectClass) != null)
246 valueBuffer.Append(" OC ");
247 valueBuffer.Append("'" + token + "'");
249 if ((strArray = RequiredNamingAttributes) != null)
251 valueBuffer.Append(" MUST ");
252 if (strArray.Length > 1)
253 valueBuffer.Append("( ");
254 for (int i = 0; i < strArray.Length; i++)
257 valueBuffer.Append(" $ ");
258 valueBuffer.Append(strArray[i]);
260 if (strArray.Length > 1)
261 valueBuffer.Append(" )");
263 if ((strArray = OptionalNamingAttributes) != null)
265 valueBuffer.Append(" MAY ");
266 if (strArray.Length > 1)
267 valueBuffer.Append("( ");
268 for (int i = 0; i < strArray.Length; i++)
271 valueBuffer.Append(" $ ");
272 valueBuffer.Append(strArray[i]);
274 if (strArray.Length > 1)
275 valueBuffer.Append(" )");
277 System.Collections.IEnumerator en;
278 if ((en = QualifierNames) != null)
280 System.String qualName;
281 System.String[] qualValue;
282 while (en.MoveNext())
284 qualName = ((System.String) en.Current);
285 valueBuffer.Append(" " + qualName + " ");
286 if ((qualValue = getQualifier(qualName)) != null)
288 if (qualValue.Length > 1)
289 valueBuffer.Append("( ");
290 for (int i = 0; i < qualValue.Length; i++)
293 valueBuffer.Append(" ");
294 valueBuffer.Append("'" + qualValue[i] + "'");
296 if (qualValue.Length > 1)
297 valueBuffer.Append(" )");
301 valueBuffer.Append(" )");
302 return valueBuffer.ToString();