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.LdapMatchingRuleUseSchema.cs
27 // Sunil Kumar (Sunilk@novell.com)
29 // (C) 2003 Novell, Inc (http://www.novell.com)
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
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
47 /// <seealso cref="LdapAttributeSchema">
49 /// <seealso cref="LdapSchemaElement">
51 /// <seealso cref="LdapSchema">
53 public class LdapMatchingRuleUseSchema
:LdapSchemaElement
55 /// <summary> Returns an array of all the attributes which this matching rule
59 /// <returns> An array of all the attributes which this matching rule applies to.
61 virtual public System
.String
[] Attributes
69 private System
.String
[] attributes
;
71 /// <summary> Constructs a matching rule use definition for adding to or deleting
75 /// <param name="names"> Name(s) of the matching rule.
78 /// <param name="oid"> Object Identifier of the the matching rule
79 /// in dotted-decimal format.
82 /// <param name="description">Optional description of the matching rule use.
85 /// <param name="obsolete"> True if the matching rule use is obsolete.
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.
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);
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();
107 /// <summary> Constructs a matching rule use definition from the raw string value
108 /// returned on a schema query for matchingRuleUse.
111 /// <param name="raw"> The raw string value returned on a schema
112 /// query for matchingRuleUse.
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
)
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.
137 /// <returns> A string representation of the attribute's definition.
139 protected internal override System
.String
formatString()
142 System
.Text
.StringBuilder valueBuffer
= new System
.Text
.StringBuilder("( ");
144 System
.String
[] strArray
;
146 if ((System
.Object
) (token
= ID
) != null)
148 valueBuffer
.Append(token
);
151 if (strArray
!= null)
153 valueBuffer
.Append(" NAME ");
154 if (strArray
.Length
== 1)
156 valueBuffer
.Append("'" + strArray
[0] + "'");
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
+ "'");
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
++)
186 valueBuffer
.Append(" $ ");
187 valueBuffer
.Append(strArray
[i
]);
189 if (strArray
.Length
> 1)
190 valueBuffer
.Append(" )");
192 valueBuffer
.Append(" )");
193 return valueBuffer
.ToString();