Package org.apache.directory.shared.ldap.schema

Examples of org.apache.directory.shared.ldap.schema.ObjectClass


        int pos = 0;

        for ( Value<?> value : attr )
        {
            ObjectClass objectClass = null;

            try
            {
                objectClass = objectClassParser.parseObjectClassDescription( value.getString() );
            }
            catch ( ParseException e )
            {
                LdapInvalidAttributeValueException iave = new LdapInvalidAttributeValueException( I18n.err( I18n.ERR_417,
                    value.getString() ), ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
                iave.setRootCause( e );
                throw iave;
            }

            // if the super objectClasses are provided make sure it exists in some schema
            if ( objectClass.getSuperiorOids() != null && objectClass.getSuperiorOids().size() > 0 )
            {
                for ( String superiorOid : objectClass.getSuperiorOids() )
                {
                    if ( superiorOid.equals( SchemaConstants.TOP_OC_OID )
                        || superiorOid.equalsIgnoreCase( SchemaConstants.TOP_OC ) )
                    {
                        continue;
                    }

                    if ( !schemaManager.getObjectClassRegistry().contains( superiorOid ) )
                    {
                        throw new LdapOperationNotSupportedException( I18n.err( I18n.ERR_418, superiorOid ),
                            ResultCodeEnum.UNWILLING_TO_PERFORM );
                    }
                }
            }

            // if the may list is provided make sure attributes exists in some schema
            if ( objectClass.getMayAttributeTypeOids() != null && objectClass.getMayAttributeTypeOids().size() > 0 )
            {
                for ( String mayAttrOid : objectClass.getMayAttributeTypeOids() )
                {
                    if ( !schemaManager.getAttributeTypeRegistry().contains( mayAttrOid ) )
                    {
                        throw new LdapOperationNotSupportedException( I18n.err( I18n.ERR_419, mayAttrOid ),
                            ResultCodeEnum.UNWILLING_TO_PERFORM );
                    }
                }
            }

            // if the must list is provided make sure attributes exists in some schema
            if ( objectClass.getMustAttributeTypeOids() != null && objectClass.getMustAttributeTypeOids().size() > 0 )
            {
                for ( String mustAttrOid : objectClass.getMustAttributeTypeOids() )
                {
                    if ( !schemaManager.getAttributeTypeRegistry().contains( mustAttrOid ) )
                    {
                        throw new LdapOperationNotSupportedException( I18n.err( I18n.ERR_420, mustAttrOid ),
                            ResultCodeEnum.UNWILLING_TO_PERFORM );
                    }
                }
            }

            List<Throwable> errors = new ArrayList<Throwable>();
            objectClass.setRegistries( schemaManager.getRegistries() );

            objectClasses[pos++] = objectClass;
        }

        return objectClasses;
View Full Code Here


    @Ignore
    public void testModifyObjectClassWithModificationItems() throws Exception
    {
        addObjectClass();
       
        ObjectClass oc = getObjectClassRegistry().lookup( OID );
        assertEquals( oc.getDescription(), DESCRIPTION0 );
        assertEquals( oc.getName(), NAME );

        DN dn = getObjectClassContainer( "apachemeta" );
        dn.add( "m-oid" + "=" + OID );
       
        ModificationItem[] mods = new ModificationItem[2];
        Attribute attr = new BasicAttribute( "m-description", DESCRIPTION1 );
        mods[0] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
        attr = new BasicAttribute( "m-name", NEW_NAME );
        mods[1] = new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
        getSchemaContext( service ).modifyAttributes( dn, mods );

        assertTrue( "objectClass OID should still be present",
            getObjectClassRegistry().contains( OID ) );
       
        assertEquals( "objectClass schema should be set to apachemeta",
            getObjectClassRegistry().getSchemaName( OID ), "apachemeta" );
       
        oc = getObjectClassRegistry().lookup( OID );
        assertEquals( oc.getDescription(), DESCRIPTION1 );
        assertEquals( oc.getName(), NEW_NAME );
    }
View Full Code Here

    @Ignore
    public void testModifyObjectClassWithAttributes() throws Exception
    {
        addObjectClass();
       
        ObjectClass oc = getObjectClassRegistry().lookup( OID );
        assertEquals( oc.getDescription(), DESCRIPTION0 );
        assertEquals( oc.getName(), NAME );

        DN dn = getObjectClassContainer( "apachemeta" );
        dn.add( "m-oid" + "=" + OID );
       
        Attributes mods = new BasicAttributes( true );
        mods.put( "m-description", DESCRIPTION1 );
        mods.put( "m-name", NEW_NAME );
        getSchemaContext( service ).modifyAttributes( dn, DirContext.REPLACE_ATTRIBUTE, mods );

        assertTrue( "objectClass OID should still be present",
            getObjectClassRegistry().contains( OID ) );
       
        assertEquals( "objectClass schema should be set to apachemeta",
            getObjectClassRegistry().getSchemaName( OID ), "apachemeta" );

        oc = getObjectClassRegistry().lookup( OID );
        assertEquals( oc.getDescription(), DESCRIPTION1 );
        assertEquals( oc.getName(), NEW_NAME );
    }
View Full Code Here

        }

        // check that there is at least one structural objectClass in the replacement set
        for ( Value<?> value:attribute )
        {
            ObjectClass ocType = schemaManager.getObjectClassRegistry().lookup( value.getString() );

            if ( ocType.getType() == ObjectClassTypeEnum.STRUCTURAL )
            {
                return;
            }
        }
View Full Code Here

        }

        // check that there is at least one structural objectClass in the replacement set
        for ( Value<?> value:objectClass )
        {
            ObjectClass ocType = registry.lookup( value.getString() );
           
            if ( ocType.getType() == ObjectClassTypeEnum.STRUCTURAL )
            {
                return;
            }
        }
View Full Code Here

        }

        // check resultant set of objectClass values for a structural objectClass
        for ( Value<?> objectClass:cloned )
        {
            ObjectClass oc = schemaManager.getObjectClassRegistry().lookup( objectClass.getString() );
           
            if ( oc.getType() == ObjectClassTypeEnum.STRUCTURAL )
            {
                return;
            }
        }
View Full Code Here

        throws Exception
    {
        DN name = opContext.getDn();
        ServerEntry entry = opContext.getEntry();
        String oid = getOid( entry );
        ObjectClass oc = factory.getObjectClass( schemaManager, targetEntry, schemaManager.getRegistries(),
            getSchemaName( name ) );
        String schemaName = getSchemaName( entry.getDn() );

        if ( isSchemaEnabled( schemaName ) )
        {
View Full Code Here

        checkOidIsUnique( entry );

        // Build the new ObjectClass from the given entry
        String schemaName = getSchemaName( dn );

        ObjectClass objectClass = factory.getObjectClass( schemaManager, entry, schemaManager.getRegistries(),
            schemaName );

        // At this point, the constructed ObjectClass has not been checked against the
        // existing Registries. It may be broken (missing SUP, or such), it will be checked
        // there, if the schema and the ObjectClass are both enabled.
        Schema schema = schemaManager.getLoadedSchema( schemaName );

        if ( schema.isEnabled() && objectClass.isEnabled() )
        {
            if ( schemaManager.add( objectClass ) )
            {
                LOG.debug( "Added {} into the enabled schema {}", dn.getName(), schemaName );
            }
View Full Code Here

           
            return;
        }
       
        // Test that the Oid exists
        ObjectClass objectClass = ( ObjectClass ) checkOidExists( entry );

        if ( schema.isEnabled() && objectClass.isEnabled() )
        {
            if ( schemaManager.delete( objectClass ) )
            {
                LOG.debug( "Removed {} from the schema {}", objectClass, schemaName );
            }
View Full Code Here

     * {@inheritDoc}
     */
    public void rename( ServerEntry entry, RDN newRdn, boolean cascade ) throws Exception
    {
        String schemaName = getSchemaName( entry.getDn() );
        ObjectClass oldOc = factory.getObjectClass( schemaManager, entry, schemaManager.getRegistries(), schemaName );

        // Dependency constraints are not managed by this class
        //        Set<ServerEntry> dependees = dao.listObjectClassDependents( oldOc );
        //       
        //        if ( dependees != null && dependees.size() > 0 )
        //        {
        //            throw new LdapOperationNotSupportedException( "The objectClass with OID " + oldOc.getOid()
        //                + " cannot be deleted until all entities"
        //                + " using this objectClass have also been deleted.  The following dependees exist: "
        //                + getOids( dependees ),
        //                ResultCodeEnum.UNWILLING_TO_PERFORM );
        //        }

        ServerEntry targetEntry = ( ServerEntry ) entry.clone();
        String newOid = ( String ) newRdn.getNormValue();
        targetEntry.put( MetaSchemaConstants.M_OID_AT, newOid );

        // Inject the new DN
        DN newDn = new DN( targetEntry.getDn() );
        newDn.remove( newDn.size() - 1 );
        newDn.add( newRdn );

        checkOidIsUnique( newOid );
        ObjectClass oc = factory.getObjectClass( schemaManager, targetEntry, schemaManager.getRegistries(), schemaName );

        if ( isSchemaEnabled( schemaName ) )
        {
            // Check that the entry has no descendant
            if ( schemaManager.getObjectClassRegistry().hasDescendants( oldOc.getOid() ) )
View Full Code Here

TOP

Related Classes of org.apache.directory.shared.ldap.schema.ObjectClass

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.