Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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

java.lang.Object
  extended by net.java.sip.communicator.impl.contactlist.MclStorageManager
All Implemented Interfaces:
EventListener, MetaContactListListener

public class MclStorageManager
extends Object
implements MetaContactListListener

The class handles read / write operations over the file where a persistent copy of the meta contact list is stored.

The load / resolve strategy that we use when storing contact lists is roughly the following:

1) The MetaContactListService is started.
2) If no file exists for the meta contact list, create one. 3) We receive an OSGI event telling us that a new ProtocolProviderService is registered or we simply retrieve one that was already in the bundle 4) We look through the contact list file and load groups and contacts belonging to this new provider. Unresolved proto groups and contacts will be created for every one of them.

Author:
Emil Ivov

Nested Class Summary
(package private) static class MclStorageManager.StoredProtoContactDescriptor
          Contains details parsed out of the contact list xml file, necessary for creating unresolved contacts.
 
Constructor Summary
MclStorageManager()
           
 
Method Summary
 void childContactsReordered(MetaContactGroupEvent evt)
          We simply ignore - we're not interested in this kind of events.
(package private)  void extractContactsForAccount(String accountID)
          Parses the contact list file and calls corresponding "add" methods belonging to mclServiceImpl for every meta contact and meta contact group stored in the (contactlist.xml) file that correspond to a provider caring the specified accountID.
(package private)  boolean isStarted()
          Determines whether the storage manager has been properly started or in other words that it has successfully found and read the xml contact list file.
 void metaContactAdded(MetaContactEvent evt)
          Indicates that a MetaContact has been successfully added to the MetaContact list.
 void metaContactAvatarUpdated(MetaContactAvatarUpdateEvent evt)
          Indicates that a new avatar is available for a MetaContact.
 void metaContactGroupAdded(MetaContactGroupEvent evt)
          Creates XML nodes for the source metacontact group, its child meta contacts and associated protogroups and adds them to the xml contact list.
 void metaContactGroupModified(MetaContactGroupEvent evt)
          Determines the exact type of the change and acts accordingly by either updating group name or .
 void metaContactGroupRemoved(MetaContactGroupEvent evt)
          Removes the corresponding node from the xml document.
 void metaContactModified(MetaContactModifiedEvent evt)
          Indicates that a MetaContact has been modified.
 void metaContactMoved(MetaContactMovedEvent evt)
          Moves the corresponding node from its old parent to the node corresponding to the new parent meta group.
 void metaContactRemoved(MetaContactEvent evt)
          Removes the corresponding node from the xml document.
 void metaContactRenamed(MetaContactRenamedEvent evt)
          Changes the display name attribute of the specified meta contact node.
 void protoContactAdded(ProtoContactEvent evt)
          Indicates that a protocol specific Contact instance has been added to the list of protocol specific buddies in this MetaContact
 void protoContactModified(ProtoContactEvent evt)
          Updates the data stored for the contact that caused this event.
 void protoContactMoved(ProtoContactEvent evt)
          Indicates that a protocol specific Contact instance has been moved from within one MetaContact to another.
 void protoContactRemoved(ProtoContactEvent evt)
          Removes the corresponding node from the xml contact list.
(package private)  void removeContactListFile()
          Removes the file where we store contact lists.
(package private)  void start(org.osgi.framework.BundleContext bc, MetaContactListServiceImpl mclServImpl)
          Initializes the storage manager and makes it do initial load and parsing of the contact list file.
 void stop()
          Prepares the storage manager for shutdown.
 void storeContactListAndStopStorageManager()
          Stops the storage manager and performs a final write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MclStorageManager

public MclStorageManager()
Method Detail

isStarted

boolean isStarted()
Determines whether the storage manager has been properly started or in other words that it has successfully found and read the xml contact list file.

Returns:
true if the storage manager has been successfully initialized and false otherwise.

stop

public void stop()
Prepares the storage manager for shutdown.


start

void start(org.osgi.framework.BundleContext bc,
           MetaContactListServiceImpl mclServImpl)
     throws IOException,
            XMLException
Initializes the storage manager and makes it do initial load and parsing of the contact list file.

Parameters:
bc - a reference to the currently valid OSGI BundleContext
mclServImpl - a reference to the currently valid instance of the MetaContactListServiceImpl that we could use to pass parsed contacts and contact groups.
Throws:
IOException - if the contact list file specified file does not exist and could not be created.
XMLException - if there is a problem with the file syntax.

storeContactListAndStopStorageManager

public void storeContactListAndStopStorageManager()
Stops the storage manager and performs a final write


extractContactsForAccount

void extractContactsForAccount(String accountID)
                         throws XMLException
Parses the contact list file and calls corresponding "add" methods belonging to mclServiceImpl for every meta contact and meta contact group stored in the (contactlist.xml) file that correspond to a provider caring the specified accountID.

Parameters:
accountID - the identifier of the account whose contacts we're interested in.
Throws:
XMLException - if a problem occurs while parsing contact list contents.

metaContactAdded

public void metaContactAdded(MetaContactEvent evt)
Indicates that a MetaContact has been successfully added to the MetaContact list.

Specified by:
metaContactAdded in interface MetaContactListListener
Parameters:
evt - the MetaContactListEvent containing the corresponding contact

metaContactGroupAdded

public void metaContactGroupAdded(MetaContactGroupEvent evt)
Creates XML nodes for the source metacontact group, its child meta contacts and associated protogroups and adds them to the xml contact list.

Specified by:
metaContactGroupAdded in interface MetaContactListListener
Parameters:
evt - the MetaContactListEvent containing the corresponding contact

metaContactGroupRemoved

public void metaContactGroupRemoved(MetaContactGroupEvent evt)
Removes the corresponding node from the xml document.

Specified by:
metaContactGroupRemoved in interface MetaContactListListener
Parameters:
evt - the MetaContactGroupEvent containing the corresponding contact

metaContactMoved

public void metaContactMoved(MetaContactMovedEvent evt)
Moves the corresponding node from its old parent to the node corresponding to the new parent meta group.

Specified by:
metaContactMoved in interface MetaContactListListener
Parameters:
evt - the MetaContactListEvent containing the corresponding contact

metaContactRemoved

public void metaContactRemoved(MetaContactEvent evt)
Removes the corresponding node from the xml document.

Specified by:
metaContactRemoved in interface MetaContactListListener
Parameters:
evt - the MetaContactListEvent containing the corresponding contact

metaContactRenamed

public void metaContactRenamed(MetaContactRenamedEvent evt)
Changes the display name attribute of the specified meta contact node.

Specified by:
metaContactRenamed in interface MetaContactListListener
Parameters:
evt - the MetaContactListEvent containing the corresponding contact

protoContactModified

public void protoContactModified(ProtoContactEvent evt)
Updates the data stored for the contact that caused this event.

Specified by:
protoContactModified in interface MetaContactListListener
Parameters:
evt - the MetaContactListEvent containing the corresponding contact

metaContactModified

public void metaContactModified(MetaContactModifiedEvent evt)
Indicates that a MetaContact has been modified.

Specified by:
metaContactModified in interface MetaContactListListener
Parameters:
evt - the MetaContactModifiedEvent containing the corresponding contact

protoContactRemoved

public void protoContactRemoved(ProtoContactEvent evt)
Removes the corresponding node from the xml contact list.

Specified by:
protoContactRemoved in interface MetaContactListListener
Parameters:
evt - a reference to the corresponding ProtoContactEvent

childContactsReordered

public void childContactsReordered(MetaContactGroupEvent evt)
We simply ignore - we're not interested in this kind of events.

Specified by:
childContactsReordered in interface MetaContactListListener
Parameters:
evt - the MetaContactGroupEvent containing details of this event.

metaContactGroupModified

public void metaContactGroupModified(MetaContactGroupEvent evt)
Determines the exact type of the change and acts accordingly by either updating group name or .

Specified by:
metaContactGroupModified in interface MetaContactListListener
Parameters:
evt - the MetaContactListEvent containing the corresponding contact

protoContactAdded

public void protoContactAdded(ProtoContactEvent evt)
Indicates that a protocol specific Contact instance has been added to the list of protocol specific buddies in this MetaContact

Specified by:
protoContactAdded in interface MetaContactListListener
Parameters:
evt - a reference to the corresponding ProtoContactEvent

protoContactMoved

public void protoContactMoved(ProtoContactEvent evt)
Indicates that a protocol specific Contact instance has been moved from within one MetaContact to another.

Specified by:
protoContactMoved in interface MetaContactListListener
Parameters:
evt - a reference to the ProtoContactMovedEvent instance.

removeContactListFile

void removeContactListFile()
Removes the file where we store contact lists.


metaContactAvatarUpdated

public void metaContactAvatarUpdated(MetaContactAvatarUpdateEvent evt)
Indicates that a new avatar is available for a MetaContact.

Specified by:
metaContactAvatarUpdated in interface MetaContactListListener
Parameters:
evt - the MetaContactAvatarUpdateEvent containing details of this event

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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