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

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


            {
                throw new IllegalStateException( "expected byte[] to normalize" );
            }
        } );

        at = new MutableAttributeType( "1.1.3.1" );
        at.setEquality( mr );
        at.setOrdering( mr );
        at.setSubstring( mr );
        at.setSyntax( s );
    }
View Full Code Here


                OpenLdapObjectIdentifierMacro oid = ( OpenLdapObjectIdentifierMacro ) obj;
                objectIdentifierMacros.put( oid.getName(), oid );
            }
            else if ( obj instanceof AttributeType )
            {
                MutableAttributeType attributeType = ( MutableAttributeType ) obj;

                attributeTypes.add( attributeType );
            }
            else if ( obj instanceof ObjectClass )
            {
                ObjectClass objectClass = ( ObjectClass ) obj;

                objectClasses.add( objectClass );
            }
        }

        if ( isResolveObjectIdentifierMacros() )
        {
            // resolve object identifier macros
            for ( OpenLdapObjectIdentifierMacro oid : objectIdentifierMacros.values() )
            {
                resolveObjectIdentifierMacro( oid );
            }

            // apply object identifier macros to object classes
            for ( ObjectClass objectClass : objectClasses )
            {
                objectClass.setOid( getResolveOid( objectClass.getOid() ) );
            }

            // apply object identifier macros to attribute types
            for ( MutableAttributeType attributeType : attributeTypes )
            {
                attributeType.setOid( getResolveOid( attributeType.getOid() ) );
                attributeType.setSyntaxOid( getResolveOid( attributeType.getSyntaxOid() ) );
            }

        }
    }
View Full Code Here

    public AttributeType[] getAttributeTypes()
    {
        MutableAttributeType[] ats = new MutableAttributeType[5];

        ats[0] = new MutableAttributeType( "2.5.4.41" );
        ats[0].addName( "name" );
        ats[0].setSyntax( getSyntaxes()[1] );
        ats[0].setSyntaxLength( 32768 );
        ats[0].setEquality( getMatchingRules()[0] );
        ats[0].setSubstring( getMatchingRules()[1] );

        // ( 2.5.4.3 NAME 'cn' SUP name )
        ats[1] = new MutableAttributeType( "2.5.4.3" );
        ats[1].addName( "cn", "commonName" );

        ats[2] = new MutableAttributeType( "2.5.4.41" );
        ats[2].addName( "name" );
        ats[2].setSyntax( getSyntaxes()[1] );
        ats[2].setSyntaxLength( 32768 );
        ats[2].setEquality( getMatchingRules()[0] );
        ats[2].setSubstring( getMatchingRules()[1] );

        ats[3] = new MutableAttributeType( "2.5.4.41" );
        ats[3].addName( "name" );
        ats[3].setSyntax( getSyntaxes()[1] );
        ats[3].setSyntaxLength( 32768 );
        ats[3].setEquality( getMatchingRules()[0] );
        ats[3].setSubstring( getMatchingRules()[1] );

        ats[4] = new MutableAttributeType( "2.5.4.41" );
        ats[4].addName( "name" );
        ats[4].setSyntax( getSyntaxes()[1] );
        ats[4].setSyntaxLength( 32768 );
        ats[4].setEquality( getMatchingRules()[0] );
        ats[4].setSubstring( getMatchingRules()[1] );
View Full Code Here


    @Test
    public void testUnregister() throws LdapException
    {
        MutableAttributeType at0 = new MutableAttributeType( "1.1" );
        at0.addName( "t", "test", "Test", "T" );
        atRegistry.register( at0 );

        atRegistry.unregister( "1.1" );
        assertFalse( atRegistry.contains( "1.1" ) );
        assertFalse( atRegistry.contains( "t" ) );
View Full Code Here


    @Test
    public void testRegister() throws LdapException
    {
        MutableAttributeType at0 = new MutableAttributeType( "1.1" );
        at0.addName( "t", "test", "Test", "T" );
        atRegistry.register( at0 );

        assertTrue( atRegistry.contains( "1.1" ) );
        assertTrue( atRegistry.contains( "t" ) );
        assertTrue( atRegistry.contains( "T" ) );
View Full Code Here

    /**
     * Build the Superior AttributeType reference for an AttributeType
     */
    private static boolean buildSuperior( MutableAttributeType attributeType, List<Throwable> errors, Registries registries )
    {
        MutableAttributeType currentSuperior = null;
        AttributeTypeRegistry attributeTypeRegistry = registries.getAttributeTypeRegistry();
       
        String superiorOid = attributeType.getSuperiorOid();

        if ( superiorOid != null )
        {
            // This AT has a superior
            try
            {
                currentSuperior = (MutableAttributeType)attributeTypeRegistry.lookup( superiorOid );
            }
            catch ( Exception e )
            {
                // Not allowed.
                String msg = I18n.err( I18n.ERR_04303, superiorOid, attributeType.getName() );

                LdapSchemaException ldapSchemaException = new LdapSchemaException(
                    LdapSchemaExceptionCodes.AT_NONEXISTENT_SUPERIOR, msg, e );
                ldapSchemaException.setSourceObject( attributeType );
                ldapSchemaException.setRelatedId( superiorOid );
                errors.add( ldapSchemaException );
                LOG.info( msg );

                // Get out now
                return false;
            }

            if ( currentSuperior != null )
            {
                // a special case : if the superior is collective, this is an error
                if ( currentSuperior.isCollective() )
                {
                    String msg = I18n.err( I18n.ERR_04482_CANNOT_SUBTYPE_COLLECTIVE,
                        currentSuperior, attributeType.getName() );

                    LdapSchemaException ldapSchemaException = new LdapSchemaException(
                        LdapSchemaExceptionCodes.AT_CANNOT_SUBTYPE_COLLECTIVE_AT, msg );
                    ldapSchemaException.setSourceObject( attributeType );
                    errors.add( ldapSchemaException );
                    LOG.info( msg );
                   
                    return false;
                }

                attributeType.setSuperior( currentSuperior );

                // Recursively update the superior if not already done. We don't recurse
                // if the superior's superior is not null, as it means it has already been
                // handled.
                if ( currentSuperior.getSuperior() == null )
                {
                    registries.buildReference( errors, currentSuperior );
                }

                // Update the descendant MAP
View Full Code Here

            {
                throw new IllegalStateException( "expected byte[] to normalize" );
            }
        } );

        at = new MutableAttributeType( "1.1.3.1" );
        at.setEquality( mr );
        at.setOrdering( mr );
        at.setSubstring( mr );
        at.setSyntax( s );
    }
View Full Code Here

     */
    @Test
    public void testBadConstructor()
    {
        // create a AT without no syntax
        MutableAttributeType attribute = new MutableAttributeType( "1.1.3.1" );

        try
        {
            new BinaryValue( attribute );
            fail();
View Full Code Here

    }


    /* no protection*/static AttributeType getCaseIgnoringAttributeNoNumbersType()
    {
        MutableAttributeType attributeType = new MutableAttributeType( "1.1.3.1" );
        LdapSyntax syntax = new LdapSyntax( "1.1.1.1", "", true );

        syntax.setSyntaxChecker( new SyntaxChecker( "1.1.2.1" )
        {
            public static final long serialVersionUID = 1L;


            public boolean isValidSyntax( Object value )
            {
                if ( value == null )
                {
                    return true;
                }

                if ( !( value instanceof String ) )
                {
                    return false;
                }

                String strval = ( String ) value;

                for ( char c : strval.toCharArray() )
                {
                    if ( Character.isDigit( c ) )
                    {
                        return false;
                    }
                }
                return true;
            }
        } );

        MutableMatchingRule matchingRule = new MutableMatchingRule( "1.1.2.1" );
        matchingRule.setSyntax( syntax );

        matchingRule.setLdapComparator( new LdapComparator<String>( matchingRule.getOid() )
        {
            public static final long serialVersionUID = 1L;


            public int compare( String o1, String o2 )
            {
                return ( o1 == null ?
                    ( o2 == null ? 0 : -1 ) :
                    ( o2 == null ? 1 : o1.compareTo( o2 ) ) );
            }
        } );

        Normalizer normalizer = new Normalizer( "1.1.1" )
        {
            public static final long serialVersionUID = 1L;


            public Value<?> normalize( Value<?> value ) throws LdapException
            {
                if ( value.isHumanReadable() )
                {
                    return new StringValue( Strings.toLowerCase( value.getString() ) );
                }

                throw new IllegalStateException( I18n.err( I18n.ERR_04474 ) );
            }


            public String normalize( String value ) throws LdapException
            {
                return Strings.toLowerCase( value );
            }
        };

        matchingRule.setNormalizer( normalizer );

        attributeType.setEquality( matchingRule );
        attributeType.setSyntax( syntax );

        return attributeType;
    }
View Full Code Here

    }


    /* no protection*/static AttributeType getIA5StringAttributeType()
    {
        MutableAttributeType attributeType = new MutableAttributeType( "1.1" );
        attributeType.addName( "1.1" );
        LdapSyntax syntax = new LdapSyntax( "1.1.1", "", true );

        syntax.setSyntaxChecker( new SyntaxChecker( "1.1.2" )
        {
            public static final long serialVersionUID = 1L;


            public boolean isValidSyntax( Object value )
            {
                return ( ( String ) value == null ) || ( ( ( String ) value ).length() < 7 );
            }
        } );

        MutableMatchingRule matchingRule = new MutableMatchingRule( "1.1.2" );
        matchingRule.setSyntax( syntax );

        matchingRule.setLdapComparator( new LdapComparator<String>( matchingRule.getOid() )
        {
            public static final long serialVersionUID = 1L;


            public int compare( String o1, String o2 )
            {
                return ( ( o1 == null ) ?
                    ( o2 == null ? 0 : -1 ) :
                    ( o2 == null ? 1 : o1.compareTo( o2 ) ) );
            }
        } );

        matchingRule.setNormalizer( new DeepTrimToLowerNormalizer( matchingRule.getOid() ) );

        attributeType.setEquality( matchingRule );
        attributeType.setSyntax( syntax );

        return attributeType;
    }
View Full Code Here

TOP

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

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.