Package netscape.ldap
Class LDAPSearchResults
java.lang.Object
netscape.ldap.LDAPSearchResults
- All Implemented Interfaces:
Serializable
,Enumeration<Object>
The results of an LDAP search operation, represented as an enumeration.
Note that you can only iterate through this enumeration once: if you
need to use these results more than once, make sure to save the
results in a separate location.
You can also use the results of a search in progress to abandon that search operation.
- Version:
- 1.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate LDAPConnection
private String[]
private boolean
private String
private LDAPConnection
private LDAPSearchConstraints
private String
private int
private Vector
<LDAPException> private boolean
private int
private boolean
private Vector
<LDAPSearchResults> private LDAPSearchListener
private boolean
(package private) static final long
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an enumeration of search results.Constructs an enumeration of search results.LDAPSearchResults
(Vector<Object> v, LDAPConnection conn, LDAPSearchConstraints cons, String base, int scope, String filter, String[] attrs, boolean attrsOnly) LDAPSearchResults
(LDAPConnection conn, LDAPSearchConstraints cons, String base, int scope, String filter, String[] attrs, boolean attrsOnly) -
Method Summary
Modifier and TypeMethodDescription(package private) void
add
(LDAPException e) Add exception(package private) void
add
(LDAPMessage msg) Add search entry of referral(package private) void
(package private) void
Prepares to return asynchronous results from a search(package private) void
(package private) void
closeOnCompletion
(LDAPConnection toClose) For asynchronous search, this mechanism allows the programmer to close a connection whenever the search completes.private void
Fetchs the next result, for asynchronous searches.int
getCount()
Returns a count of queued search results immediately available for processing.(package private) int
Returns message ID.Returns the controls returned with this search result.boolean
Returnstrue
if there are more search results to be returned.next()
Returns the next LDAP entry from the search results and throws an exception if the next result is a referral, or if a sizelimit or timelimit error occurred.Returns the next result from a search.(package private) Object
(package private) void
quicksort
(LDAPEntry[] toSort, LDAPEntryComparator compare, int low, int high) Basic quicksort algorithm.(package private) void
setMsgID
(int msgID) Sets the message ID for this search request.void
sort
(LDAPEntryComparator compare) Sorts the search results.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Enumeration
asIterator
-
Field Details
-
serialVersionUID
static final long serialVersionUID- See Also:
-
entries
-
resultSource
-
searchComplete
private boolean searchComplete -
connectionToClose
-
currConn
-
persistentSearch
private boolean persistentSearch -
currCons
-
currBase
-
currScope
private int currScope -
currFilter
-
currAttrs
-
currAttrsOnly
private boolean currAttrsOnly -
referralResults
-
exceptions
-
msgID
private int msgID -
firstResult
private boolean firstResult
-
-
Constructor Details
-
LDAPSearchResults
public LDAPSearchResults()Constructs an enumeration of search results. Note that this does not actually generate the results; you need to callLDAPConnection.search
to perform the search and get the results.- See Also:
-
LDAPSearchResults
LDAPSearchResults(LDAPConnection conn, LDAPSearchConstraints cons, String base, int scope, String filter, String[] attrs, boolean attrsOnly) -
LDAPSearchResults
Constructs an enumeration of search results. Used when returning results from a cache.- Parameters:
v
- the vector containing LDAPEntries- See Also:
-
LDAPSearchResults
LDAPSearchResults(Vector<Object> v, LDAPConnection conn, LDAPSearchConstraints cons, String base, int scope, String filter, String[] attrs, boolean attrsOnly)
-
-
Method Details
-
add
Add search entry of referral- Parameters:
msg
- LDAPSearchResult or LDAPsearchResultReference
-
add
Add exception- Parameters:
e
- exception
-
associate
Prepares to return asynchronous results from a search- Parameters:
l
- Listener which will provide results
-
associatePersistentSearch
-
addReferralEntries
-
closeOnCompletion
For asynchronous search, this mechanism allows the programmer to close a connection whenever the search completes.- Parameters:
toClose
- connection to close when the search terminates
-
quicksort
Basic quicksort algorithm. -
setMsgID
void setMsgID(int msgID) Sets the message ID for this search request. msgID is used to retrieve response controls.- Parameters:
msgID
- Message ID for this search request
-
getResponseControls
Returns the controls returned with this search result. If any control is registered withLDAPControl
, an attempt is made to instantiate the control. If the instantiation fails, the control is returned as a basicLDAPControl
.- Returns:
- an array of type
LDAPControl
. - See Also:
-
sort
Sorts the search results.The comparator (
LDAPEntryComparator
) determines the sort order used. For example, if the comparator uses theuid
attribute for comparison, the search results are sorted according touid
.The following section of code sorts results in ascending order, first by surname and then by common name.
String[] sortAttrs = {"sn", "cn"}; boolean[] ascending = {true, true}; LDAPConnection ld = new LDAPConnection(); ld.connect( ... ); LDAPSearchResults res = ld.search( ... ); res.sort( new LDAPCompareAttrNames(sortAttrs, ascending) );
NOTE: If the search results arrive asynchronously, thesort
method blocks until all the results are returned.If some of the elements of the Enumeration have already been fetched, the cursor is reset to the (new) first element.
- Parameters:
compare
- comparator used to determine the sort order of the results- See Also:
-
next
Returns the next LDAP entry from the search results and throws an exception if the next result is a referral, or if a sizelimit or timelimit error occurred.You can use this method in conjunction with the method to iterate through each entry in the search results. For example:
- Returns:
- the next LDAP entry in the search results.
- Throws:
LDAPReferralException
- A referral (thrown if the next result is a referral), or LDAPException if a limit on the number of entries or the time was exceeded.LDAPException
- See Also:
-
nextElement
Returns the next result from a search. You can use this method in conjunction with thehasMoreElements
method to iterate through all elements in the search results.Make sure to cast the returned element as the correct type. For example:
LDAPSearchResults res = ld.search( MY_SEARCHBASE, LDAPConnection.SCOPE_BASE, MY_FILTER, null, false ); while ( res.hasMoreElements() ) { Object o = res.nextElement(); if ( o instanceof LDAPEntry ) { LDAPEntry findEntry = (LDAPEntry)o; ... } else if ( o instanceof LDAPReferralException ) { LDAPReferralException e = (LDAPReferralException)o; LDAPUrl refUrls[] = e.getURLs(); ... } else if ( o instanceof LDAPException ) { LDAPException e = (LDAPException)o; ... } }
- Specified by:
nextElement
in interfaceEnumeration<Object>
- Returns:
- the next element in the search results.
- See Also:
-
nextReferralElement
Object nextReferralElement() -
hasMoreElements
public boolean hasMoreElements()Returnstrue
if there are more search results to be returned. You can use this method in conjunction with thenextElement
ornext
methods to iterate through each entry in the results. For example:LDAPSearchResults res = ld.search( MY_SEARCHBASE, LDAPConnection.SCOPE_BASE, MY_FILTER, null, false ); while ( res.hasMoreElements() ) { LDAPEntry findEntry = (LDAPEntry)res.nextElement(); ... }
- Specified by:
hasMoreElements
in interfaceEnumeration<Object>
- Returns:
true
if there are more search results.- See Also:
-
getCount
public int getCount()Returns a count of queued search results immediately available for processing. A search result is either a search entry or an exception. If the search is asynchronous (batch size not 0), this reports the number of results received so far.- Returns:
- count of search results immediatly available for processing
-
getMessageID
int getMessageID()Returns message ID.- Returns:
- Message ID.
-
fetchResult
private void fetchResult()Fetchs the next result, for asynchronous searches.
-