* @return NamingEnumeration
*/
protected EntryFilteringCursor doSearchOperation( DN dn, AliasDerefMode aliasDerefMode,
ExprNode filter, SearchControls searchControls ) throws Exception
{
OperationManager operationManager = service.getOperationManager();
EntryFilteringCursor results = null;
OperationContext opContext;
Object typesOnlyObj = getEnvironment().get( "java.naming.ldap.typesOnly" );
boolean typesOnly = false;
if( typesOnlyObj != null )
{
typesOnly = Boolean.parseBoolean( typesOnlyObj.toString() );
}
// 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, filter,
searchControls );
((SearchOperationContext)opContext).setAliasDerefMode( aliasDerefMode );
opContext.addRequestControls( JndiUtils.fromJndiControls( requestControls ) );
( ( SearchOperationContext ) opContext ).setTypesOnly( typesOnly );
if ( result )
{
ServerEntry emptyEntry = new DefaultServerEntry( service.getSchemaManager(), DN.EMPTY_DN );
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, filter, searchControls );
( ( SearchOperationContext ) opContext ).setAliasDerefMode( aliasDerefMode );
opContext.addRequestControls( JndiUtils.fromJndiControls( requestControls ) );
( ( SearchOperationContext ) opContext ).setTypesOnly( typesOnly );
// 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 = JndiUtils.toJndiControls( opContext.getResponseControls() );