PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapObjectClassSchema.cs

https://bitbucket.org/danipen/mono
C# | 376 lines | 228 code | 20 blank | 128 comment | 66 complexity | 2ceb4f78b1e16ce64d11309bda91027d MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
  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. using System;
  32. using Novell.Directory.Ldap.Utilclass;
  33. namespace Novell.Directory.Ldap
  34. {
  35. /// <summary> The schema definition of an object class in a directory server.
  36. ///
  37. /// The LdapObjectClassSchema class represents the definition of an object
  38. /// class. It is used to query the syntax of an object class.
  39. ///
  40. /// </summary>
  41. /// <seealso cref="LdapSchemaElement">
  42. /// </seealso>
  43. /// <seealso cref="LdapSchema">
  44. /// </seealso>
  45. public class LdapObjectClassSchema:LdapSchemaElement
  46. {
  47. /// <summary> Returns the object classes from which this one derives.
  48. ///
  49. /// </summary>
  50. /// <returns> The object classes superior to this class.
  51. /// </returns>
  52. virtual public System.String[] Superiors
  53. {
  54. get
  55. {
  56. return superiors;
  57. }
  58. }
  59. /// <summary> Returns a list of attributes required for an entry with this object
  60. /// class.
  61. ///
  62. /// </summary>
  63. /// <returns> The list of required attributes defined for this class.
  64. /// </returns>
  65. virtual public System.String[] RequiredAttributes
  66. {
  67. get
  68. {
  69. return required;
  70. }
  71. }
  72. /// <summary> Returns a list of optional attributes but not required of an entry
  73. /// with this object class.
  74. ///
  75. /// </summary>
  76. /// <returns> The list of optional attributes defined for this class.
  77. /// </returns>
  78. virtual public System.String[] OptionalAttributes
  79. {
  80. get
  81. {
  82. return optional;
  83. }
  84. }
  85. /// <summary> Returns the type of object class.
  86. ///
  87. /// The getType method returns one of the following constants defined in
  88. /// LdapObjectClassSchema:
  89. /// <ul>
  90. /// <li>ABSTRACT</li>
  91. /// <li>AUXILIARY</li>
  92. /// <li>STRUCTURAL</li>
  93. /// </ul>
  94. /// See the LdapSchemaElement.getQualifier method for information on
  95. /// obtaining the X-NDS flags.
  96. ///
  97. /// </summary>
  98. /// <returns> The type of object class.
  99. /// </returns>
  100. virtual public int Type
  101. {
  102. get
  103. {
  104. return type;
  105. }
  106. }
  107. internal System.String[] superiors;
  108. internal System.String[] required;
  109. internal System.String[] optional;
  110. internal int type = - 1;
  111. /// <summary> This class definition defines an abstract schema class.
  112. ///
  113. /// This is equivalent to setting the Novell eDirectory effective class
  114. /// flag to true.
  115. /// </summary>
  116. public const int ABSTRACT = 0;
  117. /// <summary> This class definition defines a structural schema class.
  118. ///
  119. /// This is equivalent to setting the Novell eDirectory effective class
  120. /// flag to true.
  121. /// </summary>
  122. public const int STRUCTURAL = 1;
  123. /// <summary> This class definition defines an auxiliary schema class.</summary>
  124. public const int AUXILIARY = 2;
  125. /// <summary> Constructs an object class definition for adding to or deleting from
  126. /// a directory's schema.
  127. ///
  128. /// </summary>
  129. /// <param name="names"> Name(s) of the object class.
  130. ///
  131. /// </param>
  132. /// <param name="oid"> Object Identifer of the object class - in
  133. /// dotted-decimal format.
  134. ///
  135. /// </param>
  136. /// <param name="description"> Optional description of the object class.
  137. ///
  138. /// </param>
  139. /// <param name="superiors"> The object classes from which this one derives.
  140. ///
  141. /// </param>
  142. /// <param name="required"> A list of attributes required
  143. /// for an entry with this object class.
  144. ///
  145. /// </param>
  146. /// <param name="optional"> A list of attributes acceptable but not required
  147. /// for an entry with this object class.
  148. ///
  149. /// </param>
  150. /// <param name="type"> One of ABSTRACT, AUXILIARY, or STRUCTURAL. These
  151. /// constants are defined in LdapObjectClassSchema.
  152. ///
  153. /// </param>
  154. /// <param name="obsolete"> true if this object is obsolete
  155. ///
  156. /// </param>
  157. 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])
  158. {
  159. base.names = new System.String[names.Length];
  160. names.CopyTo(base.names, 0);
  161. base.oid = oid;
  162. base.description = description;
  163. this.type = type;
  164. this.obsolete = obsolete;
  165. if (superiors != null)
  166. {
  167. this.superiors = new System.String[superiors.Length];
  168. superiors.CopyTo(this.superiors, 0);
  169. }
  170. if (required != null)
  171. {
  172. this.required = new System.String[required.Length];
  173. required.CopyTo(this.required, 0);
  174. }
  175. if (optional != null)
  176. {
  177. this.optional = new System.String[optional.Length];
  178. optional.CopyTo(this.optional, 0);
  179. }
  180. base.Value = formatString();
  181. return ;
  182. }
  183. /// <summary> Constructs an object class definition from the raw string value
  184. /// returned from a directory query for "objectClasses".
  185. ///
  186. /// </summary>
  187. /// <param name="raw"> The raw string value returned from a directory
  188. /// query for "objectClasses".
  189. /// </param>
  190. public LdapObjectClassSchema(System.String raw):base(LdapSchema.schemaTypeNames[LdapSchema.OBJECT_CLASS])
  191. {
  192. try
  193. {
  194. SchemaParser parser = new SchemaParser(raw);
  195. if (parser.Names != null)
  196. {
  197. base.names = new System.String[parser.Names.Length];
  198. parser.Names.CopyTo(base.names, 0);
  199. }
  200. if ((System.Object) parser.ID != null)
  201. base.oid = parser.ID;
  202. if ((System.Object) parser.Description != null)
  203. base.description = parser.Description;
  204. base.obsolete = parser.Obsolete;
  205. if (parser.Required != null)
  206. {
  207. required = new System.String[parser.Required.Length];
  208. parser.Required.CopyTo(required, 0);
  209. }
  210. if (parser.Optional != null)
  211. {
  212. optional = new System.String[parser.Optional.Length];
  213. parser.Optional.CopyTo(optional, 0);
  214. }
  215. if (parser.Superiors != null)
  216. {
  217. superiors = new System.String[parser.Superiors.Length];
  218. parser.Superiors.CopyTo(superiors, 0);
  219. }
  220. type = parser.Type;
  221. System.Collections.IEnumerator qualifiers = parser.Qualifiers;
  222. AttributeQualifier attrQualifier;
  223. while (qualifiers.MoveNext())
  224. {
  225. attrQualifier = (AttributeQualifier) qualifiers.Current;
  226. setQualifier(attrQualifier.Name, attrQualifier.Values);
  227. }
  228. base.Value = formatString();
  229. }
  230. catch (System.IO.IOException e)
  231. {
  232. }
  233. return ;
  234. }
  235. /// <summary> Returns a string in a format suitable for directly adding to a
  236. /// directory, as a value of the particular schema element class.
  237. ///
  238. /// </summary>
  239. /// <returns> A string representation of the class' definition.
  240. /// </returns>
  241. protected internal override System.String formatString()
  242. {
  243. System.Text.StringBuilder valueBuffer = new System.Text.StringBuilder("( ");
  244. System.String token;
  245. System.String[] strArray;
  246. if ((System.Object) (token = ID) != null)
  247. {
  248. valueBuffer.Append(token);
  249. }
  250. strArray = Names;
  251. if (strArray != null)
  252. {
  253. valueBuffer.Append(" NAME ");
  254. if (strArray.Length == 1)
  255. {
  256. valueBuffer.Append("'" + strArray[0] + "'");
  257. }
  258. else
  259. {
  260. valueBuffer.Append("( ");
  261. for (int i = 0; i < strArray.Length; i++)
  262. {
  263. valueBuffer.Append(" '" + strArray[i] + "'");
  264. }
  265. valueBuffer.Append(" )");
  266. }
  267. }
  268. if ((System.Object) (token = Description) != null)
  269. {
  270. valueBuffer.Append(" DESC ");
  271. valueBuffer.Append("'" + token + "'");
  272. }
  273. if (Obsolete)
  274. {
  275. valueBuffer.Append(" OBSOLETE");
  276. }
  277. if ((strArray = Superiors) != null)
  278. {
  279. valueBuffer.Append(" SUP ");
  280. if (strArray.Length > 1)
  281. valueBuffer.Append("( ");
  282. for (int i = 0; i < strArray.Length; i++)
  283. {
  284. if (i > 0)
  285. valueBuffer.Append(" $ ");
  286. valueBuffer.Append(strArray[i]);
  287. }
  288. if (strArray.Length > 1)
  289. valueBuffer.Append(" )");
  290. }
  291. if (Type != - 1)
  292. {
  293. if (Type == LdapObjectClassSchema.ABSTRACT)
  294. valueBuffer.Append(" ABSTRACT");
  295. else if (Type == LdapObjectClassSchema.AUXILIARY)
  296. valueBuffer.Append(" AUXILIARY");
  297. else if (Type == LdapObjectClassSchema.STRUCTURAL)
  298. valueBuffer.Append(" STRUCTURAL");
  299. }
  300. if ((strArray = RequiredAttributes) != null)
  301. {
  302. valueBuffer.Append(" MUST ");
  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 = OptionalAttributes) != null)
  315. {
  316. valueBuffer.Append(" MAY ");
  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. }