Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
netscape.ldap.LDAPSearchResults
public class LDAPSearchResults
extends java.lang.Object
implements Enumeration, java.io.Serializable
netscape.ldap.LDAPConnection.search(java.lang.String, int, java.lang.String, java.lang.String[], boolean)
, LDAPConnection.abandon(LDAPSearchResults)
, Serialized FormConstructor Summary | |
|
Method Summary | |
int |
|
LDAPControl[] |
|
boolean |
|
LDAPEntry |
|
Object |
|
void |
|
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:
netscape.ldap.LDAPConnection.search(java.lang.String, int, java.lang.String, java.lang.String[], boolean)
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
public LDAPControl[] 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:
LDAPControl.register(String,Class)
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(); ... }
- Returns:
true
if there are more search results.
- See Also:
nextElement()
,next()
public LDAPEntry next() throws LDAPException
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 thehasMoreElements
method to iterate through each entry in the search results. For example:LDAPSearchResults res = ld.search( MY_SEARCHBASE, LDAPConnection.SCOPE_BASE, MY_FILTER, null, false ); while ( res.hasMoreElements() ) { try { LDAPEntry findEntry = res.next(); } catch ( LDAPReferralException e ) { LDAPUrl refUrls[] = e.getURLs(); for ( int i = 0; i <32refUrls.length; i++ ) { // Your code for handling referrals } continue; } catch ( LDAPException e ) { // Your code for handling errors on limits exceeded continue; } ... }
- Returns:
- the next LDAP entry in the search results.
- See Also:
hasMoreElements()
public Object 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; ... } }
- Returns:
- the next element in the search results.
- See Also:
hasMoreElements()
public void sort(LDAPEntryComparator compare)
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:
LDAPEntryComparator