Class ModifyDNRequest

All Implemented Interfaces:
ProtocolOp, ReadOnlyLDAPRequest, ReadOnlyModifyDNRequest, Serializable

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:
  • Constructor Details

    • ModifyDNRequest

      public ModifyDNRequest(@NotNull String dn, @NotNull 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(@NotNull DN dn, @NotNull 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(@NotNull String dn, @NotNull String newRDN, boolean deleteOldRDN, @Nullable 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(@NotNull DN dn, @NotNull RDN newRDN, boolean deleteOldRDN, @Nullable 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(@NotNull String dn, @NotNull String newRDN, boolean deleteOldRDN, @Nullable 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(@NotNull DN dn, @NotNull RDN newRDN, boolean deleteOldRDN, @Nullable 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(@NotNull String dn, @NotNull String newRDN, boolean deleteOldRDN, @Nullable String newSuperiorDN, @Nullable 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(@NotNull DN dn, @NotNull RDN newRDN, boolean deleteOldRDN, @Nullable DN newSuperiorDN, @Nullable 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 Details

    • getDN

      @NotNull public 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(@NotNull 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(@NotNull 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.
    • getNewRDN

      Retrieves the new RDN for the entry.
      Specified by:
      getNewRDN in interface ReadOnlyModifyDNRequest
      Returns:
      The new RDN for the entry.
    • setNewRDN

      public void setNewRDN(@NotNull 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(@NotNull 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

      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(@Nullable 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(@Nullable 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.
    • getProtocolOpType

      public byte getProtocolOpType()
      Retrieves the BER type for this protocol op.
      Specified by:
      getProtocolOpType in interface ProtocolOp
      Returns:
      The BER type for this protocol op.
    • writeTo

      public void writeTo(@NotNull 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.
    • encodeProtocolOp

      Encodes the modify DN request protocol op to an ASN.1 element.
      Specified by:
      encodeProtocolOp in interface ProtocolOp
      Returns:
      The ASN.1 element with the encoded modify DN request protocol op.
    • process

      @NotNull protected LDAPResult process(@NotNull 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.
    • responseReceived

      Throws:
      LDAPException
    • 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.
    • getOperationType

      Retrieves the type of operation that is represented by this request.
      Specified by:
      getOperationType in class LDAPRequest
      Returns:
      The type of operation that is represented by this request.
    • duplicate

      Creates a new instance of this LDAP request that may be modified without impacting this request.
      Specified by:
      duplicate in interface ReadOnlyLDAPRequest
      Specified by:
      duplicate in interface ReadOnlyModifyDNRequest
      Returns:
      A new instance of this LDAP request that may be modified without impacting this request.
    • duplicate

      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.
    • toLDIFChangeRecord

      Retrieves an LDIF modify DN change record with the contents of this modify DN request.
      Specified by:
      toLDIFChangeRecord in interface ReadOnlyModifyDNRequest
      Returns:
      An LDIF modify DN change record with the contents of this modify DN request.
    • toLDIF

      @NotNull public 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

      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(@NotNull 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(@NotNull List<String> lineList, @NotNull 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).