Package org.ldaptive
Class SearchResponse
- java.lang.Object
-
- org.ldaptive.AbstractMessage
-
- org.ldaptive.AbstractResult
-
- org.ldaptive.SearchResponse
-
public final class SearchResponse extends AbstractResult implements Freezable
Response that encapsulates the result elements of a search request. This class formally decodes the SearchResultDone LDAP message defined as:SearchResultDone ::= [APPLICATION 5] LDAPResult
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SearchResponse.Builder
-
Nested classes/interfaces inherited from class org.ldaptive.AbstractResult
AbstractResult.AbstractBuilder<B,T extends AbstractResult>, AbstractResult.DiagnosticMessageHandler, AbstractResult.MatchedDNHandler, AbstractResult.ReferralHandler, AbstractResult.ResultCodeHandler
-
Nested classes/interfaces inherited from class org.ldaptive.AbstractMessage
AbstractMessage.ControlParser, AbstractMessage.ControlsHandler, AbstractMessage.MessageIDHandler
-
-
Field Summary
Fields Modifier and Type Field Description private static DERPath
DIAGNOSTIC_MESSAGE_PATH
DER path to diagnostic message.private static int
HASH_CODE_SEED
hash code seed.private boolean
immutable
Whether this object has been marked immutable.private static DERPath
MATCHED_DN_PATH
DER path to matched DN.static int
PROTOCOL_OP
BER protocol number.private static DERPath
REFERRAL_PATH
DER path to referral.private static DERPath
RESULT_CODE_PATH
DER path to result code.private List<LdapEntry>
resultEntries
Entries contained in this result.private List<SearchResultReference>
resultReferences
Search result references contained in this result.-
Fields inherited from interface org.ldaptive.Result
ENCODE_CNTRL_CHARS
-
-
Constructor Summary
Constructors Constructor Description SearchResponse()
Default constructor.SearchResponse(DERBuffer buffer)
Creates a new search result done.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEntries(Collection<LdapEntry> entries)
Adds entry(s) to this search result.void
addEntries(LdapEntry... entry)
Adds an entry to this search result.void
addReferences(Collection<SearchResultReference> references)
Adds references(s) to this search result.void
addReferences(SearchResultReference... reference)
Adds a reference to this search result.void
assertMutable()
Asserts that this object is in a state to permit mutations.static SearchResponse.Builder
builder()
Creates a builder for this class.static SearchResponse
copy(SearchResponse response)
Creates a mutable copy of the supplied search response.int
entrySize()
Returns the number of entries in this search result.boolean
equals(Object o)
void
freeze()
Freezes this object, making it immutable.Collection<LdapEntry>
getEntries()
Returns the entries in this search result.LdapEntry
getEntry()
Returns a single entry of this search result.LdapEntry
getEntry(String dn)
Returns the ldap entry in this result with the supplied DN.Collection<String>
getEntryDns()
Returns the entry DNs in this result.SearchResultReference
getReference()
Returns a single search reference of this result.Collection<SearchResultReference>
getReferences()
Returns a collection of search result reference.int
hashCode()
Returns the hash code for this object.boolean
isFrozen()
Determines whether this object is frozen, i.e. immutable.int
referenceSize()
Returns the number of references in this search result.void
removeEntries(Collection<LdapEntry> entries)
Removes entry(s) from this search result.void
removeEntries(LdapEntry... entry)
Removes an entry from this search result.void
removeReferences(Collection<SearchResultReference> references)
Removes references(s) from this search result.void
removeReferences(SearchResultReference... reference)
Removes a reference from this search result.static SearchResponse
sort(SearchResponse result)
Returns a new response whose entries are sorted naturally by DN.SearchResponse
subResult(int fromIndex, int toIndex)
Returns a portion of this result between the specified fromIndex, inclusive, and toIndex, exclusive.String
toString()
-
Methods inherited from class org.ldaptive.AbstractResult
addReferralURLs, copyValues, equalsResult, getDiagnosticMessage, getMatchedDN, getReferralURLs, getResultCode, setDiagnosticMessage, setMatchedDN, setResultCode
-
Methods inherited from class org.ldaptive.AbstractMessage
addControls, copyValues, equalsMessage, getControls, getMessageID, setMessageID
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.ldaptive.Message
getControl, getControls, getMessageID
-
Methods inherited from interface org.ldaptive.Result
getEncodedDiagnosticMessage, isSuccess
-
-
-
-
Field Detail
-
PROTOCOL_OP
public static final int PROTOCOL_OP
BER protocol number.- See Also:
- Constant Field Values
-
HASH_CODE_SEED
private static final int HASH_CODE_SEED
hash code seed.- See Also:
- Constant Field Values
-
RESULT_CODE_PATH
private static final DERPath RESULT_CODE_PATH
DER path to result code.
-
MATCHED_DN_PATH
private static final DERPath MATCHED_DN_PATH
DER path to matched DN.
-
DIAGNOSTIC_MESSAGE_PATH
private static final DERPath DIAGNOSTIC_MESSAGE_PATH
DER path to diagnostic message.
-
REFERRAL_PATH
private static final DERPath REFERRAL_PATH
DER path to referral.
-
resultReferences
private final List<SearchResultReference> resultReferences
Search result references contained in this result.
-
immutable
private volatile boolean immutable
Whether this object has been marked immutable.
-
-
Constructor Detail
-
SearchResponse
public SearchResponse()
Default constructor.
-
SearchResponse
public SearchResponse(DERBuffer buffer)
Creates a new search result done.- Parameters:
buffer
- to decode
-
-
Method Detail
-
freeze
public void freeze()
Description copied from interface:Freezable
Freezes this object, making it immutable.
-
isFrozen
public boolean isFrozen()
Description copied from interface:Freezable
Determines whether this object is frozen, i.e. immutable.- Specified by:
isFrozen
in interfaceFreezable
- Returns:
- True if
Freezable.freeze()
has been invoked, false otherwise.
-
assertMutable
public void assertMutable()
Description copied from interface:Freezable
Asserts that this object is in a state to permit mutations. Classes that implement this interface should invoke this method prior to performing any mutation of internal state as a means of implementing the "frozen" usage contract.- Specified by:
assertMutable
in interfaceFreezable
-
getEntries
public Collection<LdapEntry> getEntries()
Returns the entries in this search result. Collection will be immutable ifimmutable
is true.- Returns:
- collection of ldap entry
-
getEntry
public LdapEntry getEntry()
Returns a single entry of this search result. If multiple entries exist the first entry returned by the underlying iterator is used. If no entries exist null is returned.- Returns:
- search result entry
-
getEntry
public LdapEntry getEntry(String dn)
Returns the ldap entry in this result with the supplied DN. DN comparison is attempted with a normalized string comparison, seeDefaultRDnNormalizer
.- Parameters:
dn
- of the entry to return- Returns:
- search result entry or null if no entry matching the dn could be found
- Throws:
IllegalArgumentException
- if the supplied dn cannot be normalized
-
getEntryDns
public Collection<String> getEntryDns()
Returns the entry DNs in this result.- Returns:
- entry DNs
-
addEntries
public void addEntries(LdapEntry... entry)
Adds an entry to this search result.- Parameters:
entry
- entry to add
-
addEntries
public void addEntries(Collection<LdapEntry> entries)
Adds entry(s) to this search result.- Parameters:
entries
- collection of entries to add
-
removeEntries
public void removeEntries(LdapEntry... entry)
Removes an entry from this search result.- Parameters:
entry
- entry to remove
-
removeEntries
public void removeEntries(Collection<LdapEntry> entries)
Removes entry(s) from this search result.- Parameters:
entries
- collection of entries to remove
-
entrySize
public int entrySize()
Returns the number of entries in this search result.- Returns:
- number of entries in this search result
-
getReferences
public Collection<SearchResultReference> getReferences()
Returns a collection of search result reference.- Returns:
- collection of search result reference
-
getReference
public SearchResultReference getReference()
Returns a single search reference of this result. If multiple references exist the first references returned by the underlying iterator is used. If no references exist null is returned.- Returns:
- search result references
-
addReferences
public void addReferences(SearchResultReference... reference)
Adds a reference to this search result.- Parameters:
reference
- reference to add
-
addReferences
public void addReferences(Collection<SearchResultReference> references)
Adds references(s) to this search result.- Parameters:
references
- collection of references to add
-
removeReferences
public void removeReferences(SearchResultReference... reference)
Removes a reference from this search result.- Parameters:
reference
- reference to remove
-
removeReferences
public void removeReferences(Collection<SearchResultReference> references)
Removes references(s) from this search result.- Parameters:
references
- collection of references to remove
-
referenceSize
public int referenceSize()
Returns the number of references in this search result.- Returns:
- number of references in this search result
-
subResult
public SearchResponse subResult(int fromIndex, int toIndex)
Returns a portion of this result between the specified fromIndex, inclusive, and toIndex, exclusive. If fromIndex and toIndex are equal, the return result is empty. The result of this method is undefined for unordered results.- Parameters:
fromIndex
- low endpoint of the search result (inclusive)toIndex
- high endpoint of the search result (exclusive)- Returns:
- portion of this search result
- Throws:
IndexOutOfBoundsException
- for illegal index values
-
equals
public boolean equals(Object o)
- Overrides:
equals
in classAbstractResult
-
hashCode
public int hashCode()
Description copied from class:AbstractMessage
Returns the hash code for this object.- Specified by:
hashCode
in classAbstractMessage
- Returns:
- hash code
-
toString
public String toString()
- Overrides:
toString
in classAbstractResult
-
copy
public static SearchResponse copy(SearchResponse response)
Creates a mutable copy of the supplied search response.- Parameters:
response
- to copy- Returns:
- new search response instance
-
sort
public static SearchResponse sort(SearchResponse result)
Returns a new response whose entries are sorted naturally by DN. Each attribute and each attribute value are also sorted. SeeLdapEntry.sort(LdapEntry)
andLdapAttribute.sort(LdapAttribute)
.- Parameters:
result
- response to sort- Returns:
- sorted response
-
builder
public static SearchResponse.Builder builder()
Creates a builder for this class.- Returns:
- new builder
-
-