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.LdapSyntaxSchema.cs
27 // Sunil Kumar (Sunilk@novell.com)
29 // (C) 2003 Novell, Inc (http://www.novell.com)
33 using SchemaParser = Novell.Directory.Ldap.Utilclass.SchemaParser;
34 using AttributeQualifier = Novell.Directory.Ldap.Utilclass.AttributeQualifier;
36 namespace Novell.Directory.Ldap
39 /// <summary> Represents a syntax definition in the directory schema.
41 /// The LdapSyntaxSchema class represents the definition of a syntax. It is
42 /// used to discover the known set of syntaxes in effect for the subschema.
44 /// Although this extends LdapSchemaElement, it does not use the name or
45 /// obsolete members. Therefore, calls to the getName method always return
46 /// null and to the isObsolete method always returns false. There is also no
47 /// matching getSyntaxNames method in LdapSchema. Note also that adding and
48 /// removing syntaxes is not typically a supported feature of Ldap servers.
51 public class LdapSyntaxSchema:LdapSchemaElement
54 /// <summary> Constructs a syntax for adding to or deleting from the schema.
56 /// Adding and removing syntaxes is not typically a supported
57 /// feature of Ldap servers. Novell eDirectory does not allow syntaxes to
58 /// be added or removed.
61 /// <param name="oid"> The unique object identifier of the syntax - in
62 /// dotted numerical format.
65 /// <param name="description">An optional description of the syntax.
67 public LdapSyntaxSchema(System.String oid, System.String description):base(LdapSchema.schemaTypeNames[LdapSchema.SYNTAX])
70 base.description = description;
71 base.Value = formatString();
75 /// <summary> Constructs a syntax from the raw string value returned on a schema
76 /// query for LdapSyntaxes.
79 /// <param name="raw"> The raw string value returned from a schema
80 /// query for ldapSyntaxes.
82 public LdapSyntaxSchema(System.String raw):base(LdapSchema.schemaTypeNames[LdapSchema.SYNTAX])
86 SchemaParser parser = new SchemaParser(raw);
88 if ((System.Object) parser.ID != null)
90 if ((System.Object) parser.Description != null)
91 base.description = parser.Description;
92 System.Collections.IEnumerator qualifiers = parser.Qualifiers;
93 AttributeQualifier attrQualifier;
94 while (qualifiers.MoveNext())
96 attrQualifier = (AttributeQualifier) qualifiers.Current;
97 setQualifier(attrQualifier.Name, attrQualifier.Values);
99 base.Value = formatString();
101 catch (System.IO.IOException e)
103 throw new System.SystemException(e.ToString());
108 /// <summary> Returns a string in a format suitable for directly adding to a
109 /// directory, as a value of the particular schema element class.
112 /// <returns> A string representation of the syntax's definition.
114 protected internal override System.String formatString()
116 System.Text.StringBuilder valueBuffer = new System.Text.StringBuilder("( ");
119 if ((System.Object) (token = ID) != null)
121 valueBuffer.Append(token);
123 if ((System.Object) (token = Description) != null)
125 valueBuffer.Append(" DESC ");
126 valueBuffer.Append("'" + token + "'");
129 System.Collections.IEnumerator en;
130 if ((en = QualifierNames) != null)
132 System.String qualName;
133 System.String[] qualValue;
134 while (en.MoveNext())
136 qualName = ((System.String) en.Current);
137 valueBuffer.Append(" " + qualName + " ");
138 if ((qualValue = getQualifier(qualName)) != null)
140 if (qualValue.Length > 1)
142 valueBuffer.Append("( ");
143 for (int i = 0; i < qualValue.Length; i++)
147 valueBuffer.Append(" ");
149 valueBuffer.Append("'" + qualValue[i] + "'");
151 if (qualValue.Length > 1)
153 valueBuffer.Append(" )");
159 valueBuffer.Append(" )");
160 return valueBuffer.ToString();