org.ldaptive.provider.jndi
Class JndiConnection.JndiSearchIterator

java.lang.Object
  extended by org.ldaptive.provider.jndi.JndiConnection.JndiSearchIterator
All Implemented Interfaces:
SearchIterator
Enclosing class:
JndiConnection

protected class JndiConnection.JndiSearchIterator
extends Object
implements SearchIterator

Search iterator for JNDI naming enumeration.


Constructor Summary
JndiConnection.JndiSearchIterator(SearchRequest sr)
          Creates a new jndi search iterator.
 
Method Summary
 void close()
          Close any resources associated with this iterator.
protected  String formatDn(SearchResult sr, String baseDn)
          Returns a fully-qualified DN for the supplied search result.
 Response<Void> getResponse()
          Returns the response data associated with this search or null if this iterator has more ldap entries to return.
protected  SearchControls getSearchControls(SearchRequest sr)
          Returns a search controls object configured with the supplied search request.
protected  String getSearchDn(LdapContext ctx, SearchRequest sr)
          Determines the DN of the supplied search request.
protected  int getSearchScope(SearchScope ss)
          Returns the jndi integer constant for the supplied search scope.
 boolean hasNext()
          Returns true if the iteration has more elements.
protected  ResultCode ignoreSearchException(ResultCode[] ignoreResultCodes, NamingException e)
          Determines whether the supplied naming exception should be ignored.
 void initialize()
          Initializes this jndi search iterator.
protected  void initializeSearchContext(LdapContext ctx, SearchRequest sr)
          Adds any additional environment properties found in the supplied request to the supplied context.
 SearchItem next()
          Returns the next element in the iteration.
protected  String readCompositeName(String s)
          Uses a composite name to parse the supplied string.
protected  String[] readReferralUrls(LdapReferralException refEx)
          Reads all referral URLs associated with this exception by invoking the search operation on the referral context until all referrals have been read.
protected  NamingEnumeration<SearchResult> search(LdapContext ctx, SearchRequest sr)
          Executes DirContext.search( javax.naming.Name, String, Object[], SearchControls).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JndiConnection.JndiSearchIterator

public JndiConnection.JndiSearchIterator(SearchRequest sr)
Creates a new jndi search iterator.

Parameters:
sr - search request
Method Detail

initialize

public void initialize()
                throws LdapException
Initializes this jndi search iterator.

Throws:
LdapException - if an error occurs

initializeSearchContext

protected void initializeSearchContext(LdapContext ctx,
                                       SearchRequest sr)
                                throws NamingException
Adds any additional environment properties found in the supplied request to the supplied context.

Parameters:
ctx - to initialize for searching
sr - to read properties from
Throws:
NamingException - if a property cannot be added to the context

search

protected NamingEnumeration<SearchResult> search(LdapContext ctx,
                                                 SearchRequest sr)
                                          throws NamingException
Executes DirContext.search( javax.naming.Name, String, Object[], SearchControls).

Parameters:
ctx - to search
sr - to read properties from
Returns:
naming enumeration of search results
Throws:
NamingException - if an error occurs

getSearchControls

protected SearchControls getSearchControls(SearchRequest sr)
Returns a search controls object configured with the supplied search request.

Parameters:
sr - search request containing configuration to create search controls
Returns:
search controls

getSearchScope

protected int getSearchScope(SearchScope ss)
Returns the jndi integer constant for the supplied search scope.

Parameters:
ss - search scope
Returns:
integer constant

hasNext

public boolean hasNext()
                throws LdapException
Returns true if the iteration has more elements.

Specified by:
hasNext in interface SearchIterator
Returns:
true if the iterator has more elements
Throws:
LdapException - if an error occurs

next

public SearchItem next()
                throws LdapException
Returns the next element in the iteration.

Specified by:
next in interface SearchIterator
Returns:
the next element in the iteration
Throws:
LdapException - if an error occurs

ignoreSearchException

protected ResultCode ignoreSearchException(ResultCode[] ignoreResultCodes,
                                           NamingException e)
Determines whether the supplied naming exception should be ignored.

Parameters:
ignoreResultCodes - to match against the exception
e - naming exception to match
Returns:
result code that should be ignored or null

readReferralUrls

protected String[] readReferralUrls(LdapReferralException refEx)
Reads all referral URLs associated with this exception by invoking the search operation on the referral context until all referrals have been read.

Parameters:
refEx - to read URLs from
Returns:
referral urls

getResponse

public Response<Void> getResponse()
Returns the response data associated with this search or null if this iterator has more ldap entries to return.

Specified by:
getResponse in interface SearchIterator
Returns:
response data

getSearchDn

protected String getSearchDn(LdapContext ctx,
                             SearchRequest sr)
                      throws NamingException
Determines the DN of the supplied search request. Returns Context.getNameInNamespace() if it is available, otherwise returns SearchRequest.getBaseDn().

Parameters:
ctx - ldap context the search was performed on
sr - search request
Returns:
DN
Throws:
NamingException - if an error occurs

formatDn

protected String formatDn(SearchResult sr,
                          String baseDn)
                   throws NamingException
Returns a fully-qualified DN for the supplied search result. If search result is relative, the DN is created with NameClassPair.getNameInNamespace(). Otherwise the behavior is controlled by JndiProviderConfig.getRemoveDnUrls().

Parameters:
sr - to determine DN for
baseDn - that search was performed on
Returns:
fully qualified DN
Throws:
NamingException - if search result name cannot be formatted as a DN

readCompositeName

protected String readCompositeName(String s)
                            throws InvalidNameException
Uses a composite name to parse the supplied string.

Parameters:
s - composite name to read
Returns:
ldap name
Throws:
InvalidNameException - if the supplied string is not a valid composite name

close

public void close()
           throws LdapException
Close any resources associated with this iterator.

Specified by:
close in interface SearchIterator
Throws:
LdapException - if an error occurs


Copyright © 2003-2015 Virginia Tech. All Rights Reserved.