* @return NamingEnumeration
*/
protected EntryFilteringCursor doSearchOperation( Dn dn, AliasDerefMode aliasDerefMode,
ExprNode filter, SearchControls searchControls ) throws Exception
{
OperationManager operationManager = service.getOperationManager();
EntryFilteringCursor results = null;
Object typesOnlyObj = getEnvironment().get( "java.naming.ldap.typesOnly" );
boolean typesOnly = false;
if( typesOnlyObj != null )
{
typesOnly = Boolean.parseBoolean( typesOnlyObj.toString() );
}
SearchOperationContext searchContext = null;
// 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 ) )
{
CompareOperationContext compareContext = new CompareOperationContext( session, dn, ((EqualityNode <?>)filter).getAttribute(), ((EqualityNode)filter).getValue() );
// Inject the referral handling into the operation context
injectReferralControl( compareContext );
// Call the operation
boolean result = operationManager.compare( compareContext );
// setup the op context and populate with request controls
searchContext = new SearchOperationContext( session, dn, filter,
searchControls );
searchContext.setAliasDerefMode( aliasDerefMode );
searchContext.addRequestControls( convertControls( true, requestControls ) );
searchContext.setTypesOnly( typesOnly );
if ( result )
{
Entry emptyEntry = new DefaultEntry( service.getSchemaManager(), Dn.EMPTY_DN );
return new BaseEntryFilteringCursor( new SingletonCursor<Entry>( emptyEntry ), searchContext );
}
else
{
return new BaseEntryFilteringCursor( new EmptyCursor<Entry>(), searchContext );
}
}
else
{
// It's a Search
// setup the op context and populate with request controls
searchContext = new SearchOperationContext( session, dn, filter, searchControls );
searchContext.setAliasDerefMode( aliasDerefMode );
searchContext.addRequestControls( convertControls( true, requestControls ) );
searchContext.setTypesOnly( typesOnly );
// Inject the referral handling into the operation context
injectReferralControl( searchContext );
// execute search operation
results = operationManager.search( searchContext );
}
// clear the request controls and set the response controls
requestControls = EMPTY_CONTROLS;
responseControls = JndiUtils.toJndiControls( getDirectoryService().getLdapCodecService(),