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.LdapSchemaElement.cs
27 // Sunil Kumar (Sunilk@novell.com)
29 // (C) 2003 Novell, Inc (http://www.novell.com)
32 using Novell.Directory.Ldap.Utilclass;
34 namespace Novell.Directory.Ldap
37 /// <summary> The LdapSchemaElement class is the base class representing schema
38 /// elements (definitions) in Ldap.
40 /// An LdapSchemaElement is read-only, single-valued LdapAttribute.
41 /// Therefore, it does not support the addValue and removeValue methods from
42 /// LdapAttribute. This class overrides those methods and throws
43 /// <code>UnsupportedOperationException</code> if either of those methods are
44 /// invoked by an application.
47 /// <seealso cref="LdapSchema">
49 /// <seealso cref="LdapConnection.FetchSchema">
51 public abstract class LdapSchemaElement:LdapAttribute
53 private void InitBlock()
55 hashQualifier = new System.Collections.Hashtable();
57 /// <summary> Returns an array of names for the element, or null if
60 /// The getNames method accesses the NAME qualifier (from the BNF
61 /// descriptions of Ldap schema definitions). The array consists of all
62 /// values of the NAME qualifier.
65 /// <returns> An array of names for the element, or null if none
68 virtual public System.String[] Names
74 System.String[] generated_var = new System.String[names.Length];
75 names.CopyTo(generated_var, 0);
80 /// <summary> Returns the description of the element.
82 /// The getDescription method returns the value of the DESC qualifier
83 /// (from the BNF descriptions of Ldap schema definitions).
86 /// <returns> The description of the element.
89 virtual public System.String Description
97 /// <summary> Returns the unique object identifier (OID) of the element.
100 /// <returns> The OID of the element.
102 virtual public System.String ID
110 /// <summary> Returns an enumeration of all qualifiers of the element which are
111 /// vendor specific (begin with "X-").
114 /// <returns> An enumeration of all qualifiers of the element.
116 virtual public System.Collections.IEnumerator QualifierNames
120 return new EnumeratedIterator(new SupportClass.SetSupport(hashQualifier.Keys).GetEnumerator());
124 /// <summary> Returns whether the element has the OBSOLETE qualifier
125 /// in its Ldap definition.
128 /// <returns> True if the Ldap definition contains the OBSOLETE qualifier;
129 /// false if OBSOLETE qualifier is not present.
131 virtual public bool Obsolete
140 /// <summary> Creates an LdapSchemaElement by setting the name of the LdapAttribute.
141 /// Because this is the only constructor, all extended classes are expected
142 /// to call this constructor. The value of the LdapAttribute must be set
143 /// by the setValue method.
145 /// <param name="attrName"> The attribute name of the schema definition. Valid
146 /// names are one of the following:
147 /// "attributeTypes", "objectClasses", "ldapSyntaxes",
148 /// "nameForms", "dITContentRules", "dITStructureRules",
149 /// "matchingRules", or "matchingRuleUse"
151 protected internal LdapSchemaElement(System.String attrName):base(attrName)
155 /// <summary> The names of the schema element.</summary>
156 [CLSCompliantAttribute(false)]
157 protected internal System.String[] names = new System.String[]{""};
159 /// <summary> The OID for the schema element.</summary>
160 protected internal System.String oid = "";
162 /// <summary> The description for the schema element.</summary>
163 [CLSCompliantAttribute(false)]
164 protected internal System.String description = "";
166 /// <summary> If present, indicates that the element is obsolete, no longer in use in
169 [CLSCompliantAttribute(false)]
170 protected internal bool obsolete = false;
172 /// <summary> A string array of optional, or vendor-specific, qualifiers for the
175 /// These optional qualifiers begin with "X-"; the Novell eDirectory
176 /// specific qualifiers begin with "X-NDS".
178 protected internal System.String[] qualifier = new System.String[]{""};
180 /// <summary> A hash table that contains the vendor-specific qualifiers (for example,
181 /// the X-NDS flags).
183 protected internal System.Collections.Hashtable hashQualifier;
185 /// <summary> Returns an array of all values of a specified optional or non-
186 /// standard qualifier of the element.
188 /// The getQualifier method may be used to access the values of
189 /// vendor-specific qualifiers (which begin with "X-").
192 /// <param name="name"> The name of the qualifier, case-sensitive.
195 /// <returns> An array of values for the specified non-standard qualifier.
197 public virtual System.String[] getQualifier(System.String name)
199 AttributeQualifier attr = (AttributeQualifier) hashQualifier[name];
207 /// <summary> Returns a string in a format suitable for directly adding to a directory,
208 /// as a value of the particular schema element.
211 /// <returns> A string that can be used to add the element to the directory.
213 public override System.String ToString()
215 return formatString();
218 /// <summary> Implementations of formatString format a schema element into a string
219 /// suitable for using in a modify (ADD) operation to the directory.
220 /// toString uses this method. This method is needed because a call to
221 /// setQualifier requires reconstructing the string value of the schema
224 abstract protected internal System.String formatString();
226 /// <summary> Sets the values of a specified optional or non-standard qualifier of
229 /// The setQualifier method is used to set the values of vendor-
230 /// specific qualifiers (which begin with "X-").
233 /// <param name="name"> The name of the qualifier, case-sensitive.
236 /// <param name="values"> The values to set for the qualifier.
238 public virtual void setQualifier(System.String name, System.String[] values)
240 AttributeQualifier attrQualifier = new AttributeQualifier(name, values);
241 SupportClass.PutElement(hashQualifier, name, attrQualifier);
244 * This is the only method that modifies the schema element.
245 * We need to reset the attribute value since it has changed.
247 base.Value = formatString();
251 /// <summary> LdapSchemaElement is read-only and this method is over-ridden to
252 /// throw an exception.
253 /// @throws UnsupportedOperationException always thrown since
254 /// LdapSchemaElement is read-only
256 public override void addValue(System.String value_Renamed)
258 throw new System.NotSupportedException("addValue is not supported by LdapSchemaElement");
261 /// <summary> LdapSchemaElement is read-only and this method is over-ridden to
262 /// throw an exception.
263 /// @throws UnsupportedOperationException always thrown since
264 /// LdapSchemaElement is read-only
266 public virtual void addValue(System.Byte[] value_Renamed)
268 throw new System.NotSupportedException("addValue is not supported by LdapSchemaElement");
270 /// <summary> LdapSchemaElement is read-only and this method is over-ridden to
271 /// throw an exception.
272 /// @throws UnsupportedOperationException always thrown since
273 /// LdapSchemaElement is read-only
275 public override void removeValue(System.String value_Renamed)
277 throw new System.NotSupportedException("removeValue is not supported by LdapSchemaElement");
280 /// <summary> LdapSchemaElement is read-only and this method is over-ridden to
281 /// throw an exception.
282 /// @throws UnsupportedOperationException always thrown since
283 /// LdapSchemaElement is read-only
285 public virtual void removeValue(System.Byte[] value_Renamed)
287 throw new System.NotSupportedException("removeValue is not supported by LdapSchemaElement");