Class ModifyEntry

  • All Implemented Interfaces:
    java.lang.Comparable<GenericEntry>, java.lang.Iterable<Attribute>

    public class ModifyEntry
    extends ChangeEntry
    A ModifyEntry is used to store a list of modifications to the attributes within an Entry. It can be generated by comparing two Entry instances, or by being loaded from a 'Modify' LDIF change-record, or by building up the attribute changes one by one. It may be applied to a directory in an add or modify operation, or applied to another Entry in memory to generate an new Entry (with Entry.apply()), or saved as a Modify change-record to an LDIF file.
    • Constructor Detail

      • ModifyEntry

        public ModifyEntry​(DN dn)
        Create a new empty ModifyEntry using a specified DN
        Parameters:
        dn - the distinguished name (must not be null)
        Throws:
        java.lang.NullPointerException - if dn is null
        NativeLibraryException - if an unrecoverable error was detected by the native library
      • ModifyEntry

        public ModifyEntry​(Entry entry1,
                           Entry entry2)
        Create a new ModifyEntry by comparing two Entry instances. The changes are generated to convert from the first Entry to the second -- so that means that applying the resulting ModifyEntry to the first Entry would give a new Entry with identical contents to the second. If either of the Entry references is null, then it is treated as an empty Entry. The DN is copied from the first of the Entry instances which isn't null.

        Note that the comparisons done to establish whether there is a difference are NOT standard attribute-value comparisons. This is because a change from "fred" to "Fred" is significant to humans and so should be passed through, even though the values normally compare equal. So the default is a case-sensitive strict comparison of the attribute value. However, this is not appropriate in all cases. Objectclass comparisons are made case-insensitive because changes in case make no difference to the underlying OID and are therefore not significant. DN is more complicated because case-differences in RDN types are not significant, but case-differences to values are significant. Currently case-differences in RDN types are considered significant even though strictly they shouldn't be. This can be resolved by normalizing the DN attributes before passing the entry to this routine.

        Note that any Attributes inside entry1 or entry2 which contain no values are treated as if they were not present at all.

        Parameters:
        entry1 - The source Entry, or null to use an empty entry as source
        entry2 - The target Entry, or null to use an empty entry as target
        Throws:
        java.lang.NullPointerException - if both arguments are null
        NativeLibraryException - if an unrecoverable error was detected by the native library
    • Method Detail

      • getChangeIterator

        public java.util.Iterator<Attribute> getChangeIterator()
        Returns an Iterator over the change-attributes associated with this ModifyEntry. The Iterator will contain AddAttribute, DeleteAttribute and ReplaceAttribute instances.
        Overrides:
        getChangeIterator in class GenericEntry
        Returns:
        Iterator or null
      • hasChanges

        public boolean hasChanges()
        Determine whether this entry contains any change-attributes (as would be returned by a call to getChangeIterator()).
        Overrides:
        hasChanges in class GenericEntry
        Returns:
        true if this entry has modifications associated with it, false otherwise.
      • deleteAttribute

        public void deleteAttribute​(Attribute attr)
                             throws NativeLibraryException
        Specify an attribute or attribute-values to be deleted from the target entry when the ModifyEntry is applied. If the Attribute contains values, then those specific values will be deleted. If the Attribute is empty, then all values for the specified attribute-type will be deleted. A copy is made of the Attribute argument as a DeleteAttribute.
        Overrides:
        deleteAttribute in class ChangeEntry
        Parameters:
        attr - Attribute containing values to be deleted, or empty to delete all. Must not be null.
        Throws:
        java.lang.NullPointerException - if attr is null.
        NativeLibraryException - if an unrecoverable error was detected by the native library
        See Also:
        DirectorySession.modify(ModifyEntry, CommonArgs)
      • replaceAttribute

        public void replaceAttribute​(Attribute attr)
                              throws NativeLibraryException
        Specify an attribute that should be replaced in the target entry when the ModifyEntry is applied. All the attribute-values of this attribute-type that are present in the target Entry are deleted before the new values are added. A copy is made of the argument Attribute as a ReplaceAttribute.
        Overrides:
        replaceAttribute in class ChangeEntry
        Parameters:
        attr - Attribute containing values to be replaced. Must not be null.
        Throws:
        java.lang.NullPointerException - if attr is null.
        NativeLibraryException - if an unrecoverable error was detected by the native library
        See Also:
        DirectorySession.modify(ModifyEntry, CommonArgs)
      • toString

        public java.lang.String toString()
        Returns a String representation of this ModifyEntry. The String contains the Entry's DN and number of changes.
        Overrides:
        toString in class ChangeEntry
        Returns:
        a String representation of the Entry.