case REMOVE_ATTRIBUTE:
if ( tmpEntry.get( change.getId() ) == null )
{
LOG.error( "Trying to remove an non-existant attribute: " + change.getUpId() );
throw new LdapNoSuchAttributeException();
}
// We may have to remove the attribute or only some values
if ( change.size() == 0 )
{
// No value : we have to remove the entire attribute
// Check that we aren't removing a MUST attribute
if ( isRequired( change.getUpId(), objectClass ) )
{
LOG.error( "Trying to remove a required attribute: " + change.getUpId() );
throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION );
}
attr = tmpEntry.get( change.getUpId() );
if ( attr != null )
{
tmpEntry.removeAttributes( change.getUpId() );
}
}
else
{
// for required attributes we need to check if all values are removed
// if so then we have a schema violation that must be thrown
if ( isRequired( change.getUpId(), objectClass ) && isCompleteRemoval( change, entry ) )
{
LOG.error( "Trying to remove a required attribute: " + change.getUpId() );
throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION );
}
// Now remove the attribute and all its values
EntryAttribute modified = tmpEntry.removeAttributes( change.getId() ).get( 0 );
// And inject back the values except the ones to remove
for ( Value<?> value : change )
{
if ( modified.contains( value ) )
{
modified.remove( value );
}
else if ( !subSchemaModification )
{
// We are trying to remove an not existing value : error
throw new LdapNoSuchAttributeException( "Value " + value + " does not exist in the " + modified + " AT" );
}
}
// ok, done. Last check : if the attribute does not content any more value;
// and if it's a MUST one, we should thow an exception