mirror of https://github.com/sipwise/jitsi.git
parent
64a6611de5
commit
ebcbae4332
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.slick.contactlist.mockprovider;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
/**
|
||||
* A default, 1-to-1 mock implementation of the account id.
|
||||
* @author Emil Ivov
|
||||
*/
|
||||
public class MockAccountID
|
||||
extends AccountID
|
||||
{
|
||||
public static final String MOCK_SERVICE_NAME = "MockService";
|
||||
protected MockAccountID(String userName)
|
||||
{
|
||||
super( userName
|
||||
, new java.util.Hashtable()
|
||||
, ProtocolNames.SIP_COMMUNICATOR_MOCK
|
||||
, MOCK_SERVICE_NAME);
|
||||
}
|
||||
}
|
||||
@ -1,223 +0,0 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.slick.contactlist.mockprovider;
|
||||
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
private MockContactGroup parentGroup = null;
|
||||
private PresenceStatus presenceStatus = MockStatusEnum.MOCK_STATUS_50;
|
||||
private boolean isPersistent = true;
|
||||
private boolean isResolved = true;
|
||||
|
||||
/**
|
||||
* 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 the provider that created us.
|
||||
*/
|
||||
public MockContact(String id,
|
||||
MockProvider parentProvider)
|
||||
{
|
||||
this.contactID = id;
|
||||
this.parentProvider = parentProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is only called when the contact is added to a new
|
||||
* <tt>MockContactGroup</tt> by the MockContactGroup itself.
|
||||
* @param newParentGroup the <tt>MockContactGroup</tt> that is now parent
|
||||
* of this <tt>MockContact</tt>
|
||||
*/
|
||||
void setParentGroup(MockContactGroup newParentGroup)
|
||||
{
|
||||
this.parentGroup = newParentGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 getDisplayName()
|
||||
{
|
||||
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 this.presenceStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets <tt>mockPresenceStatus</tt> as the PresenceStatus that this contact
|
||||
* is currently in.
|
||||
* @param mockPresenceStatus the <tt>MockPresenceStatus</tt> currently valid
|
||||
* for this contact.
|
||||
*/
|
||||
public void setPresenceStatus(MockStatusEnum mockPresenceStatus)
|
||||
{
|
||||
this.presenceStatus = mockPresenceStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the group that contains this contact.
|
||||
* @return a reference to the MockContactGroup that contains this contact.
|
||||
*/
|
||||
public ContactGroup getParentContactGroup()
|
||||
{
|
||||
return this.parentGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this contact, containing most of its
|
||||
* representative details.
|
||||
*
|
||||
* @return a string representation of this contact.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer buff = new StringBuffer("MockContact[ DisplayName=")
|
||||
.append(getDisplayName()).append("]");
|
||||
|
||||
return buff.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not this contact is being stored by the server.
|
||||
* Non persistent contacts are common in the case of simple, non-persistent
|
||||
* presence operation sets. They could however also be seen in persistent
|
||||
* presence operation sets when for example we have received an event
|
||||
* from someone not on our contact list. Non persistent contacts are
|
||||
* volatile even when coming from a persistent presence op. set. They would
|
||||
* only exist until the application is closed and will not be there next
|
||||
* time it is loaded.
|
||||
* @return true if the contact is persistent and false otherwise.
|
||||
*/
|
||||
public boolean isPersistent()
|
||||
{
|
||||
return isPersistent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns null as no persistent data is required and the contact address is
|
||||
* sufficient for restoring the contact.
|
||||
* <p>
|
||||
* @return null as no such data is needed.
|
||||
*/
|
||||
public String getPersistentData()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not this contact has been resolved against the
|
||||
* server. Unresolved contacts are used when initially loading a contact
|
||||
* list that has been stored in a local file until the presence operation
|
||||
* set has managed to retrieve all the contact list from the server and has
|
||||
* properly mapped contacts to their on-line buddies.
|
||||
* @return true if the contact has been resolved (mapped against a buddy)
|
||||
* and false otherwise.
|
||||
*/
|
||||
public boolean isResolved()
|
||||
{
|
||||
return isResolved;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the contact resolved or unresolved.
|
||||
*
|
||||
* @param resolved true to make the contact resolved; false to
|
||||
* make it unresolved
|
||||
*/
|
||||
public void setResolved(boolean resolved)
|
||||
{
|
||||
this.isResolved = resolved;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether some other object is "equal to" this one which in terms
|
||||
* of contacts translates to having equal ids. The resolved status of the
|
||||
* contacts deliberately ignored so that contacts would be declared equal
|
||||
* even if it differs.
|
||||
* <p>
|
||||
* @param obj the reference object with which to compare.
|
||||
* @return <code>true</code> if this contact has the same id as that of the
|
||||
* <code>obj</code> argument.
|
||||
*/
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (obj == null
|
||||
|| ! (obj instanceof MockContact))
|
||||
return false;
|
||||
|
||||
MockContact mockContact = (MockContact) obj;
|
||||
|
||||
return this.getAddress().equals(mockContact.getAddress());
|
||||
}
|
||||
}
|
||||
@ -1,511 +0,0 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
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 MockContactGroup parentGroup = null;
|
||||
private boolean isPersistent = true;
|
||||
private MockProvider parentProvider = null;
|
||||
private boolean isResolved = true;
|
||||
private String uid = null;
|
||||
private static final String UID_SUFFIX = ".uid";
|
||||
|
||||
/**
|
||||
* 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.uid = groupName + UID_SUFFIX;
|
||||
this.parentProvider = parentProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the group may contain subgroups or not.
|
||||
*
|
||||
* @return always true in this implementation.
|
||||
*/
|
||||
public boolean canContainSubgroups()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the protocol provider that this group belongs to.
|
||||
* @return a regerence to the ProtocolProviderService instance that this
|
||||
* ContactGroup belongs to.
|
||||
*/
|
||||
public ProtocolProviderService getProtocolProvider()
|
||||
{
|
||||
return parentProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
contactToAdd.setParentGroup(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
subgroup.setParentGroup(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the group that is the new parent of this group
|
||||
* @param parent MockContactGroup
|
||||
*/
|
||||
void setParentGroup(MockContactGroup parent)
|
||||
{
|
||||
this.parentGroup = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contact group that currently contains this group or null if
|
||||
* this is the root contact group.
|
||||
* @return the contact group that currently contains this group or null if
|
||||
* this is the root contact group.
|
||||
*/
|
||||
public ContactGroup getParentContactGroup()
|
||||
{
|
||||
return this.parentGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified contact group from the this group's subgroups.
|
||||
* @param subgroup the MockContactGroup subgroup to remove.
|
||||
*/
|
||||
public void removeSubGroup(MockContactGroup subgroup)
|
||||
{
|
||||
this.subGroups.remove(subgroup);
|
||||
subgroup.setParentGroup(null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 group that is parent of the specified mockGroup or null
|
||||
* if no parent was found.
|
||||
* @param mockGroup the group whose parent we're looking for.
|
||||
* @return the MockContactGroup instance that mockGroup belongs to or null
|
||||
* if no parent was found.
|
||||
*/
|
||||
public MockContactGroup findGroupParent(MockContactGroup mockGroup)
|
||||
{
|
||||
if ( subGroups.contains(mockGroup) )
|
||||
return this;
|
||||
|
||||
Iterator subGroupsIter = subgroups();
|
||||
while (subGroupsIter.hasNext())
|
||||
{
|
||||
MockContactGroup subgroup = (MockContactGroup) subGroupsIter.next();
|
||||
|
||||
MockContactGroup parent = subgroup.findGroupParent(mockGroup);
|
||||
if(parent != null)
|
||||
return parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the group that is parent of the specified mockContact or null
|
||||
* if no parent was found.
|
||||
* @param mockContact the contact whose parent we're looking for.
|
||||
* @return the MockContactGroup instance that mockContact belongs to or null
|
||||
* if no parent was found.
|
||||
*/
|
||||
public MockContactGroup findContactParent(MockContact mockContact)
|
||||
{
|
||||
if ( contacts.contains(mockContact) )
|
||||
return this;
|
||||
|
||||
Iterator subGroupsIter = subgroups();
|
||||
while (subGroupsIter.hasNext())
|
||||
{
|
||||
MockContactGroup subgroup = (MockContactGroup) subGroupsIter.next();
|
||||
|
||||
MockContactGroup parent = subgroup.findContactParent(mockContact);
|
||||
if(parent != null)
|
||||
return parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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 = subgroups();
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this group a new name.
|
||||
* @param newGrpName a String containing the new name of this group.
|
||||
*/
|
||||
public void setGroupName(String newGrpName)
|
||||
{
|
||||
this.groupName = newGrpName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified contact from this group.
|
||||
* @param contact the MockContact to remove from this group
|
||||
*/
|
||||
public void removeContact(MockContact contact)
|
||||
{
|
||||
this.contacts.remove(contact);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contact with the specified id or null if no such contact
|
||||
* exists.
|
||||
* @param id the id of the contact we're looking for.
|
||||
* @return MockContact
|
||||
*/
|
||||
public MockContact findContactByID(String id)
|
||||
{
|
||||
//first go through the contacts that are direct children.
|
||||
Iterator contactsIter = contacts();
|
||||
|
||||
while(contactsIter.hasNext())
|
||||
{
|
||||
MockContact mContact = (MockContact)contactsIter.next();
|
||||
|
||||
if( mContact.getAddress().equals(id) )
|
||||
return mContact;
|
||||
}
|
||||
|
||||
//if we didn't find it here, let's try in the subougroups
|
||||
Iterator groupsIter = subgroups();
|
||||
|
||||
while( groupsIter.hasNext() )
|
||||
{
|
||||
MockContactGroup mGroup = (MockContactGroup)groupsIter.next();
|
||||
|
||||
MockContact mContact = mGroup.findContactByID(id);
|
||||
|
||||
if (mContact != null)
|
||||
return mContact;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a String representation of this group and the contacts it
|
||||
* contains (may turn out to be a relatively long string).
|
||||
* @return a String representing this group and its child contacts.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
|
||||
StringBuffer buff = new StringBuffer(getGroupName());
|
||||
buff.append(".subGroups=" + countSubgroups() + ":\n");
|
||||
|
||||
Iterator subGroups = subgroups();
|
||||
while (subGroups.hasNext())
|
||||
{
|
||||
MockContactGroup group = (MockContactGroup)subGroups.next();
|
||||
buff.append(group.toString());
|
||||
if (subGroups.hasNext())
|
||||
buff.append("\n");
|
||||
}
|
||||
|
||||
buff.append("\nChildContacts="+countContacts()+":[");
|
||||
|
||||
Iterator contacts = contacts();
|
||||
while (contacts.hasNext())
|
||||
{
|
||||
MockContact contact = (MockContact) contacts.next();
|
||||
buff.append(contact.toString());
|
||||
if(contacts.hasNext())
|
||||
buff.append(", ");
|
||||
}
|
||||
return buff.append("]").toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not this contact group is being stored by the
|
||||
* server. Non persistent contact groups exist for the sole purpose of
|
||||
* containing non persistent contacts.
|
||||
* @return true if the contact group is persistent and false otherwise.
|
||||
*/
|
||||
public boolean isPersistent()
|
||||
{
|
||||
return isPersistent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns null as no persistent data is required and the contact address is
|
||||
* sufficient for restoring the contact.
|
||||
* <p>
|
||||
* @return null as no such data is needed.
|
||||
*/
|
||||
public String getPersistentData()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not this contact has been resolved against the
|
||||
* server. Unresolved contacts are used when initially loading a contact
|
||||
* list that has been stored in a local file until the presence operation
|
||||
* set has managed to retrieve all the contact list from the server and has
|
||||
* properly mapped contacts to their on-line buddies.
|
||||
* @return true if the contact has been resolved (mapped against a buddy)
|
||||
* and false otherwise.
|
||||
*/
|
||||
public boolean isResolved()
|
||||
{
|
||||
return isResolved;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the group resolved or unresolved.
|
||||
*
|
||||
* @param resolved true to make the group resolved; false to
|
||||
* make it unresolved
|
||||
*/
|
||||
public void setResolved(boolean resolved)
|
||||
{
|
||||
this.isResolved = resolved;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a <tt>String</tt> that uniquely represnets the group inside
|
||||
* the current protocol. The string MUST be persistent (it must not change
|
||||
* across connections or runs of the application). In many cases (Jabber,
|
||||
* ICQ) the string may match the name of the group as these protocols
|
||||
* only allow a single level of contact groups and there is no danger of
|
||||
* having the same name twice in the same contact list. Other protocols
|
||||
* (no examples come to mind but that doesn't bother me ;) ) may be
|
||||
* supporting mutilple levels of grooups so it might be possible for group
|
||||
* A and group B to both contain groups named C. In such cases the
|
||||
* implementation must find a way to return a unique identifier in this
|
||||
* method and this UID should never change for a given group.
|
||||
*
|
||||
* @return a String representing this group in a unique and persistent
|
||||
* way.
|
||||
*/
|
||||
public String getUID()
|
||||
{
|
||||
return uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ugly but tricky conversion method.
|
||||
* @param uid the uid we'd like to get a name from
|
||||
* @return the name of the group with the specified <tt>uid</tt>.
|
||||
*/
|
||||
static String createNameFromUID(String uid)
|
||||
{
|
||||
return uid.substring(0, uid.length() - (UID_SUFFIX.length()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether some other object is "equal to" this one which in terms
|
||||
* of contact groups translates to having the equal names and matching
|
||||
* subgroups and child contacts. The resolved status of contactgroups and
|
||||
* contacts is deliberately ignored so that groups and/or contacts would
|
||||
* be assumed equal even if it differs.
|
||||
* <p>
|
||||
* @param obj the reference object with which to compare.
|
||||
* @return <code>true</code> if this contact group has the equal child
|
||||
* contacts and subgroups to those of the <code>obj</code> argument.
|
||||
*/
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if(obj == null
|
||||
|| !(obj instanceof MockContactGroup))
|
||||
return false;
|
||||
|
||||
MockContactGroup mockGroup = (MockContactGroup)obj;
|
||||
|
||||
if( ! mockGroup.getGroupName().equals(getGroupName())
|
||||
|| ! mockGroup.getUID().equals(getUID())
|
||||
|| mockGroup.countContacts() != countContacts()
|
||||
|| mockGroup.countSubgroups() != countSubgroups())
|
||||
return false;
|
||||
|
||||
//traverse child contacts
|
||||
Iterator theirContacts = mockGroup.contacts();
|
||||
|
||||
while(theirContacts.hasNext())
|
||||
{
|
||||
MockContact theirContact = (MockContact)theirContacts.next();
|
||||
|
||||
MockContact ourContact
|
||||
= (MockContact)getContact(theirContact.getAddress());
|
||||
|
||||
if(ourContact == null
|
||||
|| !ourContact.equals(theirContact))
|
||||
return false;
|
||||
}
|
||||
|
||||
//traverse subgroups
|
||||
Iterator theirSubgroups = mockGroup.subgroups();
|
||||
|
||||
while(theirSubgroups.hasNext())
|
||||
{
|
||||
MockContactGroup theirSubgroup
|
||||
= (MockContactGroup)theirSubgroups.next();
|
||||
|
||||
MockContactGroup ourSubgroup
|
||||
= (MockContactGroup)getGroup(theirSubgroup.getGroupName());
|
||||
|
||||
if(ourSubgroup == null
|
||||
|| !ourSubgroup.equals(theirSubgroup))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,763 +0,0 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
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.util.*;
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
private static final Logger logger =
|
||||
Logger.getLogger(MockPersistentPresenceOperationSet.class);
|
||||
/**
|
||||
* A list of listeners registered for <tt>SubscriptionEvent</tt>s.
|
||||
*/
|
||||
private Vector subscriptionListeners = new Vector();
|
||||
|
||||
/**
|
||||
* A list of listeners registered for <tt>ServerStoredGroupChangeEvent</tt>s.
|
||||
*/
|
||||
private Vector serverStoredGroupListeners = new Vector();
|
||||
|
||||
/**
|
||||
* A list of listeners registered for
|
||||
* <tt>ProviderPresenceStatusChangeEvent</tt>s.
|
||||
*/
|
||||
private Vector providerPresenceStatusListeners = new Vector();
|
||||
|
||||
/**
|
||||
* A list of listeneres registered for
|
||||
* <tt>ContactPresenceStatusChangeEvent</tt>s.
|
||||
*/
|
||||
private Vector contactPresenceStatusListeners = new Vector();
|
||||
|
||||
/**
|
||||
* The root of the mock contact list.
|
||||
*/
|
||||
private MockContactGroup contactListRoot = null;
|
||||
|
||||
/**
|
||||
* The provider that created us.
|
||||
*/
|
||||
private MockProvider parentProvider = null;
|
||||
|
||||
/**
|
||||
* The currently active status message.
|
||||
*/
|
||||
private String statusMessage = "Default Status Message";
|
||||
|
||||
/**
|
||||
* Our default presence status.
|
||||
*/
|
||||
private PresenceStatus presenceStatus = MockStatusEnum.MOCK_STATUS_50;
|
||||
|
||||
public MockPersistentPresenceOperationSet(MockProvider provider)
|
||||
{
|
||||
this.parentProvider = provider;
|
||||
contactListRoot = new MockContactGroup("RootMockGroup", provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock implementation of the corresponding ProtocolProviderService method.
|
||||
*
|
||||
* @param listener a dummy param.
|
||||
*/
|
||||
public void addContactPresenceStatusListener(
|
||||
ContactPresenceStatusListener listener)
|
||||
{
|
||||
contactPresenceStatusListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies all registered listeners of the new event.
|
||||
*
|
||||
* @param source the contact that has caused the event.
|
||||
* @param parentGroup the group that contains the source contact.
|
||||
* @param oldValue the status that the source contact detained before
|
||||
* changing it.
|
||||
*/
|
||||
public void fireContactPresenceStatusChangeEvent(MockContact source,
|
||||
ContactGroup parentGroup,
|
||||
PresenceStatus oldValue)
|
||||
{
|
||||
ContactPresenceStatusChangeEvent evt
|
||||
= new ContactPresenceStatusChangeEvent(source, parentProvider
|
||||
, parentGroup, oldValue, source.getPresenceStatus());
|
||||
for ( int i = 0; i < contactPresenceStatusListeners.size(); i++ )
|
||||
{
|
||||
|
||||
ContactPresenceStatusListener listener
|
||||
= (ContactPresenceStatusListener)contactPresenceStatusListeners
|
||||
.get(i);
|
||||
|
||||
listener.contactPresenceStatusChanged(evt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notifies all registered listeners of the new event.
|
||||
*
|
||||
* @param source the contact that has caused the event.
|
||||
* @param parentGroup the group that contains the source contact.
|
||||
* @param eventID an identifier of the event to dispatch.
|
||||
*/
|
||||
public void fireSubscriptionEvent(MockContact source,
|
||||
ContactGroup parentGroup,
|
||||
int eventID)
|
||||
{
|
||||
SubscriptionEvent evt = new SubscriptionEvent(source, this.parentProvider,
|
||||
parentGroup, eventID);
|
||||
for ( int i = 0; i < subscriptionListeners.size(); i++ )
|
||||
{
|
||||
SubscriptionListener listener = (SubscriptionListener)
|
||||
subscriptionListeners.get(i);
|
||||
if(eventID == SubscriptionEvent.SUBSCRIPTION_CREATED)
|
||||
{
|
||||
listener.subscriptionCreated(evt);
|
||||
}
|
||||
else if (eventID == SubscriptionEvent.SUBSCRIPTION_FAILED)
|
||||
{
|
||||
listener.subscriptionFailed(evt);
|
||||
}
|
||||
else if (eventID == SubscriptionEvent.SUBSCRIPTION_REMOVED)
|
||||
{
|
||||
listener.subscriptionRemoved(evt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies all registered listeners of the new event.
|
||||
*
|
||||
* @param source the contact that has caused the event.
|
||||
* @param eventID an identifier of the event to dispatch.
|
||||
*/
|
||||
public void fireServerStoredGroupEvent(MockContactGroup source,
|
||||
int eventID)
|
||||
{
|
||||
ServerStoredGroupEvent evt = new ServerStoredGroupEvent(
|
||||
source, eventID, (MockContactGroup)source.getParentContactGroup()
|
||||
, this.parentProvider, this);
|
||||
|
||||
for ( int i = 0; i < serverStoredGroupListeners.size(); i++ )
|
||||
{
|
||||
ServerStoredGroupListener listener = (ServerStoredGroupListener)
|
||||
serverStoredGroupListeners.get(i);
|
||||
if(eventID == ServerStoredGroupEvent.GROUP_CREATED_EVENT)
|
||||
{
|
||||
listener.groupCreated(evt);
|
||||
}
|
||||
else if(eventID == ServerStoredGroupEvent.GROUP_RENAMED_EVENT)
|
||||
{
|
||||
listener.groupNameChanged(evt);
|
||||
}
|
||||
else if(eventID == ServerStoredGroupEvent.GROUP_REMOVED_EVENT)
|
||||
{
|
||||
listener.groupRemoved(evt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies all registered listeners of the new event.
|
||||
*
|
||||
* @param oldValue the presence status we were in before the change.
|
||||
*/
|
||||
public void fireProviderStatusChangeEvent(PresenceStatus oldValue)
|
||||
{
|
||||
ProviderPresenceStatusChangeEvent evt
|
||||
= new ProviderPresenceStatusChangeEvent(this.parentProvider,
|
||||
oldValue, this.getPresenceStatus());
|
||||
|
||||
for ( int i = 0; i < providerPresenceStatusListeners.size(); i++ )
|
||||
{
|
||||
ProviderPresenceStatusListener listener =
|
||||
(ProviderPresenceStatusListener)providerPresenceStatusListeners
|
||||
.get(i);
|
||||
listener.providerStatusChanged(evt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock implementation of the corresponding ProtocolProviderService method.
|
||||
*
|
||||
* @param listener a dummy param.
|
||||
*/
|
||||
public void addProviderPresenceStatusListener(
|
||||
ProviderPresenceStatusListener listener)
|
||||
{
|
||||
this.providerPresenceStatusListeners.add(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)
|
||||
{
|
||||
serverStoredGroupListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock implementation of the corresponding ProtocolProviderService method.
|
||||
*
|
||||
* @param listener the SubscriptionListener to register
|
||||
*/
|
||||
public void addSubsciptionListener(SubscriptionListener listener)
|
||||
{
|
||||
this.subscriptionListeners.add( 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)
|
||||
{
|
||||
MockContactGroup newGroup
|
||||
= new MockContactGroup(groupName, parentProvider);
|
||||
|
||||
((MockContactGroup)parent).addSubgroup(newGroup);
|
||||
|
||||
this.fireServerStoredGroupEvent(
|
||||
newGroup, ServerStoredGroupEvent.GROUP_CREATED_EVENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Mock Provider method to use for fast filling of a contact list.
|
||||
*
|
||||
* @param contactGroup the group to add
|
||||
*/
|
||||
public void addMockGroup(MockContactGroup contactGroup)
|
||||
{
|
||||
contactListRoot.addSubgroup(contactGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Mock Provider method to use for fast filling of a contact list. This
|
||||
* method would add both the group and fire an event.
|
||||
*
|
||||
* @param parent the group where <tt>contactGroup</tt> should be added.
|
||||
* @param contactGroup the group to add
|
||||
*/
|
||||
public void addMockGroupAndFireEvent(MockContactGroup parent
|
||||
, MockContactGroup contactGroup)
|
||||
{
|
||||
parent.addSubgroup(contactGroup);
|
||||
|
||||
this.fireServerStoredGroupEvent(
|
||||
contactGroup, ServerStoredGroupEvent.GROUP_CREATED_EVENT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
return contactListRoot.findContactByID(contactID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the specified status message.
|
||||
* @param statusMessage a String containing the new status message.
|
||||
*/
|
||||
public void setStatusMessage(String statusMessage)
|
||||
{
|
||||
this.statusMessage = statusMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
return statusMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 presenceStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 MockStatusEnum.supportedStatusSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
MockContact mockContact = (MockContact)contactToMove;
|
||||
|
||||
MockContactGroup parentMockGroup = findContactParent(mockContact);
|
||||
|
||||
parentMockGroup.removeContact(mockContact);
|
||||
|
||||
((MockContactGroup)newParent).addContact(mockContact);
|
||||
|
||||
/** @todo fire an event (we probably need to create a new family of
|
||||
* move events) */
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
PresenceStatus oldPresenceStatus = this.presenceStatus;
|
||||
this.presenceStatus = status;
|
||||
this.statusMessage = statusMessage;
|
||||
|
||||
this.fireProviderStatusChangeEvent(oldPresenceStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 findContactByID(contactIdentifier).getPresenceStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the presence status of <tt>contact</tt> to <tt>newStatus</tt>.
|
||||
* @param contact the <tt>MockContact</tt> whose status we'd like to set.
|
||||
* @param newStatus the new status we'd like to set to <tt>contact</tt>.
|
||||
*/
|
||||
public void changePresenceStatusForContact(MockContact contact
|
||||
, MockStatusEnum newStatus)
|
||||
{
|
||||
PresenceStatus oldStatus = contact.getPresenceStatus();
|
||||
contact.setPresenceStatus(newStatus);
|
||||
|
||||
fireContactPresenceStatusChangeEvent(
|
||||
contact, findContactParent(contact), oldStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
contactPresenceStatusListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
this.providerPresenceStatusListeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the group that is parent of the specified mockGroup or null
|
||||
* if no parent was found.
|
||||
* @param mockGroup the group whose parent we're looking for.
|
||||
* @return the MockContactGroup instance that mockGroup belongs to or null
|
||||
* if no parent was found.
|
||||
*/
|
||||
public MockContactGroup findGroupParent(MockContactGroup mockGroup)
|
||||
{
|
||||
return contactListRoot.findGroupParent(mockGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the group that is parent of the specified mockContact or null
|
||||
* if no parent was found.
|
||||
* @param mockContact the contact whose parent we're looking for.
|
||||
* @return the MockContactGroup instance that mockContact belongs to or null
|
||||
* if no parent was found.
|
||||
*/
|
||||
public MockContactGroup findContactParent(MockContact mockContact)
|
||||
{
|
||||
return (MockContactGroup)mockContact.getParentContactGroup();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes the specified group from the server stored contact list.
|
||||
*
|
||||
* @param group the group to remove.
|
||||
*
|
||||
* @throws IllegalArgumentException if <tt>group</tt> was not found in this
|
||||
* protocol's contact list.
|
||||
*/
|
||||
public void removeServerStoredContactGroup(ContactGroup group)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
MockContactGroup mockGroup = (MockContactGroup)group;
|
||||
|
||||
MockContactGroup parent = findGroupParent(mockGroup);
|
||||
|
||||
if(parent == null){
|
||||
throw new IllegalArgumentException(
|
||||
"group " + group
|
||||
+ " does not seem to belong to this protocol's contact list.");
|
||||
}
|
||||
|
||||
parent.removeSubGroup(mockGroup);
|
||||
|
||||
this.fireServerStoredGroupEvent(
|
||||
mockGroup, ServerStoredGroupEvent.GROUP_REMOVED_EVENT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
serverStoredGroupListeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified subscription listener.
|
||||
*
|
||||
* @param listener the listener to remove.
|
||||
*/
|
||||
public void removeSubscriptionListener(SubscriptionListener listener)
|
||||
{
|
||||
this.subscriptionListeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
((MockContactGroup)group).setGroupName(newName);
|
||||
|
||||
this.fireServerStoredGroupEvent(
|
||||
(MockContactGroup)group, ServerStoredGroupEvent.GROUP_RENAMED_EVENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
MockContact contact = new MockContact(contactIdentifier
|
||||
, parentProvider);
|
||||
|
||||
((MockContactGroup)parent).addContact(contact);
|
||||
|
||||
fireSubscriptionEvent(contact,
|
||||
parent,
|
||||
SubscriptionEvent.SUBSCRIPTION_CREATED);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
MockContact contact = new MockContact(contactIdentifier
|
||||
, parentProvider);
|
||||
|
||||
contactListRoot.addContact(contact);
|
||||
|
||||
fireSubscriptionEvent(contact,
|
||||
contactListRoot,
|
||||
SubscriptionEvent.SUBSCRIPTION_CREATED);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
MockContactGroup parentGroup = (MockContactGroup)((MockContact)contact)
|
||||
.getParentContactGroup();
|
||||
|
||||
parentGroup.removeContact((MockContact)contact);
|
||||
|
||||
fireSubscriptionEvent((MockContact)contact,
|
||||
((MockContact)contact).getParentContactGroup(),
|
||||
SubscriptionEvent.SUBSCRIPTION_REMOVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a unresolved contact from the specified
|
||||
* <tt>address</tt> and <tt>persistentData</tt>. 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.
|
||||
*
|
||||
* @param address an identifier of the contact that we'll be creating.
|
||||
* @param persistentData a String returned Contact's getPersistentData()
|
||||
* method during a previous run and that has been persistently stored
|
||||
* locally.
|
||||
* @return the unresolved <tt>Contact</tt> created from the specified
|
||||
* <tt>address</tt> and <tt>persistentData</tt>
|
||||
*/
|
||||
public Contact createUnresolvedContact(String address,
|
||||
String persistentData)
|
||||
{
|
||||
MockContact contact = new MockContact(address, parentProvider);
|
||||
contact.setResolved(false);
|
||||
|
||||
( (MockContactGroup) getServerStoredContactListRoot())
|
||||
.addContact(contact);
|
||||
|
||||
fireSubscriptionEvent(contact,
|
||||
getServerStoredContactListRoot(),
|
||||
SubscriptionEvent.SUBSCRIPTION_CREATED);
|
||||
|
||||
return contact;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a unresolved contact from the specified
|
||||
* <tt>address</tt> and <tt>persistentData</tt>. 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.
|
||||
*
|
||||
* @param address an identifier of the contact that we'll be creating.
|
||||
* @param persistentData a String returned Contact's getPersistentData()
|
||||
* method during a previous run and that has been persistently stored
|
||||
* locally.
|
||||
* @param parentProtoGroup the group where the unresolved contact is
|
||||
* supposed to belong to.
|
||||
*
|
||||
* @return the unresolved <tt>Contact</tt> created from the specified
|
||||
* <tt>address</tt> and <tt>persistentData</tt>
|
||||
*/
|
||||
public Contact createUnresolvedContact(String address,
|
||||
String persistentData,
|
||||
ContactGroup parent)
|
||||
{
|
||||
MockContact contact = new MockContact(address, parentProvider);
|
||||
contact.setResolved(false);
|
||||
|
||||
( (MockContactGroup) parent).addContact(contact);
|
||||
|
||||
fireSubscriptionEvent(contact,
|
||||
parent,
|
||||
SubscriptionEvent.SUBSCRIPTION_CREATED);
|
||||
|
||||
return contact;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a unresolved contact group from the specified
|
||||
* <tt>address</tt> and <tt>persistentData</tt>. The method will not try
|
||||
* to establish a network connection and resolve the newly created
|
||||
* <tt>ContactGroup</tt> 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.
|
||||
*
|
||||
* @param groupUID an identifier, returned by ContactGroup's getGroupUID,
|
||||
* that the protocol provider may use in order to create the group.
|
||||
* @param persistentData a String returned ContactGroups's getPersistentData()
|
||||
* method during a previous run and that has been persistently stored
|
||||
* locally.
|
||||
* @param parentGroup the group under which the new group is to be created
|
||||
* or null if this is group directly underneath the root.
|
||||
* @return the unresolved <tt>ContactGroup</tt> created from the specified
|
||||
* <tt>uid</tt> and <tt>persistentData</tt>
|
||||
*/
|
||||
public ContactGroup createUnresolvedContactGroup(String groupUID,
|
||||
String persistentData, ContactGroup parentGroup)
|
||||
{
|
||||
MockContactGroup newGroup
|
||||
= new MockContactGroup(MockContactGroup.createNameFromUID(groupUID)
|
||||
, parentProvider);
|
||||
newGroup.setResolved(false);
|
||||
|
||||
//if parent is null then we're adding under root.
|
||||
if(parentGroup == null)
|
||||
parentGroup = getServerStoredContactListRoot();
|
||||
|
||||
((MockContactGroup)parentGroup).addSubgroup(newGroup);
|
||||
|
||||
this.fireServerStoredGroupEvent(
|
||||
newGroup, ServerStoredGroupEvent.GROUP_CREATED_EVENT);
|
||||
|
||||
return newGroup;
|
||||
}
|
||||
}
|
||||
@ -1,162 +0,0 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* A mock protocol provider implementation that comes with a single operation
|
||||
* set (OperationSetPersistentPresence) for use by the MetaContactListSlcik.
|
||||
*
|
||||
* @author Emil Ivov
|
||||
*/
|
||||
public class MockProvider
|
||||
implements ProtocolProviderService
|
||||
{
|
||||
/**
|
||||
* The SIP Communicator Mock Protocol name.
|
||||
*/
|
||||
private static final String PROTO_NAME = "TheSipCommMockProtocol";
|
||||
|
||||
/**
|
||||
* The operation sets that our mock provider supports.
|
||||
*/
|
||||
private Hashtable supportedOperationSets = new Hashtable();
|
||||
|
||||
/**
|
||||
* The presence operation set supported by the mock provider.
|
||||
*/
|
||||
private MockPersistentPresenceOperationSet mockPresOpSet = null;
|
||||
|
||||
/**
|
||||
* The identifier of the account.
|
||||
*/
|
||||
private AccountID accountID = null;
|
||||
|
||||
/**
|
||||
* Creates an instance of this mockprovider with a <tt>supportedOperationSet-s</tt>
|
||||
* map set to contain a single persistent presence operation set.
|
||||
*
|
||||
* @param userName an almost ignorable string (any value is accepted) that
|
||||
* should be used when constructing account id's
|
||||
*/
|
||||
public MockProvider(String userName)
|
||||
{
|
||||
accountID = new MockAccountID(userName);
|
||||
|
||||
mockPresOpSet = new MockPersistentPresenceOperationSet(this);
|
||||
this.supportedOperationSets.put(
|
||||
OperationSetPersistentPresence.class.getName(),
|
||||
mockPresOpSet);
|
||||
|
||||
this.supportedOperationSets.put(
|
||||
OperationSetPresence.class.getName(),
|
||||
mockPresOpSet);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock implementation of the corresponding ProtocolProviderService method.
|
||||
*
|
||||
* @param listener a param.
|
||||
*/
|
||||
public void addRegistrationStateChangeListener(
|
||||
RegistrationStateChangeListener listener)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock implementation of the corresponding ProtocolProviderService method.
|
||||
*
|
||||
* @return a String describing this mock protocol.
|
||||
*/
|
||||
public String getProtocolName()
|
||||
{
|
||||
return PROTO_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock implementation of the corresponding ProtocolProviderService method.
|
||||
*
|
||||
* @return a Registered RegistrationState.
|
||||
*/
|
||||
public RegistrationState getRegistrationState()
|
||||
{
|
||||
return RegistrationState.REGISTERED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing all operation sets supported by the
|
||||
* current implementation.
|
||||
*
|
||||
* @return a java.util.Map containing instance of all supported
|
||||
* operation sets mapped against their class names (e.g.
|
||||
* OperationSetPresence.class.getName()) .
|
||||
*/
|
||||
public Map getSupportedOperationSets()
|
||||
{
|
||||
return this.supportedOperationSets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock implementation of the corresponding ProtocolProviderService method.
|
||||
*
|
||||
* @return always true.
|
||||
*/
|
||||
public boolean isRegistered()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock implementation of the corresponding ProtocolProviderService method.
|
||||
*
|
||||
* @param authority a dummy param
|
||||
*/
|
||||
public void register(SecurityAuthority authority)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock implementation of the corresponding ProtocolProviderService method.
|
||||
*
|
||||
* @param listener a dummy param.
|
||||
*/
|
||||
public void removeRegistrationStateChangeListener(
|
||||
RegistrationStateChangeListener listener)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock implementation of the corresponding ProtocolProviderService method.
|
||||
*/
|
||||
public void shutdown()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock implementation of the corresponding ProtocolProviderService method.
|
||||
*/
|
||||
public void unregister()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the AccountID that uniquely identifies the account represented by
|
||||
* this instance of the ProtocolProviderService.
|
||||
* @return the id of the account represented by this provider.
|
||||
*/
|
||||
public AccountID getAccountID()
|
||||
{
|
||||
return accountID;
|
||||
}
|
||||
}
|
||||
@ -1,125 +0,0 @@
|
||||
/*
|
||||
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.slick.contactlist.mockprovider;
|
||||
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* An implementation of <tt>PresenceStatus</tt> that allows third parties
|
||||
* (external to the protocol provider) to create and eventually set custom
|
||||
* presence status intances.
|
||||
*
|
||||
* @author Emil Ivov
|
||||
*/
|
||||
public class MockStatusEnum
|
||||
extends PresenceStatus
|
||||
{
|
||||
/**
|
||||
* Indicates a status with 0 connectivity.
|
||||
*/
|
||||
public static final MockStatusEnum MOCK_STATUS_00
|
||||
= new MockStatusEnum(0, "MockStatus00");
|
||||
|
||||
/**
|
||||
* Indicates a status with a connectivity index of 10.
|
||||
*/
|
||||
public static final MockStatusEnum MOCK_STATUS_10
|
||||
= new MockStatusEnum(10, "MockStatus10");
|
||||
|
||||
/**
|
||||
* Indicates a status with a connectivity index of 20.
|
||||
*/
|
||||
public static final MockStatusEnum MOCK_STATUS_20
|
||||
= new MockStatusEnum(20, "MockStatus20");
|
||||
|
||||
/**
|
||||
* Indicates a status with a connectivity index of 30.
|
||||
*/
|
||||
public static final MockStatusEnum MOCK_STATUS_30
|
||||
= new MockStatusEnum(30, "MockStatus30");
|
||||
|
||||
/**
|
||||
* Indicates a status with a connectivity index of 40.
|
||||
*/
|
||||
public static final MockStatusEnum MOCK_STATUS_40
|
||||
= new MockStatusEnum(40, "MockStatus40");
|
||||
|
||||
/**
|
||||
* Indicates a status with a connectivity index of 50.
|
||||
*/
|
||||
public static final MockStatusEnum MOCK_STATUS_50
|
||||
= new MockStatusEnum(50, "MockStatus50");
|
||||
|
||||
/**
|
||||
* Indicates a status with a connectivity index of 60.
|
||||
*/
|
||||
public static final MockStatusEnum MOCK_STATUS_60
|
||||
= new MockStatusEnum(60, "MockStatus60");
|
||||
|
||||
/**
|
||||
* Indicates a status with a connectivity index of 70.
|
||||
*/
|
||||
public static final MockStatusEnum MOCK_STATUS_70
|
||||
= new MockStatusEnum(70, "MockStatus70");
|
||||
|
||||
/**
|
||||
* Indicates a status with a connectivity index of 80.
|
||||
*/
|
||||
public static final MockStatusEnum MOCK_STATUS_80
|
||||
= new MockStatusEnum(80, "MockStatus80");
|
||||
|
||||
/**
|
||||
* Indicates a status with a connectivity index of 90.
|
||||
*/
|
||||
public static final MockStatusEnum MOCK_STATUS_90
|
||||
= new MockStatusEnum(90, "MockStatus90");
|
||||
|
||||
/**
|
||||
* Indicates a status with a connectivity index of 100.
|
||||
*/
|
||||
public static final MockStatusEnum MOCK_STATUS_100
|
||||
= new MockStatusEnum(100, "MockStatus100");
|
||||
|
||||
|
||||
private static List supportedStatusSet = new LinkedList();
|
||||
static{
|
||||
supportedStatusSet.add(MOCK_STATUS_00);
|
||||
supportedStatusSet.add(MOCK_STATUS_10);
|
||||
supportedStatusSet.add(MOCK_STATUS_20);
|
||||
supportedStatusSet.add(MOCK_STATUS_30);
|
||||
supportedStatusSet.add(MOCK_STATUS_40);
|
||||
supportedStatusSet.add(MOCK_STATUS_50);
|
||||
supportedStatusSet.add(MOCK_STATUS_60);
|
||||
supportedStatusSet.add(MOCK_STATUS_70);
|
||||
supportedStatusSet.add(MOCK_STATUS_80);
|
||||
supportedStatusSet.add(MOCK_STATUS_90);
|
||||
supportedStatusSet.add(MOCK_STATUS_100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of <tt>MockPresneceStatus</tt> with the specified
|
||||
* parameters.
|
||||
* @param status the connectivity level of the new presence status instance
|
||||
* @param statusName the name of the presence status.
|
||||
*/
|
||||
private MockStatusEnum(int status, String statusName)
|
||||
{
|
||||
super(status, statusName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator over all status instances supproted by the mock
|
||||
* provider.
|
||||
* @return an <tt>Iterator</tt> over all status instances supported by the
|
||||
* mock provider.
|
||||
*/
|
||||
static Iterator supportedStatusSet()
|
||||
{
|
||||
return supportedStatusSet.iterator();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue