PageRenderTime 81ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 0ms

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

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