// clear old children
clearCaches( parent, purgeAllCaches );
// create search
ISearch search = createSearch( parent, pagedSearchControl, false, false, false );
// search
executeSearch( parent, search, monitor );
ISearchResult[] srs = search.getSearchResults();
SearchContinuation[] scs = search.getSearchContinuations();
// fill children in search result
if ( ( srs != null && srs.length > 0 ) || ( scs != null && scs.length > 0 ) )
{
// clearing old children before filling new children is
// necessary to handle aliases and referrals.
clearCaches( parent, false );
do
{
if ( srs != null )
{
for ( ISearchResult searchResult : srs )
{
parent.addChild( searchResult.getEntry() );
}
srs = null;
}
if ( scs != null )
{
for ( SearchContinuation searchContinuation : scs )
{
ContinuedSearchResultEntry entry = new ContinuedSearchResultEntry( parent
.getBrowserConnection(), searchContinuation.getUrl().getDn() );
entry.setUnresolved( searchContinuation.getUrl() );
parent.addChild( entry );
}
scs = null;
}
StudioPagedResultsControl sprRequestControl = null;
StudioPagedResultsControl sprResponseControl = null;
for ( StudioControl responseControl : search.getResponseControls() )
{
if ( responseControl instanceof StudioPagedResultsControl )
{
sprResponseControl = ( StudioPagedResultsControl ) responseControl;
}
}
for ( StudioControl requestControl : search.getControls() )
{
if ( requestControl instanceof StudioPagedResultsControl )
{
sprRequestControl = ( StudioPagedResultsControl ) requestControl;
}
}
if ( sprRequestControl != null && sprResponseControl != null )
{
if ( sprRequestControl.isScrollMode() )
{
if ( sprRequestControl.getCookie() != null )
{
// create top page search runnable, same as original search
InitializeChildrenRunnable topPageChildrenRunnable = new InitializeChildrenRunnable(
parent, null );
parent.setTopPageChildrenRunnable( topPageChildrenRunnable );
}
if ( sprResponseControl.getCookie() != null )
{
StudioPagedResultsControl newSprc = new StudioPagedResultsControl( sprRequestControl
.getSize(), sprResponseControl.getCookie(), sprRequestControl.isCritical(),
sprRequestControl.isScrollMode() );
InitializeChildrenRunnable nextPageChildrenRunnable = new InitializeChildrenRunnable(
parent, newSprc );
parent.setNextPageChildrenRunnable( nextPageChildrenRunnable );
}
}
else
{
// transparently continue search, till count limit is reached
if ( sprResponseControl.getCookie() != null
&& ( search.getCountLimit() == 0 || search.getSearchResults().length < search
.getCountLimit() ) )
{
search.setSearchResults( new ISearchResult[0] );
search.getResponseControls().clear();
sprRequestControl.setCookie( sprResponseControl.getCookie() );
executeSearch( parent, search, monitor );
srs = search.getSearchResults();
scs = search.getSearchContinuations();
}
}
}
}
while ( srs != null && srs.length > 0 );
}
else
{
parent.setHasChildrenHint( false );
}
// get sub-entries
ISearch subSearch = createSearch( parent, null, true, false, false );
if ( parent.getBrowserConnection().isFetchSubentries() || parent.isFetchSubentries() )
{
executeSubSearch( parent, subSearch, monitor );
}
// get aliases and referrals
ISearch aliasOrReferralSearch = createSearch( parent, null, false, parent.isFetchAliases(), parent
.isFetchReferrals() );
if ( parent.isFetchAliases() || parent.isFetchReferrals() )
{
executeSubSearch( parent, aliasOrReferralSearch, monitor );
}
// check exceeded limits / canceled
parent.setHasMoreChildren( search.isCountLimitExceeded() || subSearch.isCountLimitExceeded()
|| aliasOrReferralSearch.isCountLimitExceeded() || monitor.isCanceled() );
// set initialized state
parent.setChildrenInitialized( true );
}