* @return NamingEnumeration
*/
protected EntryFilteringCursor doSearchOperation( LdapDN dn, AliasDerefMode aliasDerefMode,
ExprNode filter, SearchControls searchControls ) throws Exception
{
OperationManager operationManager = service.getOperationManager();
EntryFilteringCursor results = null;
OperationContext opContext;
// We have to check if it's a compare operation or a search.
// A compare operation has a OBJECT scope search, the filter must
// be of the form (object=value) (no wildcards), and no attributes
// should be asked to be returned.
if ( ( searchControls.getSearchScope() == SearchControls.OBJECT_SCOPE )
&& ( ( searchControls.getReturningAttributes() != null )
&& ( searchControls.getReturningAttributes().length == 0 ) )
&& ( filter instanceof EqualityNode ) )
{
opContext = new CompareOperationContext( session, dn, ((EqualityNode)filter).getAttribute(), ((EqualityNode)filter).getValue() );
// Inject the referral handling into the operation context
injectReferralControl( opContext );
// Call the operation
boolean result = operationManager.compare( (CompareOperationContext)opContext );
// setup the op context and populate with request controls
opContext = new SearchOperationContext( session, dn, aliasDerefMode, filter,
searchControls );
opContext.addRequestControls( requestControls );
if ( result )
{
ServerEntry emptyEntry = new DefaultServerEntry( service.getRegistries(), LdapDN.EMPTY_LDAPDN );
return new BaseEntryFilteringCursor( new SingletonCursor<ServerEntry>( emptyEntry ), (SearchOperationContext)opContext );
}
else
{
return new BaseEntryFilteringCursor( new EmptyCursor<ServerEntry>(), (SearchOperationContext)opContext );
}
}
else
{
// It's a Search
// setup the op context and populate with request controls
opContext = new SearchOperationContext( session, dn, aliasDerefMode, filter,
searchControls );
opContext.addRequestControls( requestControls );
// Inject the referral handling into the operation context
injectReferralControl( opContext );
// execute search operation
results = operationManager.search( (SearchOperationContext)opContext );
}
// clear the request controls and set the response controls
requestControls = EMPTY_CONTROLS;
responseControls = opContext.getResponseControls();