/* (non-Javadoc)
* @see org.apache.directory.server.core.partition.PartitionNexus#search(org.apache.directory.server.core.interceptor.context.SearchOperationContext)
*/
public EntryFilteringCursor search( SearchOperationContext opContext ) throws Exception
{
DN base = opContext.getDn();
SearchControls searchCtls = opContext.getSearchControls();
ExprNode filter = opContext.getFilter();
// TODO since we're handling the *, and + in the EntryFilteringCursor
// we may not need this code: we need see if this is actually the
// case and remove this code.
if ( base.size() == 0 )
{
// We are searching from the rootDSE. We have to distinguish three cases :
// 1) The scope is OBJECT : we have to return the rootDSE entry, filtered
// 2) The scope is ONELEVEL : we have to return all the Namin
boolean isObjectScope = searchCtls.getSearchScope() == SearchControls.OBJECT_SCOPE;
boolean isOnelevelScope = searchCtls.getSearchScope() == SearchControls.ONELEVEL_SCOPE;
boolean isSublevelScope = searchCtls.getSearchScope() == SearchControls.SUBTREE_SCOPE;
// test for (objectClass=*)
boolean isSearchAll = false;
// We have to be careful, as we may have a filter which is not a PresenceFilter
if ( filter instanceof PresenceNode )
{
isSearchAll = ( ( PresenceNode ) filter ).getAttribute().equals( SchemaConstants.OBJECT_CLASS_AT_OID );
}
/*
* if basedn is "", filter is "(objectclass=*)" and scope is object
* then we have a request for the rootDSE
*/
if ( ( filter instanceof PresenceNode) && isObjectScope && isSearchAll )
{
return searchRootDSE( opContext );
}
else if ( isObjectScope && ( ! isSearchAll ) )
{
return new BaseEntryFilteringCursor( new EmptyCursor<ServerEntry>(), opContext );
}
else if( isOnelevelScope )
{
List<EntryFilteringCursor> cursors = new ArrayList<EntryFilteringCursor>();
for ( Partition p : partitions.values() )
{
opContext.setDn( p.getSuffixDn() );
opContext.setScope( SearchScope.OBJECT );
cursors.add( p.search( opContext ) );
}
return new CursorList( cursors, opContext );
}
else if ( isSublevelScope )
{
List<EntryFilteringCursor> cursors = new ArrayList<EntryFilteringCursor>();
for ( Partition p : partitions.values() )
{
ClonedServerEntry entry = p.lookup( new LookupOperationContext( directoryService.getAdminSession(), p.getSuffixDn() ) );
if( entry != null )
{
Partition backend = getPartition( entry.getDn() );
opContext.setDn( entry.getDn() );
cursors.add( backend.search( opContext ) );
}
}
// don't feed the above Cursors' list to a BaseEntryFilteringCursor it is skipping the naming context entry of each partition
return new CursorList( cursors, opContext );
}
// TODO : handle searches based on the RootDSE
throw new LdapNameNotFoundException();
}
base.normalize( schemaManager.getNormalizerMapping() );
Partition backend = getPartition( base );
return backend.search( opContext );
}