mirror of https://github.com/sipwise/jitsi.git
parent
fdd89fde0d
commit
66d2d0b0eb
@ -0,0 +1,95 @@
|
||||
package net.java.sip.communicator.slick.contactlist.mockprovider;
|
||||
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
import net.java.sip.communicator.service.protocol.icqconstants.*;
|
||||
|
||||
/**
|
||||
* A simple, straightforward mock implementation of the Contact interface
|
||||
* that can be manually created and used in testing a
|
||||
* MetaContactList service
|
||||
*
|
||||
* @author Emil Ivov
|
||||
*/
|
||||
public class MockContact
|
||||
implements Contact
|
||||
{
|
||||
private String contactID = null;
|
||||
private MockProvider parentProvider = null;
|
||||
|
||||
/**
|
||||
* Creates an instance of a meta contact with the specified string used
|
||||
* as a name and identifier.
|
||||
*
|
||||
* @param id the identifier of this contact (also used as a name).
|
||||
* @param parentProvider
|
||||
*/
|
||||
public MockContact(String id, MockProvider parentProvider)
|
||||
{
|
||||
this.contactID = id;
|
||||
this.parentProvider = parentProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String that can be used for identifying the contact.
|
||||
*
|
||||
* @return a String id representing and uniquely identifying the contact.
|
||||
*/
|
||||
public String getAddress()
|
||||
{
|
||||
return contactID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String that could be used by any user interacting modules
|
||||
* for referring to this contact.
|
||||
*
|
||||
* @return a String that can be used for referring to this contact when
|
||||
* interacting with the user.
|
||||
*/
|
||||
public String getAlias()
|
||||
{
|
||||
return contactID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a byte array containing an image (most often a photo or an
|
||||
* avatar) that the contact uses as a representation.
|
||||
*
|
||||
* @return byte[] an image representing the contact.
|
||||
*/
|
||||
public byte[] getImage()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status of the contact.
|
||||
*
|
||||
* @return always IcqStatusEnum.ONLINE.
|
||||
*/
|
||||
public PresenceStatus getPresenceStatus()
|
||||
{
|
||||
return IcqStatusEnum.ONLINE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the protocol provider that created the contact.
|
||||
*
|
||||
* @return a refererence to an instance of the ProtocolProviderService
|
||||
*/
|
||||
public ProtocolProviderService getProtocolProvider()
|
||||
{
|
||||
return parentProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not this contact represents our own identity.
|
||||
*
|
||||
* @return true in case this is a contact that represents ourselves and
|
||||
* false otherwise.
|
||||
*/
|
||||
public boolean isLocal()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,182 @@
|
||||
|
||||
package net.java.sip.communicator.slick.contactlist.mockprovider;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
/**
|
||||
* A simple, straightforward mock implementation of the ContactGroup interface
|
||||
* that can be manually created and filled and used in testing a
|
||||
* MetaContactList service
|
||||
* @author Emil Ivov
|
||||
*/
|
||||
public class MockContactGroup
|
||||
implements ContactGroup
|
||||
{
|
||||
private String groupName = null;
|
||||
|
||||
private Vector contacts = new Vector();
|
||||
private Vector subGroups = new Vector();
|
||||
|
||||
private MockProvider parentProvider = null;
|
||||
|
||||
/**
|
||||
* Creates a MockGroup with the specified name.
|
||||
* @param groupName the name of the group.
|
||||
* @param parentProvider the protocol provider that created this group.
|
||||
*/
|
||||
public MockContactGroup(String groupName, MockProvider parentProvider)
|
||||
{
|
||||
this.groupName = groupName;
|
||||
this.parentProvider = parentProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the group may contain subgroups or not.
|
||||
*
|
||||
* @return always true in this implementation.
|
||||
*/
|
||||
public boolean canContainSubgroups()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Iterator over all contacts, member of this
|
||||
* <tt>ContactGroup</tt>.
|
||||
*
|
||||
* @return a java.util.Iterator over all contacts inside this
|
||||
* <tt>ContactGroup</tt>
|
||||
*/
|
||||
public Iterator contacts()
|
||||
{
|
||||
return contacts.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified contact to this group.
|
||||
* @param contactToAdd the MockContact to add to this group.
|
||||
*/
|
||||
public void addContact(MockContact contactToAdd)
|
||||
{
|
||||
this.contacts.add(contactToAdd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of <tt>Contact</tt> members of this
|
||||
* <tt>ContactGroup</tt>
|
||||
*
|
||||
* @return an int indicating the number of <tt>Contact</tt>s, members of
|
||||
* this <tt>ContactGroup</tt>.
|
||||
*/
|
||||
public int countContacts()
|
||||
{
|
||||
return contacts.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of subgroups contained by this
|
||||
* <tt>ContactGroup</tt>.
|
||||
*
|
||||
* @return the number of subGroups currently added to this group.
|
||||
*/
|
||||
public int countSubGroups()
|
||||
{
|
||||
return subGroups.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified contact group to the contained by this group.
|
||||
* @param subGroup the MockContactGroup to add as a subgroup to this group.
|
||||
*/
|
||||
public void addSubGroup(MockContactGroup subGroup)
|
||||
{
|
||||
this.subGroups.add(subGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <tt>Contact</tt> with the specified index.
|
||||
*
|
||||
* @param index the index of the <tt>Contact</tt> to return.
|
||||
* @return the <tt>Contact</tt> with the specified index.
|
||||
*/
|
||||
public Contact getContact(int index)
|
||||
{
|
||||
return (MockContact)contacts.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <tt>Contact</tt> with the specified address or identifier.
|
||||
*
|
||||
* @param id the addres or identifier of the <tt>Contact</tt> we are
|
||||
* looking for.
|
||||
* @return the <tt>Contact</tt> with the specified id or address.
|
||||
*/
|
||||
public Contact getContact(String id)
|
||||
{
|
||||
Iterator contactsIter = contacts();
|
||||
while (contactsIter.hasNext())
|
||||
{
|
||||
MockContact contact = (MockContact) contactsIter.next();
|
||||
if (contact.getAddress().equals(id))
|
||||
return contact;
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the subgroup with the specified index.
|
||||
*
|
||||
* @param index the index of the <tt>ContactGroup</tt> to retrieve.
|
||||
* @return the <tt>ContactGroup</tt> with the specified index.
|
||||
*/
|
||||
public ContactGroup getGroup(int index)
|
||||
{
|
||||
return (ContactGroup)subGroups.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the subgroup with the specified name.
|
||||
*
|
||||
* @param groupName the name of the <tt>ContactGroup</tt> to retrieve.
|
||||
* @return the <tt>ContactGroup</tt> with the specified index.
|
||||
*/
|
||||
public ContactGroup getGroup(String groupName)
|
||||
{
|
||||
Iterator groupsIter = contacts();
|
||||
while (groupsIter.hasNext())
|
||||
{
|
||||
MockContactGroup contactGroup
|
||||
= (MockContactGroup) groupsIter.next();
|
||||
if (contactGroup.getGroupName().equals(groupName))
|
||||
return contactGroup;
|
||||
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this group.
|
||||
*
|
||||
* @return a String containing the name of this group.
|
||||
*/
|
||||
public String getGroupName()
|
||||
{
|
||||
return this.groupName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator over the sub groups that this
|
||||
* <tt>ContactGroup</tt> contains.
|
||||
*
|
||||
* @return a java.util.Iterator over the <tt>ContactGroup</tt> children
|
||||
* of this group (i.e. subgroups).
|
||||
*/
|
||||
public Iterator subGroups()
|
||||
{
|
||||
return subGroups.iterator();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,372 @@
|
||||
package net.java.sip.communicator.slick.contactlist.mockprovider;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
import net.java.sip.communicator.service.protocol.event.*;
|
||||
import net.java.sip.communicator.service.protocol.icqconstants.*;
|
||||
|
||||
/**
|
||||
* A mock implementation of a persistent presence operation set containing a
|
||||
* constant contact list and used for testing the meta contact list.
|
||||
* @author Emil Ivov
|
||||
*/
|
||||
public class MockPersistentPresenceOperationSet
|
||||
implements OperationSetPersistentPresence
|
||||
{
|
||||
|
||||
/**
|
||||
* The root of the mock contact list.
|
||||
*/
|
||||
private MockContactGroup contactListRoot = null;
|
||||
|
||||
|
||||
public MockPersistentPresenceOperationSet(MockProvider provider)
|
||||
{
|
||||
contactListRoot = new MockContactGroup("RootMockGroup", provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock implementation of the corresponding ProtocolProviderService method.
|
||||
*
|
||||
* @param listener a dummy param.
|
||||
*/
|
||||
public void addContactPresenceStatusListener(ContactPresenceStatusListener
|
||||
listener)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock implementation of the corresponding ProtocolProviderService method.
|
||||
*
|
||||
* @param listener a dummy param.
|
||||
*/
|
||||
public void addProviderPresenceStatusListener(
|
||||
ProviderPresenceStatusListener listener)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a listener that would receive events upon changes in server
|
||||
* stored groups.
|
||||
*
|
||||
* @param listener a ServerStoredGroupChangeListener impl that would
|
||||
* receive events upong group changes.
|
||||
*/
|
||||
public void addServerStoredGroupChangeListener(ServerStoredGroupListener
|
||||
listener)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock implementation of the corresponding ProtocolProviderService method.
|
||||
*
|
||||
* @param listener the SubscriptionListener to register
|
||||
*/
|
||||
public void addSubsciptionListener(SubscriptionListener listener)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a group with the specified name and parent in the server
|
||||
* stored contact list.
|
||||
*
|
||||
* @param parent the group where the new group should be created
|
||||
* @param groupName the name of the new group to create.
|
||||
*/
|
||||
public void createServerStoredContactGroup(ContactGroup parent,
|
||||
String groupName)
|
||||
{
|
||||
/** @todo implement createServerStoredContactGroup() */
|
||||
}
|
||||
|
||||
/**
|
||||
* A Mock Provider method to use for fast filling of a contact list.
|
||||
*/
|
||||
public void addMockGroup(MockContactGroup contactGroup)
|
||||
{
|
||||
contactListRoot.addSubGroup(contactGroup);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a reference to the contact with the specified ID in case we
|
||||
* have a subscription for it and null otherwise/
|
||||
*
|
||||
* @param contactID a String identifier of the contact which we're
|
||||
* seeking a reference of.
|
||||
* @return a reference to the Contact with the specified
|
||||
* <tt>contactID</tt> or null if we don't have a subscription for the
|
||||
* that identifier.
|
||||
*/
|
||||
public Contact findContactByID(String contactID)
|
||||
{
|
||||
/** @todo implement findContactByID() */
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status message that was last set through
|
||||
* setCurrentStatusMessage.
|
||||
*
|
||||
* @return the last status message that we have requested and the aim
|
||||
* server has confirmed.
|
||||
*/
|
||||
public String getCurrentStatusMessage()
|
||||
{
|
||||
/** @todo implement getCurrentStatusMessage() */
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the protocol specific contact instance representing the local
|
||||
* user.
|
||||
*
|
||||
* @return the Contact (address, phone number, or uin) that the Provider
|
||||
* implementation is communicating on behalf of.
|
||||
*/
|
||||
public Contact getLocalContact()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a PresenceStatus instance representing the state this provider
|
||||
* is currently in.
|
||||
*
|
||||
* @return the PresenceStatus last published by this provider.
|
||||
*/
|
||||
public PresenceStatus getPresenceStatus()
|
||||
{
|
||||
return IcqStatusEnum.ONLINE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the root group of the server stored contact list.
|
||||
*
|
||||
* @return the root ContactGroup for the ContactList stored by this
|
||||
* service.
|
||||
*/
|
||||
public ContactGroup getServerStoredContactListRoot()
|
||||
{
|
||||
return contactListRoot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set of PresenceStatus objects that a user of this service
|
||||
* may request the provider to enter.
|
||||
*
|
||||
* @return Iterator a PresenceStatus array containing "enterable" status
|
||||
* instances.
|
||||
*/
|
||||
public Iterator getSupportedStatusSet()
|
||||
{
|
||||
return IcqStatusEnum.icqStatusSet.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified contact from its current parent and places it
|
||||
* under <tt>newParent</tt>.
|
||||
*
|
||||
* @param contactToMove the <tt>Contact</tt> to move
|
||||
* @param newParent the <tt>ContactGroup</tt> where <tt>Contact</tt>
|
||||
* would be placed.
|
||||
*/
|
||||
public void moveContactToGroup(Contact contactToMove,
|
||||
ContactGroup newParent)
|
||||
{
|
||||
/** @todo implement moveContactToGroup() */
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests the provider to enter into a status corresponding to the
|
||||
* specified paramters.
|
||||
*
|
||||
* @param status the PresenceStatus as returned by
|
||||
* getRequestableStatusSet
|
||||
* @param 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.
|
||||
* @throws IllegalStateException if the provider is not currently
|
||||
* registered.
|
||||
* @throws OperationFailedException with code NETWORK_FAILURE if
|
||||
* publishing the status fails due to a network error.
|
||||
*/
|
||||
public void publishPresenceStatus(PresenceStatus status,
|
||||
String statusMessage) throws
|
||||
IllegalArgumentException, IllegalStateException,
|
||||
OperationFailedException
|
||||
{
|
||||
/** @todo implement publishPresenceStatus() */
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PresenceStatus for a particular contact.
|
||||
*
|
||||
* @param contactIdentifier the identifier of the contact whose status
|
||||
* we're interested in.
|
||||
* @return PresenceStatus the <tt>PresenceStatus</tt> of the specified
|
||||
* <tt>contact</tt>
|
||||
* @throws IllegalArgumentException if <tt>contact</tt> is not a contact
|
||||
* known to the underlying protocol provider
|
||||
* @throws IllegalStateException if the underlying protocol provider is
|
||||
* not registered/signed on a public service.
|
||||
* @throws OperationFailedException with code NETWORK_FAILURE if
|
||||
* retrieving the status fails due to errors experienced during
|
||||
* network communication
|
||||
*/
|
||||
public PresenceStatus queryContactStatus(String contactIdentifier) throws
|
||||
IllegalArgumentException, IllegalStateException,
|
||||
OperationFailedException
|
||||
{
|
||||
return IcqStatusEnum.ONLINE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified listener so that it won't receive any further
|
||||
* updates on contact presence status changes
|
||||
*
|
||||
* @param listener the listener to remove.
|
||||
*/
|
||||
public void removeContactPresenceStatusListener(
|
||||
ContactPresenceStatusListener listener)
|
||||
{
|
||||
/** @todo implement removeContactPresenceStatusListener() */
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters the specified listener so that it does not receive further
|
||||
* events upon changes in local presence status.
|
||||
*
|
||||
* @param listener ProviderPresenceStatusListener
|
||||
*/
|
||||
public void removeProviderPresenceStatusListener(
|
||||
ProviderPresenceStatusListener listener)
|
||||
{
|
||||
/** @todo implement removeProviderPresenceStatusListener() */
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified group from the server stored contact list.
|
||||
*
|
||||
* @param group the group to remove.
|
||||
*/
|
||||
public void removeServerStoredContactGroup(ContactGroup group)
|
||||
{
|
||||
/** @todo implement removeServerStoredContactGroup() */
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified group change listener so that it won't receive
|
||||
* any further events.
|
||||
*
|
||||
* @param listener the ServerStoredGroupChangeListener to remove
|
||||
*/
|
||||
public void removeServerStoredGroupChangeListener(ServerStoredGroupListener
|
||||
listener)
|
||||
{
|
||||
/** @todo implement removeServerStoredGroupChangeListener() */
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified subscription listener.
|
||||
*
|
||||
* @param listener the listener to remove.
|
||||
*/
|
||||
public void removeSubsciptionListener(SubscriptionListener listener)
|
||||
{
|
||||
/** @todo implement removeSubsciptionListener() */
|
||||
}
|
||||
|
||||
/**
|
||||
* Renames the specified group from the server stored contact list.
|
||||
*
|
||||
* @param group the group to rename.
|
||||
* @param newName the new name of the group.
|
||||
*/
|
||||
public void renameServerStoredContactGroup(ContactGroup group,
|
||||
String newName)
|
||||
{
|
||||
/** @todo implement renameServerStoredContactGroup() */
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for incoming authorization requests.
|
||||
*
|
||||
* @param handler an instance of an AuthorizationHandler for
|
||||
* authorization requests coming from other users requesting
|
||||
* permission add us to their contact list.
|
||||
*/
|
||||
public void setAuthorizationHandler(AuthorizationHandler handler)
|
||||
{
|
||||
/** @todo implement setAuthorizationHandler() */
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param parent the parent group of the server stored contact list
|
||||
* where the contact should be added. <p>
|
||||
* @param contactIdentifier the contact whose status updates we are
|
||||
* subscribing for.
|
||||
* @throws IllegalArgumentException if <tt>contact</tt> or
|
||||
* <tt>parent</tt> are not a contact known to the underlying protocol
|
||||
* provider.
|
||||
* @throws IllegalStateException if the underlying protocol provider is
|
||||
* not registered/signed on a public service.
|
||||
* @throws OperationFailedException with code NETWORK_FAILURE if
|
||||
* subscribing fails due to errors experienced during network
|
||||
* communication
|
||||
*/
|
||||
public void subscribe(ContactGroup parent, String contactIdentifier) throws
|
||||
IllegalArgumentException, IllegalStateException,
|
||||
OperationFailedException
|
||||
{
|
||||
/** @todo implement subscribe() */
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a subscription for the presence status of the contact
|
||||
* corresponding to the specified contactIdentifier.
|
||||
*
|
||||
* @param contactIdentifier the identifier of the contact whose status
|
||||
* updates we are subscribing for. <p>
|
||||
* @throws IllegalArgumentException if <tt>contact</tt> is not a contact
|
||||
* known to the underlying protocol provider
|
||||
* @throws IllegalStateException if the underlying protocol provider is
|
||||
* not registered/signed on a public service.
|
||||
* @throws OperationFailedException with code NETWORK_FAILURE if
|
||||
* subscribing fails due to errors experienced during network
|
||||
* communication
|
||||
*/
|
||||
public void subscribe(String contactIdentifier) throws
|
||||
IllegalArgumentException, IllegalStateException,
|
||||
OperationFailedException
|
||||
{
|
||||
/** @todo implement subscribe() */
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a subscription for the presence status of the specified
|
||||
* contact.
|
||||
*
|
||||
* @param contact the contact whose status updates we are unsubscribing
|
||||
* from.
|
||||
* @throws IllegalArgumentException if <tt>contact</tt> is not a contact
|
||||
* known to the underlying protocol provider
|
||||
* @throws IllegalStateException if the underlying protocol provider is
|
||||
* not registered/signed on a public service.
|
||||
* @throws OperationFailedException with code NETWORK_FAILURE if
|
||||
* unsubscribing fails due to errors experienced during network
|
||||
* communication
|
||||
*/
|
||||
public void unsubscribe(Contact contact) throws IllegalArgumentException,
|
||||
IllegalStateException, OperationFailedException
|
||||
{
|
||||
/** @todo implement unsubscribe() */
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue