Class ModifyDNRequest

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

    @Mutable
    @ThreadSafety(level=NOT_THREADSAFE)
    public final class ModifyDNRequest
    extends UpdatableLDAPRequest
    implements ReadOnlyModifyDNRequest, ProtocolOp
    This class implements the processing necessary to perform an LDAPv3 modify DN operation, which can be used to rename and/or move an entry or subtree in the directory. A modify DN request contains the DN of the target entry, the new RDN to use for that entry, and a flag which indicates whether to remove the current RDN attribute value(s) from the entry. It may optionally contain a new superior DN, which will cause the entry to be moved below that new parent entry.

    Note that some directory servers may not support all possible uses of the modify DN operation. In particular, some servers may not support the use of a new superior DN, especially if it may cause the entry to be moved to a different database or another server. Also, some servers may not support renaming or moving non-leaf entries (i.e., entries that have one or more subordinates).

    ModifyDNRequest objects are mutable and therefore can be altered and re-used for multiple requests. Note, however, that ModifyDNRequest objects are not threadsafe and therefore a single ModifyDNRequest object instance should not be used to process multiple requests at the same time.

    Example

    The following example demonstrates the process for performing a modify DN operation. In this case, it will rename "ou=People,dc=example,dc=com" to "ou=Users,dc=example,dc=com". It will not move the entry below a new parent.
     ModifyDNRequest modifyDNRequest =
          new ModifyDNRequest("ou=People,dc=example,dc=com", "ou=Users", true);
     LDAPResult modifyDNResult;
    
     try
     {
       modifyDNResult = connection.modifyDN(modifyDNRequest);
       // If we get here, the delete was successful.
     }
     catch (LDAPException le)
     {
       // The modify DN operation failed.
       modifyDNResult = le.toLDAPResult();
       ResultCode resultCode = le.getResultCode();
       String errorMessageFromServer = le.getDiagnosticMessage();
     }
     
    See Also:
    Serialized Form
    • Constructor Detail

      • ModifyDNRequest

        public ModifyDNRequest​(java.lang.String dn,
                               java.lang.String newRDN,
                               boolean deleteOldRDN)
        Creates a new modify DN request that will rename the entry but will not move it below a new entry.
        Parameters:
        dn - The current DN for the entry to rename. It must not be null.
        newRDN - The new RDN for the target entry. It must not be null.
        deleteOldRDN - Indicates whether to delete the current RDN value from the target entry.
      • ModifyDNRequest

        public ModifyDNRequest​(DN dn,
                               RDN newRDN,
                               boolean deleteOldRDN)
        Creates a new modify DN request that will rename the entry but will not move it below a new entry.
        Parameters:
        dn - The current DN for the entry to rename. It must not be null.
        newRDN - The new RDN for the target entry. It must not be null.
        deleteOldRDN - Indicates whether to delete the current RDN value from the target entry.
      • ModifyDNRequest

        public ModifyDNRequest​(java.lang.String dn,
                               java.lang.String newRDN,
                               boolean deleteOldRDN,
                               java.lang.String newSuperiorDN)
        Creates a new modify DN request that will rename the entry and will optionally move it below a new entry.
        Parameters:
        dn - The current DN for the entry to rename. It must not be null.
        newRDN - The new RDN for the target entry. It must not be null.
        deleteOldRDN - Indicates whether to delete the current RDN value from the target entry.
        newSuperiorDN - The new superior DN for the entry. It may be null if the entry is not to be moved below a new parent.
      • ModifyDNRequest

        public ModifyDNRequest​(DN dn,
                               RDN newRDN,
                               boolean deleteOldRDN,
                               DN newSuperiorDN)
        Creates a new modify DN request that will rename the entry and will optionally move it below a new entry.
        Parameters:
        dn - The current DN for the entry to rename. It must not be null.
        newRDN - The new RDN for the target entry. It must not be null.
        deleteOldRDN - Indicates whether to delete the current RDN value from the target entry.
        newSuperiorDN - The new superior DN for the entry. It may be null if the entry is not to be moved below a new parent.
      • ModifyDNRequest

        public ModifyDNRequest​(java.lang.String dn,
                               java.lang.String newRDN,
                               boolean deleteOldRDN,
                               Control[] controls)
        Creates a new modify DN request that will rename the entry but will not move it below a new entry.
        Parameters:
        dn - The current DN for the entry to rename. It must not be null.
        newRDN - The new RDN for the target entry. It must not be null.
        deleteOldRDN - Indicates whether to delete the current RDN value from the target entry.
        controls - The set of controls to include in the request.
      • ModifyDNRequest

        public ModifyDNRequest​(DN dn,
                               RDN newRDN,
                               boolean deleteOldRDN,
                               Control[] controls)
        Creates a new modify DN request that will rename the entry but will not move it below a new entry.
        Parameters:
        dn - The current DN for the entry to rename. It must not be null.
        newRDN - The new RDN for the target entry. It must not be null.
        deleteOldRDN - Indicates whether to delete the current RDN value from the target entry.
        controls - The set of controls to include in the request.
      • ModifyDNRequest

        public ModifyDNRequest​(java.lang.String dn,
                               java.lang.String newRDN,
                               boolean deleteOldRDN,
                               java.lang.String newSuperiorDN,
                               Control[] controls)
        Creates a new modify DN request that will rename the entry and will optionally move it below a new entry.
        Parameters:
        dn - The current DN for the entry to rename. It must not be null.
        newRDN - The new RDN for the target entry. It must not be null.
        deleteOldRDN - Indicates whether to delete the current RDN value from the target entry.
        newSuperiorDN - The new superior DN for the entry. It may be null if the entry is not to be moved below a new parent.
        controls - The set of controls to include in the request.
      • ModifyDNRequest

        public ModifyDNRequest​(DN dn,
                               RDN newRDN,
                               boolean deleteOldRDN,
                               DN newSuperiorDN,
                               Control[] controls)
        Creates a new modify DN request that will rename the entry and will optionally move it below a new entry.
        Parameters:
        dn - The current DN for the entry to rename. It must not be null.
        newRDN - The new RDN for the target entry. It must not be null.
        deleteOldRDN - Indicates whether to delete the current RDN value from the target entry.
        newSuperiorDN - The new superior DN for the entry. It may be null if the entry is not to be moved below a new parent.
        controls - The set of controls to include in the request.
    • Method Detail

      • getDN

        public java.lang.String getDN()
        Retrieves the current DN of the entry to move/rename.
        Specified by:
        getDN in interface ReadOnlyModifyDNRequest
        Returns:
        The current DN of the entry to move/rename.
      • setDN

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

        public void setDN​(DN dn)
        Specifies the current DN of the entry to move/rename.
        Parameters:
        dn - The current DN of the entry to move/rename. It must not be null.
      • setNewRDN

        public void setNewRDN​(java.lang.String newRDN)
        Specifies the new RDN for the entry.
        Parameters:
        newRDN - The new RDN for the entry. It must not be null.
      • setNewRDN

        public void setNewRDN​(RDN newRDN)
        Specifies the new RDN for the entry.
        Parameters:
        newRDN - The new RDN for the entry. It must not be null.
      • deleteOldRDN

        public boolean deleteOldRDN()
        Indicates whether the current RDN value should be removed from the entry.
        Specified by:
        deleteOldRDN in interface ReadOnlyModifyDNRequest
        Returns:
        true if the current RDN value should be removed from the entry, or false if not.
      • setDeleteOldRDN

        public void setDeleteOldRDN​(boolean deleteOldRDN)
        Specifies whether the current RDN value should be removed from the entry.
        Parameters:
        deleteOldRDN - Specifies whether the current RDN value should be removed from the entry.
      • getNewSuperiorDN

        public java.lang.String getNewSuperiorDN()
        Retrieves the new superior DN for the entry.
        Specified by:
        getNewSuperiorDN in interface ReadOnlyModifyDNRequest
        Returns:
        The new superior DN for the entry, or null if the entry is not to be moved below a new parent.
      • setNewSuperiorDN

        public void setNewSuperiorDN​(java.lang.String newSuperiorDN)
        Specifies the new superior DN for the entry.
        Parameters:
        newSuperiorDN - The new superior DN for the entry. It may be null if the entry is not to be removed below a new parent.
      • setNewSuperiorDN

        public void setNewSuperiorDN​(DN newSuperiorDN)
        Specifies the new superior DN for the entry.
        Parameters:
        newSuperiorDN - The new superior DN for the entry. It may be null if the entry is not to be removed below a new parent.
      • 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 DN 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 DN 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 ModifyDNRequest 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 ReadOnlyModifyDNRequest
        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 DN change record.
        Specified by:
        toLDIF in interface ReadOnlyModifyDNRequest
        Returns:
        A string array whose lines contain an LDIF representation of the corresponding modify DN change record.
      • toLDIFString

        public java.lang.String toLDIFString()
        Retrieves an LDIF string representation of this modify DN request.
        Specified by:
        toLDIFString in interface ReadOnlyModifyDNRequest
        Returns:
        An LDIF string representation of this modify DN 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).