if ( mod.equals( previous ) )
{
continue;
}
Modification reverseModification = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE,
mod );
reverseModifications.add( 0, reverseModification );
break;
case REMOVE_ATTRIBUTE:
mod = modification.getAttribute();
previous = clonedEntry.get( mod.getId() );
if ( previous == null )
{
// Nothing to do if the previous attribute didn't exist
continue;
}
if ( mod.get() == null )
{
reverseModification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, previous );
reverseModifications.add( 0, reverseModification );
break;
}
reverseModification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, mod );
reverseModifications.add( 0, reverseModification );
break;
case REPLACE_ATTRIBUTE:
mod = modification.getAttribute();
previous = clonedEntry.get( mod.getId() );
/*
* The server accepts without complaint replace
* modifications to non-existing attributes in the
* entry. When this occurs nothing really happens
* but this method freaks out. To prevent that we
* make such no-op modifications produce the same
* modification for the reverse direction which should
* do nothing as well.
*/
if ( ( mod.get() == null ) && ( previous == null ) )
{
reverseModification = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE,
new DefaultAttribute( mod.getId() ) );
reverseModifications.add( 0, reverseModification );
continue;
}
if ( mod.get() == null )
{
reverseModification = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE,
previous );
reverseModifications.add( 0, reverseModification );
continue;
}
if ( previous == null )
{
Attribute emptyAttribute = new DefaultAttribute( mod.getId() );
reverseModification = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE,
emptyAttribute );
reverseModifications.add( 0, reverseModification );
continue;
}
reverseModification = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, previous );
reverseModifications.add( 0, reverseModification );
break;
default:
break; // Do nothing