Beispiel #1
0
        /// <summary> Constructs an LdapSchema object from attributes of an LdapEntry.
        /// The object is empty if the entry parameter contains no schema
        /// attributes.  The recognized schema attributes are the following:
        /// <pre><code>
        /// "attributeTypes", "objectClasses", "ldapSyntaxes",
        /// "nameForms", "dITContentRules", "dITStructureRules",
        /// "matchingRules","matchingRuleUse"
        /// </code></pre>
        /// </summary>
        /// <param name="ent">         An LdapEntry containing schema information.
        /// </param>
        public LdapSchema(LdapEntry ent) : base(ent.DN, ent.getAttributeSet())
        {
            InitBlock();
            //reset all definitions
            for (int i = 0; i < schemaTypeNames.Length; i++)
            {
                idTable[i]   = new System.Collections.Hashtable();
                nameTable[i] = new System.Collections.Hashtable();
            }
            System.Collections.IEnumerator itr = getAttributeSet().GetEnumerator();
            while (itr.MoveNext())
            {
                LdapAttribute attr = (LdapAttribute)itr.Current;
                string        value_Renamed, attrName = attr.Name;
                System.Collections.IEnumerator enumString = attr.StringValues;

                if (attrName.ToUpper().Equals(schemaTypeNames[OBJECT_CLASS].ToUpper()))
                {
                    LdapObjectClassSchema classSchema;
                    while (enumString.MoveNext())
                    {
                        value_Renamed = ((string)enumString.Current);
                        try
                        {
                            classSchema = new LdapObjectClassSchema(value_Renamed);
                        }
                        catch (Exception e)
                        {
                            continue; //Error parsing: do not add this definition
                        }
                        addElement(OBJECT_CLASS, classSchema);
                    }
                }
                else if (attrName.ToUpper().Equals(schemaTypeNames[ATTRIBUTE].ToUpper()))
                {
                    LdapAttributeSchema attrSchema;
                    while (enumString.MoveNext())
                    {
                        value_Renamed = ((string)enumString.Current);
                        try
                        {
                            attrSchema = new LdapAttributeSchema(value_Renamed);
                        }
                        catch (Exception e)
                        {
                            continue; //Error parsing: do not add this definition
                        }
                        addElement(ATTRIBUTE, attrSchema);
                    }
                }
                else if (attrName.ToUpper().Equals(schemaTypeNames[SYNTAX].ToUpper()))
                {
                    LdapSyntaxSchema syntaxSchema;
                    while (enumString.MoveNext())
                    {
                        value_Renamed = ((string)enumString.Current);
                        syntaxSchema  = new LdapSyntaxSchema(value_Renamed);
                        addElement(SYNTAX, syntaxSchema);
                    }
                }
                else if (attrName.ToUpper().Equals(schemaTypeNames[MATCHING].ToUpper()))
                {
                    LdapMatchingRuleSchema matchingRuleSchema;
                    while (enumString.MoveNext())
                    {
                        value_Renamed      = ((string)enumString.Current);
                        matchingRuleSchema = new LdapMatchingRuleSchema(value_Renamed, null);
                        addElement(MATCHING, matchingRuleSchema);
                    }
                }
                else if (attrName.ToUpper().Equals(schemaTypeNames[MATCHING_USE].ToUpper()))
                {
                    LdapMatchingRuleUseSchema matchingRuleUseSchema;
                    while (enumString.MoveNext())
                    {
                        value_Renamed         = ((string)enumString.Current);
                        matchingRuleUseSchema = new LdapMatchingRuleUseSchema(value_Renamed);
                        addElement(MATCHING_USE, matchingRuleUseSchema);
                    }
                }
                else if (attrName.ToUpper().Equals(schemaTypeNames[DITCONTENT].ToUpper()))
                {
                    LdapDITContentRuleSchema dITContentRuleSchema;
                    while (enumString.MoveNext())
                    {
                        value_Renamed        = ((string)enumString.Current);
                        dITContentRuleSchema = new LdapDITContentRuleSchema(value_Renamed);
                        addElement(DITCONTENT, dITContentRuleSchema);
                    }
                }
                else if (attrName.ToUpper().Equals(schemaTypeNames[DITSTRUCTURE].ToUpper()))
                {
                    LdapDITStructureRuleSchema dITStructureRuleSchema;
                    while (enumString.MoveNext())
                    {
                        value_Renamed          = ((string)enumString.Current);
                        dITStructureRuleSchema = new LdapDITStructureRuleSchema(value_Renamed);
                        addElement(DITSTRUCTURE, dITStructureRuleSchema);
                    }
                }
                else if (attrName.ToUpper().Equals(schemaTypeNames[NAME_FORM].ToUpper()))
                {
                    LdapNameFormSchema nameFormSchema;
                    while (enumString.MoveNext())
                    {
                        value_Renamed  = ((string)enumString.Current);
                        nameFormSchema = new LdapNameFormSchema(value_Renamed);
                        addElement(NAME_FORM, nameFormSchema);
                    }
                }
                //All non schema attributes are ignored.
                continue;
            }
        }