<commit_before>/*
 * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package net.java.sip.communicator.impl.protocol.msn;

import java.util.*;

import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
import net.sf.jml.*;
import net.sf.jml.event.*;
import net.sf.jml.impl.*;

/**
 * This class encapsulates the Roster class. Once created, it will
 * register itself as a listener to the encapsulated Roster and modify it's
 * local copy of Contacts and ContactGroups every time an event is generated
 * by the underlying framework. The class would also generate
 * corresponding sip-communicator events to all events coming from smack.
 *
 * @author <NAME>
 */
public class ServerStoredContactListMsnImpl
{
    private static final Logger logger =
        Logger.getLogger(ServerStoredContactListMsnImpl.class);

    /**
     * The name of the Volatile group
     */
    private static final String VOLATILE_GROUP_NAME = "NotInContactList";

    /**
     * The root contagroup. The container for all msn buddies and groups.
     */
    private RootContactGroupMsnImpl rootGroup = new RootContactGroupMsnImpl();

    /**
     * The operation set that created us and that we could use when dispatching
     * subscription events.
     */
    private OperationSetPersistentPresenceMsnImpl parentOperationSet = null;

    /**
     * The provider that is on top of us.
     */
    private ProtocolProviderServiceMsnImpl msnProvider = null;

    private MsnMessenger messenger = null;

    /**
     * Listeners that would receive event notifications for changes in group
     * names or other properties, removal or creation of groups.
     */
    private Vector serverStoredGroupListeners = new Vector();

    /**
     * Manages and fires contact list modifications
     */
    private EventManager contactListModManager = null;

    private ContactListModListenerImpl contactListModListenerImpl
        = new ContactListModListenerImpl();

    /**
     * indicates whether or not the contactlist is initialized and ready.
     */
    private boolean isInitialized = false;

    /**
     * Creates a ServerStoredContactList wrapper for the specified BuddyList.
     *
     * @param parentOperationSet the operation set that created us and that
     * we could use for dispatching subscription events
     * @param provider the provider that has instantiated us.
     */
    ServerStoredContactListMsnImpl(
        OperationSetPersistentPresenceMsnImpl parentOperationSet,
        ProtocolProviderServiceMsnImpl        provider)
    {
        //We need to init these as early as possible to ensure that the provider
        //and the operationsset would not be null in the incoming events.
        this.parentOperationSet = parentOperationSet;

        this.msnProvider = provider;

        // listens for provider registered events to set the isInitialized state
        // of the contact list
        provider.addRegistrationStateChangeListener(
            new RegistrationStateChangeListener()
            {
                public void registrationStateChanged(
                    RegistrationStateChangeEvent evt)
                {
                    if (evt.getNewState() == RegistrationState.UNREGISTERED
                        || evt.getNewState() == RegistrationState.AUTHENTICATION_FAILED
                        || evt.getNewState() == RegistrationState.CONNECTION_FAILED)
                    {
                        isInitialized = false;
                    }
                }
            }
        );
    }

    /**
     * Returns the root group of the contact list.
     *<commit_msg>Fix setting provider for the root group<commit_after>/*
 * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package net.java.sip.communicator.impl.protocol.msn;

import java.util.*;

import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
import net.sf.jml.*;
import net.sf.jml.event.*;
import net.sf.jml.impl.*;

/**
 * This class encapsulates the Roster class. Once created, it will
 * register itself as a listener to the encapsulated Roster and modify it's
 * local copy of Contacts and ContactGroups every time an event is generated
 * by the underlying framework. The class would also generate
 * corresponding sip-communicator events to all events coming from smack.
 *
 * @author <NAME>
 */
public class ServerStoredContactListMsnImpl
{
    private static final Logger logger =
        Logger.getLogger(ServerStoredContactListMsnImpl.class);

    /**
     * The name of the Volatile group
     */
    private static final String VOLATILE_GROUP_NAME = "NotInContactList";

    /**
     * The root contagroup. The container for all msn buddies and groups.
     */
    private RootContactGroupMsnImpl rootGroup = new RootContactGroupMsnImpl();

    /**
     * The operation set that created us and that we could use when dispatching
     * subscription events.
     */
    private OperationSetPersistentPresenceMsnImpl parentOperationSet = null;

    /**
     * The provider that is on top of us.
     */
    private ProtocolProviderServiceMsnImpl msnProvider = null;

    private MsnMessenger messenger = null;

    /**
     * Listeners that would receive event notifications for changes in group
     * names or other properties, removal or creation of groups.
     */
    private Vector serverStoredGroupListeners = new Vector();

    /**
     * Manages and fires contact list modifications
     */
    private EventManager contactListModManager = null;

    private ContactListModListenerImpl contactListModListenerImpl
        = new ContactListModListenerImpl();

    /**
     * indicates whether or not the contactlist is initialized and ready.
     */
    private boolean isInitialized = false;

    /**
     * Creates a ServerStoredContactList wrapper for the specified BuddyList.
     *
     * @param parentOperationSet the operation set that created us and that
     * we could use for dispatching subscription events
     * @param provider the provider that has instantiated us.
     */
    ServerStoredContactListMsnImpl(
        OperationSetPersistentPresenceMsnImpl parentOperationSet,
        ProtocolProviderServiceMsnImpl        provider)
    {
        //We need to init these as early as possible to ensure that the provider
        //and the operationsset would not be null in the incoming events.
        this.parentOperationSet = parentOperationSet;

        this.msnProvider = provider;
        rootGroup.setOwnerProvider(provider);

        // listens for provider registered events to set the isInitialized state
        // of the contact list
        provider.addRegistrationStateChangeListener(
            new RegistrationStateChangeListener()
            {
                public void registrationStateChanged(
                    RegistrationStateChangeEvent evt)
                {
                    if (evt.getNewState() == RegistrationState.UNREGISTERED
                        || evt.getNewState() == RegistrationState.AUTHENTICATION_FAILED
                        || evt.getNewState() == RegistrationState.CONNECTION_FAILED)
                    {
                        isInitialized = false;
                    }
                }
            }
        );
    }

    /**
     * Returns the root group of the contact list.
     *
{'fraction_non_alphanumeric': 0.0664754953076121, 'fraction_numerical': 0.0, 'mean_word_length': 2.560556844547564, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3876649', 'n_tokens_mistral': 1930, 'n_tokens_neox': 1861, 'n_words': 651}