Class ModifyRequest

  • All Implemented Interfaces:
    ProtocolOp, ReadOnlyLDAPRequest, ReadOnlyModifyRequest, java.io.Serializable

    @Mutable
    @ThreadSafety(level=NOT_THREADSAFE)
    public final class ModifyRequest
    extends UpdatableLDAPRequest
    implements ReadOnlyModifyRequest, ProtocolOp
    This class implements the processing necessary to perform an LDAPv3 modify operation, which can be used to update an entry in the directory server. A modify request contains the DN of the entry to modify, as well as one or more changes to apply to that entry. See the Modification class for more information about the types of modifications that may be processed.

    A modify request can be created with a DN and set of modifications, but it can also be as a list of the lines that comprise the LDIF representation of the modification as described in RFC 2849. For example, the following code demonstrates creating a modify request from the LDIF representation of the modification:
       ModifyRequest modifyRequest = new ModifyRequest(
         "dn: dc=example,dc=com",
         "changetype: modify",
         "replace: description",
         "description: This is the new description.");
     


    ModifyRequest objects are mutable and therefore can be altered and re-used for multiple requests. Note, however, that ModifyRequest objects are not threadsafe and therefore a single ModifyRequest object instance should not be used to process multiple requests at the same time.
    See Also:
    Serialized Form
    • Constructor Detail

      • ModifyRequest

        public ModifyRequest​(java.lang.String dn,
                             Modification mod)
        Creates a new modify request with the provided information.
        Parameters:
        dn - The DN of the entry to modify. It must not be null.
        mod - The modification to apply to the entry. It must not be null.
      • ModifyRequest

        public ModifyRequest​(java.lang.String dn,
                             Modification... mods)
        Creates a new modify request with the provided information.
        Parameters:
        dn - The DN of the entry to modify. It must not be null.
        mods - The set of modifications to apply to the entry. It must not be null or empty.
      • ModifyRequest

        public ModifyRequest​(java.lang.String dn,
                             java.util.List<Modification> mods)
        Creates a new modify request with the provided information.
        Parameters:
        dn - The DN of the entry to modify. It must not be null.
        mods - The set of modifications to apply to the entry. It must not be null or empty.
      • ModifyRequest

        public ModifyRequest​(DN dn,
                             Modification mod)
        Creates a new modify request with the provided information.
        Parameters:
        dn - The DN of the entry to modify. It must not be null.
        mod - The modification to apply to the entry. It must not be null.
      • ModifyRequest

        public ModifyRequest​(DN dn,
                             Modification... mods)
        Creates a new modify request with the provided information.
        Parameters:
        dn - The DN of the entry to modify. It must not be null.
        mods - The set of modifications to apply to the entry. It must not be null or empty.
      • ModifyRequest

        public ModifyRequest​(DN dn,
                             java.util.List<Modification> mods)
        Creates a new modify request with the provided information.
        Parameters:
        dn - The DN of the entry to modify. It must not be null.
        mods - The set of modifications to apply to the entry. It must not be null or empty.
      • ModifyRequest

        public ModifyRequest​(java.lang.String dn,
                             Modification mod,
                             Control[] controls)
        Creates a new modify request with the provided information.
        Parameters:
        dn - The DN of the entry to modify. It must not be null.
        mod - The modification to apply to the entry. It must not be null.
        controls - The set of controls to include in the request.
      • ModifyRequest

        public ModifyRequest​(java.lang.String dn,
                             Modification[] mods,
                             Control[] controls)
        Creates a new modify request with the provided information.
        Parameters:
        dn - The DN of the entry to modify. It must not be null.
        mods - The set of modifications to apply to the entry. It must not be null or empty.
        controls - The set of controls to include in the request.
      • ModifyRequest

        public ModifyRequest​(java.lang.String dn,
                             java.util.List<Modification> mods,
                             Control[] controls)
        Creates a new modify request with the provided information.
        Parameters:
        dn - The DN of the entry to modify. It must not be null.
        mods - The set of modifications to apply to the entry. It must not be null or empty.
        controls - The set of controls to include in the request.
      • ModifyRequest

        public ModifyRequest​(DN dn,
                             Modification mod,
                             Control[] controls)
        Creates a new modify request with the provided information.
        Parameters:
        dn - The DN of the entry to modify. It must not be null.
        mod - The modification to apply to the entry. It must not be null.
        controls - The set of controls to include in the request.
      • ModifyRequest

        public ModifyRequest​(DN dn,
                             Modification[] mods,
                             Control[] controls)
        Creates a new modify request with the provided information.
        Parameters:
        dn - The DN of the entry to modify. It must not be null.
        mods - The set of modifications to apply to the entry. It must not be null or empty.
        controls - The set of controls to include in the request.
      • ModifyRequest

        public ModifyRequest​(DN dn,
                             java.util.List<Modification> mods,
                             Control[] controls)
        Creates a new modify request with the provided information.
        Parameters:
        dn - The DN of the entry to modify. It must not be null.
        mods - The set of modifications to apply to the entry. It must not be null or empty.
        controls - The set of controls to include in the request.
      • ModifyRequest

        public ModifyRequest​(java.lang.String... ldifModificationLines)
                      throws LDIFException
        Creates a new modify request from the provided LDIF representation of the changes.
        Parameters:
        ldifModificationLines - The lines that comprise an LDIF representation of a modify change record. It must not be null or empty.
        Throws:
        LDIFException - If the provided set of lines cannot be parsed as an LDIF modify change record.
    • Method Detail

      • getDN

        public java.lang.String getDN()
        Retrieves the DN of the entry to modify.
        Specified by:
        getDN in interface ReadOnlyModifyRequest
        Returns:
        The DN of the entry to modify.
      • setDN

        public void setDN​(java.lang.String dn)
        Specifies the DN of the entry to modify.
        Parameters:
        dn - The DN of the entry to modify. It must not be null.
      • setDN

        public void setDN​(DN dn)
        Specifies the DN of the entry to modify.
        Parameters:
        dn - The DN of the entry to modify. It must not be null.
      • addModification

        public void addModification​(Modification mod)
        Adds the provided modification to the set of modifications for this modify request.
        Parameters:
        mod - The modification to be added. It must not be null.
      • removeModification

        public boolean removeModification​(Modification mod)
        Removes the provided modification from the set of modifications for this modify request.
        Parameters:
        mod - The modification to be removed. It must not be null.
        Returns:
        true if the specified modification was found and removed, or false if not.
      • setModifications

        public void setModifications​(Modification mod)
        Replaces the existing set of modifications for this modify request with the provided modification.
        Parameters:
        mod - The modification to use for this modify request. It must not be null.
      • setModifications

        public void setModifications​(Modification[] mods)
        Replaces the existing set of modifications for this modify request with the provided modifications.
        Parameters:
        mods - The set of modification to use for this modify request. It must not be null or empty.
      • setModifications

        public void setModifications​(java.util.List<Modification> mods)
        Replaces the existing set of modifications for this modify request with the provided modifications.
        Parameters:
        mods - The set of modification to use for this modify request. It must not be null or empty.
      • writeTo

        public void writeTo​(ASN1Buffer writer)
        Writes an ASN.1-encoded representation of this LDAP protocol op to the provided ASN.1 buffer. This method is intended for internal use only and should not be used by third-party code.
        Specified by:
        writeTo in interface ProtocolOp
        Parameters:
        writer - The ASN.1 buffer to which the encoded representation should be written.
      • process

        protected LDAPResult process​(LDAPConnection connection,
                                     int depth)
                              throws LDAPException
        Sends this modify request to the directory server over the provided connection and returns the associated response.
        Specified by:
        process in class LDAPRequest
        Parameters:
        connection - The connection to use to communicate with the directory server.
        depth - The current referral depth for this request. It should always be one for the initial request, and should only be incremented when following referrals.
        Returns:
        An LDAP result object that provides information about the result of the modify processing.
        Throws:
        LDAPException - If a problem occurs while sending the request or reading the response.
      • getLastMessageID

        public int getLastMessageID()
        Retrieves the message ID for the last LDAP message sent using this request.
        Specified by:
        getLastMessageID in class LDAPRequest
        Returns:
        The message ID for the last LDAP message sent using this request, or -1 if it no LDAP messages have yet been sent using this request.
      • duplicate

        public ModifyRequest duplicate​(Control[] controls)
        Creates a new instance of this LDAP request that may be modified without impacting this request. The provided controls will be used for the new request instead of duplicating the controls from this request.
        Specified by:
        duplicate in interface ReadOnlyLDAPRequest
        Specified by:
        duplicate in interface ReadOnlyModifyRequest
        Parameters:
        controls - The set of controls to include in the duplicate request.
        Returns:
        A new instance of this LDAP request that may be modified without impacting this request.
      • toLDIF

        public java.lang.String[] toLDIF()
        Retrieves a string array whose lines contain an LDIF representation of the corresponding modify change record.
        Specified by:
        toLDIF in interface ReadOnlyModifyRequest
        Returns:
        A string array whose lines contain an LDIF representation of the corresponding modify change record.
      • toLDIFString

        public java.lang.String toLDIFString()
        Retrieves an LDIF string representation of this modify request.
        Specified by:
        toLDIFString in interface ReadOnlyModifyRequest
        Returns:
        An LDIF string representation of this modify request.
      • toString

        public void toString​(java.lang.StringBuilder buffer)
        Appends a string representation of this request to the provided buffer.
        Specified by:
        toString in interface ProtocolOp
        Specified by:
        toString in interface ReadOnlyLDAPRequest
        Specified by:
        toString in class LDAPRequest
        Parameters:
        buffer - The buffer to which to append a string representation of this request.
      • toCode

        public void toCode​(java.util.List<java.lang.String> lineList,
                           java.lang.String requestID,
                           int indentSpaces,
                           boolean includeProcessing)
        Appends a number of lines comprising the Java source code that can be used to recreate this request to the given list.
        Specified by:
        toCode in interface ReadOnlyLDAPRequest
        Parameters:
        lineList - The list to which the source code lines should be added.
        requestID - The name that should be used as an identifier for the request. If this is null or empty, then a generic ID will be used.
        indentSpaces - The number of spaces that should be used to indent the generated code. It must not be negative.
        includeProcessing - Indicates whether the generated code should include code required to actually process the request and handle the result (if true), or just to generate the request (if false).