Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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

java.lang.Object
  extended by net.java.sip.communicator.service.protocol.AbstractOperationSetPersistentPresence<ProtocolProviderServiceJabberImpl>
      extended by net.java.sip.communicator.impl.protocol.jabber.OperationSetPersistentPresenceJabberImpl
All Implemented Interfaces:
OperationSet, OperationSetPersistentPresence, OperationSetPresence

public class OperationSetPersistentPresenceJabberImpl
extends AbstractOperationSetPersistentPresence<ProtocolProviderServiceJabberImpl>

The Jabber implementation of a Persistent Presence Operation set. This class manages our own presence status as well as subscriptions for the presence status of our buddies. It also offers methods for retrieving and modifying the buddy contact list and adding listeners for changes in its layout.

Author:
Damian Minkov, Lubomir Marinov

Field Summary
 
Fields inherited from class net.java.sip.communicator.service.protocol.AbstractOperationSetPersistentPresence
parentProvider
 
Constructor Summary
OperationSetPersistentPresenceJabberImpl(ProtocolProviderServiceJabberImpl provider)
          Creates the OperationSet.
 
Method Summary
 void addServerStoredGroupChangeListener(ServerStoredGroupListener listener)
          Registers a listener that would receive events upon changes in server stored groups.
(package private)  void assertConnected()
          Utility method throwing an exception if the stack is not properly initialized.
 void createServerStoredContactGroup(ContactGroup parent, String groupName)
          Creates a group with the specified name and parent in the server stored contact list.
 Contact createUnresolvedContact(String address, String persistentData)
          Creates and returns a unresolved contact from the specified address and persistentData.
 Contact createUnresolvedContact(String address, String persistentData, ContactGroup parentGroup)
          Creates and returns a unresolved contact from the specified address and persistentData.
 ContactGroup createUnresolvedContactGroup(String groupUID, String persistentData, ContactGroup parentGroup)
          Creates and returns a unresolved contact group from the specified address and persistentData.
 ContactJabberImpl createVolatileContact(String id)
          Creates a non persistent contact for the specified address.
 Contact findContactByID(String contactID)
          Returns a reference to the contact with the specified ID in case we have a subscription for it and null otherwise/
(package private)  void firePresenceStatusChanged(org.jivesoftware.smack.packet.Presence presence)
          Fires the status change, respecting resource priorities.
 void fireProviderStatusChangeEvent(PresenceStatus oldStatus, PresenceStatus newStatus)
          Fires provider status change.
 String getCurrentStatusMessage()
          Returns the status message that was confirmed by the serfver
 Contact getLocalContact()
          Returns the protocol specific contact instance representing the local user.
 PresenceStatus getPresenceStatus()
          Returns a PresenceStatus instance representing the state this provider is currently in.
 int getResourcePriority()
          Returns the jabber account resource priority property value.
 ContactGroup getServerStoredContactListRoot()
          Returns the root group of the server stored contact list.
 Iterator<PresenceStatus> getSupportedStatusSet()
          Returns the set of PresenceStatus objects that a user of this service may request the provider to enter.
static PresenceStatus jabberStatusToPresenceStatus(org.jivesoftware.smack.packet.Presence presence, ProtocolProviderServiceJabberImpl jabberProvider)
          Converts the specified jabber status to one of the status fields of the JabberStatusEnum class.
 void moveContactToGroup(Contact contactToMove, ContactGroup newParent)
          Removes the specified contact from its current parent and places it under newParent.
static org.jivesoftware.smack.packet.Presence.Mode presenceStatusToJabberMode(PresenceStatus status)
          Converts the specified JabberStatusEnum member to the corresponding Jabber Mode
 void publishPresenceStatus(PresenceStatus status, String statusMessage)
          Requests the provider to enter into a status corresponding to the specified parameters.
 PresenceStatus queryContactStatus(String contactIdentifier)
          Gets the PresenceStatus of a contact with a specific String identifier.
 void removeServerStoredContactGroup(ContactGroup group)
          Removes the specified group from the server stored contact list.
 void removeServerStoredGroupChangeListener(ServerStoredGroupListener listener)
          Removes the specified group change listener so that it won't receive any further events.
 void renameServerStoredContactGroup(ContactGroup group, String newName)
          Renames the specified group from the server stored contact list.
 void setAuthorizationHandler(AuthorizationHandler handler)
          Handler for incoming authorization requests.
 void setDisplayName(Contact contact, String newName)
          Sets the display name for contact to be newName.
 void setResourcePriority(int resourcePriority)
          Updates the jabber account resource priority property value.
 void subscribe(ContactGroup parent, String contactIdentifier)
          Persistently adds a subscription for the presence status of the contact corresponding to the specified contactIdentifier and indicates that it should be added to the specified group of the server stored contact list.
 void subscribe(String contactIdentifier)
          Adds a subscription for the presence status of the contact corresponding to the specified contactIdentifier.
 void unsubscribe(Contact contact)
          Removes a subscription for the presence status of the specified contact.
 
Methods inherited from class net.java.sip.communicator.service.protocol.AbstractOperationSetPersistentPresence
addContactPresenceStatusListener, addProviderPresenceStatusListener, addSubscriptionListener, fireContactPresenceStatusChangeEvent, fireContactPresenceStatusChangeEvent, fireContactPropertyChangeEvent, fireProviderStatusChangeEvent, fireProviderStatusMessageChangeEvent, fireServerStoredGroupEvent, fireSubscriptionEvent, fireSubscriptionEvent, fireSubscriptionMovedEvent, removeContactPresenceStatusListener, removeProviderPresenceStatusListener, removeSubscriptionListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OperationSetPersistentPresenceJabberImpl

public OperationSetPersistentPresenceJabberImpl(ProtocolProviderServiceJabberImpl provider)
Creates the OperationSet.

Parameters:
provider - the parent provider.
Method Detail

addServerStoredGroupChangeListener

public void addServerStoredGroupChangeListener(ServerStoredGroupListener listener)
Registers a listener that would receive events upon changes in server stored groups.

Specified by:
addServerStoredGroupChangeListener in interface OperationSetPersistentPresence
Overrides:
addServerStoredGroupChangeListener in class AbstractOperationSetPersistentPresence<ProtocolProviderServiceJabberImpl>
Parameters:
listener - a ServerStoredGroupChangeListener impl that would receive events upon group changes.

createServerStoredContactGroup

public void createServerStoredContactGroup(ContactGroup parent,
                                           String groupName)
                                    throws OperationFailedException
Creates a group with the specified name and parent in the server stored contact list.

Parameters:
parent - the group where the new group should be created
groupName - the name of the new group to create.
Throws:
OperationFailedException - if such group already exists

createVolatileContact

public 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. The volatile contact would remain in the list until it is really added to the contact list or until the application is terminated.

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

createUnresolvedContact

public Contact createUnresolvedContact(String address,
                                       String persistentData,
                                       ContactGroup parentGroup)
Creates and returns a unresolved contact from the specified address and persistentData.

Parameters:
address - an identifier of the contact that we'll be creating.
persistentData - a String returned Contact's getPersistentData() method during a previous run and that has been persistently stored locally.
parentGroup - the group where the unresolved contact is supposed to belong to.
Returns:
the unresolved Contact created from the specified address and persistentData

createUnresolvedContact

public Contact createUnresolvedContact(String address,
                                       String persistentData)
Creates and returns a unresolved contact from the specified address and persistentData.

Parameters:
address - an identifier of the contact that we'll be creating.
persistentData - a String returned Contact's getPersistentData() method during a previous run and that has been persistently stored locally.
Returns:
the unresolved Contact created from the specified address and persistentData

createUnresolvedContactGroup

public ContactGroup createUnresolvedContactGroup(String groupUID,
                                                 String persistentData,
                                                 ContactGroup parentGroup)
Creates and returns a unresolved contact group from the specified address and persistentData.

Parameters:
groupUID - an identifier, returned by ContactGroup's getGroupUID, that the protocol provider may use in order to create the group.
persistentData - a String returned ContactGroups's getPersistentData() method during a previous run and that has been persistently stored locally.
parentGroup - the group under which the new group is to be created or null if this is group directly underneath the root.
Returns:
the unresolved ContactGroup created from the specified uid and persistentData

findContactByID

public Contact findContactByID(String contactID)
Returns a reference to the contact with the specified ID in case we have a subscription for it and null otherwise/

Parameters:
contactID - a String identifier of the contact which we're seeking a reference of.
Returns:
a reference to the Contact with the specified contactID or null if we don't have a subscription for the that identifier.

getCurrentStatusMessage

public String getCurrentStatusMessage()
Returns the status message that was confirmed by the serfver

Returns:
the last status message that we have requested and the aim server has confirmed.

getLocalContact

public Contact getLocalContact()
Returns the protocol specific contact instance representing the local user.

Returns:
the Contact (address, phone number, or uin) that the Provider implementation is communicating on behalf of.

getPresenceStatus

public PresenceStatus getPresenceStatus()
Returns a PresenceStatus instance representing the state this provider is currently in.

Returns:
the PresenceStatus last published by this provider.

getServerStoredContactListRoot

public ContactGroup getServerStoredContactListRoot()
Returns the root group of the server stored contact list.

Returns:
the root ContactGroup for the ContactList stored by this service.

getSupportedStatusSet

public Iterator<PresenceStatus> getSupportedStatusSet()
Returns the set of PresenceStatus objects that a user of this service may request the provider to enter.

Returns:
Iterator a PresenceStatus array containing "enterable" status instances.

moveContactToGroup

public void moveContactToGroup(Contact contactToMove,
                               ContactGroup newParent)
Removes the specified contact from its current parent and places it under newParent.

Parameters:
contactToMove - the Contact to move
newParent - the ContactGroup where Contact would be placed.

publishPresenceStatus

public void publishPresenceStatus(PresenceStatus status,
                                  String statusMessage)
                           throws IllegalArgumentException,
                                  IllegalStateException,
                                  OperationFailedException
Requests the provider to enter into a status corresponding to the specified parameters.

Parameters:
status - the PresenceStatus as returned by getRequestableStatusSet
statusMessage - the message that should be set as the reason to enter that status
Throws:
IllegalArgumentException - if the status requested is not a valid PresenceStatus supported by this provider.
IllegalStateException - if the provider is not currently registered.
OperationFailedException - with code NETWORK_FAILURE if publishing the status fails due to a network error.

queryContactStatus

public PresenceStatus queryContactStatus(String contactIdentifier)
                                  throws IllegalArgumentException,
                                         IllegalStateException,
                                         OperationFailedException
Gets the PresenceStatus of a contact with a specific String identifier.

Parameters:
contactIdentifier - the identifier of the contact whose status we're interested in.
Returns:
the PresenceStatus of the contact with the specified contactIdentifier
Throws:
IllegalArgumentException - if the specified contactIdentifier does not identify a contact known to the underlying protocol provider
IllegalStateException - if the underlying protocol provider is not registered/signed on a public service
OperationFailedException - with code NETWORK_FAILURE if retrieving the status fails due to errors experienced during network communication

removeServerStoredContactGroup

public void removeServerStoredContactGroup(ContactGroup group)
Removes the specified group from the server stored contact list.

Parameters:
group - the group to remove.

removeServerStoredGroupChangeListener

public void removeServerStoredGroupChangeListener(ServerStoredGroupListener listener)
Removes the specified group change listener so that it won't receive any further events.

Specified by:
removeServerStoredGroupChangeListener in interface OperationSetPersistentPresence
Overrides:
removeServerStoredGroupChangeListener in class AbstractOperationSetPersistentPresence<ProtocolProviderServiceJabberImpl>
Parameters:
listener - the ServerStoredGroupChangeListener to remove

renameServerStoredContactGroup

public void renameServerStoredContactGroup(ContactGroup group,
                                           String newName)
Renames the specified group from the server stored contact list.

Parameters:
group - the group to rename.
newName - the new name of the group.

setAuthorizationHandler

public void setAuthorizationHandler(AuthorizationHandler handler)
Handler for incoming authorization requests.

Parameters:
handler - an instance of an AuthorizationHandler for authorization requests coming from other users requesting permission add us to their contact list.

subscribe

public void subscribe(ContactGroup parent,
                      String contactIdentifier)
               throws IllegalArgumentException,
                      IllegalStateException,
                      OperationFailedException
Persistently adds a subscription for the presence status of the contact corresponding to the specified contactIdentifier and indicates that it should be added to the specified group of the server stored contact list.

Parameters:
parent - the parent group of the server stored contact list where the contact should be added.

contactIdentifier - the contact whose status updates we are subscribing for.
Throws:
IllegalArgumentException - if contact or parent are not a contact known to the underlying protocol provider.
IllegalStateException - if the underlying protocol provider is not registered/signed on a public service.
OperationFailedException - with code NETWORK_FAILURE if subscribing fails due to errors experienced during network communication

subscribe

public void subscribe(String contactIdentifier)
               throws IllegalArgumentException,
                      IllegalStateException,
                      OperationFailedException
Adds a subscription for the presence status of the contact corresponding to the specified contactIdentifier.

Parameters:
contactIdentifier - the identifier of the contact whose status updates we are subscribing for.

Throws:
IllegalArgumentException - if contact is not a contact known to the underlying protocol provider
IllegalStateException - if the underlying protocol provider is not registered/signed on a public service.
OperationFailedException - with code NETWORK_FAILURE if subscribing fails due to errors experienced during network communication

unsubscribe

public void unsubscribe(Contact contact)
                 throws IllegalArgumentException,
                        IllegalStateException,
                        OperationFailedException
Removes a subscription for the presence status of the specified contact.

Parameters:
contact - the contact whose status updates we are unsubscribing from.
Throws:
IllegalArgumentException - if contact is not a contact known to the underlying protocol provider
IllegalStateException - if the underlying protocol provider is not registered/signed on a public service.
OperationFailedException - with code NETWORK_FAILURE if unsubscribing fails due to errors experienced during network communication

jabberStatusToPresenceStatus

public static PresenceStatus jabberStatusToPresenceStatus(org.jivesoftware.smack.packet.Presence presence,
                                                          ProtocolProviderServiceJabberImpl jabberProvider)
Converts the specified jabber status to one of the status fields of the JabberStatusEnum class.

Parameters:
presence - the Jabber Status
jabberProvider - the parent provider.
Returns:
a PresenceStatus instance representation of the Jabber Status parameter. The returned result is one of the JabberStatusEnum fields.

presenceStatusToJabberMode

public static org.jivesoftware.smack.packet.Presence.Mode presenceStatusToJabberMode(PresenceStatus status)
Converts the specified JabberStatusEnum member to the corresponding Jabber Mode

Parameters:
status - the jabberStatus
Returns:
a PresenceStatus instance

assertConnected

void assertConnected()
               throws IllegalStateException
Utility method throwing an exception if the stack is not properly initialized.

Throws:
IllegalStateException - if the underlying stack is not registered and initialized.

fireProviderStatusChangeEvent

public void fireProviderStatusChangeEvent(PresenceStatus oldStatus,
                                          PresenceStatus newStatus)
Fires provider status change.

Overrides:
fireProviderStatusChangeEvent in class AbstractOperationSetPersistentPresence<ProtocolProviderServiceJabberImpl>
Parameters:
oldStatus - old status
newStatus - new status

setDisplayName

public void setDisplayName(Contact contact,
                           String newName)
                    throws IllegalArgumentException
Sets the display name for contact to be newName.

Specified by:
setDisplayName in interface OperationSetPersistentPresence
Overrides:
setDisplayName in class AbstractOperationSetPersistentPresence<ProtocolProviderServiceJabberImpl>
Parameters:
contact - the Contact that we are renaming
newName - a String containing the new display name for metaContact.
Throws:
IllegalArgumentException - if contact is not an instance that belongs to the underlying implementation.

firePresenceStatusChanged

void firePresenceStatusChanged(org.jivesoftware.smack.packet.Presence presence)
Fires the status change, respecting resource priorities.

Parameters:
presence - the presence changed.

getResourcePriority

public int getResourcePriority()
Returns the jabber account resource priority property value.

Returns:
the jabber account resource priority property value

setResourcePriority

public void setResourcePriority(int resourcePriority)
Updates the jabber account resource priority property value.

Parameters:
resourcePriority - the new priority to set

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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