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.LdapObjectClassSchema.cs
27 // Sunil Kumar (Sunilk@novell.com)
29 // (C) 2003 Novell, Inc (http://www.novell.com)
33 using Novell
.Directory
.Ldap
.Utilclass
;
35 namespace Novell
.Directory
.Ldap
38 /// <summary> The schema definition of an object class in a directory server.
40 /// The LdapObjectClassSchema class represents the definition of an object
41 /// class. It is used to query the syntax of an object class.
44 /// <seealso cref="LdapSchemaElement">
46 /// <seealso cref="LdapSchema">
48 public class LdapObjectClassSchema
:LdapSchemaElement
50 /// <summary> Returns the object classes from which this one derives.
53 /// <returns> The object classes superior to this class.
55 virtual public System
.String
[] Superiors
63 /// <summary> Returns a list of attributes required for an entry with this object
67 /// <returns> The list of required attributes defined for this class.
69 virtual public System
.String
[] RequiredAttributes
77 /// <summary> Returns a list of optional attributes but not required of an entry
78 /// with this object class.
81 /// <returns> The list of optional attributes defined for this class.
83 virtual public System
.String
[] OptionalAttributes
91 /// <summary> Returns the type of object class.
93 /// The getType method returns one of the following constants defined in
94 /// LdapObjectClassSchema:
97 /// <li>AUXILIARY</li>
98 /// <li>STRUCTURAL</li>
100 /// See the LdapSchemaElement.getQualifier method for information on
101 /// obtaining the X-NDS flags.
104 /// <returns> The type of object class.
106 virtual public int 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.
121 /// This is equivalent to setting the Novell eDirectory effective class
124 public const int ABSTRACT
= 0;
126 /// <summary> This class definition defines a structural schema class.
128 /// This is equivalent to setting the Novell eDirectory effective class
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.
140 /// <param name="names"> Name(s) of the object class.
143 /// <param name="oid"> Object Identifer of the object class - in
144 /// dotted-decimal format.
147 /// <param name="description"> Optional description of the object class.
150 /// <param name="superiors"> The object classes from which this one derives.
153 /// <param name="required"> A list of attributes required
154 /// for an entry with this object class.
157 /// <param name="optional"> A list of attributes acceptable but not required
158 /// for an entry with this object class.
161 /// <param name="type"> One of ABSTRACT, AUXILIARY, or STRUCTURAL. These
162 /// constants are defined in LdapObjectClassSchema.
165 /// <param name="obsolete"> true if this object is obsolete
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);
173 base.description
= description
;
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();
197 /// <summary> Constructs an object class definition from the raw string value
198 /// returned from a directory query for "objectClasses".
201 /// <param name="raw"> The raw string value returned from a directory
202 /// query for "objectClasses".
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);
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
)
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.
256 /// <returns> A string representation of the class' definition.
258 protected internal override System
.String
formatString()
261 System
.Text
.StringBuilder valueBuffer
= new System
.Text
.StringBuilder("( ");
263 System
.String
[] strArray
;
265 if ((System
.Object
) (token
= ID
) != null)
267 valueBuffer
.Append(token
);
270 if (strArray
!= null)
272 valueBuffer
.Append(" NAME ");
273 if (strArray
.Length
== 1)
275 valueBuffer
.Append("'" + strArray
[0] + "'");
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
+ "'");
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
++)
305 valueBuffer
.Append(" $ ");
306 valueBuffer
.Append(strArray
[i
]);
308 if (strArray
.Length
> 1)
309 valueBuffer
.Append(" )");
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
++)
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
++)
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
++)
364 valueBuffer
.Append(" ");
365 valueBuffer
.Append("'" + qualValue
[i
] + "'");
367 if (qualValue
.Length
> 1)
368 valueBuffer
.Append(" )");
372 valueBuffer
.Append(" )");
373 return valueBuffer
.ToString();