} catch( ReferralException e ) { ReferralImpl refs = new ReferralImpl(); result.setReferral( refs ); result.setResultCode( ResultCodeEnum.REFERRAL ); result.setErrorMessage( "Encountered referral attempting to handle modify request." );   do { refs.addLdapUrl( ( String ) e.getReferralInfo() ); } while( e.skipReferral() ); session.write( req.getResultResponse() ); return;
    public void messageReceived( IoSession session, Object request )    {        ModifyRequest req = ( ModifyRequest ) request;        LdapResult result = req.getResultResponse().getLdapResult();        try        {            LdapContext ctx = SessionRegistry.getSingleton().getLdapContext( session, null, true );            if ( req.getControls().containsKey( ManageDsaITControl.CONTROL_OID ) )            {                ctx.addToEnvironment( Context.REFERRAL, "ignore" );            }            else            {                ctx.addToEnvironment( Context.REFERRAL, "throw" );            }            ctx.setRequestControls( ( Control[] ) req.getControls().values().toArray( EMPTY_CONTROLS ) );            Object[] mods = req.getModificationItems().toArray( EMPTY );            ctx.modifyAttributes( req.getName(), ( ModificationItem[] ) mods );        }        catch ( NamingException e )        {            String msg = "failed to modify entry " + req.getName();            if ( LOG.isDebugEnabled() )            {                msg += ":\n" + ExceptionUtils.getStackTrace( e );            }            ResultCodeEnum code;            if ( e instanceof LdapException )            {                code = ( ( LdapException ) e ).getResultCode() ;            }            else            {                code = ResultCodeEnum.getBestEstimate( e, req.getType() );            }            result.setResultCode( code );            result.setErrorMessage( msg );            if ( ( e.getResolvedName() != null ) &&                    ( ( code == ResultCodeEnum.NOSUCHOBJECT ) ||                      ( code == ResultCodeEnum.ALIASPROBLEM ) ||                      ( code == ResultCodeEnum.INVALIDDNSYNTAX ) ||                      ( code == ResultCodeEnum.ALIASDEREFERENCINGPROBLEM ) ) )            {                result.setMatchedDn( e.getResolvedName().toString() );            }            session.write( req.getResultResponse() );            return;        }        result.setResultCode( ResultCodeEnum.SUCCESS );        session.write( req.getResultResponse() );        return;    }