protected ModificationItem getCompensatingModificationItem ( Attributes originalAttributes , ModificationItem modificationItem ) { Attribute modificationAttribute = modificationItem . getAttribute ( ) ; Attribute originalAttribute = originalAttributes . get ( modificationAttribute . getID ( ) ) ; if ( modificationItem . getModificationOp ( ) == DirContext . REMOVE_ATTRIBUTE ) { if ( modificationAttribute . size ( ) == 0 ) { // If the modification attribute size it means that the // Attribute should be removed entirely - we should store a // ModificationItem to restore all present values for rollback. return new ModificationItem ( DirContext . ADD_ATTRIBUTE , ( Attribute ) originalAttribute . clone ( ) ) ; } else { // The rollback modification will be to re-add the removed // attribute values. return new ModificationItem ( DirContext . ADD_ATTRIBUTE , ( Attribute ) modificationAttribute . clone ( ) ) ; } } else if ( modificationItem . getModificationOp ( ) == DirContext . REPLACE_ATTRIBUTE ) { if ( originalAttribute != null ) { return new ModificationItem ( DirContext . REPLACE_ATTRIBUTE , ( Attribute ) originalAttribute . clone ( ) ) ; } else { // The attribute doesn't previously exist - the rollback // operation will be to remove the attribute. return new ModificationItem ( DirContext . REMOVE_ATTRIBUTE , new BasicAttribute ( modificationAttribute . getID ( ) ) ) ; } } else { // An ADD_ATTRIBUTE operation if ( originalAttribute == null ) { // The attribute doesn't previously exist - the rollback // operation will be to remove the attribute. return new ModificationItem ( DirContext . REMOVE_ATTRIBUTE , new BasicAttribute ( modificationAttribute . getID ( ) ) ) ; } else { // The attribute does exist before - we should store the // previous value and it should be used for replacing in // rollback. return new ModificationItem ( DirContext . REPLACE_ATTRIBUTE , ( Attribute ) originalAttribute . clone ( ) ) ; } } }
Get a ModificationItem to use for rollback of the supplied modification .