/* * Jitsi, the OpenSource Java VoIP and Instant Messaging client. * * Distributable under LGPL license. * See terms of license at gnu.org. */ package net.java.sip.communicator.service.contactsource; import java.util.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.util.*; /** * Implements a generic SourceContact for the purposes of the support * for the OS-specific Address Book. * * @author Lyubomir Marinov */ public class GenericSourceContact extends DataObject implements SourceContact { /** * The ContactDetails of this SourceContact. */ private final List contactDetails; /** * The ContactSourceService which has created this * SourceContact. */ private final ContactSourceService contactSource; /** * The display name of this SourceContact. */ private final String displayName; /** * The image/avatar of this SourceContact */ private byte[] image; /** * Initializes a new AddrBookSourceContact instance. * * @param contactSource the ContactSourceService which is creating * the new instance * @param displayName the display name of the new instance * @param contactDetails the ContactDetails of the new instance */ public GenericSourceContact( ContactSourceService contactSource, String displayName, List contactDetails) { this.contactSource = contactSource; this.displayName = displayName; this.contactDetails = contactDetails; } /** * Gets the ContactDetails of this SourceContact. * * @return the ContactDetails of this SourceContact * @see SourceContact#getContactDetails() */ public List getContactDetails() { return Collections.unmodifiableList(contactDetails); } /** * Gets the ContactDetails of this SourceContact which * support a specific OperationSet. * * @param operationSet the OperationSet the supporting * ContactDetails of which are to be returned * @return the ContactDetails of this SourceContact which * support the specified operationSet * @see SourceContact#getContactDetails(Class) */ public List getContactDetails( Class operationSet) { List contactDetails = new LinkedList(); for (ContactDetail contactDetail : getContactDetails()) { List> supportedOperationSets = contactDetail.getSupportedOperationSets(); if ((supportedOperationSets != null) && supportedOperationSets.contains(operationSet)) contactDetails.add(contactDetail); } return contactDetails; } /** * Returns a list of all ContactDetails corresponding to the given * category. * @param category the OperationSet class we're looking for * @return a list of all ContactDetails corresponding to the given * category */ public List getContactDetails(String category) { List contactDetails = new LinkedList(); for (ContactDetail contactDetail : getContactDetails()) { String detailCategory = contactDetail.getCategory(); if (detailCategory != null && detailCategory.equals(category)) contactDetails.add(contactDetail); } return contactDetails; } /** * Gets the ContactSourceService which has created this * SourceContact. * * @return the ContactSourceService which has created this * SourceContact * @see SourceContact#getContactSource() */ public ContactSourceService getContactSource() { return contactSource; } /** * Gets the display details of this SourceContact. * * @return the display details of this SourceContact * @see SourceContact#getDisplayDetails() */ public String getDisplayDetails() { // TODO Auto-generated method stub return null; } /** * Gets the display name of this SourceContact. * * @return the display name of this SourceContact * @see SourceContact#getDisplayName() */ public String getDisplayName() { return displayName; } /** * Gets the image/avatar of this SourceContact. * * @return the image/avatar of this SourceContact * @see SourceContact#getImage() */ public byte[] getImage() { return image; } /** * Gets the preferred ContactDetail for a specific * OperationSet. * * @param operationSet the OperationSet to get the preferred * ContactDetail for * @return the preferred ContactDetail for the specified * operationSet * @see SourceContact#getPreferredContactDetail(Class) */ public ContactDetail getPreferredContactDetail( Class operationSet) { List contactDetails = getContactDetails(operationSet); return contactDetails.isEmpty() ? null : contactDetails.get(0); } /** * Sets the image/avatar of this SourceContact. * * @param image the image/avatar to be set on this SourceContact */ public void setImage(byte[] image) { this.image = image; } /** * Returns the status of the source contact. And null if such information * is not available. * @return the PresenceStatus representing the state of this source contact. */ public PresenceStatus getPresenceStatus() { return null; } }