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: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 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 *******************************************************************************/ 23 // 24 // Novell.Directory.Ldap.LdapSyntaxSchema.cs 25 // 26 // Author: 27 // Sunil Kumar (Sunilk@novell.com) 28 // 29 // (C) 2003 Novell, Inc (http://www.novell.com) 30 // 31 32 using System; 33 using SchemaParser = Novell.Directory.Ldap.Utilclass.SchemaParser; 34 using AttributeQualifier = Novell.Directory.Ldap.Utilclass.AttributeQualifier; 35 36 namespace Novell.Directory.Ldap 37 { 38 39 /// <summary> Represents a syntax definition in the directory schema. 40 /// 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. 43 /// 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. 49 /// </summary> 50 51 public class LdapSyntaxSchema:LdapSchemaElement 52 { 53 54 /// <summary> Constructs a syntax for adding to or deleting from the schema. 55 /// 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. 59 /// 60 /// </summary> 61 /// <param name="oid"> The unique object identifier of the syntax - in 62 /// dotted numerical format. 63 /// 64 /// </param> 65 /// <param name="description">An optional description of the syntax. 66 /// </param> LdapSyntaxSchema(System.String oid, System.String description)67 public LdapSyntaxSchema(System.String oid, System.String description):base(LdapSchema.schemaTypeNames[LdapSchema.SYNTAX]) 68 { 69 base.oid = oid; 70 base.description = description; 71 base.Value = formatString(); 72 return ; 73 } 74 75 /// <summary> Constructs a syntax from the raw string value returned on a schema 76 /// query for LdapSyntaxes. 77 /// 78 /// </summary> 79 /// <param name="raw"> The raw string value returned from a schema 80 /// query for ldapSyntaxes. 81 /// </param> LdapSyntaxSchema(System.String raw)82 public LdapSyntaxSchema(System.String raw):base(LdapSchema.schemaTypeNames[LdapSchema.SYNTAX]) 83 { 84 try 85 { 86 SchemaParser parser = new SchemaParser(raw); 87 88 if ((System.Object) parser.ID != null) 89 base.oid = parser.ID; 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()) 95 { 96 attrQualifier = (AttributeQualifier) qualifiers.Current; 97 setQualifier(attrQualifier.Name, attrQualifier.Values); 98 } 99 base.Value = formatString(); 100 } 101 catch (System.IO.IOException e) 102 { 103 throw new System.SystemException(e.ToString()); 104 } 105 return ; 106 } 107 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. 110 /// 111 /// </summary> 112 /// <returns> A string representation of the syntax's definition. 113 /// </returns> formatString()114 protected internal override System.String formatString() 115 { 116 System.Text.StringBuilder valueBuffer = new System.Text.StringBuilder("( "); 117 System.String token; 118 119 if ((System.Object) (token = ID) != null) 120 { 121 valueBuffer.Append(token); 122 } 123 if ((System.Object) (token = Description) != null) 124 { 125 valueBuffer.Append(" DESC "); 126 valueBuffer.Append("'" + token + "'"); 127 } 128 129 System.Collections.IEnumerator en; 130 if ((en = QualifierNames) != null) 131 { 132 System.String qualName; 133 System.String[] qualValue; 134 while (en.MoveNext()) 135 { 136 qualName = ((System.String) en.Current); 137 valueBuffer.Append(" " + qualName + " "); 138 if ((qualValue = getQualifier(qualName)) != null) 139 { 140 if (qualValue.Length > 1) 141 { 142 valueBuffer.Append("( "); 143 for (int i = 0; i < qualValue.Length; i++) 144 { 145 if (i > 0) 146 { 147 valueBuffer.Append(" "); 148 } 149 valueBuffer.Append("'" + qualValue[i] + "'"); 150 } 151 if (qualValue.Length > 1) 152 { 153 valueBuffer.Append(" )"); 154 } 155 } 156 } 157 } 158 } 159 valueBuffer.Append(" )"); 160 return valueBuffer.ToString(); 161 } 162 } 163 } 164