private static void getSchema()

in plugins/schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/GenericSchemaConnector.java [184:368]


    private static void getSchema( Schema schema, ConnectionWrapper wrapper, Entry entry,
        StudioProgressMonitor monitor ) throws SchemaConnectorException
    {
        // The counter for parser exceptions
        int parseErrorCount = 0;

        Attribute attributeTypesAttribute = entry.get( SchemaConstants.ATTRIBUTE_TYPES_AT );
        if ( attributeTypesAttribute != null )
        {
                for ( Value value : attributeTypesAttribute )
                {
                    try
                    {
                        AttributeTypeDescriptionSchemaParser parser = new AttributeTypeDescriptionSchemaParser();
                        parser.setQuirksMode( true );

                        AttributeType atd = parser.parse( value.getString() );

                        AttributeType impl = new AttributeType( atd.getOid() );
                        impl.setNames( atd.getNames().toArray( new String[0] ) );
                        impl.setDescription( atd.getDescription() );
                        impl.setSuperiorOid( atd.getSuperiorOid() );
                        impl.setUsage( atd.getUsage() );
                        impl.setSyntaxOid( atd.getSyntaxOid() );
                        impl.setSyntaxLength( atd.getSyntaxLength() );
                        impl.setObsolete( atd.isObsolete() );
                        impl.setCollective( atd.isCollective() );
                        impl.setSingleValued( atd.isSingleValued() );
                        impl.setUserModifiable( atd.isUserModifiable() );
                        impl.setEqualityOid( atd.getEqualityOid() );
                        impl.setOrderingOid( atd.getOrderingOid() );
                        impl.setSubstringOid( atd.getSubstringOid() );
                        impl.setSchemaName( schema.getSchemaName() );

                        // Active Directory hack
                        if ( impl.getSyntaxOid() != null && "OctetString".equalsIgnoreCase( impl.getSyntaxOid() ) ) //$NON-NLS-1$
                        {
                            impl.setSyntaxOid( SchemaConstants.OCTET_STRING_SYNTAX );
                        }

                        schema.addAttributeType( impl );
                    }
                    catch ( ParseException e )
                    {
                        // Logging the exception and incrementing the counter
                        PluginUtils.logError( "Unable to parse the attribute type.", e ); //$NON-NLS-1$
                        parseErrorCount++;
                    }
            }
        }

        Attribute objectClassesAttribute = entry.get( SchemaConstants.OBJECT_CLASSES_AT );
        if ( objectClassesAttribute != null )
        {
                for ( Value value : objectClassesAttribute )
                {
                    try
                    {
                        ObjectClassDescriptionSchemaParser parser = new ObjectClassDescriptionSchemaParser();
                        parser.setQuirksMode( true );
                        ObjectClass ocd = parser.parse( value.getString() );

                        ObjectClass impl = new ObjectClass( ocd.getOid() );
                        impl.setNames( ocd.getNames().toArray( new String[0] ) );
                        impl.setDescription( ocd.getDescription() );
                        impl.setSuperiorOids( ocd.getSuperiorOids() );
                        impl.setType( ocd.getType() );
                        impl.setObsolete( ocd.isObsolete() );
                        impl.setMustAttributeTypeOids( ocd.getMustAttributeTypeOids() );
                        impl.setMayAttributeTypeOids( ocd.getMayAttributeTypeOids() );
                        impl.setSchemaName( schema.getSchemaName() );

                        schema.addObjectClass( impl );
                    }
                    catch ( ParseException e )
                    {
                        // Logging the exception and incrementing the counter
                        PluginUtils.logError( "Unable to parse the object class.", e ); //$NON-NLS-1$
                        parseErrorCount++;
                    }
                }
        }

        Attribute ldapSyntaxesAttribute = entry.get( SchemaConstants.LDAP_SYNTAXES_AT );
        if ( ldapSyntaxesAttribute != null )
        {
                for ( Value value : ldapSyntaxesAttribute )
                {
                    try
                    {
                        LdapSyntaxDescriptionSchemaParser parser = new LdapSyntaxDescriptionSchemaParser();
                        parser.setQuirksMode( true );
                        LdapSyntax lsd = parser.parse( value.getString() );

                        LdapSyntax impl = new LdapSyntax( lsd.getOid() );
                        impl.setDescription( lsd.getDescription() );
                        impl.setNames( new String[]
                            { lsd.getDescription() } );
                        //impl.setObsolete( lsd.isObsolete() );
                        impl.setHumanReadable( true );
                        impl.setSchemaName( schema.getSchemaName() );

                        schema.addSyntax( impl );
                    }
                    catch ( ParseException e )
                    {
                        // Logging the exception and incrementing the counter
                        PluginUtils.logError( "Unable to parse the syntax.", e ); //$NON-NLS-1$
                        parseErrorCount++;
                    }
                }
        }

        // if online: assume all received syntaxes in attributes are valid -> create dummy syntaxes if missing
        for ( AttributeType at : schema.getAttributeTypes() )
        {
            String syntaxOid = at.getSyntaxOid();
            
            if ( ( syntaxOid != null ) && ( schema.getSyntax( syntaxOid ) == null ) )
            {
                LdapSyntax impl = new LdapSyntax( syntaxOid );
                impl.setSchemaName( schema.getSchemaName() );
                String oidDescription = Utils.getOidDescription( syntaxOid );
                impl.setDescription( oidDescription != null ? oidDescription : "Dummy" ); //$NON-NLS-1$
                impl.setNames( new String[]
                    { impl.getDescription() } );
                schema.addSyntax( impl );
            }
        }

        Attribute matchingRulesAttribute = entry.get( SchemaConstants.MATCHING_RULES_AT );
        if ( matchingRulesAttribute != null )
        {
                for ( Value value : matchingRulesAttribute )
                {
                    try
                    {
                        MatchingRuleDescriptionSchemaParser parser = new MatchingRuleDescriptionSchemaParser();
                        parser.setQuirksMode( true );
                        MatchingRule mrd = parser.parse( value.getString() );

                        MatchingRule impl = new MatchingRule( mrd.getOid() );
                        impl.setDescription( mrd.getDescription() );
                        impl.setNames( mrd.getNames().toArray( new String[0] ) );
                        impl.setObsolete( mrd.isObsolete() );
                        impl.setSyntaxOid( mrd.getSyntaxOid() );
                        impl.setSchemaName( schema.getSchemaName() );

                        schema.addMatchingRule( impl );
                    }
                    catch ( ParseException e )
                    {
                        // Logging the exception and incrementing the counter
                        PluginUtils.logError( "Unable to parse the matching rule.", e ); //$NON-NLS-1$
                        parseErrorCount++;
                    }
                }
        }

        // if online: assume all received matching rules in attributes are valid -> create dummy matching rules if missing
        for ( AttributeType at : schema.getAttributeTypes() )
        {
            String equalityName = at.getEqualityOid();
            String orderingName = at.getOrderingOid();
            String substrName = at.getSubstringOid();
            checkMatchingRules( schema, equalityName, orderingName, substrName );
        }

        // Showing an error
        if ( parseErrorCount > 0 )
        {
            if ( parseErrorCount == 1 )
            {
                throw new SchemaConnectorException(
                    Messages.getString( "GenericSchemaConnector.OneSchemaElementCouldNotBeParsedError" ) ); //$NON-NLS-1$

            }
            else
            {
                throw new SchemaConnectorException( NLS.bind(
                    Messages.getString( "GenericSchemaConnector.MultipleSchemaElementsCouldNotBeParsedError" ), //$NON-NLS-1$
                    parseErrorCount ) );
            }
        }
    }