Package org.apache.directory.api.ldap.model.schema

Examples of org.apache.directory.api.ldap.model.schema.MutableObjectClass


     * @param ocl
     *      the Object Class Literal
     */
    private void updateObjectClass( ObjectClass ocl )
    {
        MutableObjectClass modifiedObjectClass = getModifiedObjectClass();

        modifiedObjectClass.setDescription( ocl.getDescription() );
        modifiedObjectClass.setMayAttributeTypeOids( ocl.getMayAttributeTypeOids() );
        modifiedObjectClass.setMustAttributeTypeOids( ocl.getMustAttributeTypeOids() );
        modifiedObjectClass.setNames( ocl.getNames() );
        modifiedObjectClass.setObsolete( ocl.isObsolete() );
        modifiedObjectClass.setOid( ocl.getOid() );
        modifiedObjectClass.setSuperiorOids( ocl.getSuperiorOids() );
        modifiedObjectClass.setType( ocl.getType() );
    }
View Full Code Here


                    {
                        ObjectClassDescriptionSchemaParser parser = new ObjectClassDescriptionSchemaParser();
                        parser.setQuirksMode( true );
                        ObjectClass ocd = parser.parseObjectClassDescription( value );

                        MutableObjectClass impl = new MutableObjectClass( 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 );
                        parseErrorCount++;
                    }
                }
            }
        }

        Attribute ldapSyntaxesAttribute = searchResult.getAttributes().get( "ldapSyntaxes" ); //$NON-NLS-1$
        if ( ldapSyntaxesAttribute != null )
        {
            NamingEnumeration<?> ne = ldapSyntaxesAttribute.getAll();
            if ( ne != null )
            {
                while ( ne.hasMoreElements() )
                {
                    String value = ( String ) ne.nextElement();

                    try
                    {
                        LdapSyntaxDescriptionSchemaParser parser = new LdapSyntaxDescriptionSchemaParser();
                        parser.setQuirksMode( true );
                        LdapSyntax lsd = parser.parseLdapSyntaxDescription( value );

                        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 );
                        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 = searchResult.getAttributes().get( "matchingRules" ); //$NON-NLS-1$
        if ( matchingRulesAttribute != null )
        {
            NamingEnumeration<?> ne = matchingRulesAttribute.getAll();
            if ( ne != null )
            {
                while ( ne.hasMoreElements() )
                {
                    String value = ( String ) ne.nextElement();

                    try
                    {
                        MatchingRuleDescriptionSchemaParser parser = new MatchingRuleDescriptionSchemaParser();
                        parser.setQuirksMode( true );
                        MatchingRule mrd = parser.parseMatchingRuleDescription( value );

                        MutableMatchingRule impl = new MutableMatchingRule( 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 )
                    {
View Full Code Here

                            AttributeType at = createAttributeType( searchResult );
                            at.setSchemaName( name );
                            schema.addAttributeType( at );
                            break;
                        case OBJECT_CLASS:
                            MutableObjectClass oc = createObjectClass( searchResult );
                            oc.setSchemaName( name );
                            schema.addObjectClass( oc );
                            break;
                        case MATCHING_RULE:
                            MatchingRule mr = createMatchingRule( searchResult );
                            mr.setSchemaName( name );
View Full Code Here

     * ObjectClassImpl could be created
     * @throws NamingException
     */
    private static MutableObjectClass createObjectClass( SearchResult sr ) throws NamingException
    {
        MutableObjectClass oc = new MutableObjectClass( getOid( sr ) );
        oc.setNames( getNames( sr ) );
        oc.setDescription( getDescription( sr ) );
        oc.setObsolete( isObsolete( sr ) );
        oc.setSuperiorOids( getSuperiors( sr ) );
        oc.setType( getType( sr ) );
        oc.setMayAttributeTypeOids( getMay( sr ) );
        oc.setMustAttributeTypeOids( getMust( sr ) );
        return oc;
    }
View Full Code Here

     *      the schema
     * @throws XMLSchemaFileImportException
     */
    private static void readObjectClass( Element element, Schema schema ) throws XMLSchemaFileImportException
    {
        MutableObjectClass oc = null;

        // OID
        Attribute oidAttribute = element.attribute( OID_TAG );
        if ( ( oidAttribute != null ) && ( !oidAttribute.getValue().equals( "" ) ) ) //$NON-NLS-1$
        {
            oc = new MutableObjectClass( oidAttribute.getValue() );
        }
        else
        {
            throw new XMLSchemaFileImportException( Messages.getString( "XMLSchemaFileImporter.NoOIDInClass" ) ); //$NON-NLS-1$
        }

        // Schema
        oc.setSchemaName( schema.getSchemaName() );

        // Aliases
        Element aliasesElement = element.element( ALIASES_TAG );
        if ( aliasesElement != null )
        {
            List<String> aliases = new ArrayList<String>();
            for ( Iterator<?> i = aliasesElement.elementIterator( ALIAS_TAG ); i.hasNext(); )
            {
                Element aliasElement = ( Element ) i.next();
                aliases.add( aliasElement.getText() );
            }
            if ( aliases.size() >= 1 )
            {
                oc.setNames( aliases.toArray( new String[0] ) );
            }
        }

        // Description
        Element descriptionElement = element.element( DESCRIPTION_TAG );
        if ( ( descriptionElement != null ) && ( !descriptionElement.getText().equals( "" ) ) ) //$NON-NLS-1$
        {
            oc.setDescription( descriptionElement.getText() );
        }

        // Superiors
        Element superiorsElement = element.element( SUPERIORS_TAG );
        if ( superiorsElement != null )
        {
            List<String> superiors = new ArrayList<String>();
            for ( Iterator<?> i = superiorsElement.elementIterator( SUPERIOR_TAG ); i.hasNext(); )
            {
                Element superiorElement = ( Element ) i.next();
                superiors.add( superiorElement.getText() );
            }
            if ( superiors.size() >= 1 )
            {
                oc.setSuperiorOids( superiors );
            }
        }

        // Class Type
        Element classTypeElement = element.element( TYPE_TAG );
        if ( ( classTypeElement != null ) && ( !classTypeElement.getText().equals( "" ) ) ) //$NON-NLS-1$
        {
            try
            {
                oc.setType( ObjectClassTypeEnum.valueOf( classTypeElement.getText() ) );
            }
            catch ( IllegalArgumentException e )
            {
                throw new XMLSchemaFileImportException(
                    Messages.getString( "XMLSchemaFileImporter.UnconvertableValue" ), e ); //$NON-NLS-1$
            }
        }

        // Obsolete
        Attribute obsoleteAttribute = element.attribute( OBSOLETE_TAG );
        if ( ( obsoleteAttribute != null ) && ( !obsoleteAttribute.getValue().equals( "" ) ) ) //$NON-NLS-1$
        {
            oc.setObsolete( readBoolean( obsoleteAttribute.getValue() ) );
        }

        // Mandatory Attribute Types
        Element mandatoryElement = element.element( MANDATORY_TAG );
        if ( mandatoryElement != null )
        {
            List<String> mandatoryATs = new ArrayList<String>();
            for ( Iterator<?> i = mandatoryElement.elementIterator( ATTRIBUTE_TYPE_TAG ); i.hasNext(); )
            {
                Element attributeTypeElement = ( Element ) i.next();
                mandatoryATs.add( attributeTypeElement.getText() );
            }
            if ( mandatoryATs.size() >= 1 )
            {
                oc.setMustAttributeTypeOids( mandatoryATs );
            }
        }

        // Optional Attribute Types
        Element optionalElement = element.element( OPTIONAL_TAG );
        if ( optionalElement != null )
        {
            List<String> optionalATs = new ArrayList<String>();
            for ( Iterator<?> i = optionalElement.elementIterator( ATTRIBUTE_TYPE_TAG ); i.hasNext(); )
            {
                Element attributeTypeElement = ( Element ) i.next();
                optionalATs.add( attributeTypeElement.getText() );
            }
            if ( optionalATs.size() >= 1 )
            {
                oc.setMayAttributeTypeOids( optionalATs );
            }
        }

        // Adding the object class to the schema
        schema.addObjectClass( oc );
View Full Code Here

     * @return
     *      a clone of the given object class
     */
    public static MutableObjectClass getClone( ObjectClass oc )
    {
        MutableObjectClass clone = new MutableObjectClass( oc.getOid() );
        clone.setNames( oc.getNames() );
        clone.setSchemaName( oc.getSchemaName() );
        clone.setDescription( oc.getDescription() );
        clone.setSuperiorOids( oc.getSuperiorOids() );
        clone.setType( oc.getType() );
        clone.setObsolete( oc.isObsolete() );
        clone.setMustAttributeTypeOids( oc.getMustAttributeTypeOids() );
        clone.setMayAttributeTypeOids( oc.getMayAttributeTypeOids() );

        return clone;
    }
View Full Code Here

                                    childNode = new AttributeTypeWrapper( at, atFolder );
                                    atFolder.addChild( childNode );
                                }
                                else if ( rootChild instanceof ObjectClass )
                                {
                                    MutableObjectClass oc = ( MutableObjectClass ) rootChild;
                                    childNode = new ObjectClassWrapper( oc, ocFolder );
                                    ocFolder.addChild( childNode );
                                }

                                // Filling the 'Elements To Wrappers' Map
View Full Code Here

                    childNode = new AttributeTypeWrapper( at, node );
                    node.addChild( childNode );
                }
                else if ( child instanceof ObjectClass )
                {
                    MutableObjectClass oc = ( MutableObjectClass ) child;
                    childNode = new ObjectClassWrapper( oc, node );
                    node.addChild( childNode );
                }

                // Filling the 'Elements To Wrappers' Map
View Full Code Here

        {
            moved = false;
            Iterator<MutableObjectClass> unsortedIterator = unsortedObjectClasses.iterator();
            while ( unsortedIterator.hasNext() )
            {
                MutableObjectClass oc = unsortedIterator.next();
                for ( String superName : oc.getSuperiorOids() )
                {
                    if ( !objectClassNames.contains( Strings.toLowerCase( superName ) )
                        || movedObjectClasses.contains( Strings.toLowerCase( superName ) ) )
                    {
                        unsortedIterator.remove();
                        sortedObjectClasses.add( oc );
                        for ( String name : oc.getNames() )
                        {
                            movedObjectClasses.add( Strings.toLowerCase( name ) );
                        }
                        moved = true;
                        break;
View Full Code Here

     * @throws Exception
     */
    public void testAddMandatoryATDifference() throws Exception
    {
        ObjectClass o1 = new ObjectClass( "1.2.3.4" ); //$NON-NLS-1$
        MutableObjectClass o2 = new MutableObjectClass( "1.2.3.4" ); //$NON-NLS-1$
        o2.setMustAttributeTypeOids( Arrays.asList( new String[]
            { "must" } ) ); //$NON-NLS-1$

        List<PropertyDifference> differences = DifferenceEngine.getDifferences( o1, o2 );

        assertEquals( 1, differences.size() );
View Full Code Here

TOP

Related Classes of org.apache.directory.api.ldap.model.schema.MutableObjectClass

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.