Package com.unboundid.ldap.sdk
Class CompareRequest
- java.lang.Object
-
- com.unboundid.ldap.sdk.LDAPRequest
-
- com.unboundid.ldap.sdk.UpdatableLDAPRequest
-
- com.unboundid.ldap.sdk.CompareRequest
-
- All Implemented Interfaces:
ProtocolOp
,ReadOnlyCompareRequest
,ReadOnlyLDAPRequest
,java.io.Serializable
@Mutable @ThreadSafety(level=NOT_THREADSAFE) public final class CompareRequest extends UpdatableLDAPRequest implements ReadOnlyCompareRequest, ProtocolOp
This class implements the processing necessary to perform an LDAPv3 compare operation, which may be used to determine whether a specified entry contains a given attribute value. Compare requests include the DN of the target entry, the name of the target attribute, and the value for which to make the determination. It may also include a set of controls to send to the server.
The assertion value may be specified as either a string or a byte array. If it is specified as a byte array, then it may represent either a binary or a string value. If a string value is provided as a byte array, then it should use the UTF-8 encoding for that value.
CompareRequest
objects are mutable and therefore can be altered and re-used for multiple requests. Note, however, thatCompareRequest
objects are not threadsafe and therefore a singleCompareRequest
object instance should not be used to process multiple requests at the same time.
Example
The following example demonstrates the process for performing a compare operation:CompareRequest compareRequest = new CompareRequest("dc=example,dc=com", "description", "test"); CompareResult compareResult; try { compareResult = connection.compare(compareRequest); // The compare operation didn't throw an exception, so we can try to // determine whether the compare matched. if (compareResult.compareMatched()) { // The entry does have a description value of test. } else { // The entry does not have a description value of test. } } catch (LDAPException le) { // The compare operation failed. compareResult = new CompareResult(le.toLDAPResult()); ResultCode resultCode = le.getResultCode(); String errorMessageFromServer = le.getDiagnosticMessage(); }
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description CompareRequest(DN dn, java.lang.String attributeName, byte[] assertionValue)
Creates a new compare request with the provided information.CompareRequest(DN dn, java.lang.String attributeName, byte[] assertionValue, Control[] controls)
Creates a new compare request with the provided information.CompareRequest(DN dn, java.lang.String attributeName, ASN1OctetString assertionValue, Control[] controls)
Creates a new compare request with the provided information.CompareRequest(DN dn, java.lang.String attributeName, java.lang.String assertionValue)
Creates a new compare request with the provided information.CompareRequest(DN dn, java.lang.String attributeName, java.lang.String assertionValue, Control[] controls)
Creates a new compare request with the provided information.CompareRequest(java.lang.String dn, java.lang.String attributeName, byte[] assertionValue)
Creates a new compare request with the provided information.CompareRequest(java.lang.String dn, java.lang.String attributeName, byte[] assertionValue, Control[] controls)
Creates a new compare request with the provided information.CompareRequest(java.lang.String dn, java.lang.String attributeName, java.lang.String assertionValue)
Creates a new compare request with the provided information.CompareRequest(java.lang.String dn, java.lang.String attributeName, java.lang.String assertionValue, Control[] controls)
Creates a new compare request with the provided information.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompareRequest
duplicate()
Creates a new instance of this LDAP request that may be modified without impacting this request.CompareRequest
duplicate(Control[] controls)
Creates a new instance of this LDAP request that may be modified without impacting this request.ASN1Element
encodeProtocolOp()
Encodes the compare request protocol op to an ASN.1 element.java.lang.String
getAssertionValue()
Retrieves the assertion value to verify within the target entry.byte[]
getAssertionValueBytes()
Retrieves the assertion value to verify within the target entry, formatted as a byte array.java.lang.String
getAttributeName()
Retrieves the name of the attribute for which the comparison is to be performed.java.lang.String
getDN()
Retrieves the DN of the entry in which the comparison is to be performed.int
getLastMessageID()
Retrieves the message ID for the last LDAP message sent using this request.OperationType
getOperationType()
Retrieves the type of operation that is represented by this request.byte
getProtocolOpType()
Retrieves the BER type for this protocol op.ASN1OctetString
getRawAssertionValue()
Retrieves the assertion value to verify within the target entry.protected CompareResult
process(LDAPConnection connection, int depth)
Sends this delete request to the directory server over the provided connection and returns the associated response.void
responseReceived(LDAPResponse response)
void
setAssertionValue(byte[] assertionValue)
Specifies the assertion value to specify within the target entry.void
setAssertionValue(ASN1OctetString assertionValue)
Specifies the assertion value to specify within the target entry.void
setAssertionValue(java.lang.String assertionValue)
Specifies the assertion value to specify within the target entry.void
setAttributeName(java.lang.String attributeName)
Specifies the name of the attribute for which the comparison is to be performed.void
setDN(DN dn)
Specifies the DN of the entry in which the comparison is to be performed.void
setDN(java.lang.String dn)
Specifies the DN of the entry in which the comparison is to be performed.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.void
toString(java.lang.StringBuilder buffer)
Appends a string representation of this request to the provided buffer.void
writeTo(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, 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, getControls, getReferralConnector, getResponseTimeoutMillis, hasControl, hasControl, toString
-
-
-
-
Constructor Detail
-
CompareRequest
public CompareRequest(java.lang.String dn, java.lang.String attributeName, java.lang.String assertionValue)
Creates a new compare request with the provided information.- Parameters:
dn
- The DN of the entry in which the comparison is to be performed. It must not benull
.attributeName
- The name of the target attribute for which the comparison is to be performed. It must not benull
.assertionValue
- The assertion value to verify within the entry. It must not benull
.
-
CompareRequest
public CompareRequest(java.lang.String dn, java.lang.String attributeName, byte[] assertionValue)
Creates a new compare request with the provided information.- Parameters:
dn
- The DN of the entry in which the comparison is to be performed. It must not benull
.attributeName
- The name of the target attribute for which the comparison is to be performed. It must not benull
.assertionValue
- The assertion value to verify within the entry. It must not benull
.
-
CompareRequest
public CompareRequest(DN dn, java.lang.String attributeName, java.lang.String assertionValue)
Creates a new compare request with the provided information.- Parameters:
dn
- The DN of the entry in which the comparison is to be performed. It must not benull
.attributeName
- The name of the target attribute for which the comparison is to be performed. It must not benull
.assertionValue
- The assertion value to verify within the entry. It must not benull
.
-
CompareRequest
public CompareRequest(DN dn, java.lang.String attributeName, byte[] assertionValue)
Creates a new compare request with the provided information.- Parameters:
dn
- The DN of the entry in which the comparison is to be performed. It must not benull
.attributeName
- The name of the target attribute for which the comparison is to be performed. It must not benull
.assertionValue
- The assertion value to verify within the entry. It must not benull
.
-
CompareRequest
public CompareRequest(java.lang.String dn, java.lang.String attributeName, java.lang.String assertionValue, Control[] controls)
Creates a new compare request with the provided information.- Parameters:
dn
- The DN of the entry in which the comparison is to be performed. It must not benull
.attributeName
- The name of the target attribute for which the comparison is to be performed. It must not benull
.assertionValue
- The assertion value to verify within the entry. It must not benull
.controls
- The set of controls for this compare request.
-
CompareRequest
public CompareRequest(java.lang.String dn, java.lang.String attributeName, byte[] assertionValue, Control[] controls)
Creates a new compare request with the provided information.- Parameters:
dn
- The DN of the entry in which the comparison is to be performed. It must not benull
.attributeName
- The name of the target attribute for which the comparison is to be performed. It must not benull
.assertionValue
- The assertion value to verify within the entry. It must not benull
.controls
- The set of controls for this compare request.
-
CompareRequest
public CompareRequest(DN dn, java.lang.String attributeName, java.lang.String assertionValue, Control[] controls)
Creates a new compare request with the provided information.- Parameters:
dn
- The DN of the entry in which the comparison is to be performed. It must not benull
.attributeName
- The name of the target attribute for which the comparison is to be performed. It must not benull
.assertionValue
- The assertion value to verify within the entry. It must not benull
.controls
- The set of controls for this compare request.
-
CompareRequest
public CompareRequest(DN dn, java.lang.String attributeName, ASN1OctetString assertionValue, Control[] controls)
Creates a new compare request with the provided information.- Parameters:
dn
- The DN of the entry in which the comparison is to be performed. It must not benull
.attributeName
- The name of the target attribute for which the comparison is to be performed. It must not benull
.assertionValue
- The assertion value to verify within the entry. It must not benull
.controls
- The set of controls for this compare request.
-
CompareRequest
public CompareRequest(DN dn, java.lang.String attributeName, byte[] assertionValue, Control[] controls)
Creates a new compare request with the provided information.- Parameters:
dn
- The DN of the entry in which the comparison is to be performed. It must not benull
.attributeName
- The name of the target attribute for which the comparison is to be performed. It must not benull
.assertionValue
- The assertion value to verify within the entry. It must not benull
.controls
- The set of controls for this compare request.
-
-
Method Detail
-
getDN
public java.lang.String getDN()
Retrieves the DN of the entry in which the comparison is to be performed.- Specified by:
getDN
in interfaceReadOnlyCompareRequest
- Returns:
- The DN of the entry in which the comparison is to be performed.
-
setDN
public void setDN(java.lang.String dn)
Specifies the DN of the entry in which the comparison is to be performed.- Parameters:
dn
- The DN of the entry in which the comparison is to be performed. It must not benull
.
-
setDN
public void setDN(DN dn)
Specifies the DN of the entry in which the comparison is to be performed.- Parameters:
dn
- The DN of the entry in which the comparison is to be performed. It must not benull
.
-
getAttributeName
public java.lang.String getAttributeName()
Retrieves the name of the attribute for which the comparison is to be performed.- Specified by:
getAttributeName
in interfaceReadOnlyCompareRequest
- Returns:
- The name of the attribute for which the comparison is to be performed.
-
setAttributeName
public void setAttributeName(java.lang.String attributeName)
Specifies the name of the attribute for which the comparison is to be performed.- Parameters:
attributeName
- The name of the attribute for which the comparison is to be performed. It must not benull
.
-
getAssertionValue
public java.lang.String getAssertionValue()
Retrieves the assertion value to verify within the target entry.- Specified by:
getAssertionValue
in interfaceReadOnlyCompareRequest
- Returns:
- The assertion value to verify within the target entry.
-
getAssertionValueBytes
public byte[] getAssertionValueBytes()
Retrieves the assertion value to verify within the target entry, formatted as a byte array.- Specified by:
getAssertionValueBytes
in interfaceReadOnlyCompareRequest
- Returns:
- The assertion value to verify within the target entry, formatted as a byte array.
-
getRawAssertionValue
public ASN1OctetString getRawAssertionValue()
Retrieves the assertion value to verify within the target entry.- Specified by:
getRawAssertionValue
in interfaceReadOnlyCompareRequest
- Returns:
- The assertion value to verify within the target entry.
-
setAssertionValue
public void setAssertionValue(java.lang.String assertionValue)
Specifies the assertion value to specify within the target entry.- Parameters:
assertionValue
- The assertion value to specify within the target entry. It must not benull
.
-
setAssertionValue
public void setAssertionValue(byte[] assertionValue)
Specifies the assertion value to specify within the target entry.- Parameters:
assertionValue
- The assertion value to specify within the target entry. It must not benull
.
-
setAssertionValue
public void setAssertionValue(ASN1OctetString assertionValue)
Specifies the assertion value to specify within the target entry.- Parameters:
assertionValue
- The assertion value to specify within the target entry. It must not benull
.
-
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 buffer)
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:
buffer
- The ASN.1 buffer to which the encoded representation should be written.
-
encodeProtocolOp
public ASN1Element encodeProtocolOp()
Encodes the compare request protocol op to an ASN.1 element.- Specified by:
encodeProtocolOp
in interfaceProtocolOp
- Returns:
- The ASN.1 element with the encoded compare request protocol op.
-
process
protected CompareResult process(LDAPConnection connection, int depth) throws LDAPException
Sends this delete 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 delete 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 CompareRequest duplicate()
Creates a new instance of this LDAP request that may be modified without impacting this request.- Specified by:
duplicate
in interfaceReadOnlyCompareRequest
- Specified by:
duplicate
in interfaceReadOnlyLDAPRequest
- Returns:
- A new instance of this LDAP request that may be modified without impacting this request.
-
duplicate
public CompareRequest 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 interfaceReadOnlyCompareRequest
- Specified by:
duplicate
in 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.
-
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
).
-
-