Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.contactlist
Class MetaContactListServiceImpl

java.lang.Object
  extended by net.java.sip.communicator.impl.contactlist.MetaContactListServiceImpl
All Implemented Interfaces:
EventListener, MetaContactListService, ContactCapabilitiesListener, ContactPresenceStatusListener, org.osgi.framework.ServiceListener

public class MetaContactListServiceImpl
extends Object
implements MetaContactListService, org.osgi.framework.ServiceListener, ContactPresenceStatusListener, ContactCapabilitiesListener

An implementation of the MetaContactListService that would connect to protocol service providers and build it s contact list accordingly basing itself on the contact list stored by the various protocol provider services and the contact list instance saved on the hard disk.

Author:
Emil Ivov

Field Summary
static int CONTACT_LIST_MODIFICATION_TIMEOUT
          The number of milliseconds to wait for confirmations of account modifications before deciding to drop.
(package private)  MetaContactGroupImpl rootMetaGroup
          The root of the meta contact list.
 
Fields inherited from interface net.java.sip.communicator.service.contactlist.MetaContactListService
PROVIDER_MASK_PROPERTY
 
Constructor Summary
MetaContactListServiceImpl()
          Creates an instance of this class.
 
Method Summary
 void addMetaContactListListener(MetaContactListListener listener)
          Adds a listener for MetaContactListChangeEvents posted after the tree changes.
 void addNewContactToMetaContact(ProtocolProviderService provider, MetaContact metaContact, String contactID)
          First makes the specified protocol provider create the contact as indicated by contactID, and then associates it to the _existing_ metaContact given as an argument.
 void addNewContactToMetaContact(ProtocolProviderService provider, MetaContact metaContact, String contactID, boolean fireEvent)
          First makes the specified protocol provider create the contact as indicated by contactID, and then associates it to the _existing_ metaContact given as an argument.
 void changeMetaContactAvatar(MetaContact metaContact, Contact protoContact, byte[] newAvatar)
          Sets the avatar for metaContact to be newAvatar.
 void contactPresenceStatusChanged(ContactPresenceStatusChangeEvent evt)
          Upon each status notification this method finds the corresponding meta contact and updates the ordering in its parent group.
 MetaContact createMetaContact(ProtocolProviderService provider, MetaContactGroup metaContactGroup, String contactID)
          First makes the specified protocol provider create a contact corresponding to the specified contactID, then creates a new MetaContact which will encapsulate the newly created protocol specific contact.
 MetaContactGroup createMetaContactGroup(MetaContactGroup parent, String groupName)
          Creates a MetaContactGroup with the specified group name.
 Iterator<MetaContact> findAllMetaContactsForProvider(ProtocolProviderService protocolProvider)
          Returns a list of all MetaContacts containing a protocol contact from the given ProtocolProviderService.
 Iterator<MetaContact> findAllMetaContactsForProvider(ProtocolProviderService protocolProvider, MetaContactGroup metaContactGroup)
          Returns a list of all MetaContacts contained in the given group and containing a protocol contact from the given ProtocolProviderService.
 MetaContact findMetaContactByContact(Contact contact)
          Returns the MetaContact containing the specified contact or null if no such MetaContact was found.
 MetaContact findMetaContactByContact(String contactAddress, String accountID)
          Returns the MetaContact containing a contact with an address equal to contactAddress and with a source provider matching accountID, or null if no such MetaContact was found.
 MetaContact findMetaContactByMetaUID(String metaContactID)
          Returns the MetaContact that corresponds to the specified metaContactID.
 MetaContactGroup findMetaContactGroupByContactGroup(ContactGroup contactGroup)
          Returns the MetaContactGroup corresponding to the specified contactGroup or null if no such MetaContactGroup was found.
 MetaContactGroup findMetaContactGroupByMetaUID(String metaGroupID)
          Returns the MetaContactGroup that corresponds to the specified metaGroupID.
 MetaContactGroup findParentMetaContactGroup(MetaContact child)
          Returns the meta contact group that is a direct parent of the specified child.
 MetaContactGroup findParentMetaContactGroup(MetaContactGroup child)
          Returns the meta contact group that is a direct parent of the specified child.
(package private)  void fireMetaContactEvent(MetaContactPropertyChangeEvent event)
          Creates the corresponding MetaContactPropertyChangeEvent instance and notifies all MetaContactListListeners that a MetaContact has been modified.
 MetaContactGroup getRoot()
          Returns the root MetaContactGroup in this contact list.
(package private)  ContactGroup loadStoredContactGroup(MetaContactGroupImpl containingMetaGroup, String contactGroupUID, ContactGroup parentProtoGroup, String persistentData, String accountID)
          Creates a unresolved instance of the proto specific contact group according to the specified arguments and adds it to containingMetaContactGroup
(package private)  void loadStoredMetaContact(MetaContactGroupImpl parentGroup, String metaUID, String displayName, Map<String,List<String>> details, List<MclStorageManager.StoredProtoContactDescriptor> protoContacts, String accountID)
          The method is called from the storage manager whenever a new contact has been parsed and it has to be created.
(package private)  MetaContactGroupImpl loadStoredMetaContactGroup(MetaContactGroupImpl parentGroup, String metaContactGroupUID, String displayName)
          The method is called from the storage manager whenever a new contact group has been parsed and it has to be created.
 void moveContact(Contact contact, MetaContact newParentMetaContact)
          Makes the specified contact a child of the newParent MetaContact.
 void moveContact(Contact contact, MetaContactGroup newParentMetaGroup)
          Makes the specified contact a child of the newParentMetaGroup MetaContactGroup.
 void moveMetaContact(MetaContact metaContact, MetaContactGroup newMetaGroup)
          Moves the specified MetaContact to newGroup.
 void purgeLocallyStoredContactListCopy()
          Removes local resources storing copies of the meta contact list.
 void removeContact(Contact contact)
          Deletes the specified contact from both the local contact list and (if applicable) the server stored contact list if supported by the corresponding protocol.
 void removeContactGroupFromMetaContactGroup(MetaContactGroupImpl metaContainer, ContactGroup groupToRemove, ProtocolProviderService sourceProvider)
          Removes the protocol specific group from the specified meta contact group and removes from meta contacts all proto contacts that belong to the same provider as the group which is being removed.
 void removeMetaContact(MetaContact metaContact)
          Removes the specified metaContact as well as all of its underlying contacts.
 void removeMetaContactGroup(MetaContactGroup groupToRemove)
          Removes the specified meta contact group, all its corresponding protocol specific groups and all their children.
 void removeMetaContactListListener(MetaContactListListener listener)
          Removes a listener previously added with addContactListListener.
 void renameMetaContact(MetaContact metaContact, String newDisplayName)
          Sets the display name for metaContact to be newName.
 void renameMetaContactGroup(MetaContactGroup group, String newGroupName)
          Renames the specified MetaContactGroup as indicated by the newName param.
 void serviceChanged(org.osgi.framework.ServiceEvent event)
          Implements the ServiceListener method.
 void start(org.osgi.framework.BundleContext bc)
          Starts this implementation of the MetaContactListService.
 void stop(org.osgi.framework.BundleContext bc)
          Prepares the meta contact list service for shutdown.
 void supportedOperationSetsChanged(ContactCapabilitiesEvent event)
          Notifies this listener that the list of the OperationSet capabilities of a Contact has changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rootMetaGroup

final MetaContactGroupImpl rootMetaGroup
The root of the meta contact list.


CONTACT_LIST_MODIFICATION_TIMEOUT

public static final int CONTACT_LIST_MODIFICATION_TIMEOUT
The number of milliseconds to wait for confirmations of account modifications before deciding to drop.

See Also:
Constant Field Values
Constructor Detail

MetaContactListServiceImpl

public MetaContactListServiceImpl()
Creates an instance of this class.

Method Detail

start

public void start(org.osgi.framework.BundleContext bc)
Starts this implementation of the MetaContactListService. The implementation would first restore a default contact list from what has been stored in a file. It would then connect to OSGI and retrieve any existing protocol providers and if
1) They provide implementations of OperationSetPersistentPresence, it would synchronize their contact lists with the local one (adding subscriptions for contacts that do not exist in the server stored contact list and adding locally contacts that were found on the server but not in the local file).

2) The only provide non persistent implementations of OperationSetPresence, the meta contact list impl would create subscriptions for all local contacts in the corresponding protocol provider.

This implementation would also start listening for any newly registered protocol provider implementations and perform the same algorithm with them.

Parameters:
bc - the currently valid OSGI bundle context.

stop

public void stop(org.osgi.framework.BundleContext bc)
Prepares the meta contact list service for shutdown.

Parameters:
bc - the currently active bundle context.

addMetaContactListListener

public void addMetaContactListListener(MetaContactListListener listener)
Adds a listener for MetaContactListChangeEvents posted after the tree changes.

Specified by:
addMetaContactListListener in interface MetaContactListService
Parameters:
listener - the listener to add

addNewContactToMetaContact

public void addNewContactToMetaContact(ProtocolProviderService provider,
                                       MetaContact metaContact,
                                       String contactID)
                                throws MetaContactListException
First makes the specified protocol provider create the contact as indicated by contactID, and then associates it to the _existing_ metaContact given as an argument.

Specified by:
addNewContactToMetaContact in interface MetaContactListService
Parameters:
provider - the ProtocolProviderService that should create the contact indicated by contactID.
metaContact - the meta contact where that the newly created contact should be associated to.
contactID - the identifier of the contact that the specified provider
Throws:
MetaContactListException - with an appropriate code if the operation fails for some reason.

addNewContactToMetaContact

public void addNewContactToMetaContact(ProtocolProviderService provider,
                                       MetaContact metaContact,
                                       String contactID,
                                       boolean fireEvent)
                                throws MetaContactListException
First makes the specified protocol provider create the contact as indicated by contactID, and then associates it to the _existing_ metaContact given as an argument.

Parameters:
provider - the ProtocolProviderService that should create the contact indicated by contactID.
metaContact - the meta contact where that the newly created contact should be associated to.
contactID - the identifier of the contact that the specified provider
fireEvent - specifies whether or not an even is to be fire at the end of the method.Used when this method is called upon creation of a new meta contact and not only a new contact.
Throws:
MetaContactListException - with an appropriate code if the operation fails for some reason.

findParentMetaContactGroup

public MetaContactGroup findParentMetaContactGroup(MetaContactGroup child)
Returns the meta contact group that is a direct parent of the specified child. If no parent is found null is returned.

Specified by:
findParentMetaContactGroup in interface MetaContactListService
Parameters:
child - the MetaContactGroup whose parent group we're looking for. If no parent is found null is returned.
Returns:
the MetaContactGroup that contains child or null if no parent was found.

findParentMetaContactGroup

public MetaContactGroup findParentMetaContactGroup(MetaContact child)
Returns the meta contact group that is a direct parent of the specified child.

Specified by:
findParentMetaContactGroup in interface MetaContactListService
Parameters:
child - the MetaContact whose parent group we're looking for.
Returns:
the MetaContactGroup
Throws:
IllegalArgumentException - if child is not an instance of MetaContactImpl

createMetaContact

public MetaContact createMetaContact(ProtocolProviderService provider,
                                     MetaContactGroup metaContactGroup,
                                     String contactID)
                              throws MetaContactListException
First makes the specified protocol provider create a contact corresponding to the specified contactID, then creates a new MetaContact which will encapsulate the newly created protocol specific contact.

Specified by:
createMetaContact in interface MetaContactListService
Parameters:
provider - a ref to ProtocolProviderService instance which will create the actual protocol specific contact.
metaContactGroup - the MetaContactGroup where the newly created meta contact should be stored.
contactID - a protocol specific string identifier indicating the contact the protocol provider should create.
Returns:
the newly created MetaContact
Throws:
MetaContactListException - with an appropriate code if the operation fails for some reason.

createMetaContactGroup

public MetaContactGroup createMetaContactGroup(MetaContactGroup parent,
                                               String groupName)
                                        throws MetaContactListException
Creates a MetaContactGroup with the specified group name. The meta contact group would only be created locally and resolved against the different server stored protocol contact lists upon the creation of the first protocol specific child contact in the respective group.

Specified by:
createMetaContactGroup in interface MetaContactListService
Parameters:
parent - the meta contact group inside which the new child group must be created.
groupName - the name of the MetaContactGroup to create.
Returns:
the newly created MetaContactGroup
Throws:
MetaContactListException - with an appropriate code if the operation fails for some reason.

renameMetaContactGroup

public void renameMetaContactGroup(MetaContactGroup group,
                                   String newGroupName)
Renames the specified MetaContactGroup as indicated by the newName param. The operation would only affect the local meta group and would not "touch" any encapsulated protocol specific group.

Specified by:
renameMetaContactGroup in interface MetaContactListService
Parameters:
group - the group to rename.
newGroupName - the new name of the MetaContactGroup to rename.

getRoot

public MetaContactGroup getRoot()
Returns the root MetaContactGroup in this contact list.

Specified by:
getRoot in interface MetaContactListService
Returns:
the root MetaContactGroup for this contact list.

renameMetaContact

public void renameMetaContact(MetaContact metaContact,
                              String newDisplayName)
                       throws IllegalArgumentException
Sets the display name for metaContact to be newName.

Specified by:
renameMetaContact in interface MetaContactListService
Parameters:
metaContact - the MetaContact that we are renaming
newDisplayName - a String containing the new display name for metaContact.
Throws:
IllegalArgumentException - if metaContact is not an instance that belongs to the underlying implementation.

changeMetaContactAvatar

public void changeMetaContactAvatar(MetaContact metaContact,
                                    Contact protoContact,
                                    byte[] newAvatar)
                             throws IllegalArgumentException
Sets the avatar for metaContact to be newAvatar.

Parameters:
metaContact - the MetaContact that change avatar
protoContact - the Contact> that change avatar
newAvatar - avatar image bytes
Throws:
IllegalArgumentException - if metaContact is not an instance that belongs to the underlying implementation.

moveContact

public void moveContact(Contact contact,
                        MetaContactGroup newParentMetaGroup)
                 throws MetaContactListException
Makes the specified contact a child of the newParentMetaGroup MetaContactGroup. If contact was previously a child of a meta contact, it will be removed from its old parent and to a newly created one even if they both are in the same group. If the specified contact was the only child of its previous parent, then the meta contact will also be moved.

Specified by:
moveContact in interface MetaContactListService
Parameters:
contact - the Contact to move to the
newParentMetaGroup - the MetaContactGroup where we'd like contact to be moved.
Throws:
MetaContactListException - with an appropriate code if the operation fails for some reason.

moveContact

public void moveContact(Contact contact,
                        MetaContact newParentMetaContact)
                 throws MetaContactListException
Makes the specified contact a child of the newParent MetaContact.

Specified by:
moveContact in interface MetaContactListService
Parameters:
contact - the Contact to move to the
newParentMetaContact - the MetaContact where we'd like contact to be moved.
Throws:
MetaContactListException - with an appropriate code if the operation fails for some reason.

moveMetaContact

public void moveMetaContact(MetaContact metaContact,
                            MetaContactGroup newMetaGroup)
                     throws MetaContactListException,
                            IllegalArgumentException
Moves the specified MetaContact to newGroup.

Specified by:
moveMetaContact in interface MetaContactListService
Parameters:
metaContact - the MetaContact to move.
newMetaGroup - the MetaContactGroup that should be the new parent of contact.
Throws:
MetaContactListException - with an appropriate code if the operation fails for some reason.
IllegalArgumentException - if newMetaGroup or metaCOntact do not come from this implementation.

removeContact

public void removeContact(Contact contact)
                   throws MetaContactListException
Deletes the specified contact from both the local contact list and (if applicable) the server stored contact list if supported by the corresponding protocol.

Specified by:
removeContact in interface MetaContactListService
Parameters:
contact - the contact to remove.
Throws:
MetaContactListException - with an appropriate code if the operation fails for some reason.

removeMetaContactListListener

public void removeMetaContactListListener(MetaContactListListener listener)
Removes a listener previously added with addContactListListener.

Specified by:
removeMetaContactListListener in interface MetaContactListService
Parameters:
listener - the listener to remove

removeMetaContact

public void removeMetaContact(MetaContact metaContact)
                       throws MetaContactListException
Removes the specified metaContact as well as all of its underlying contacts.

Specified by:
removeMetaContact in interface MetaContactListService
Parameters:
metaContact - the metaContact to remove.
Throws:
MetaContactListException - with an appropriate code if the operation fails for some reason.

removeMetaContactGroup

public void removeMetaContactGroup(MetaContactGroup groupToRemove)
                            throws MetaContactListException
Removes the specified meta contact group, all its corresponding protocol specific groups and all their children.

Specified by:
removeMetaContactGroup in interface MetaContactListService
Parameters:
groupToRemove - the MetaContactGroup to have removed.
Throws:
MetaContactListException - with an appropriate code if the operation fails for some reason.

removeContactGroupFromMetaContactGroup

public void removeContactGroupFromMetaContactGroup(MetaContactGroupImpl metaContainer,
                                                   ContactGroup groupToRemove,
                                                   ProtocolProviderService sourceProvider)
Removes the protocol specific group from the specified meta contact group and removes from meta contacts all proto contacts that belong to the same provider as the group which is being removed.

Parameters:
metaContainer - the MetaContactGroup that we'd like to remove a contact group from.
groupToRemove - the ContactGroup that we'd like removed.
sourceProvider - the ProtocolProvider that the contact group belongs to.

purgeLocallyStoredContactListCopy

public void purgeLocallyStoredContactListCopy()
Removes local resources storing copies of the meta contact list. This method is meant primarily to aid automated testing which may depend on beginning the tests with an empty local contact list.

Specified by:
purgeLocallyStoredContactListCopy in interface MetaContactListService

findMetaContactGroupByContactGroup

public MetaContactGroup findMetaContactGroupByContactGroup(ContactGroup contactGroup)
Returns the MetaContactGroup corresponding to the specified contactGroup or null if no such MetaContactGroup was found.

Specified by:
findMetaContactGroupByContactGroup in interface MetaContactListService
Parameters:
contactGroup - the protocol specific contactGroup that we're looking for.
Returns:
the MetaContactGroup corresponding to the specified contactGroup or null if no such MetaContactGroup was found.

findMetaContactByContact

public MetaContact findMetaContactByContact(Contact contact)
Returns the MetaContact containing the specified contact or null if no such MetaContact was found. The method can be used when for example we need to find the MetaContact that is the author of an incoming message and the corresponding ProtocolProviderService has only provided a Contact as its author.

Specified by:
findMetaContactByContact in interface MetaContactListService
Parameters:
contact - the protocol specific contact that we're looking for.
Returns:
the MetaContact containing the specified contact or null if no such contact is present in this contact list.

findMetaContactByContact

public MetaContact findMetaContactByContact(String contactAddress,
                                            String accountID)
Returns the MetaContact containing a contact with an address equal to contactAddress and with a source provider matching accountID, or null if no such MetaContact was found. The method can be used when for example we need to find the MetaContact that is the author of an incoming message and the corresponding ProtocolProviderService has only provided a Contact as its author.

Parameters:
contactAddress - the address of the protocol specific contact that we're looking for.
accountID - the ID of the account that the contact we're looking for must belong to.
Returns:
the MetaContact containing the specified contact or null if no such contact is present in this contact list.

findMetaContactByMetaUID

public MetaContact findMetaContactByMetaUID(String metaContactID)
Returns the MetaContact that corresponds to the specified metaContactID.

Specified by:
findMetaContactByMetaUID in interface MetaContactListService
Parameters:
metaContactID - a String identifier of a meta contact.
Returns:
the MetaContact with the specified string identifier or null if no such meta contact was found.

findMetaContactGroupByMetaUID

public MetaContactGroup findMetaContactGroupByMetaUID(String metaGroupID)
Returns the MetaContactGroup that corresponds to the specified metaGroupID.

Specified by:
findMetaContactGroupByMetaUID in interface MetaContactListService
Parameters:
metaGroupID - a String identifier of a meta contact group.
Returns:
the MetaContactGroup with the specified string identifier or null if no such meta contact was found.

findAllMetaContactsForProvider

public Iterator<MetaContact> findAllMetaContactsForProvider(ProtocolProviderService protocolProvider)
Returns a list of all MetaContacts containing a protocol contact from the given ProtocolProviderService.

Specified by:
findAllMetaContactsForProvider in interface MetaContactListService
Parameters:
protocolProvider - the ProtocolProviderService whose contacts we're looking for.
Returns:
a list of all MetaContacts containing a protocol contact from the given ProtocolProviderService.

findAllMetaContactsForProvider

public Iterator<MetaContact> findAllMetaContactsForProvider(ProtocolProviderService protocolProvider,
                                                            MetaContactGroup metaContactGroup)
Returns a list of all MetaContacts contained in the given group and containing a protocol contact from the given ProtocolProviderService.

Specified by:
findAllMetaContactsForProvider in interface MetaContactListService
Parameters:
protocolProvider - the ProtocolProviderService whose contacts we're looking for.
metaContactGroup - the parent group.
Returns:
a list of all MetaContacts containing a protocol contact from the given ProtocolProviderService.

serviceChanged

public void serviceChanged(org.osgi.framework.ServiceEvent event)
Implements the ServiceListener method. Verifies whether the passed event concerns a ProtocolProviderService and modifies the list of registered protocol providers accordingly.

Specified by:
serviceChanged in interface org.osgi.framework.ServiceListener
Parameters:
event - The ServiceEvent object.

fireMetaContactEvent

void fireMetaContactEvent(MetaContactPropertyChangeEvent event)
Creates the corresponding MetaContactPropertyChangeEvent instance and notifies all MetaContactListListeners that a MetaContact has been modified. Synchronized to avoid firing events when we are editing the account (there we temporally remove and then add again the storage manager and don't want anybody to interrupt us).

Parameters:
event - the event to dispatch.

contactPresenceStatusChanged

public void contactPresenceStatusChanged(ContactPresenceStatusChangeEvent evt)
Upon each status notification this method finds the corresponding meta contact and updates the ordering in its parent group.

Specified by:
contactPresenceStatusChanged in interface ContactPresenceStatusListener
Parameters:
evt - the ContactPresenceStatusChangeEvent describing the status change.

loadStoredMetaContactGroup

MetaContactGroupImpl loadStoredMetaContactGroup(MetaContactGroupImpl parentGroup,
                                                String metaContactGroupUID,
                                                String displayName)
The method is called from the storage manager whenever a new contact group has been parsed and it has to be created.

Parameters:
parentGroup - the group that contains the meta contact group we're about to load.
metaContactGroupUID - the unique identifier of the meta contact group.
displayName - the name of the meta contact group.
Returns:
the newly created meta contact group.

loadStoredContactGroup

ContactGroup loadStoredContactGroup(MetaContactGroupImpl containingMetaGroup,
                                    String contactGroupUID,
                                    ContactGroup parentProtoGroup,
                                    String persistentData,
                                    String accountID)
Creates a unresolved instance of the proto specific contact group according to the specified arguments and adds it to containingMetaContactGroup

Parameters:
containingMetaGroup - the MetaContactGroupImpl where the restored contact group should be added.
contactGroupUID - the unique identifier of the group.
parentProtoGroup - the identifier of the parent proto group.
persistentData - the persistent data last returned by the contact group.
accountID - the ID of the account that the proto group belongs to.
Returns:
a reference to the newly created (unresolved) contact group.

loadStoredMetaContact

void loadStoredMetaContact(MetaContactGroupImpl parentGroup,
                           String metaUID,
                           String displayName,
                           Map<String,List<String>> details,
                           List<MclStorageManager.StoredProtoContactDescriptor> protoContacts,
                           String accountID)
The method is called from the storage manager whenever a new contact has been parsed and it has to be created.

Parameters:
parentGroup - the group that contains the meta contact we're about to load.
metaUID - the unique identifier of the meta contact.
displayName - the display name of the meta contact.
details - the details for the contact to create.
protoContacts - a list containing descriptors of proto contacts encapsulated by the meta contact that we're about to create.
accountID - the identifier of the account that the contacts originate from.

supportedOperationSetsChanged

public void supportedOperationSetsChanged(ContactCapabilitiesEvent event)
Notifies this listener that the list of the OperationSet capabilities of a Contact has changed.

Specified by:
supportedOperationSetsChanged in interface ContactCapabilitiesListener
Parameters:
event - a ContactCapabilitiesEvent with ID ContactCapabilitiesEvent.SUPPORTED_OPERATION_SETS_CHANGED which specifies the Contact whose list of OperationSet capabilities has changed

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.