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.LdapMatchingRuleSchema.cs
27 // Sunil Kumar (Sunilk@novell.com)
29 // (C) 2003 Novell, Inc (http://www.novell.com)
33 using SchemaParser
= Novell
.Directory
.Ldap
.Utilclass
.SchemaParser
;
35 namespace Novell
.Directory
.Ldap
37 /// <summary> The schematic definition of a particular matching rule
38 /// in a particular Directory Server.
40 /// The LdapMatchingRuleSchema class represents the definition of a mathcing
41 /// rule. It is used to query matching rule syntax, and to add or delete a
42 /// matching rule definition in a directory.
44 /// Novell eDirectory does not currently allow matching rules to be added
45 /// or deleted from the schema.
48 /// <seealso cref="LdapAttributeSchema">
50 /// <seealso cref="LdapSchemaElement">
52 /// <seealso cref="LdapSchema">
54 public class LdapMatchingRuleSchema
:LdapSchemaElement
56 /// <summary> Returns the OIDs of the attributes to which this rule applies.
59 /// <returns> The OIDs of the attributes to which this matching rule applies.
61 virtual public System
.String
[] Attributes
69 /// <summary> Returns the OID of the syntax that this matching rule is valid for.
72 /// <returns> The OID of the syntax that this matching rule is valid for.
74 virtual public System
.String SyntaxString
82 private System
.String syntaxString
;
83 private System
.String
[] attributes
;
84 /// <summary> Constructs a matching rule definition for adding to or deleting from
88 /// <param name="names"> The names of the attribute.
91 /// <param name="oid"> Object Identifier of the attribute - in
92 /// dotted-decimal format.
95 /// <param name="description"> Optional description of the attribute.
98 /// <param name="attributes"> The OIDs of attributes to which the rule applies.
99 /// This parameter may be null. All attributes added to
100 /// this array must use the same syntax.
103 /// <param name="obsolete"> true if this matching rule is obsolete.
107 /// <param name="syntaxString"> The unique object identifer of the syntax of the
108 /// attribute, in dotted numerical format.
111 public LdapMatchingRuleSchema(System
.String
[] names
, System
.String oid
, System
.String description
, System
.String
[] attributes
, bool obsolete
, System
.String syntaxString
):base(LdapSchema
.schemaTypeNames
[LdapSchema
.MATCHING
])
113 base.names
= new System
.String
[names
.Length
];
114 names
.CopyTo(base.names
, 0);
116 base.description
= description
;
117 base.obsolete
= obsolete
;
118 this.attributes
= new System
.String
[attributes
.Length
];
119 attributes
.CopyTo(this.attributes
, 0);
120 this.syntaxString
= syntaxString
;
121 base.Value
= formatString();
126 /// <summary> Constructs a matching rule definition from the raw string values
127 /// returned from a schema query for "matchingRule" and for
128 /// "matchingRuleUse" for the same rule.
131 /// <param name="rawMatchingRule"> The raw string value returned on a directory
132 /// query for "matchingRule".
135 /// <param name="rawMatchingRuleUse"> The raw string value returned on a directory
136 /// query for "matchingRuleUse".
138 public LdapMatchingRuleSchema(System
.String rawMatchingRule
, System
.String rawMatchingRuleUse
):base(LdapSchema
.schemaTypeNames
[LdapSchema
.MATCHING
])
142 SchemaParser matchParser
= new SchemaParser(rawMatchingRule
);
143 base.names
= new System
.String
[matchParser
.Names
.Length
];
144 matchParser
.Names
.CopyTo(base.names
, 0);
145 base.oid
= matchParser
.ID
;
146 base.description
= matchParser
.Description
;
147 base.obsolete
= matchParser
.Obsolete
;
148 this.syntaxString
= matchParser
.Syntax
;
149 if ((System
.Object
) rawMatchingRuleUse
!= null)
151 SchemaParser matchUseParser
= new SchemaParser(rawMatchingRuleUse
);
152 this.attributes
= matchUseParser
.Applies
;
154 base.Value
= formatString();
156 catch (System
.IO
.IOException e
)
162 /// <summary> Returns a string in a format suitable for directly adding to a
163 /// directory, as a value of the particular schema element attribute.
166 /// <returns> A string representation of the attribute's definition.
168 protected internal override System
.String
formatString()
171 System
.Text
.StringBuilder valueBuffer
= new System
.Text
.StringBuilder("( ");
173 System
.String
[] strArray
;
175 if ((System
.Object
) (token
= ID
) != null)
177 valueBuffer
.Append(token
);
180 if (strArray
!= null)
182 valueBuffer
.Append(" NAME ");
183 if (strArray
.Length
== 1)
185 valueBuffer
.Append("'" + strArray
[0] + "'");
189 valueBuffer
.Append("( ");
191 for (int i
= 0; i
< strArray
.Length
; i
++)
193 valueBuffer
.Append(" '" + strArray
[i
] + "'");
195 valueBuffer
.Append(" )");
198 if ((System
.Object
) (token
= Description
) != null)
200 valueBuffer
.Append(" DESC ");
201 valueBuffer
.Append("'" + token
+ "'");
205 valueBuffer
.Append(" OBSOLETE");
207 if ((System
.Object
) (token
= SyntaxString
) != null)
209 valueBuffer
.Append(" SYNTAX ");
210 valueBuffer
.Append(token
);
212 valueBuffer
.Append(" )");
213 return valueBuffer
.ToString();