|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnetscape.ldap.LDAPSearchResults
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.
LDAPConnection.search(java.lang.String, int, java.lang.String, java.lang.String[], boolean)
,
LDAPConnection.abandon(netscape.ldap.LDAPSearchResults)
,
Serialized FormField Summary | |
(package private) static long |
serialVersionUID
|
Constructor Summary | |
|
LDAPSearchResults()
Constructs an enumeration of search results. |
(package private) |
LDAPSearchResults(LDAPConnection conn,
LDAPSearchConstraints cons,
java.lang.String base,
int scope,
java.lang.String filter,
java.lang.String[] attrs,
boolean attrsOnly)
|
(package private) |
LDAPSearchResults(java.util.Vector v)
Constructs an enumeration of search results. |
(package private) |
LDAPSearchResults(java.util.Vector v,
LDAPConnection conn,
LDAPSearchConstraints cons,
java.lang.String base,
int scope,
java.lang.String filter,
java.lang.String[] attrs,
boolean attrsOnly)
|
Method Summary | |
(package private) void |
add(LDAPException e)
Add exception |
(package private) void |
add(LDAPMessage msg)
Add search entry of referral |
(package private) void |
addReferralEntries(LDAPSearchResults res)
|
(package private) void |
associate(LDAPSearchListener l)
Prepares to return asynchronous results from a search |
(package private) void |
associatePersistentSearch(LDAPSearchListener l)
|
(package private) void |
closeOnCompletion(LDAPConnection toClose)
For asynchronous search, this mechanism allows the programmer to close a connection whenever the search completes. |
int |
getCount()
Returns a count of queued search results immediately available for processing. |
(package private) int |
getMessageID()
Returns message ID. |
LDAPControl[] |
getResponseControls()
Returns the controls returned with this search result. |
boolean |
hasMoreElements()
Returns true if there are more search results
to be returned. |
LDAPEntry |
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. |
java.lang.Object |
nextElement()
Returns the next result from a search. |
(package private) java.lang.Object |
nextReferralElement()
|
(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 |
Field Detail |
static final long serialVersionUID
Constructor Detail |
public LDAPSearchResults()
LDAPConnection.search
to
perform the search and get the results.
LDAPConnection.search(java.lang.String, int, java.lang.String, java.lang.String[], boolean)
LDAPSearchResults(LDAPConnection conn, LDAPSearchConstraints cons, java.lang.String base, int scope, java.lang.String filter, java.lang.String[] attrs, boolean attrsOnly)
LDAPSearchResults(java.util.Vector v)
v
- the vector containing LDAPEntriesLDAPConnection.search(java.lang.String, int, java.lang.String, java.lang.String[], boolean)
LDAPSearchResults(java.util.Vector v, LDAPConnection conn, LDAPSearchConstraints cons, java.lang.String base, int scope, java.lang.String filter, java.lang.String[] attrs, boolean attrsOnly)
Method Detail |
void add(LDAPMessage msg)
msg
- LDAPSearchResult or LDAPsearchResultReferencevoid add(LDAPException e)
e
- exceptionvoid associate(LDAPSearchListener l)
l
- Listener which will provide resultsvoid associatePersistentSearch(LDAPSearchListener l)
void addReferralEntries(LDAPSearchResults res)
void closeOnCompletion(LDAPConnection toClose)
toClose
- connection to close when the search terminatesvoid quicksort(LDAPEntry[] toSort, LDAPEntryComparator compare, int low, int high)
void setMsgID(int msgID)
msgID
- Message ID for this search requestpublic LDAPControl[] getResponseControls()
LDAPControl
, an attempt is made to
instantiate the control. If the instantiation fails, the control is
returned as a basic LDAPControl
.
LDAPControl
.LDAPControl.register(java.lang.String, java.lang.Class)
public void sort(LDAPEntryComparator compare)
The comparator (LDAPEntryComparator
) determines the
sort order used. For example, if the comparator uses the uid
attribute for comparison, the search results are sorted according to
uid
.
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, the
sort
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.
compare
- comparator used to determine the sort order of the resultsLDAPEntryComparator
public LDAPEntry next() throws LDAPException
You can use this method in conjunction with the
hasMoreElements
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 < refUrls.length; i++ ) { // Your code for handling referrals } continue; } catch ( LDAPException e ) { // Your code for handling errors on limits exceeded continue; } ... }
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
hasMoreElements()
public java.lang.Object nextElement()
hasMoreElements
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; ... } }
nextElement
in interface java.util.Enumeration
hasMoreElements()
java.lang.Object nextReferralElement()
public boolean hasMoreElements()
true
if there are more search results
to be returned. You can use this method in conjunction with the
nextElement
or next
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(); ... }
hasMoreElements
in interface java.util.Enumeration
true
if there are more search results.nextElement()
,
next()
public int getCount()
int getMessageID()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |