**** Merged from MCS ****
[mono-project.git] / mcs / class / Novell.Directory.Ldap / Novell.Directory.Ldap / LdapMatchingRuleUseSchema.cs
blob402a54bc5c1ff369fce06c6da9cc8c89448c2f7b
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:
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
21 * SOFTWARE.
22 *******************************************************************************/
24 // Novell.Directory.Ldap.LdapMatchingRuleUseSchema.cs
26 // Author:
27 // Sunil Kumar (Sunilk@novell.com)
29 // (C) 2003 Novell, Inc (http://www.novell.com)
31 using System;
32 using SchemaParser = Novell.Directory.Ldap.Utilclass.SchemaParser;
34 namespace Novell.Directory.Ldap
37 /// <summary>Represents the definition of a specific matching rule use in the
38 /// directory schema.
39 ///
40 /// The LdapMatchingRuleUseSchema class represents the definition of a
41 /// matching rule use. It is used to discover or modify which attributes are
42 /// suitable for use with an extensible matching rule. It contains the name and
43 /// identifier of a matching rule, and a list of attributes which
44 /// it applies to.
45 ///
46 /// </summary>
47 /// <seealso cref="LdapAttributeSchema">
48 /// </seealso>
49 /// <seealso cref="LdapSchemaElement">
50 /// </seealso>
51 /// <seealso cref="LdapSchema">
52 /// </seealso>
53 public class LdapMatchingRuleUseSchema:LdapSchemaElement
55 /// <summary> Returns an array of all the attributes which this matching rule
56 /// applies to.
57 ///
58 /// </summary>
59 /// <returns> An array of all the attributes which this matching rule applies to.
60 /// </returns>
61 virtual public System.String[] Attributes
63 get
65 return attributes;
69 private System.String[] attributes;
71 /// <summary> Constructs a matching rule use definition for adding to or deleting
72 /// from the schema.
73 ///
74 /// </summary>
75 /// <param name="names"> Name(s) of the matching rule.
76 ///
77 /// </param>
78 /// <param name="oid"> Object Identifier of the the matching rule
79 /// in dotted-decimal format.
80 ///
81 /// </param>
82 /// <param name="description">Optional description of the matching rule use.
83 ///
84 /// </param>
85 /// <param name="obsolete"> True if the matching rule use is obsolete.
86 ///
87 /// </param>
88 /// <param name="attributes"> List of attributes that this matching rule
89 /// applies to. These values may be either the
90 /// names or numeric oids of the attributes.
91 /// </param>
92 public LdapMatchingRuleUseSchema(System.String[] names, System.String oid, System.String description, bool obsolete, System.String[] attributes):base(LdapSchema.schemaTypeNames[LdapSchema.MATCHING_USE])
94 base.names = new System.String[names.Length];
95 names.CopyTo(base.names, 0);
96 base.oid = oid;
97 base.description = description;
98 base.obsolete = obsolete;
99 this.attributes = new System.String[attributes.Length];
100 attributes.CopyTo(this.attributes, 0);
101 base.Value = formatString();
102 return ;
107 /// <summary> Constructs a matching rule use definition from the raw string value
108 /// returned on a schema query for matchingRuleUse.
109 ///
110 /// </summary>
111 /// <param name="raw"> The raw string value returned on a schema
112 /// query for matchingRuleUse.
113 /// </param>
114 public LdapMatchingRuleUseSchema(System.String raw):base(LdapSchema.schemaTypeNames[LdapSchema.MATCHING_USE])
118 SchemaParser matchParser = new SchemaParser(raw);
119 base.names = new System.String[matchParser.Names.Length];
120 matchParser.Names.CopyTo(base.names, 0);
121 base.oid = matchParser.ID;
122 base.description = matchParser.Description;
123 base.obsolete = matchParser.Obsolete;
124 this.attributes = matchParser.Applies;
125 base.Value = formatString();
127 catch (System.IO.IOException e)
130 return ;
133 /// <summary> Returns a string in a format suitable for directly adding to a
134 /// directory, as a value of the particular schema element attribute.
135 ///
136 /// </summary>
137 /// <returns> A string representation of the attribute's definition.
138 /// </returns>
139 protected internal override System.String formatString()
142 System.Text.StringBuilder valueBuffer = new System.Text.StringBuilder("( ");
143 System.String token;
144 System.String[] strArray;
146 if ((System.Object) (token = ID) != null)
148 valueBuffer.Append(token);
150 strArray = Names;
151 if (strArray != null)
153 valueBuffer.Append(" NAME ");
154 if (strArray.Length == 1)
156 valueBuffer.Append("'" + strArray[0] + "'");
158 else
160 valueBuffer.Append("( ");
162 for (int i = 0; i < strArray.Length; i++)
164 valueBuffer.Append(" '" + strArray[i] + "'");
166 valueBuffer.Append(" )");
169 if ((System.Object) (token = Description) != null)
171 valueBuffer.Append(" DESC ");
172 valueBuffer.Append("'" + token + "'");
174 if (Obsolete)
176 valueBuffer.Append(" OBSOLETE");
178 if ((strArray = Attributes) != null)
180 valueBuffer.Append(" APPLIES ");
181 if (strArray.Length > 1)
182 valueBuffer.Append("( ");
183 for (int i = 0; i < strArray.Length; i++)
185 if (i > 0)
186 valueBuffer.Append(" $ ");
187 valueBuffer.Append(strArray[i]);
189 if (strArray.Length > 1)
190 valueBuffer.Append(" )");
192 valueBuffer.Append(" )");
193 return valueBuffer.ToString();