return new SearchResponseIterator( req, list );
    public Iterator handle( ClientKey key, Object request )    {        LdapContext ctx;        SearchRequest req = ( SearchRequest ) request;        InitialContext ictx = SessionRegistry.getSingleton( null ).get( key );        NamingEnumeration list = null;        // check the attributes to see if a referral's ref attribute is included        String[] ids = null;        Collection retAttrs = new HashSet();        retAttrs.addAll( req.getAttributes() );        if ( retAttrs.size() > 0 && ! retAttrs.contains( "ref" ) )        {            retAttrs.add( "ref" );            ids = ( String [] ) retAttrs.toArray( ArrayUtils.EMPTY_STRING_ARRAY );        }        else if ( retAttrs.size() > 0 )        {            ids = ( String [] ) retAttrs.toArray( ArrayUtils.EMPTY_STRING_ARRAY );        }        // prepare all the search controls        SearchControls controls = new SearchControls();        controls.setCountLimit( req.getSizeLimit() );        controls.setTimeLimit( req.getTimeLimit() );        controls.setSearchScope( req.getScope().getValue() );        controls.setReturningObjFlag( req.getTypesOnly() );        controls.setReturningAttributes( ids );        controls.setDerefLinkFlag( true );        try        {            ctx = ( LdapContext ) ictx.lookup( "" );            ctx.addToEnvironment( DEREFALIASES_KEY, req.getDerefAliases().getName() );            list = ctx.search( req.getBase(), req.getFilter().toString(), controls );        }        catch ( NamingException e )        {            String msg = "failed on search operation:\n" + req + "\n";            msg += ExceptionUtils.getStackTrace( e );            SearchResponseDone resp = new SearchResponseDoneImpl( req.getMessageId() );            ResultCodeEnum rc = ResultCodeEnum.getBestEstimate( e, req.getType() );            resp.setLdapResult( new LdapResultImpl( resp ) );            resp.getLdapResult().setResultCode( rc );            resp.getLdapResult().setErrorMessage( msg );            if ( e.getResolvedName() != null )            {                resp.getLdapResult().setMatchedDn( e.getResolvedName().toString() );            }            else            {                resp.getLdapResult().setMatchedDn( "" );            }            return Collections.singleton( resp ).iterator();        }        return new SearchResponseIterator( req, list );    }