Package com.unboundid.ldap.sdk
Class ModifyRequest
- java.lang.Object
-
- com.unboundid.ldap.sdk.LDAPRequest
-
- com.unboundid.ldap.sdk.UpdatableLDAPRequest
-
- com.unboundid.ldap.sdk.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 theModificationclass 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.");
ModifyRequestobjects are mutable and therefore can be altered and re-used for multiple requests. Note, however, thatModifyRequestobjects are not threadsafe and therefore a singleModifyRequestobject instance should not be used to process multiple requests at the same time.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ModifyRequest(DN dn, Modification mod)Creates a new modify request with the provided information.ModifyRequest(DN dn, Modification... mods)Creates a new modify request with the provided information.ModifyRequest(DN dn, Modification[] mods, Control[] controls)Creates a new modify request with the provided information.ModifyRequest(DN dn, Modification mod, Control[] controls)Creates a new modify request with the provided information.ModifyRequest(DN dn, java.util.List<Modification> mods)Creates a new modify request with the provided information.ModifyRequest(DN dn, java.util.List<Modification> mods, Control[] controls)Creates a new modify request with the provided information.ModifyRequest(java.lang.String... ldifModificationLines)Creates a new modify request from the provided LDIF representation of the changes.ModifyRequest(java.lang.String dn, Modification mod)Creates a new modify request with the provided information.ModifyRequest(java.lang.String dn, Modification... mods)Creates a new modify request with the provided information.ModifyRequest(java.lang.String dn, Modification[] mods, Control[] controls)Creates a new modify request with the provided information.ModifyRequest(java.lang.String dn, Modification mod, Control[] controls)Creates a new modify request with the provided information.ModifyRequest(java.lang.String dn, java.util.List<Modification> mods)Creates a new modify request with the provided information.ModifyRequest(java.lang.String dn, java.util.List<Modification> mods, Control[] controls)Creates a new modify request with the provided information.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddModification(Modification mod)Adds the provided modification to the set of modifications for this modify request.ModifyRequestduplicate()Creates a new instance of this LDAP request that may be modified without impacting this request.ModifyRequestduplicate(Control[] controls)Creates a new instance of this LDAP request that may be modified without impacting this request.ASN1ElementencodeProtocolOp()Encodes the modify request protocol op to an ASN.1 element.java.lang.StringgetDN()Retrieves the DN of the entry to modify.intgetLastMessageID()Retrieves the message ID for the last LDAP message sent using this request.java.util.List<Modification>getModifications()Retrieves the set of modifications for this modify request.OperationTypegetOperationType()Retrieves the type of operation that is represented by this request.bytegetProtocolOpType()Retrieves the BER type for this protocol op.protected LDAPResultprocess(LDAPConnection connection, int depth)Sends this modify request to the directory server over the provided connection and returns the associated response.booleanremoveModification(Modification mod)Removes the provided modification from the set of modifications for this modify request.voidresponseReceived(LDAPResponse response)voidsetDN(DN dn)Specifies the DN of the entry to modify.voidsetDN(java.lang.String dn)Specifies the DN of the entry to modify.voidsetModifications(Modification mod)Replaces the existing set of modifications for this modify request with the provided modification.voidsetModifications(Modification[] mods)Replaces the existing set of modifications for this modify request with the provided modifications.voidsetModifications(java.util.List<Modification> mods)Replaces the existing set of modifications for this modify request with the provided modifications.voidtoCode(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 change record.LDIFModifyChangeRecordtoLDIFChangeRecord()Retrieves an LDIF modify change record with the contents of this modify request.java.lang.StringtoLDIFString()Retrieves an LDIF string representation of this modify request.voidtoString(java.lang.StringBuilder buffer)Appends a string representation of this request to the provided buffer.voidwriteTo(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, getReferralConnectorInternal, getReferralDepth, getResponseTimeoutMillis, hasControl, hasControl, setFollowReferrals, setIntermediateResponseListener, setReferralConnector, setReferralDepth, 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, getControls, getReferralConnector, getResponseTimeoutMillis, hasControl, hasControl, toString
-
-
-
-
Constructor Detail
-
ModifyRequest
public ModifyRequest(@NotNull java.lang.String dn, @NotNull Modification mod)
Creates a new modify request with the provided information.- Parameters:
dn- The DN of the entry to modify. It must not benull.mod- The modification to apply to the entry. It must not benull.
-
ModifyRequest
public ModifyRequest(@NotNull java.lang.String dn, @NotNull Modification... mods)
Creates a new modify request with the provided information.- Parameters:
dn- The DN of the entry to modify. It must not benull.mods- The set of modifications to apply to the entry. It must not benullor empty.
-
ModifyRequest
public ModifyRequest(@NotNull java.lang.String dn, @NotNull 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 benull.mods- The set of modifications to apply to the entry. It must not benullor empty.
-
ModifyRequest
public ModifyRequest(@NotNull DN dn, @NotNull Modification mod)
Creates a new modify request with the provided information.- Parameters:
dn- The DN of the entry to modify. It must not benull.mod- The modification to apply to the entry. It must not benull.
-
ModifyRequest
public ModifyRequest(@NotNull DN dn, @NotNull Modification... mods)
Creates a new modify request with the provided information.- Parameters:
dn- The DN of the entry to modify. It must not benull.mods- The set of modifications to apply to the entry. It must not benullor empty.
-
ModifyRequest
public ModifyRequest(@NotNull DN dn, @NotNull 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 benull.mods- The set of modifications to apply to the entry. It must not benullor empty.
-
ModifyRequest
public ModifyRequest(@NotNull java.lang.String dn, @NotNull Modification mod, @Nullable Control[] controls)
Creates a new modify request with the provided information.- Parameters:
dn- The DN of the entry to modify. It must not benull.mod- The modification to apply to the entry. It must not benull.controls- The set of controls to include in the request.
-
ModifyRequest
public ModifyRequest(@NotNull java.lang.String dn, @NotNull Modification[] mods, @Nullable Control[] controls)
Creates a new modify request with the provided information.- Parameters:
dn- The DN of the entry to modify. It must not benull.mods- The set of modifications to apply to the entry. It must not benullor empty.controls- The set of controls to include in the request.
-
ModifyRequest
public ModifyRequest(@NotNull java.lang.String dn, @NotNull java.util.List<Modification> mods, @Nullable Control[] controls)
Creates a new modify request with the provided information.- Parameters:
dn- The DN of the entry to modify. It must not benull.mods- The set of modifications to apply to the entry. It must not benullor empty.controls- The set of controls to include in the request.
-
ModifyRequest
public ModifyRequest(@NotNull DN dn, @NotNull Modification mod, @Nullable Control[] controls)
Creates a new modify request with the provided information.- Parameters:
dn- The DN of the entry to modify. It must not benull.mod- The modification to apply to the entry. It must not benull.controls- The set of controls to include in the request.
-
ModifyRequest
public ModifyRequest(@NotNull DN dn, @NotNull Modification[] mods, @Nullable Control[] controls)
Creates a new modify request with the provided information.- Parameters:
dn- The DN of the entry to modify. It must not benull.mods- The set of modifications to apply to the entry. It must not benullor empty.controls- The set of controls to include in the request.
-
ModifyRequest
public ModifyRequest(@NotNull DN dn, @NotNull java.util.List<Modification> mods, @Nullable Control[] controls)
Creates a new modify request with the provided information.- Parameters:
dn- The DN of the entry to modify. It must not benull.mods- The set of modifications to apply to the entry. It must not benullor empty.controls- The set of controls to include in the request.
-
ModifyRequest
public ModifyRequest(@NotNull 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 benullor empty.- Throws:
LDIFException- If the provided set of lines cannot be parsed as an LDIF modify change record.
-
-
Method Detail
-
getDN
@NotNull public java.lang.String getDN()
Retrieves the DN of the entry to modify.- Specified by:
getDNin interfaceReadOnlyModifyRequest- Returns:
- The DN of the entry to modify.
-
setDN
public void setDN(@NotNull java.lang.String dn)
Specifies the DN of the entry to modify.- Parameters:
dn- The DN of the entry to modify. It must not benull.
-
setDN
public void setDN(@NotNull DN dn)
Specifies the DN of the entry to modify.- Parameters:
dn- The DN of the entry to modify. It must not benull.
-
getModifications
@NotNull public java.util.List<Modification> getModifications()
Retrieves the set of modifications for this modify request. The returned list must not be altered.- Specified by:
getModificationsin interfaceReadOnlyModifyRequest- Returns:
- The set of modifications for this modify request.
-
addModification
public void addModification(@NotNull 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 benull.
-
removeModification
public boolean removeModification(@NotNull 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 benull.- Returns:
trueif the specified modification was found and removed, orfalseif not.
-
setModifications
public void setModifications(@NotNull 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 benull.
-
setModifications
public void setModifications(@NotNull 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 benullor empty.
-
setModifications
public void setModifications(@NotNull 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 benullor empty.
-
getProtocolOpType
public byte getProtocolOpType()
Retrieves the BER type for this protocol op.- Specified by:
getProtocolOpTypein interfaceProtocolOp- 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:
writeToin interfaceProtocolOp- Parameters:
writer- The ASN.1 buffer to which the encoded representation should be written.
-
encodeProtocolOp
@NotNull public ASN1Element encodeProtocolOp()
Encodes the modify request protocol op to an ASN.1 element.- Specified by:
encodeProtocolOpin interfaceProtocolOp- Returns:
- The ASN.1 element with the encoded modify request protocol op.
-
process
@NotNull protected LDAPResult process(@NotNull 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:
processin 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 processing.
- Throws:
LDAPException- If a problem occurs while sending the request or reading the response.
-
responseReceived
@InternalUseOnly public void responseReceived(@NotNull 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:
getLastMessageIDin 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
@NotNull public OperationType getOperationType()
Retrieves the type of operation that is represented by this request.- Specified by:
getOperationTypein classLDAPRequest- Returns:
- The type of operation that is represented by this request.
-
duplicate
@NotNull public ModifyRequest duplicate()
Creates a new instance of this LDAP request that may be modified without impacting this request.- Specified by:
duplicatein interfaceReadOnlyLDAPRequest- Specified by:
duplicatein interfaceReadOnlyModifyRequest- Returns:
- A new instance of this LDAP request that may be modified without impacting this request.
-
duplicate
@NotNull public ModifyRequest duplicate(@Nullable 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:
duplicatein interfaceReadOnlyLDAPRequest- Specified by:
duplicatein interfaceReadOnlyModifyRequest- 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
@NotNull public LDIFModifyChangeRecord toLDIFChangeRecord()
Retrieves an LDIF modify change record with the contents of this modify request.- Specified by:
toLDIFChangeRecordin interfaceReadOnlyModifyRequest- Returns:
- An LDIF modify change record with the contents of this modify request.
-
toLDIF
@NotNull public java.lang.String[] toLDIF()
Retrieves a string array whose lines contain an LDIF representation of the corresponding modify change record.- Specified by:
toLDIFin interfaceReadOnlyModifyRequest- Returns:
- A string array whose lines contain an LDIF representation of the corresponding modify change record.
-
toLDIFString
@NotNull public java.lang.String toLDIFString()
Retrieves an LDIF string representation of this modify request.- Specified by:
toLDIFStringin interfaceReadOnlyModifyRequest- Returns:
- An LDIF string representation of this modify request.
-
toString
public void toString(@NotNull java.lang.StringBuilder buffer)
Appends a string representation of this request to the provided buffer.- Specified by:
toStringin interfaceProtocolOp- Specified by:
toStringin interfaceReadOnlyLDAPRequest- Specified by:
toStringin classLDAPRequest- Parameters:
buffer- The buffer to which to append a string representation of this request.
-
toCode
public void toCode(@NotNull java.util.List<java.lang.String> lineList, @NotNull 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:
toCodein 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 isnullor 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).
-
-