[xbuild] Implements property functions using constructor syntax. Fixes #12999
[mono.git] / mcs / class / Novell.Directory.Ldap / Novell.Directory.Ldap / LdapObjectClassSchema.cs
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:
11
12 * The above copyright notice and this permission notice shall be included in 
13 * all copies or substantial portions of the Software.
14
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 *******************************************************************************/
23 //
24 // Novell.Directory.Ldap.LdapObjectClassSchema.cs
25 //
26 // Author:
27 //   Sunil Kumar (Sunilk@novell.com)
28 //
29 // (C) 2003 Novell, Inc (http://www.novell.com)
30 //
31
32 using System;
33 using Novell.Directory.Ldap.Utilclass;
34
35 namespace Novell.Directory.Ldap
36 {
37         
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
49         {
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
56                 {
57                         get
58                         {
59                                 return superiors;
60                         }
61                         
62                 }
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
70                 {
71                         get
72                         {
73                                 return required;
74                         }
75                         
76                 }
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
84                 {
85                         get
86                         {
87                                 return optional;
88                         }
89                         
90                 }
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
107                 {
108                         get
109                         {
110                                 return type;
111                         }
112                         
113                 }
114                 internal System.String[] superiors;
115                 internal System.String[] required;
116                 internal System.String[] optional;
117                 internal int type = - 1;
118                 
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;
125                 
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;
132                 
133                 /// <summary> This class definition defines an auxiliary schema class.</summary>
134                 public const int AUXILIARY = 2;
135                 
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])
169                 {
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)
177                         {
178                                 this.superiors = new System.String[superiors.Length];
179                                 superiors.CopyTo(this.superiors, 0);
180                         }
181                         if (required != null)
182                         {
183                                 this.required = new System.String[required.Length];
184                                 required.CopyTo(this.required, 0);
185                         }
186                         if (optional != null)
187                         {
188                                 this.optional = new System.String[optional.Length];
189                                 optional.CopyTo(this.optional, 0);
190                         }
191                         base.Value = formatString();
192                         return ;
193                 }
194                 
195                 
196                 
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])
205                 {
206                         try
207                         {
208                                 SchemaParser parser = new SchemaParser(raw);
209                                 
210                                 if (parser.Names != null)
211                                 {
212                                         base.names = new System.String[parser.Names.Length];
213                                         parser.Names.CopyTo(base.names, 0);
214                                 }
215                                 
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)
222                                 {
223                                         required = new System.String[parser.Required.Length];
224                                         parser.Required.CopyTo(required, 0);
225                                 }
226                                 if (parser.Optional != null)
227                                 {
228                                         optional = new System.String[parser.Optional.Length];
229                                         parser.Optional.CopyTo(optional, 0);
230                                 }
231                                 if (parser.Superiors != null)
232                                 {
233                                         superiors = new System.String[parser.Superiors.Length];
234                                         parser.Superiors.CopyTo(superiors, 0);
235                                 }
236                                 type = parser.Type;
237                                 System.Collections.IEnumerator qualifiers = parser.Qualifiers;
238                                 AttributeQualifier attrQualifier;
239                                 while (qualifiers.MoveNext())
240                                 {
241                                         attrQualifier = (AttributeQualifier) qualifiers.Current;
242                                         setQualifier(attrQualifier.Name, attrQualifier.Values);
243                                 }
244                                 base.Value = formatString();
245                         }
246                         catch (System.IO.IOException e)
247                         {
248                         }
249                         return ;
250                 }
251                 
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()
259                 {
260                         
261                         System.Text.StringBuilder valueBuffer = new System.Text.StringBuilder("( ");
262                         System.String token;
263                         System.String[] strArray;
264                         
265                         if ((System.Object) (token = ID) != null)
266                         {
267                                 valueBuffer.Append(token);
268                         }
269                         strArray = Names;
270                         if (strArray != null)
271                         {
272                                 valueBuffer.Append(" NAME ");
273                                 if (strArray.Length == 1)
274                                 {
275                                         valueBuffer.Append("'" + strArray[0] + "'");
276                                 }
277                                 else
278                                 {
279                                         valueBuffer.Append("( ");
280                                         
281                                         for (int i = 0; i < strArray.Length; i++)
282                                         {
283                                                 valueBuffer.Append(" '" + strArray[i] + "'");
284                                         }
285                                         valueBuffer.Append(" )");
286                                 }
287                         }
288                         if ((System.Object) (token = Description) != null)
289                         {
290                                 valueBuffer.Append(" DESC ");
291                                 valueBuffer.Append("'" + token + "'");
292                         }
293                         if (Obsolete)
294                         {
295                                 valueBuffer.Append(" OBSOLETE");
296                         }
297                         if ((strArray = Superiors) != null)
298                         {
299                                 valueBuffer.Append(" SUP ");
300                                 if (strArray.Length > 1)
301                                         valueBuffer.Append("( ");
302                                 for (int i = 0; i < strArray.Length; i++)
303                                 {
304                                         if (i > 0)
305                                                 valueBuffer.Append(" $ ");
306                                         valueBuffer.Append(strArray[i]);
307                                 }
308                                 if (strArray.Length > 1)
309                                         valueBuffer.Append(" )");
310                         }
311                         if (Type != - 1)
312                         {
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");
319                         }
320                         if ((strArray = RequiredAttributes) != null)
321                         {
322                                 valueBuffer.Append(" MUST ");
323                                 if (strArray.Length > 1)
324                                         valueBuffer.Append("( ");
325                                 for (int i = 0; i < strArray.Length; i++)
326                                 {
327                                         if (i > 0)
328                                                 valueBuffer.Append(" $ ");
329                                         valueBuffer.Append(strArray[i]);
330                                 }
331                                 if (strArray.Length > 1)
332                                         valueBuffer.Append(" )");
333                         }
334                         if ((strArray = OptionalAttributes) != null)
335                         {
336                                 valueBuffer.Append(" MAY ");
337                                 if (strArray.Length > 1)
338                                         valueBuffer.Append("( ");
339                                 for (int i = 0; i < strArray.Length; i++)
340                                 {
341                                         if (i > 0)
342                                                 valueBuffer.Append(" $ ");
343                                         valueBuffer.Append(strArray[i]);
344                                 }
345                                 if (strArray.Length > 1)
346                                         valueBuffer.Append(" )");
347                         }
348                         System.Collections.IEnumerator en;
349                         if ((en = QualifierNames) != null)
350                         {
351                                 System.String qualName;
352                                 System.String[] qualValue;
353                                 while (en.MoveNext())
354                                 {
355                                         qualName = ((System.String) en.Current);
356                                         valueBuffer.Append(" " + qualName + " ");
357                                         if ((qualValue = getQualifier(qualName)) != null)
358                                         {
359                                                 if (qualValue.Length > 1)
360                                                         valueBuffer.Append("( ");
361                                                 for (int i = 0; i < qualValue.Length; i++)
362                                                 {
363                                                         if (i > 0)
364                                                                 valueBuffer.Append(" ");
365                                                         valueBuffer.Append("'" + qualValue[i] + "'");
366                                                 }
367                                                 if (qualValue.Length > 1)
368                                                         valueBuffer.Append(" )");
369                                         }
370                                 }
371                         }
372                         valueBuffer.Append(" )");
373                         return valueBuffer.ToString();
374                 }
375         }
376 }