SubtreeSpecification ssNew = null;
SubtreeSpecification ssNew;
    public void modify( NextInterceptor next, Name name, int modOp, Attributes mods ) throws NamingException    {        Attributes entry = nexus.lookup( name );        Attribute objectClasses = entry.get( "objectClass" );        if ( objectClasses.contains( "subentry" ) && mods.get( "subtreeSpecification" ) != null )        {            SubtreeSpecification ssOld = ( SubtreeSpecification ) subtrees.remove( name.toString() );            SubtreeSpecification ssNew = null;            try            {                ssNew = ssParser.parse( ( String ) mods.get( "subtreeSpecification" ).get() );            }            catch ( Exception e )            {                String msg = "failed to parse the new subtreeSpecification";                log.error( msg, e );                throw new LdapInvalidAttributeValueException( msg, ResultCodeEnum.INVALIDATTRIBUTESYNTAX );            }            subtrees.put( name.toString(), ssNew );            next.modify( name, modOp, mods );            // search for all entries selected by the old SS and remove references to subentry            Name apName = ( Name ) name.clone();            apName.remove( apName.size() - 1 );            Name oldBaseDn = ( Name ) apName.clone();            oldBaseDn.addAll( ssOld.getBase() );            ExprNode filter = new PresenceNode( "objectClass" );            SearchControls controls = new SearchControls();            controls.setSearchScope( SearchControls.SUBTREE_SCOPE );            controls.setReturningAttributes( new String[] { "+", "*" } );            NamingEnumeration subentries = nexus.search( oldBaseDn, factoryCfg.getEnvironment(), filter, controls );            while ( subentries.hasMore() )            {                SearchResult result = ( SearchResult ) subentries.next();                Attributes candidate = result.getAttributes();                Name dn = dnParser.parse( result.getName() );                if ( evaluator.evaluate( ssOld, apName, dn, candidate.get( "objectClass" ) ) )                {                    nexus.modify( dn, getOperationalModsForRemove( name, candidate ) );                }            }            // search for all selected entries by the new SS and add references to subentry            Attributes apAttrs = nexus.lookup( apName );            Attribute administrativeRole = apAttrs.get( "administrativeRole" );            Attributes operational = getSubentryOperatationalAttributes( name, administrativeRole );            Name newBaseDn = ( Name ) apName.clone();            newBaseDn.addAll( ssNew.getBase() );            subentries = nexus.search( newBaseDn, factoryCfg.getEnvironment(), filter, controls );            while ( subentries.hasMore() )            {                SearchResult result = ( SearchResult ) subentries.next();                Attributes candidate = result.getAttributes();                Name dn = dnParser.parse( result.getName() );                if ( evaluator.evaluate( ssNew, apName, dn, candidate.get( "objectClass" ) ) )                {                    nexus.modify( dn, getOperationalModsForAdd( candidate, operational ) );                }            }        }        else        {            next.modify( name, modOp, mods );        }    }