Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.protocol.zeroconf
Class OperationSetPersistentPresenceZeroconfImpl

java.lang.Object
  extended by net.java.sip.communicator.service.protocol.AbstractOperationSetPersistentPresence<ProtocolProviderServiceZeroconfImpl>
      extended by net.java.sip.communicator.impl.protocol.zeroconf.OperationSetPersistentPresenceZeroconfImpl
All Implemented Interfaces:
OperationSet, OperationSetPersistentPresence, OperationSetPresence

public class OperationSetPersistentPresenceZeroconfImpl
extends AbstractOperationSetPersistentPresence<ProtocolProviderServiceZeroconfImpl>

A Zeroconf implementation of a persistent presence operation set. In order to simulate server persistence, this operation set would simply accept all unresolved contacts and resolve them immediately. A real world protocol implementation would save it on a server using methods provided by the protocol stack.

Author:
Christian Vincenot, Maxime Catelin, Jonathan Martin

Field Summary
 
Fields inherited from class net.java.sip.communicator.service.protocol.AbstractOperationSetPersistentPresence
parentProvider
 
Constructor Summary
OperationSetPersistentPresenceZeroconfImpl(ProtocolProviderServiceZeroconfImpl provider)
          Creates an instance of this operation set keeping a reference to the specified parent provider.
 
Method Summary
 void addZeroconfGroup(ContactGroupZeroconfImpl contactGroup)
          A Zeroconf Provider method to use for fast filling of a contact list.
 void addZeroconfGroupAndFireEvent(ContactGroupZeroconfImpl parent, ContactGroupZeroconfImpl contactGroup)
          A Zeroconf Provider method to use for fast filling of a contact list.
protected  void changePresenceStatusForAllContacts(ContactGroup parent, PresenceStatus newStatus)
          Sets the presence status of all contacts in our contact list (except those that correspond to another provider registered with SC) to newStatus.
 void changePresenceStatusForContact(ContactZeroconfImpl contact, PresenceStatus newStatus)
          Sets the presence status of contact to newStatus.
 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 parent)
          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.
 ContactZeroconfImpl createVolatileContact(String contactAddress, BonjourService bonjourService, String name, InetAddress ip, int port)
          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/
 ContactGroupZeroconfImpl findContactParent(ContactZeroconfImpl zeroconfContact)
          Returns the group that is parent of the specified zeroconfContact or null if no parent was found.
 ContactGroupZeroconfImpl findGroupParent(ContactGroupZeroconfImpl zeroconfGroup)
          Returns the group that is parent of the specified zeroconfGroup or null if no parent was found.
 ProtocolProviderServiceZeroconfImpl findProviderForZeroconfUserID(String zeroconfUserID)
          Looks for a zeroconf protocol provider registered for a user id matching zeroconfUserID.
 String getCurrentStatusMessage()
          Returns the status message that was last set through setCurrentStatusMessage.
 Contact getLocalContact()
           
 ContactGroupZeroconfImpl getNonPersistentGroup()
          Returns the volatile group or null if this group has not yet been created.
 PresenceStatus getPresenceStatus()
          Returns a PresenceStatus instance representing the state this provider is currently in.
 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.
 void moveContactToGroup(Contact contactToMove, ContactGroup newParent)
          Removes the specified contact from its current parent and places it under newParent.
 void publishPresenceStatus(PresenceStatus status, String statusMessage)
          Requests the provider to enter into a status corresponding to the specified paramters.
 PresenceStatus queryContactStatus(String contactIdentifier)
          Get the PresenceStatus for a particular contact.
 void removeServerStoredContactGroup(ContactGroup group)
          Removes the specified group from the server stored contact list.
 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 setStatusMessage(String statusMessage)
          Sets the specified status message.
 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, addServerStoredGroupChangeListener, addSubscriptionListener, fireContactPresenceStatusChangeEvent, fireContactPresenceStatusChangeEvent, fireContactPropertyChangeEvent, fireProviderStatusChangeEvent, fireProviderStatusChangeEvent, fireProviderStatusMessageChangeEvent, fireServerStoredGroupEvent, fireSubscriptionEvent, fireSubscriptionEvent, fireSubscriptionMovedEvent, removeContactPresenceStatusListener, removeProviderPresenceStatusListener, removeServerStoredGroupChangeListener, removeSubscriptionListener, setDisplayName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OperationSetPersistentPresenceZeroconfImpl

public OperationSetPersistentPresenceZeroconfImpl(ProtocolProviderServiceZeroconfImpl provider)
Creates an instance of this operation set keeping a reference to the specified parent provider.

Parameters:
provider - the ProtocolProviderServiceZeroconfImpl instance that created us.
Method Detail

createServerStoredContactGroup

public void createServerStoredContactGroup(ContactGroup parent,
                                           String groupName)
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.

addZeroconfGroup

public void addZeroconfGroup(ContactGroupZeroconfImpl contactGroup)
A Zeroconf Provider method to use for fast filling of a contact list.

Parameters:
contactGroup - the group to add

addZeroconfGroupAndFireEvent

public void addZeroconfGroupAndFireEvent(ContactGroupZeroconfImpl parent,
                                         ContactGroupZeroconfImpl contactGroup)
A Zeroconf Provider method to use for fast filling of a contact list. This method would add both the group and fire an event.

Parameters:
parent - the group where contactGroup should be added.
contactGroup - the group to add

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.

setStatusMessage

public void setStatusMessage(String statusMessage)
Sets the specified status message.

Parameters:
statusMessage - a String containing the new status message.

getCurrentStatusMessage

public String getCurrentStatusMessage()
Returns the status message that was last set through setCurrentStatusMessage.

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

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 paramters.

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
Get the PresenceStatus for a particular contact.

Parameters:
contactIdentifier - the identifier of the contact whose status we're interested in.
Returns:
PresenceStatus the PresenceStatus of the specified contact
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 retrieving the status fails due to errors experienced during network communication

changePresenceStatusForContact

public void changePresenceStatusForContact(ContactZeroconfImpl contact,
                                           PresenceStatus newStatus)
Sets the presence status of contact to newStatus.

Parameters:
contact - the ContactZeroconfImpl whose status we'd like to set.
newStatus - the new status we'd like to set to contact.

changePresenceStatusForAllContacts

protected void changePresenceStatusForAllContacts(ContactGroup parent,
                                                  PresenceStatus newStatus)
Sets the presence status of all contacts in our contact list (except those that correspond to another provider registered with SC) to newStatus.

Parameters:
newStatus - the new status we'd like to set to contact.
parent - the group in which we'd have to update the status of all direct and indirect child contacts.

findGroupParent

public ContactGroupZeroconfImpl findGroupParent(ContactGroupZeroconfImpl zeroconfGroup)
Returns the group that is parent of the specified zeroconfGroup or null if no parent was found.

Parameters:
zeroconfGroup - the group whose parent we're looking for.
Returns:
the ContactGroupZeroconfImpl instance that zeroconfGroup belongs to or null if no parent was found.

findContactParent

public ContactGroupZeroconfImpl findContactParent(ContactZeroconfImpl zeroconfContact)
Returns the group that is parent of the specified zeroconfContact or null if no parent was found.

Parameters:
zeroconfContact - the contact whose parent we're looking for.
Returns:
the ContactGroupZeroconfImpl instance that zeroconfContact belongs to or null if no parent was found.

removeServerStoredContactGroup

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

Parameters:
group - the group to remove.
Throws:
IllegalArgumentException - if group was not found in this protocol's contact list.

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

createUnresolvedContact

public Contact createUnresolvedContact(String address,
                                       String persistentData)
Creates and returns a unresolved contact from the specified address and persistentData. The method will not try to establish a network connection and resolve the newly created Contact against the server. The protocol provider may will later try and resolve the contact. When this happens the corresponding event would notify interested subscription listeners.

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

createUnresolvedContact

public Contact createUnresolvedContact(String address,
                                       String persistentData,
                                       ContactGroup parent)
Creates and returns a unresolved contact from the specified address and persistentData. The method will not try to establish a network connection and resolve the newly created Contact against the server. The protocol provider may will later try and resolve the contact. When this happens the corresponding event would notify interested subscription listeners.

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.
parent - the group where the unresolved contact is supposed to belong to.
Returns:
the unresolved Contact created from the specified address and persistentData

findProviderForZeroconfUserID

public ProtocolProviderServiceZeroconfImpl findProviderForZeroconfUserID(String zeroconfUserID)
Looks for a zeroconf protocol provider registered for a user id matching zeroconfUserID.

Parameters:
zeroconfUserID - the ID of the Zeroconf user whose corresponding protocol provider we'd like to find.
Returns:
ProtocolProviderServiceZeroconfImpl a zeroconf protocol provider registered for a user with id zeroconfUserID or null if there is no such protocol provider.

createUnresolvedContactGroup

public ContactGroup createUnresolvedContactGroup(String groupUID,
                                                 String persistentData,
                                                 ContactGroup parentGroup)
Creates and returns a unresolved contact group from the specified address and persistentData. The method will not try to establish a network connection and resolve the newly created ContactGroup against the server or the contact itself. The protocol provider will later resolve the contact group. When this happens the corresponding event would notify interested subscription listeners.

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

getNonPersistentGroup

public ContactGroupZeroconfImpl getNonPersistentGroup()
Returns the volatile group or null if this group has not yet been created.

Returns:
a volatile group existing in our contact list or null if such a group has not yet been created.

createVolatileContact

public ContactZeroconfImpl createVolatileContact(String contactAddress,
                                                 BonjourService bonjourService,
                                                 String name,
                                                 InetAddress ip,
                                                 int port)
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:
bonjourService - BonjourService responsible for the chat with this contact
name - Display name of the contact
ip - IP address of the contact
port - Port declared by the contact for direct chat
contactAddress - the address of the volatile contact we'd like to create.
Returns:
the newly created volatile contact.

getLocalContact

public Contact getLocalContact()

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

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