Package com.unboundid.ldap.sdk
Class AddRequest
java.lang.Object
com.unboundid.ldap.sdk.LDAPRequest
com.unboundid.ldap.sdk.UpdatableLDAPRequest
com.unboundid.ldap.sdk.AddRequest
- All Implemented Interfaces:
ProtocolOp,ReadOnlyAddRequest,ReadOnlyLDAPRequest,Serializable
@Mutable
@ThreadSafety(level=NOT_THREADSAFE)
public final class AddRequest
extends UpdatableLDAPRequest
implements ReadOnlyAddRequest, ProtocolOp
This class implements the processing necessary to perform an LDAPv3 add
operation, which creates a new entry in the directory. An add request
contains the DN for the entry and the set of attributes to include. It may
also include a set of controls to send to the server.
The contents of the entry to may be specified as a separate DN and collection of attributes, as an
The contents of the entry to may be specified as a separate DN and collection of attributes, as an
Entry object, or as a list of the lines that
comprise the LDIF representation of the entry to add as described in
RFC 2849. For example, the
following code demonstrates creating an add request from the LDIF
representation of the entry:
AddRequest addRequest = new AddRequest(
"dn: dc=example,dc=com",
"objectClass: top",
"objectClass: domain",
"dc: example");
AddRequest objects are mutable and therefore can be altered and
re-used for multiple requests. Note, however, that AddRequest
objects are not threadsafe and therefore a single AddRequest object
instance should not be used to process multiple requests at the same time.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionAddRequest(DN dn, Attribute... attributes) Creates a new add request with the provided DN and set of attributes.AddRequest(DN dn, Attribute[] attributes, Control[] controls) Creates a new add request with the provided DN and set of attributes.AddRequest(DN dn, Collection<Attribute> attributes) Creates a new add request with the provided DN and set of attributes.AddRequest(DN dn, Collection<Attribute> attributes, Control[] controls) Creates a new add request with the provided DN and set of attributes.AddRequest(Entry entry) Creates a new add request to add the provided entry.AddRequest(Entry entry, Control[] controls) Creates a new add request to add the provided entry.AddRequest(String... ldifLines) Creates a new add request with the provided entry in LDIF form.AddRequest(String dn, Attribute... attributes) Creates a new add request with the provided DN and set of attributes.AddRequest(String dn, Attribute[] attributes, Control[] controls) Creates a new add request with the provided DN and set of attributes.AddRequest(String dn, Collection<Attribute> attributes) Creates a new add request with the provided DN and set of attributes.AddRequest(String dn, Collection<Attribute> attributes, Control[] controls) Creates a new add request with the provided DN and set of attributes. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAttribute(Attribute attribute) Adds the provided attribute to the entry to add.voidaddAttribute(String name, byte[] value) Adds the provided attribute to the entry to add.voidaddAttribute(String name, byte[]... values) Adds the provided attribute to the entry to add.voidaddAttribute(String name, String value) Adds the provided attribute to the entry to add.voidaddAttribute(String name, String... values) Adds the provided attribute to the entry to add.Creates a new instance of this LDAP request that may be modified without impacting this request.Creates a new instance of this LDAP request that may be modified without impacting this request.Encodes the add request protocol op to an ASN.1 element.getAttribute(String attributeName) Retrieves the specified attribute from this add request.Retrieves the set of attributes for this add request.getDN()Retrieves the DN for this add request.intRetrieves the message ID for the last LDAP message sent using this request.Retrieves the type of operation that is represented by this request.byteRetrieves the BER type for this protocol op.booleanhasAttribute(Attribute attribute) Indicates whether this add request contains the specified attribute.booleanhasAttribute(String attributeName) Indicates whether this add request contains the specified attribute.booleanhasAttributeValue(String attributeName, byte[] attributeValue) Indicates whether this add request contains an attribute with the given name and value.booleanhasAttributeValue(String attributeName, byte[] attributeValue, MatchingRule matchingRule) Indicates whether this add request contains an attribute with the given name and value.booleanhasAttributeValue(String attributeName, String attributeValue) Indicates whether this add request contains an attribute with the given name and value.booleanhasAttributeValue(String attributeName, String attributeValue, MatchingRule matchingRule) Indicates whether this add request contains an attribute with the given name and value.booleanhasObjectClass(String objectClassName) Indicates whether this add request contains the specified object class.protected LDAPResultprocess(LDAPConnection connection, int depth) Sends this add request to the directory server over the provided connection and returns the associated response.booleanremoveAttribute(String attributeName) Removes the attribute with the specified name from the entry to add.booleanremoveAttribute(String name, byte[] value) Removes the specified attribute value from this add request.booleanremoveAttributeValue(String name, String value) Removes the specified attribute value from this add request.voidreplaceAttribute(Attribute attribute) Replaces the specified attribute in the entry to add.voidreplaceAttribute(String name, byte[] value) Replaces the specified attribute in the entry to add.voidreplaceAttribute(String name, byte[]... values) Replaces the specified attribute in the entry to add.voidreplaceAttribute(String name, String value) Replaces the specified attribute in the entry to add.voidreplaceAttribute(String name, String... values) Replaces the specified attribute in the entry to add.voidresponseReceived(LDAPResponse response) voidsetAttributes(Attribute[] attributes) Specifies the set of attributes for this add request.voidsetAttributes(Collection<Attribute> attributes) Specifies the set of attributes for this add request.voidSpecifies the DN for this add request.voidSpecifies the DN for this add request.voidAppends a number of lines comprising the Java source code that can be used to recreate this request to the given list.toEntry()Retrieves anEntryobject containing the DN and attributes of this add request.String[]toLDIF()Retrieves a string array whose lines contain an LDIF representation of the corresponding add change record.Retrieves an LDIF add change record with the contents of this add request.Retrieves an LDIF string representation of this add request.voidtoString(StringBuilder buffer) Appends a string representation of this request to the provided buffer.voidwriteTo(ASN1Buffer buffer) 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, setControlsMethods inherited from class com.unboundid.ldap.sdk.LDAPRequest
followReferrals, getControl, getControlList, getControls, getIntermediateResponseListener, getReferralConnector, getReferralConnectorInternal, getReferralDepth, getResponseTimeoutMillis, hasControl, hasControl, setFollowReferrals, setIntermediateResponseListener, setReferralConnector, setReferralDepth, setResponseTimeoutMillis, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.unboundid.ldap.sdk.ReadOnlyLDAPRequest
followReferrals, getControl, getControlList, getControls, getReferralConnector, getResponseTimeoutMillis, hasControl, hasControl, toString
-
Constructor Details
-
AddRequest
Creates a new add request with the provided DN and set of attributes.- Parameters:
dn- The DN for the entry to add. It must not benull.attributes- The set of attributes to include in the entry to add. It must not benull.
-
AddRequest
public AddRequest(@NotNull String dn, @NotNull Attribute[] attributes, @Nullable Control[] controls) Creates a new add request with the provided DN and set of attributes.- Parameters:
dn- The DN for the entry to add. It must not benull.attributes- The set of attributes to include in the entry to add. It must not benull.controls- The set of controls to include in the request.
-
AddRequest
Creates a new add request with the provided DN and set of attributes.- Parameters:
dn- The DN for the entry to add. It must not benull.attributes- The set of attributes to include in the entry to add. It must not benull.
-
AddRequest
public AddRequest(@NotNull String dn, @NotNull Collection<Attribute> attributes, @Nullable Control[] controls) Creates a new add request with the provided DN and set of attributes.- Parameters:
dn- The DN for the entry to add. It must not benull.attributes- The set of attributes to include in the entry to add. It must not benull.controls- The set of controls to include in the request.
-
AddRequest
Creates a new add request with the provided DN and set of attributes.- Parameters:
dn- The DN for the entry to add. It must not benull.attributes- The set of attributes to include in the entry to add. It must not benull.
-
AddRequest
Creates a new add request with the provided DN and set of attributes.- Parameters:
dn- The DN for the entry to add. It must not benull.attributes- The set of attributes to include in the entry to add. It must not benull.controls- The set of controls to include in the request.
-
AddRequest
Creates a new add request with the provided DN and set of attributes.- Parameters:
dn- The DN for the entry to add. It must not benull.attributes- The set of attributes to include in the entry to add. It must not benull.
-
AddRequest
public AddRequest(@NotNull DN dn, @NotNull Collection<Attribute> attributes, @Nullable Control[] controls) Creates a new add request with the provided DN and set of attributes.- Parameters:
dn- The DN for the entry to add. It must not benull.attributes- The set of attributes to include in the entry to add. It must not benull.controls- The set of controls to include in the request.
-
AddRequest
Creates a new add request to add the provided entry.- Parameters:
entry- The entry to be added. It must not benull.
-
AddRequest
Creates a new add request to add the provided entry.- Parameters:
entry- The entry to be added. It must not benull.controls- The set of controls to include in the request.
-
AddRequest
Creates a new add request with the provided entry in LDIF form.- Parameters:
ldifLines- The lines that comprise the LDIF representation of the entry to add. It must not benullor empty. It may represent a standard LDIF entry, or it may represent an LDIF add change record (optionally including controls).- Throws:
LDIFException- If the provided LDIF data cannot be decoded as an entry.
-
-
Method Details
-
getDN
Retrieves the DN for this add request.- Specified by:
getDNin interfaceReadOnlyAddRequest- Returns:
- The DN for this add request.
-
setDN
Specifies the DN for this add request.- Parameters:
dn- The DN for this add request. It must not benull.
-
setDN
Specifies the DN for this add request.- Parameters:
dn- The DN for this add request. It must not benull.
-
getAttributes
Retrieves the set of attributes for this add request.- Specified by:
getAttributesin interfaceReadOnlyAddRequest- Returns:
- The set of attributes for this add request.
-
getAttribute
Retrieves the specified attribute from this add request.- Specified by:
getAttributein interfaceReadOnlyAddRequest- Parameters:
attributeName- The name of the attribute to retrieve. It must not benull.- Returns:
- The requested attribute, or
nullif it does not exist in the add request.
-
hasAttribute
Indicates whether this add request contains the specified attribute.- Specified by:
hasAttributein interfaceReadOnlyAddRequest- Parameters:
attributeName- The name of the attribute for which to make the determination. It must not benull.- Returns:
trueif this add request contains the specified attribute, orfalseif not.
-
hasAttribute
Indicates whether this add request contains the specified attribute. It will only returntrueif this add request contains an attribute with the same name and exact set of values.- Specified by:
hasAttributein interfaceReadOnlyAddRequest- Parameters:
attribute- The attribute for which to make the determination. It must not benull.- Returns:
trueif this add request contains the specified attribute, orfalseif not.
-
hasAttributeValue
Indicates whether this add request contains an attribute with the given name and value.- Specified by:
hasAttributeValuein interfaceReadOnlyAddRequest- Parameters:
attributeName- The name of the attribute for which to make the determination. It must not benull.attributeValue- The value for which to make the determination. It must not benull.- Returns:
trueif this add request contains an attribute with the specified name and value, orfalseif not.
-
hasAttributeValue
public boolean hasAttributeValue(@NotNull String attributeName, @NotNull String attributeValue, @NotNull MatchingRule matchingRule) Indicates whether this add request contains an attribute with the given name and value.- Specified by:
hasAttributeValuein interfaceReadOnlyAddRequest- Parameters:
attributeName- The name of the attribute for which to make the determination. It must not benull.attributeValue- The value for which to make the determination. It must not benull.matchingRule- The matching rule to use to make the determination. It must not benull.- Returns:
trueif this add request contains an attribute with the specified name and value, orfalseif not.
-
hasAttributeValue
Indicates whether this add request contains an attribute with the given name and value.- Specified by:
hasAttributeValuein interfaceReadOnlyAddRequest- Parameters:
attributeName- The name of the attribute for which to make the determination. It must not benull.attributeValue- The value for which to make the determination. It must not benull.- Returns:
trueif this add request contains an attribute with the specified name and value, orfalseif not.
-
hasAttributeValue
public boolean hasAttributeValue(@NotNull String attributeName, @NotNull byte[] attributeValue, @NotNull MatchingRule matchingRule) Indicates whether this add request contains an attribute with the given name and value.- Specified by:
hasAttributeValuein interfaceReadOnlyAddRequest- Parameters:
attributeName- The name of the attribute for which to make the determination. It must not benull.attributeValue- The value for which to make the determination. It must not benull.matchingRule- The matching rule to use to make the determination. It must not benull.- Returns:
trueif this add request contains an attribute with the specified name and value, orfalseif not.
-
hasObjectClass
Indicates whether this add request contains the specified object class.- Specified by:
hasObjectClassin interfaceReadOnlyAddRequest- Parameters:
objectClassName- The name of the object class for which to make the determination. It must not benull.- Returns:
trueif this add request contains the specified object class, orfalseif not.
-
toEntry
Retrieves anEntryobject containing the DN and attributes of this add request.- Specified by:
toEntryin interfaceReadOnlyAddRequest- Returns:
- An
Entryobject containing the DN and attributes of this add request.
-
setAttributes
Specifies the set of attributes for this add request. It must not benull.- Parameters:
attributes- The set of attributes for this add request.
-
setAttributes
Specifies the set of attributes for this add request. It must not benull.- Parameters:
attributes- The set of attributes for this add request.
-
addAttribute
Adds the provided attribute to the entry to add.- Parameters:
attribute- The attribute to be added to the entry to add. It must not benull.
-
addAttribute
Adds the provided attribute to the entry to add.- Parameters:
name- The name of the attribute to add. It must not benull.value- The value for the attribute to add. It must not benull.
-
addAttribute
Adds the provided attribute to the entry to add.- Parameters:
name- The name of the attribute to add. It must not benull.value- The value for the attribute to add. It must not benull.
-
addAttribute
Adds the provided attribute to the entry to add.- Parameters:
name- The name of the attribute to add. It must not benull.values- The set of values for the attribute to add. It must not benull.
-
addAttribute
Adds the provided attribute to the entry to add.- Parameters:
name- The name of the attribute to add. It must not benull.values- The set of values for the attribute to add. It must not benull.
-
removeAttribute
Removes the attribute with the specified name from the entry to add.- Parameters:
attributeName- The name of the attribute to remove. It must not benull.- Returns:
trueif the attribute was removed from this add request, orfalseif the add request did not include the specified attribute.
-
removeAttributeValue
Removes the specified attribute value from this add request.- Parameters:
name- The name of the attribute to remove. It must not benull.value- The value of the attribute to remove. It must not benull.- Returns:
trueif the attribute value was removed from this add request, orfalseif the add request did not include the specified attribute value.
-
removeAttribute
Removes the specified attribute value from this add request.- Parameters:
name- The name of the attribute to remove. It must not benull.value- The value of the attribute to remove. It must not benull.- Returns:
trueif the attribute value was removed from this add request, orfalseif the add request did not include the specified attribute value.
-
replaceAttribute
Replaces the specified attribute in the entry to add. If no attribute with the given name exists in the add request, it will be added.- Parameters:
attribute- The attribute to be replaced in this add request. It must not benull.
-
replaceAttribute
Replaces the specified attribute in the entry to add. If no attribute with the given name exists in the add request, it will be added.- Parameters:
name- The name of the attribute to be replaced. It must not benull.value- The new value for the attribute. It must not benull.
-
replaceAttribute
Replaces the specified attribute in the entry to add. If no attribute with the given name exists in the add request, it will be added.- Parameters:
name- The name of the attribute to be replaced. It must not benull.value- The new value for the attribute. It must not benull.
-
replaceAttribute
Replaces the specified attribute in the entry to add. If no attribute with the given name exists in the add request, it will be added.- Parameters:
name- The name of the attribute to be replaced. It must not benull.values- The new set of values for the attribute. It must not benull.
-
replaceAttribute
Replaces the specified attribute in the entry to add. If no attribute with the given name exists in the add request, it will be added.- Parameters:
name- The name of the attribute to be replaced. It must not benull.values- The new set of values for the attribute. It must not benull.
-
getProtocolOpType
Retrieves the BER type for this protocol op.- Specified by:
getProtocolOpTypein interfaceProtocolOp- Returns:
- The BER type for this protocol op.
-
writeTo
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:
buffer- The ASN.1 buffer to which the encoded representation should be written.
-
encodeProtocolOp
Encodes the add request protocol op to an ASN.1 element.- Specified by:
encodeProtocolOpin interfaceProtocolOp- Returns:
- The ASN.1 element with the encoded add request protocol op.
-
process
@NotNull protected LDAPResult process(@NotNull LDAPConnection connection, int depth) throws LDAPException Sends this add 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 add processing.
- Throws:
LDAPException- If a problem occurs while sending the request or reading the response.
-
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
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
Creates a new instance of this LDAP request that may be modified without impacting this request.- Specified by:
duplicatein interfaceReadOnlyAddRequest- Specified by:
duplicatein interfaceReadOnlyLDAPRequest- 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:
duplicatein interfaceReadOnlyAddRequest- Specified by:
duplicatein interfaceReadOnlyLDAPRequest- 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.
-
responseReceived
- Throws:
LDAPException
-
toLDIFChangeRecord
Retrieves an LDIF add change record with the contents of this add request.- Specified by:
toLDIFChangeRecordin interfaceReadOnlyAddRequest- Returns:
- An LDIF add change record with the contents of this add request.
-
toLDIF
Retrieves a string array whose lines contain an LDIF representation of the corresponding add change record.- Specified by:
toLDIFin interfaceReadOnlyAddRequest- Returns:
- A string array whose lines contain an LDIF representation of the corresponding add change record.
-
toLDIFString
Retrieves an LDIF string representation of this add request.- Specified by:
toLDIFStringin interfaceReadOnlyAddRequest- Returns:
- An LDIF string representation of this add request.
-
toString
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 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:
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).
-