protected void registerCapabilities( @Nonnull JID entity, @Nonnull EntityCapabilities newCapabilities )
    {
        entityCapabilitiesMap.put( newCapabilities.getVerAttribute(), newCapabilities );
        String oldVerAttribute;

        final Lock lock = entityCapabilitiesUserMap.getLock(entity.asBareJID());
        lock.lock();
        try {
            oldVerAttribute = entityCapabilitiesUserMap.put(entity, newCapabilities.getVerAttribute());
            String updatedVerValue = capabilitiesBeingUpdated.remove(entity);
            if (oldVerAttribute == null) {
                oldVerAttribute = updatedVerValue;
            }
        } finally {
            lock.unlock();
        }

        // Invoke listeners when capabilities changed.
        if (oldVerAttribute == null )
        {
            dispatch( entity, newCapabilities, null );
        }
        else if ( !oldVerAttribute.equals( newCapabilities.getVerAttribute() ) )
        {
            final EntityCapabilities oldCapabilities = entityCapabilitiesMap.get( oldVerAttribute );
            dispatch( entity, newCapabilities, oldCapabilities );
        }

        // If this replaced another 'ver' hash, purge the capabilities if needed.
        if ( oldVerAttribute != null && !oldVerAttribute.equals( newCapabilities.getVerAttribute() ) )
        {
            checkObsolete( oldVerAttribute );
        }
    }
Registers that a particular entity has a particular set of capabilities, invoking event listeners when
appropriate.

@param entity The entity for which a set of capabilities is detected.
@param newCapabilities The capabilities that are detected.
xmppserver/src/main/java/org/jivesoftware/openfire/entitycaps/EntityCapabilitiesManager.java