[xbuild] Implements property functions using constructor syntax. Fixes #12999
[mono.git] / mcs / class / Novell.Directory.Ldap / Novell.Directory.Ldap / LdapDITContentRuleSchema.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.LdapDITContentRuleSchema.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 SchemaParser = Novell.Directory.Ldap.Utilclass.SchemaParser;
34 using AttributeQualifier = Novell.Directory.Ldap.Utilclass.AttributeQualifier;
35
36 namespace Novell.Directory.Ldap
37 {
38         
39         /// <summary>  Represents a DIT (Directory Information Tree) content rule
40         /// in a directory schema.
41         /// 
42         /// The LdapDITContentRuleSchema class is used to discover or modify
43         /// additional auxiliary classes, mandatory and optional attributes, and
44         /// restricted attributes in effect for an object class.
45         /// </summary>
46         public class LdapDITContentRuleSchema:LdapSchemaElement
47         {
48                 /// <summary> Returns the list of allowed auxiliary classes.
49                 /// 
50                 /// </summary>
51                 /// <returns> The list of allowed auxiliary classes.
52                 /// </returns>
53                 virtual public System.String[] AuxiliaryClasses
54                 {
55                         get
56                         {
57                                 return auxiliary;
58                         }
59                         
60                 }
61                 /// <summary> Returns the list of additional required attributes for an entry
62                 /// controlled by this content rule.
63                 /// 
64                 /// </summary>
65                 /// <returns> The list of additional required attributes.
66                 /// </returns>
67                 virtual public System.String[] RequiredAttributes
68                 {
69                         get
70                         {
71                                 return required;
72                         }
73                         
74                 }
75                 /// <summary> Returns the list of additional optional attributes for an entry
76                 /// controlled by this content rule.
77                 /// 
78                 /// </summary>
79                 /// <returns> The list of additional optional attributes.
80                 /// </returns>
81                 virtual public System.String[] OptionalAttributes
82                 {
83                         get
84                         {
85                                 return optional;
86                         }
87                         
88                 }
89                 /// <summary> Returns the list of precluded attributes for an entry controlled by
90                 /// this content rule.
91                 /// 
92                 /// </summary>
93                 /// <returns> The list of precluded attributes.
94                 /// </returns>
95                 virtual public System.String[] PrecludedAttributes
96                 {
97                         get
98                         {
99                                 return precluded;
100                         }
101                         
102                 }
103                 private System.String[] auxiliary = new System.String[]{""};
104                 private System.String[] required = new System.String[]{""};
105                 private System.String[] optional = new System.String[]{""};
106                 private System.String[] precluded = new System.String[]{""};
107                 
108                 /// <summary> Constructs a DIT content rule for adding to or deleting from the
109                 /// schema.
110                 /// 
111                 /// </summary>
112                 /// <param name="names">       The names of the content rule.
113                 /// 
114                 /// </param>
115                 /// <param name="oid">        The unique object identifier of the content rule -
116                 /// in dotted numerical format.
117                 /// 
118                 /// </param>
119                 /// <param name="description">The optional description of the content rule.
120                 /// 
121                 /// </param>
122                 /// <param name="obsolete">   True if the content rule is obsolete.
123                 /// 
124                 /// </param>
125                 /// <param name="auxiliary">  A list of auxiliary object classes allowed for
126                 /// an entry to which this content rule applies.
127                 /// These may either be specified by name or
128                 /// numeric oid.
129                 /// 
130                 /// </param>
131                 /// <param name="required">   A list of attributes that an entry
132                 /// to which this content rule applies must
133                 /// contain in addition to its normal set of
134                 /// mandatory attributes. These attributes may be
135                 /// specified by either name or numeric oid.
136                 /// 
137                 /// </param>
138                 /// <param name="optional">   A list of attributes that an entry
139                 /// to which this content rule applies may contain
140                 /// in addition to its normal set of optional
141                 /// attributes. These attributes may be specified by
142                 /// either name or numeric oid.
143                 /// 
144                 /// </param>
145                 /// <param name="precluded">  A list, consisting of a subset of the optional
146                 /// attributes of the structural and
147                 /// auxiliary object classes which are precluded
148                 /// from an entry to which this content rule
149                 /// applies. These may be specified by either name
150                 /// or numeric oid.
151                 /// </param>
152                 public LdapDITContentRuleSchema(System.String[] names, System.String oid, System.String description, bool obsolete, System.String[] auxiliary, System.String[] required, System.String[] optional, System.String[] precluded):base(LdapSchema.schemaTypeNames[LdapSchema.DITCONTENT])
153                 {
154                         base.names = new System.String[names.Length];
155                         names.CopyTo(base.names, 0);
156                         base.oid = oid;
157                         base.description = description;
158                         base.obsolete = obsolete;
159                         this.auxiliary = auxiliary;
160                         this.required = required;
161                         this.optional = optional;
162                         this.precluded = precluded;
163                         base.Value = formatString();
164                         return ;
165                 }
166                 
167                 /// <summary> Constructs a DIT content rule from the raw string value returned from a
168                 /// schema query for dITContentRules.
169                 /// 
170                 /// </summary>
171                 /// <param name="raw">        The raw string value returned from a schema query
172                 /// for content rules.
173                 /// </param>
174                 public LdapDITContentRuleSchema(System.String raw):base(LdapSchema.schemaTypeNames[LdapSchema.DITCONTENT])
175                 {
176                         base.obsolete = false;
177                         try
178                         {
179                                 SchemaParser parser = new SchemaParser(raw);
180                                 
181                                 if (parser.Names != null)
182                                 {
183                                         base.names = new System.String[parser.Names.Length];
184                                         parser.Names.CopyTo(base.names, 0);
185                                 }
186                                 
187                                 if ((System.Object) parser.ID != null)
188                                         base.oid = parser.ID;
189                                 if ((System.Object) parser.Description != null)
190                                         base.description = parser.Description;
191                                 if (parser.Auxiliary != null)
192                                 {
193                                         auxiliary = new System.String[parser.Auxiliary.Length];
194                                         parser.Auxiliary.CopyTo(auxiliary, 0);
195                                 }
196                                 if (parser.Required != null)
197                                 {
198                                         required = new System.String[parser.Required.Length];
199                                         parser.Required.CopyTo(required, 0);
200                                 }
201                                 if (parser.Optional != null)
202                                 {
203                                         optional = new System.String[parser.Optional.Length];
204                                         parser.Optional.CopyTo(optional, 0);
205                                 }
206                                 if (parser.Precluded != null)
207                                 {
208                                         precluded = new System.String[parser.Precluded.Length];
209                                         parser.Precluded.CopyTo(precluded, 0);
210                                 }
211                                 base.obsolete = parser.Obsolete;
212                                 System.Collections.IEnumerator qualifiers = parser.Qualifiers;
213                                 AttributeQualifier attrQualifier;
214                                 while (qualifiers.MoveNext())
215                                 {
216                                         attrQualifier = (AttributeQualifier) qualifiers.Current;
217                                         setQualifier(attrQualifier.Name, attrQualifier.Values);
218                                 }
219                                 base.Value = formatString();
220                         }
221                         catch (System.IO.IOException e)
222                         {
223                         }
224                         return ;
225                 }
226                 
227                 /// <summary> Returns a string in a format suitable for directly adding to a
228                 /// directory, as a value of the particular schema element class.
229                 /// 
230                 /// </summary>
231                 /// <returns> A string representation of the class' definition.
232                 /// </returns>
233                 protected internal override System.String formatString()
234                 {
235                         
236                         System.Text.StringBuilder valueBuffer = new System.Text.StringBuilder("( ");
237                         System.String token;
238                         System.String[] strArray;
239                         
240                         if ((System.Object) (token = ID) != null)
241                         {
242                                 valueBuffer.Append(token);
243                         }
244                         strArray = Names;
245                         if (strArray != null)
246                         {
247                                 valueBuffer.Append(" NAME ");
248                                 if (strArray.Length == 1)
249                                 {
250                                         valueBuffer.Append("'" + strArray[0] + "'");
251                                 }
252                                 else
253                                 {
254                                         valueBuffer.Append("( ");
255                                         
256                                         for (int i = 0; i < strArray.Length; i++)
257                                         {
258                                                 valueBuffer.Append(" '" + strArray[i] + "'");
259                                         }
260                                         valueBuffer.Append(" )");
261                                 }
262                         }
263                         if ((System.Object) (token = Description) != null)
264                         {
265                                 valueBuffer.Append(" DESC ");
266                                 valueBuffer.Append("'" + token + "'");
267                         }
268                         if (Obsolete)
269                         {
270                                 valueBuffer.Append(" OBSOLETE");
271                         }
272                         if ((strArray = AuxiliaryClasses) != null)
273                         {
274                                 valueBuffer.Append(" AUX ");
275                                 if (strArray.Length > 1)
276                                         valueBuffer.Append("( ");
277                                 for (int i = 0; i < strArray.Length; i++)
278                                 {
279                                         if (i > 0)
280                                                 valueBuffer.Append(" $ ");
281                                         valueBuffer.Append(strArray[i]);
282                                 }
283                                 if (strArray.Length > 1)
284                                         valueBuffer.Append(" )");
285                         }
286                         if ((strArray = RequiredAttributes) != null)
287                         {
288                                 valueBuffer.Append(" MUST ");
289                                 if (strArray.Length > 1)
290                                         valueBuffer.Append("( ");
291                                 for (int i = 0; i < strArray.Length; i++)
292                                 {
293                                         if (i > 0)
294                                                 valueBuffer.Append(" $ ");
295                                         valueBuffer.Append(strArray[i]);
296                                 }
297                                 if (strArray.Length > 1)
298                                         valueBuffer.Append(" )");
299                         }
300                         if ((strArray = OptionalAttributes) != null)
301                         {
302                                 valueBuffer.Append(" MAY ");
303                                 if (strArray.Length > 1)
304                                         valueBuffer.Append("( ");
305                                 for (int i = 0; i < strArray.Length; i++)
306                                 {
307                                         if (i > 0)
308                                                 valueBuffer.Append(" $ ");
309                                         valueBuffer.Append(strArray[i]);
310                                 }
311                                 if (strArray.Length > 1)
312                                         valueBuffer.Append(" )");
313                         }
314                         if ((strArray = PrecludedAttributes) != null)
315                         {
316                                 valueBuffer.Append(" NOT ");
317                                 if (strArray.Length > 1)
318                                         valueBuffer.Append("( ");
319                                 for (int i = 0; i < strArray.Length; i++)
320                                 {
321                                         if (i > 0)
322                                                 valueBuffer.Append(" $ ");
323                                         valueBuffer.Append(strArray[i]);
324                                 }
325                                 if (strArray.Length > 1)
326                                         valueBuffer.Append(" )");
327                         }
328                         System.Collections.IEnumerator en;
329                         if ((en = QualifierNames) != null)
330                         {
331                                 System.String qualName;
332                                 System.String[] qualValue;
333                                 while (en.MoveNext())
334                                 {
335                                         qualName = ((System.String) en.Current);
336                                         valueBuffer.Append(" " + qualName + " ");
337                                         if ((qualValue = getQualifier(qualName)) != null)
338                                         {
339                                                 if (qualValue.Length > 1)
340                                                         valueBuffer.Append("( ");
341                                                 for (int i = 0; i < qualValue.Length; i++)
342                                                 {
343                                                         if (i > 0)
344                                                                 valueBuffer.Append(" ");
345                                                         valueBuffer.Append("'" + qualValue[i] + "'");
346                                                 }
347                                                 if (qualValue.Length > 1)
348                                                         valueBuffer.Append(" )");
349                                         }
350                                 }
351                         }
352                         valueBuffer.Append(" )");
353                         return valueBuffer.ToString();
354                 }
355         }
356 }