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.LdapDITContentRuleSchema.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> Represents a DIT (Directory Information Tree) content rule
40 /// in a directory schema.
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.
46 public class LdapDITContentRuleSchema
:LdapSchemaElement
48 /// <summary> Returns the list of allowed auxiliary classes.
51 /// <returns> The list of allowed auxiliary classes.
53 virtual public System
.String
[] AuxiliaryClasses
61 /// <summary> Returns the list of additional required attributes for an entry
62 /// controlled by this content rule.
65 /// <returns> The list of additional required attributes.
67 virtual public System
.String
[] RequiredAttributes
75 /// <summary> Returns the list of additional optional attributes for an entry
76 /// controlled by this content rule.
79 /// <returns> The list of additional optional attributes.
81 virtual public System
.String
[] OptionalAttributes
89 /// <summary> Returns the list of precluded attributes for an entry controlled by
90 /// this content rule.
93 /// <returns> The list of precluded attributes.
95 virtual public System
.String
[] PrecludedAttributes
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
[]{""}
;
108 /// <summary> Constructs a DIT content rule for adding to or deleting from the
112 /// <param name="names"> The names of the content rule.
115 /// <param name="oid"> The unique object identifier of the content rule -
116 /// in dotted numerical format.
119 /// <param name="description">The optional description of the content rule.
122 /// <param name="obsolete"> True if the content rule is obsolete.
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
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.
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.
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
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
])
154 base.names
= new System
.String
[names
.Length
];
155 names
.CopyTo(base.names
, 0);
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();
167 /// <summary> Constructs a DIT content rule from the raw string value returned from a
168 /// schema query for dITContentRules.
171 /// <param name="raw"> The raw string value returned from a schema query
172 /// for content rules.
174 public LdapDITContentRuleSchema(System
.String raw
):base(LdapSchema
.schemaTypeNames
[LdapSchema
.DITCONTENT
])
176 base.obsolete
= false;
179 SchemaParser parser
= new SchemaParser(raw
);
181 if (parser
.Names
!= null)
183 base.names
= new System
.String
[parser
.Names
.Length
];
184 parser
.Names
.CopyTo(base.names
, 0);
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)
193 auxiliary
= new System
.String
[parser
.Auxiliary
.Length
];
194 parser
.Auxiliary
.CopyTo(auxiliary
, 0);
196 if (parser
.Required
!= null)
198 required
= new System
.String
[parser
.Required
.Length
];
199 parser
.Required
.CopyTo(required
, 0);
201 if (parser
.Optional
!= null)
203 optional
= new System
.String
[parser
.Optional
.Length
];
204 parser
.Optional
.CopyTo(optional
, 0);
206 if (parser
.Precluded
!= null)
208 precluded
= new System
.String
[parser
.Precluded
.Length
];
209 parser
.Precluded
.CopyTo(precluded
, 0);
211 base.obsolete
= parser
.Obsolete
;
212 System
.Collections
.IEnumerator qualifiers
= parser
.Qualifiers
;
213 AttributeQualifier attrQualifier
;
214 while (qualifiers
.MoveNext())
216 attrQualifier
= (AttributeQualifier
) qualifiers
.Current
;
217 setQualifier(attrQualifier
.Name
, attrQualifier
.Values
);
219 base.Value
= formatString();
221 catch (System
.IO
.IOException e
)
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.
231 /// <returns> A string representation of the class' definition.
233 protected internal override System
.String
formatString()
236 System
.Text
.StringBuilder valueBuffer
= new System
.Text
.StringBuilder("( ");
238 System
.String
[] strArray
;
240 if ((System
.Object
) (token
= ID
) != null)
242 valueBuffer
.Append(token
);
245 if (strArray
!= null)
247 valueBuffer
.Append(" NAME ");
248 if (strArray
.Length
== 1)
250 valueBuffer
.Append("'" + strArray
[0] + "'");
254 valueBuffer
.Append("( ");
256 for (int i
= 0; i
< strArray
.Length
; i
++)
258 valueBuffer
.Append(" '" + strArray
[i
] + "'");
260 valueBuffer
.Append(" )");
263 if ((System
.Object
) (token
= Description
) != null)
265 valueBuffer
.Append(" DESC ");
266 valueBuffer
.Append("'" + token
+ "'");
270 valueBuffer
.Append(" OBSOLETE");
272 if ((strArray
= AuxiliaryClasses
) != null)
274 valueBuffer
.Append(" AUX ");
275 if (strArray
.Length
> 1)
276 valueBuffer
.Append("( ");
277 for (int i
= 0; i
< strArray
.Length
; i
++)
280 valueBuffer
.Append(" $ ");
281 valueBuffer
.Append(strArray
[i
]);
283 if (strArray
.Length
> 1)
284 valueBuffer
.Append(" )");
286 if ((strArray
= RequiredAttributes
) != null)
288 valueBuffer
.Append(" MUST ");
289 if (strArray
.Length
> 1)
290 valueBuffer
.Append("( ");
291 for (int i
= 0; i
< strArray
.Length
; i
++)
294 valueBuffer
.Append(" $ ");
295 valueBuffer
.Append(strArray
[i
]);
297 if (strArray
.Length
> 1)
298 valueBuffer
.Append(" )");
300 if ((strArray
= OptionalAttributes
) != null)
302 valueBuffer
.Append(" MAY ");
303 if (strArray
.Length
> 1)
304 valueBuffer
.Append("( ");
305 for (int i
= 0; i
< strArray
.Length
; i
++)
308 valueBuffer
.Append(" $ ");
309 valueBuffer
.Append(strArray
[i
]);
311 if (strArray
.Length
> 1)
312 valueBuffer
.Append(" )");
314 if ((strArray
= PrecludedAttributes
) != null)
316 valueBuffer
.Append(" NOT ");
317 if (strArray
.Length
> 1)
318 valueBuffer
.Append("( ");
319 for (int i
= 0; i
< strArray
.Length
; i
++)
322 valueBuffer
.Append(" $ ");
323 valueBuffer
.Append(strArray
[i
]);
325 if (strArray
.Length
> 1)
326 valueBuffer
.Append(" )");
328 System
.Collections
.IEnumerator en
;
329 if ((en
= QualifierNames
) != null)
331 System
.String qualName
;
332 System
.String
[] qualValue
;
333 while (en
.MoveNext())
335 qualName
= ((System
.String
) en
.Current
);
336 valueBuffer
.Append(" " + qualName
+ " ");
337 if ((qualValue
= getQualifier(qualName
)) != null)
339 if (qualValue
.Length
> 1)
340 valueBuffer
.Append("( ");
341 for (int i
= 0; i
< qualValue
.Length
; i
++)
344 valueBuffer
.Append(" ");
345 valueBuffer
.Append("'" + qualValue
[i
] + "'");
347 if (qualValue
.Length
> 1)
348 valueBuffer
.Append(" )");
352 valueBuffer
.Append(" )");
353 return valueBuffer
.ToString();