Package com.unboundid.ldap.sdk
Class DNEntrySource
java.lang.Object
com.unboundid.ldap.sdk.EntrySource
com.unboundid.ldap.sdk.DNEntrySource
- All Implemented Interfaces:
Closeable,AutoCloseable
This class provides an
It is not necessary to close this entry source when it is no longer needed, although there is no cost or penalty in doing so. Any exceptions thrown by the
EntrySource that will retrieve entries
referenced by a provided set of DNs. The connection will remain open after
all entries have been read.
It is not necessary to close this entry source when it is no longer needed, although there is no cost or penalty in doing so. Any exceptions thrown by the
nextEntry() method will have the mayContinueReading
value set to true.
Example
The following example demonstrates the process for retrieving a static group entry and using aDNEntrySource to iterate across the members of that
group:
Entry groupEntry =
connection.getEntry("cn=My Group,ou=Groups,dc=example,dc=com");
String[] memberValues = groupEntry.getAttributeValues("member");
int entriesReturned = 0;
int exceptionsCaught = 0;
if (memberValues != null)
{
DNEntrySource entrySource =
new DNEntrySource(connection, memberValues, "cn");
try
{
while (true)
{
Entry memberEntry;
try
{
memberEntry = entrySource.nextEntry();
}
catch (EntrySourceException ese)
{
// A problem was encountered while attempting to obtain an entry.
// We may be able to continue reading entries (e.g., if the problem
// was that the group referenced an entry that doesn't exist), or
// we may not (e.g., if the problem was a significant search error
// or problem with the connection).
exceptionsCaught++;
if (ese.mayContinueReading())
{
continue;
}
else
{
break;
}
}
if (memberEntry == null)
{
// We've retrieved all of the entries for the given set of DNs.
break;
}
else
{
entriesReturned++;
}
}
}
finally
{
entrySource.close();
}
}
-
Constructor Summary
ConstructorsConstructorDescriptionDNEntrySource(LDAPInterface connection, DN[] dns, String... attributes) Creates a new DN entry source with the provided information.DNEntrySource(LDAPInterface connection, String[] dns, String... attributes) Creates a new DN entry source with the provided information.DNEntrySource(LDAPInterface connection, Collection<String> dns, String... attributes) Creates a new DN entry source with the provided information. -
Method Summary
-
Constructor Details
-
DNEntrySource
public DNEntrySource(@NotNull LDAPInterface connection, @NotNull DN[] dns, @Nullable String... attributes) Creates a new DN entry source with the provided information.- Parameters:
connection- The connection to the directory server from which the entries will be read. It must not benull.dns- The set of DNs to be read. It must not benull.attributes- The set of attributes to include in entries that are returned. If this is empty ornull, then all user attributes will be requested.
-
DNEntrySource
public DNEntrySource(@NotNull LDAPInterface connection, @NotNull String[] dns, @Nullable String... attributes) Creates a new DN entry source with the provided information.- Parameters:
connection- The connection to the directory server from which the entries will be read. It must not benull.dns- The set of DNs to be read. It must not benull.attributes- The set of attributes to include in entries that are returned. If this is empty ornull, then all user attributes will be requested.
-
DNEntrySource
public DNEntrySource(@NotNull LDAPInterface connection, @NotNull Collection<String> dns, @Nullable String... attributes) Creates a new DN entry source with the provided information.- Parameters:
connection- The connection to the directory server from which the entries will be read. It must not benull.dns- The set of DNs to be read. It must not benull.attributes- The set of attributes to include in entries that are returned. If this is empty ornull, then all user attributes will be requested.
-
-
Method Details
-
nextEntry
Retrieves the next entry from the entry source, if there is at least one remaining entry. This method may block if no entries are immediately available.- Specified by:
nextEntryin classEntrySource- Returns:
- The next entry from the entry source, or
nullif there are no more entries to retrieve. - Throws:
EntrySourceException- If a problem occurs while attempting to read the next entry from the entry source.
-
close
Indicates that this entry source will no longer be needed and any resources associated with it may be closed. This method MUST be called if the entry source is no longer needed before all entries have been read. It MAY be called after all entries have been read with no ill effects, but this is not necessary as the entry source will have already been closed after all entries have been read.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classEntrySource
-