Package com.unboundid.ldap.sdk
Class ModifyDNRequest
- java.lang.Object
-
- com.unboundid.ldap.sdk.LDAPRequest
-
- com.unboundid.ldap.sdk.UpdatableLDAPRequest
-
- com.unboundid.ldap.sdk.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, thatModifyDNRequest
objects are not threadsafe and therefore a singleModifyDNRequest
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 Summary
Constructors Constructor Description 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.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.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.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.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.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.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.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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
deleteOldRDN()
Indicates whether the current RDN value should be removed from the entry.ModifyDNRequest
duplicate()
Creates a new instance of this LDAP request that may be modified without impacting this request.ModifyDNRequest
duplicate(Control[] controls)
Creates a new instance of this LDAP request that may be modified without impacting this request.ASN1Element
encodeProtocolOp()
Encodes the modify DN request protocol op to an ASN.1 element.java.lang.String
getDN()
Retrieves the current DN of the entry to move/rename.int
getLastMessageID()
Retrieves the message ID for the last LDAP message sent using this request.java.lang.String
getNewRDN()
Retrieves the new RDN for the entry.java.lang.String
getNewSuperiorDN()
Retrieves the new superior DN for the entry.OperationType
getOperationType()
Retrieves the type of operation that is represented by this request.byte
getProtocolOpType()
Retrieves the BER type for this protocol op.protected LDAPResult
process(LDAPConnection connection, int depth)
Sends this modify DN request to the directory server over the provided connection and returns the associated response.void
responseReceived(LDAPResponse response)
void
setDeleteOldRDN(boolean deleteOldRDN)
Specifies whether the current RDN value should be removed from the entry.void
setDN(DN dn)
Specifies the current DN of the entry to move/rename.void
setDN(java.lang.String dn)
Specifies the current DN of the entry to move/rename.void
setNewRDN(RDN newRDN)
Specifies the new RDN for the entry.void
setNewRDN(java.lang.String newRDN)
Specifies the new RDN for the entry.void
setNewSuperiorDN(DN newSuperiorDN)
Specifies the new superior DN for the entry.void
setNewSuperiorDN(java.lang.String newSuperiorDN)
Specifies the new superior DN for the entry.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.java.lang.String[]
toLDIF()
Retrieves a string array whose lines contain an LDIF representation of the corresponding modify DN change record.LDIFModifyDNChangeRecord
toLDIFChangeRecord()
Retrieves an LDIF modify DN change record with the contents of this modify DN request.java.lang.String
toLDIFString()
Retrieves an LDIF string representation of this modify DN request.void
toString(java.lang.StringBuilder buffer)
Appends a string representation of this request to the provided buffer.void
writeTo(ASN1Buffer writer)
Writes an ASN.1-encoded representation of this LDAP protocol op to the provided ASN.1 buffer.-
Methods inherited from class com.unboundid.ldap.sdk.UpdatableLDAPRequest
addControl, addControls, clearControls, removeControl, removeControl, replaceControl, replaceControl, setControls, setControls
-
Methods inherited from class com.unboundid.ldap.sdk.LDAPRequest
followReferrals, getControl, getControlList, getControls, getIntermediateResponseListener, getReferralConnector, getResponseTimeoutMillis, hasControl, hasControl, setFollowReferrals, setIntermediateResponseListener, setReferralConnector, setResponseTimeoutMillis, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.unboundid.ldap.sdk.ReadOnlyLDAPRequest
followReferrals, getControl, getControlList, getReferralConnector, getResponseTimeoutMillis, hasControl, hasControl, toString
-
-
-
-
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 benull
.newRDN
- The new RDN for the target entry. It must not benull
.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 benull
.newRDN
- The new RDN for the target entry. It must not benull
.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 benull
.newRDN
- The new RDN for the target entry. It must not benull
.deleteOldRDN
- Indicates whether to delete the current RDN value from the target entry.newSuperiorDN
- The new superior DN for the entry. It may benull
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 benull
.newRDN
- The new RDN for the target entry. It must not benull
.deleteOldRDN
- Indicates whether to delete the current RDN value from the target entry.newSuperiorDN
- The new superior DN for the entry. It may benull
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 benull
.newRDN
- The new RDN for the target entry. It must not benull
.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 benull
.newRDN
- The new RDN for the target entry. It must not benull
.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 benull
.newRDN
- The new RDN for the target entry. It must not benull
.deleteOldRDN
- Indicates whether to delete the current RDN value from the target entry.newSuperiorDN
- The new superior DN for the entry. It may benull
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 benull
.newRDN
- The new RDN for the target entry. It must not benull
.deleteOldRDN
- Indicates whether to delete the current RDN value from the target entry.newSuperiorDN
- The new superior DN for the entry. It may benull
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 interfaceReadOnlyModifyDNRequest
- 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 benull
.
-
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 benull
.
-
getNewRDN
public java.lang.String getNewRDN()
Retrieves the new RDN for the entry.- Specified by:
getNewRDN
in interfaceReadOnlyModifyDNRequest
- Returns:
- The new RDN for the entry.
-
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 benull
.
-
setNewRDN
public void setNewRDN(RDN newRDN)
Specifies the new RDN for the entry.- Parameters:
newRDN
- The new RDN for the entry. It must not benull
.
-
deleteOldRDN
public boolean deleteOldRDN()
Indicates whether the current RDN value should be removed from the entry.- Specified by:
deleteOldRDN
in interfaceReadOnlyModifyDNRequest
- Returns:
true
if the current RDN value should be removed from the entry, orfalse
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 interfaceReadOnlyModifyDNRequest
- 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 benull
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 benull
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 interfaceProtocolOp
- Returns:
- The BER type for this protocol op.
-
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 interfaceProtocolOp
- Parameters:
writer
- The ASN.1 buffer to which the encoded representation should be written.
-
encodeProtocolOp
public ASN1Element encodeProtocolOp()
Encodes the modify DN request protocol op to an ASN.1 element.- Specified by:
encodeProtocolOp
in interfaceProtocolOp
- Returns:
- The ASN.1 element with the encoded modify DN request protocol op.
-
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 classLDAPRequest
- 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
@InternalUseOnly public void responseReceived(LDAPResponse response) throws LDAPException
- Throws:
LDAPException
-
getLastMessageID
public int getLastMessageID()
Retrieves the message ID for the last LDAP message sent using this request.- Specified by:
getLastMessageID
in classLDAPRequest
- 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
public OperationType getOperationType()
Retrieves the type of operation that is represented by this request.- Specified by:
getOperationType
in classLDAPRequest
- Returns:
- The type of operation that is represented by this request.
-
duplicate
public ModifyDNRequest duplicate()
Creates a new instance of this LDAP request that may be modified without impacting this request.- Specified by:
duplicate
in interfaceReadOnlyLDAPRequest
- Specified by:
duplicate
in interfaceReadOnlyModifyDNRequest
- Returns:
- A new instance of this LDAP request that may be modified without impacting 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 interfaceReadOnlyLDAPRequest
- Specified by:
duplicate
in interfaceReadOnlyModifyDNRequest
- 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
public LDIFModifyDNChangeRecord toLDIFChangeRecord()
Retrieves an LDIF modify DN change record with the contents of this modify DN request.- Specified by:
toLDIFChangeRecord
in interfaceReadOnlyModifyDNRequest
- Returns:
- An LDIF modify DN change record with the contents of this modify DN 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 interfaceReadOnlyModifyDNRequest
- 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 interfaceReadOnlyModifyDNRequest
- 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 interfaceProtocolOp
- Specified by:
toString
in interfaceReadOnlyLDAPRequest
- Specified by:
toString
in classLDAPRequest
- 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 interfaceReadOnlyLDAPRequest
- 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 isnull
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 (iftrue
), or just to generate the request (iffalse
).
-
-