Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.protocol.jabber
Class ServerStoredContactListJabberImpl

java.lang.Object
  extended by net.java.sip.communicator.impl.protocol.jabber.ServerStoredContactListJabberImpl

public class ServerStoredContactListJabberImpl
extends Object

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:
Damian Minkov, Emil Ivov

Constructor Summary
ServerStoredContactListJabberImpl(OperationSetPersistentPresenceJabberImpl parentOperationSet, ProtocolProviderServiceJabberImpl provider)
          Creates a ServerStoredContactList wrapper for the specified BuddyList.
 
Method Summary
 void addContact(ContactGroup parent, String id)
          Adds a new contact with the specified screenname to the list under the specified group.
 void addContact(String id)
          Adds a new contact with the specified screenname to the list under a default location.
protected  void addContactForImageUpdate(ContactJabberImpl c)
          when there is no image for contact we must retrieve it add contacts for image update
(package private)  void addGroupListener(ServerStoredGroupListener listener)
          Registers the specified group listener so that it would receive events on group modification/creation/destruction.
(package private)  void cleanup()
          Cleanups references and listeners.
 void createGroup(String groupName)
          Creates the specified group on the server stored contact list.
(package private)  ContactJabberImpl createUnresolvedContact(ContactGroup parentGroup, String id)
          Creates a non resolved contact for the specified address and inside the specified group.
(package private)  ContactGroupJabberImpl createUnresolvedContactGroup(String groupName)
          Creates a non resolved contact group for the specified name.
(package private)  ContactJabberImpl createVolatileContact(String id)
          Creates a non persistent contact for the specified address.
 ContactJabberImpl findContactById(String id)
          Returns the Contact with the specified id or null if no such id was found.
 ContactGroup findContactGroup(ContactJabberImpl child)
          Returns the ContactGroup containing the specified contact or null if no such group or contact exist.
 ContactGroupJabberImpl findContactGroup(String name)
          Returns the ConntactGroup with the specified name or null if no such group was found.
(package private)  void fireContactAdded(ContactGroup parentGroup, ContactJabberImpl contact)
          Make the parent persistent presence operation set dispatch a contact added event.
(package private)  void fireContactRemoved(ContactGroup parentGroup, ContactJabberImpl contact)
          Make the parent persistent presence operation set dispatch a contact removed event.
(package private)  void fireContactResolved(ContactGroup parentGroup, ContactJabberImpl contact)
          Make the parent persistent presence operation set dispatch a contact resolved event.
(package private)  ProtocolProviderServiceJabberImpl getParentProvider()
          Retrns a reference to the provider that created us.
 ContactGroup getRootGroup()
          Returns the root group of the contact list.
(package private)  org.jivesoftware.smack.RosterEntry getRosterEntry(String user)
          Returns the roster entry associated with the given XMPP address or null if the user is not an entry in the roster.
(package private)  org.jivesoftware.smack.RosterGroup getRosterGroup(String name)
          Returns the roster group with the specified name, or null if the group doesn't exist.
(package private)  void init(OperationSetPersistentPresenceJabberImpl.ContactChangesListener presenceChangeListener)
          Sets a reference to the currently active and valid instance of roster that this list is to use for retrieving server stored information
(package private) static boolean isEntryDisplayable(org.jivesoftware.smack.RosterEntry entry)
          Some roster entries are not supposed to be seen.
 void moveContact(ContactJabberImpl contact, ContactGroupJabberImpl newParent)
          Moves the specified contact to the group indicated by newParent.
(package private)  void removeContact(ContactJabberImpl contactToRemove)
          Removes a contact from the serverside list Event will come for successful operation
 void removeGroup(ContactGroupJabberImpl groupToRemove)
          Removes the specified group from the buddy list.
(package private)  void removeGroupListener(ServerStoredGroupListener listener)
          Removes the specified group listener so that it won't receive further events on group modification/creation/destruction.
 void renameGroup(ContactGroupJabberImpl groupToRename, String newName)
          Renames the specified group according to the specified new name..
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServerStoredContactListJabberImpl

ServerStoredContactListJabberImpl(OperationSetPersistentPresenceJabberImpl parentOperationSet,
                                  ProtocolProviderServiceJabberImpl provider)
Creates a ServerStoredContactList wrapper for the specified BuddyList.

Parameters:
parentOperationSet - the operation set that created us and that we could use for dispatching subscription events
provider - the provider that has instantiated us.
Method Detail

getRootGroup

public ContactGroup getRootGroup()
Returns the root group of the contact list.

Returns:
the root ContactGroup for the ContactList

getRosterEntry

org.jivesoftware.smack.RosterEntry getRosterEntry(String user)
Returns the roster entry associated with the given XMPP address or null if the user is not an entry in the roster.

Parameters:
user - the XMPP address of the user (e.g. "jsmith@example.com"). The address could be in any valid format (e.g. "domain/resource", "user@domain" or "user@domain/resource").
Returns:
the roster entry or null if it does not exist.

getRosterGroup

org.jivesoftware.smack.RosterGroup getRosterGroup(String name)
Returns the roster group with the specified name, or null if the group doesn't exist.

Parameters:
name - the name of the group.
Returns:
the roster group with the specified name.

addGroupListener

void addGroupListener(ServerStoredGroupListener listener)
Registers the specified group listener so that it would receive events on group modification/creation/destruction.

Parameters:
listener - the ServerStoredGroupListener to register for group events

removeGroupListener

void removeGroupListener(ServerStoredGroupListener listener)
Removes the specified group listener so that it won't receive further events on group modification/creation/destruction.

Parameters:
listener - the ServerStoredGroupListener to unregister

fireContactRemoved

void fireContactRemoved(ContactGroup parentGroup,
                        ContactJabberImpl contact)
Make the parent persistent presence operation set dispatch a contact removed event.

Parameters:
parentGroup - the group where that the removed contact belonged to.
contact - the contact that was removed.

getParentProvider

ProtocolProviderServiceJabberImpl getParentProvider()
Retrns a reference to the provider that created us.

Returns:
a reference to a ProtocolProviderServiceImpl instance.

findContactGroup

public ContactGroupJabberImpl findContactGroup(String name)
Returns the ConntactGroup with the specified name or null if no such group was found.

Parameters:
name - the name of the group we're looking for.
Returns:
a reference to the ContactGroupJabberImpl instance we're looking for or null if no such group was found.

findContactById

public ContactJabberImpl findContactById(String id)
Returns the Contact with the specified id or null if no such id was found.

Parameters:
id - the id of the contact to find.
Returns:
the Contact carrying the specified screenName or null if no such contact exits.

findContactGroup

public ContactGroup findContactGroup(ContactJabberImpl child)
Returns the ContactGroup containing the specified contact or null if no such group or contact exist.

Parameters:
child - the contact whose parent group we're looking for.
Returns:
the ContactGroup containing the specified contact or null if no such groupo or contact exist.

addContact

public void addContact(String id)
                throws OperationFailedException
Adds a new contact with the specified screenname to the list under a default location.

Parameters:
id - the id of the contact to add.
Throws:
OperationFailedException

addContact

public void addContact(ContactGroup parent,
                       String id)
                throws OperationFailedException
Adds a new contact with the specified screenname to the list under the specified group.

Parameters:
id - the id of the contact to add.
parent - the group under which we want the new contact placed.
Throws:
OperationFailedException - if the contact already exist

createVolatileContact

ContactJabberImpl createVolatileContact(String id)
Creates a non persistent contact for the specified address. This would also create (if necessary) a group for volatile contacts that would not be added to the server stored contact list. This method would have no effect on the server stored contact list.

Parameters:
id - the address of the contact to create.
Returns:
the newly created volatile ContactImpl

createUnresolvedContact

ContactJabberImpl createUnresolvedContact(ContactGroup parentGroup,
                                          String id)
Creates a non resolved contact for the specified address and inside the specified group. The newly created contact would be added to the local contact list as a standard contact but when an event is received from the server concerning this contact, then it will be reused and only its isResolved field would be updated instead of creating the whole contact again.

Parameters:
parentGroup - the group where the unersolved contact is to be created
id - the Address of the contact to create.
Returns:
the newly created unresolved ContactImpl

createUnresolvedContactGroup

ContactGroupJabberImpl createUnresolvedContactGroup(String groupName)
Creates a non resolved contact group for the specified name. The newly created group would be added to the local contact list as any other group but when an event is received from the server concerning this group, then it will be reused and only its isResolved field would be updated instead of creating the whole group again.

Parameters:
groupName - the name of the group to create.
Returns:
the newly created unresolved ContactGroupImpl

createGroup

public void createGroup(String groupName)
                 throws OperationFailedException
Creates the specified group on the server stored contact list.

Parameters:
groupName - a String containing the name of the new group.
Throws:
OperationFailedException - with code CONTACT_GROUP_ALREADY_EXISTS if the group we're trying to create is already in our contact list.

removeGroup

public void removeGroup(ContactGroupJabberImpl groupToRemove)
Removes the specified group from the buddy list.

Parameters:
groupToRemove - the group that we'd like removed.

removeContact

void removeContact(ContactJabberImpl contactToRemove)
             throws OperationFailedException
Removes a contact from the serverside list Event will come for successful operation

Parameters:
contactToRemove - ContactJabberImpl
Throws:
OperationFailedException

renameGroup

public void renameGroup(ContactGroupJabberImpl groupToRename,
                        String newName)
Renames the specified group according to the specified new name..

Parameters:
groupToRename - the group that we'd like removed.
newName - the new name of the group

moveContact

public void moveContact(ContactJabberImpl contact,
                        ContactGroupJabberImpl newParent)
Moves the specified contact to the group indicated by newParent.

Parameters:
contact - the contact that we'd like moved under the new group.
newParent - the group where we'd like the parent placed.

init

void init(OperationSetPersistentPresenceJabberImpl.ContactChangesListener presenceChangeListener)
Sets a reference to the currently active and valid instance of roster that this list is to use for retrieving server stored information


cleanup

void cleanup()
Cleanups references and listeners.


fireContactAdded

void fireContactAdded(ContactGroup parentGroup,
                      ContactJabberImpl contact)
Make the parent persistent presence operation set dispatch a contact added event.

Parameters:
parentGroup - the group where the new contact was added
contact - the contact that was added

fireContactResolved

void fireContactResolved(ContactGroup parentGroup,
                         ContactJabberImpl contact)
Make the parent persistent presence operation set dispatch a contact resolved event.

Parameters:
parentGroup - the group that the resolved contact belongs to.
contact - the contact that was resolved

addContactForImageUpdate

protected void addContactForImageUpdate(ContactJabberImpl c)
when there is no image for contact we must retrieve it add contacts for image update

Parameters:
c - ContactJabberImpl

isEntryDisplayable

static boolean isEntryDisplayable(org.jivesoftware.smack.RosterEntry entry)
Some roster entries are not supposed to be seen. Like some services automatically add contacts from their addressbook to the roster and those contacts are with subscription none. Best practices in XEP-0162. - subscription='both' or subscription='to' - ((subscription='none' or subscription='from') and ask='subscribe') - ((subscription='none' or subscription='from') and (name attribute or group child))

Parameters:
entry - the entry to check.
Returns:
is item to be hidden/ignored.

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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