(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / Novell.Directory.Ldap / Novell.Directory.Ldap / LdapObjectClassSchema.cs
blob462f6198cb4d2e74922ce6221ed1dd89b27d3ce7
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.LdapObjectClassSchema.cs
26 // Author:
27 // Sunil Kumar (Sunilk@novell.com)
29 // (C) 2003 Novell, Inc (http://www.novell.com)
32 using System;
33 using Novell.Directory.Ldap.Utilclass;
35 namespace Novell.Directory.Ldap
38 /// <summary> The schema definition of an object class in a directory server.
39 ///
40 /// The LdapObjectClassSchema class represents the definition of an object
41 /// class. It is used to query the syntax of an object class.
42 ///
43 /// </summary>
44 /// <seealso cref="LdapSchemaElement">
45 /// </seealso>
46 /// <seealso cref="LdapSchema">
47 /// </seealso>
48 public class LdapObjectClassSchema:LdapSchemaElement
50 /// <summary> Returns the object classes from which this one derives.
51 ///
52 /// </summary>
53 /// <returns> The object classes superior to this class.
54 /// </returns>
55 virtual public System.String[] Superiors
57 get
59 return superiors;
63 /// <summary> Returns a list of attributes required for an entry with this object
64 /// class.
65 ///
66 /// </summary>
67 /// <returns> The list of required attributes defined for this class.
68 /// </returns>
69 virtual public System.String[] RequiredAttributes
71 get
73 return required;
77 /// <summary> Returns a list of optional attributes but not required of an entry
78 /// with this object class.
79 ///
80 /// </summary>
81 /// <returns> The list of optional attributes defined for this class.
82 /// </returns>
83 virtual public System.String[] OptionalAttributes
85 get
87 return optional;
91 /// <summary> Returns the type of object class.
92 ///
93 /// The getType method returns one of the following constants defined in
94 /// LdapObjectClassSchema:
95 /// <ul>
96 /// <li>ABSTRACT</li>
97 /// <li>AUXILIARY</li>
98 /// <li>STRUCTURAL</li>
99 /// </ul>
100 /// See the LdapSchemaElement.getQualifier method for information on
101 /// obtaining the X-NDS flags.
102 ///
103 /// </summary>
104 /// <returns> The type of object class.
105 /// </returns>
106 virtual public int Type
110 return type;
114 internal System.String[] superiors;
115 internal System.String[] required;
116 internal System.String[] optional;
117 internal int type = - 1;
119 /// <summary> This class definition defines an abstract schema class.
120 ///
121 /// This is equivalent to setting the Novell eDirectory effective class
122 /// flag to true.
123 /// </summary>
124 public const int ABSTRACT = 0;
126 /// <summary> This class definition defines a structural schema class.
127 ///
128 /// This is equivalent to setting the Novell eDirectory effective class
129 /// flag to true.
130 /// </summary>
131 public const int STRUCTURAL = 1;
133 /// <summary> This class definition defines an auxiliary schema class.</summary>
134 public const int AUXILIARY = 2;
136 /// <summary> Constructs an object class definition for adding to or deleting from
137 /// a directory's schema.
138 ///
139 /// </summary>
140 /// <param name="names"> Name(s) of the object class.
141 ///
142 /// </param>
143 /// <param name="oid"> Object Identifer of the object class - in
144 /// dotted-decimal format.
145 ///
146 /// </param>
147 /// <param name="description"> Optional description of the object class.
148 ///
149 /// </param>
150 /// <param name="superiors"> The object classes from which this one derives.
151 ///
152 /// </param>
153 /// <param name="required"> A list of attributes required
154 /// for an entry with this object class.
155 ///
156 /// </param>
157 /// <param name="optional"> A list of attributes acceptable but not required
158 /// for an entry with this object class.
159 ///
160 /// </param>
161 /// <param name="type"> One of ABSTRACT, AUXILIARY, or STRUCTURAL. These
162 /// constants are defined in LdapObjectClassSchema.
163 ///
164 /// </param>
165 /// <param name="obsolete"> true if this object is obsolete
166 ///
167 /// </param>
168 public LdapObjectClassSchema(System.String[] names, System.String oid, System.String[] superiors, System.String description, System.String[] required, System.String[] optional, int type, bool obsolete):base(LdapSchema.schemaTypeNames[LdapSchema.OBJECT_CLASS])
170 base.names = new System.String[names.Length];
171 names.CopyTo(base.names, 0);
172 base.oid = oid;
173 base.description = description;
174 this.type = type;
175 this.obsolete = obsolete;
176 if (superiors != null)
178 this.superiors = new System.String[superiors.Length];
179 superiors.CopyTo(this.superiors, 0);
181 if (required != null)
183 this.required = new System.String[required.Length];
184 required.CopyTo(this.required, 0);
186 if (optional != null)
188 this.optional = new System.String[optional.Length];
189 optional.CopyTo(this.optional, 0);
191 base.Value = formatString();
192 return ;
197 /// <summary> Constructs an object class definition from the raw string value
198 /// returned from a directory query for "objectClasses".
199 ///
200 /// </summary>
201 /// <param name="raw"> The raw string value returned from a directory
202 /// query for "objectClasses".
203 /// </param>
204 public LdapObjectClassSchema(System.String raw):base(LdapSchema.schemaTypeNames[LdapSchema.OBJECT_CLASS])
208 SchemaParser parser = new SchemaParser(raw);
210 if (parser.Names != null)
212 base.names = new System.String[parser.Names.Length];
213 parser.Names.CopyTo(base.names, 0);
216 if ((System.Object) parser.ID != null)
217 base.oid = parser.ID;
218 if ((System.Object) parser.Description != null)
219 base.description = parser.Description;
220 base.obsolete = parser.Obsolete;
221 if (parser.Required != null)
223 required = new System.String[parser.Required.Length];
224 parser.Required.CopyTo(required, 0);
226 if (parser.Optional != null)
228 optional = new System.String[parser.Optional.Length];
229 parser.Optional.CopyTo(optional, 0);
231 if (parser.Superiors != null)
233 superiors = new System.String[parser.Superiors.Length];
234 parser.Superiors.CopyTo(superiors, 0);
236 type = parser.Type;
237 System.Collections.IEnumerator qualifiers = parser.Qualifiers;
238 AttributeQualifier attrQualifier;
239 while (qualifiers.MoveNext())
241 attrQualifier = (AttributeQualifier) qualifiers.Current;
242 setQualifier(attrQualifier.Name, attrQualifier.Values);
244 base.Value = formatString();
246 catch (System.IO.IOException e)
249 return ;
252 /// <summary> Returns a string in a format suitable for directly adding to a
253 /// directory, as a value of the particular schema element class.
254 ///
255 /// </summary>
256 /// <returns> A string representation of the class' definition.
257 /// </returns>
258 protected internal override System.String formatString()
261 System.Text.StringBuilder valueBuffer = new System.Text.StringBuilder("( ");
262 System.String token;
263 System.String[] strArray;
265 if ((System.Object) (token = ID) != null)
267 valueBuffer.Append(token);
269 strArray = Names;
270 if (strArray != null)
272 valueBuffer.Append(" NAME ");
273 if (strArray.Length == 1)
275 valueBuffer.Append("'" + strArray[0] + "'");
277 else
279 valueBuffer.Append("( ");
281 for (int i = 0; i < strArray.Length; i++)
283 valueBuffer.Append(" '" + strArray[i] + "'");
285 valueBuffer.Append(" )");
288 if ((System.Object) (token = Description) != null)
290 valueBuffer.Append(" DESC ");
291 valueBuffer.Append("'" + token + "'");
293 if (Obsolete)
295 valueBuffer.Append(" OBSOLETE");
297 if ((strArray = Superiors) != null)
299 valueBuffer.Append(" SUP ");
300 if (strArray.Length > 1)
301 valueBuffer.Append("( ");
302 for (int i = 0; i < strArray.Length; i++)
304 if (i > 0)
305 valueBuffer.Append(" $ ");
306 valueBuffer.Append(strArray[i]);
308 if (strArray.Length > 1)
309 valueBuffer.Append(" )");
311 if (Type != - 1)
313 if (Type == LdapObjectClassSchema.ABSTRACT)
314 valueBuffer.Append(" ABSTRACT");
315 else if (Type == LdapObjectClassSchema.AUXILIARY)
316 valueBuffer.Append(" AUXILIARY");
317 else if (Type == LdapObjectClassSchema.STRUCTURAL)
318 valueBuffer.Append(" STRUCTURAL");
320 if ((strArray = RequiredAttributes) != null)
322 valueBuffer.Append(" MUST ");
323 if (strArray.Length > 1)
324 valueBuffer.Append("( ");
325 for (int i = 0; i < strArray.Length; i++)
327 if (i > 0)
328 valueBuffer.Append(" $ ");
329 valueBuffer.Append(strArray[i]);
331 if (strArray.Length > 1)
332 valueBuffer.Append(" )");
334 if ((strArray = OptionalAttributes) != null)
336 valueBuffer.Append(" MAY ");
337 if (strArray.Length > 1)
338 valueBuffer.Append("( ");
339 for (int i = 0; i < strArray.Length; i++)
341 if (i > 0)
342 valueBuffer.Append(" $ ");
343 valueBuffer.Append(strArray[i]);
345 if (strArray.Length > 1)
346 valueBuffer.Append(" )");
348 System.Collections.IEnumerator en;
349 if ((en = QualifierNames) != null)
351 System.String qualName;
352 System.String[] qualValue;
353 while (en.MoveNext())
355 qualName = ((System.String) en.Current);
356 valueBuffer.Append(" " + qualName + " ");
357 if ((qualValue = getQualifier(qualName)) != null)
359 if (qualValue.Length > 1)
360 valueBuffer.Append("( ");
361 for (int i = 0; i < qualValue.Length; i++)
363 if (i > 0)
364 valueBuffer.Append(" ");
365 valueBuffer.Append("'" + qualValue[i] + "'");
367 if (qualValue.Length > 1)
368 valueBuffer.Append(" )");
372 valueBuffer.Append(" )");
373 return valueBuffer.ToString();