diff options
16 files changed, 319 insertions, 1561 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/dict/OperationSetPersistentPresenceDictImpl.java b/src/net/java/sip/communicator/impl/protocol/dict/OperationSetPersistentPresenceDictImpl.java index 06f6e3f..dacea1a 100644 --- a/src/net/java/sip/communicator/impl/protocol/dict/OperationSetPersistentPresenceDictImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/dict/OperationSetPersistentPresenceDictImpl.java @@ -25,13 +25,10 @@ import org.osgi.framework.*; * @author LITZELMANN Cedric */ public class OperationSetPersistentPresenceDictImpl - implements OperationSetPersistentPresence + extends AbstractOperationSetPersistentPresence<ProtocolProviderServiceDictImpl> { private static final Logger logger = Logger.getLogger(OperationSetPersistentPresenceDictImpl.class); - /** - */ - private Vector subscriptionListeners = new Vector(); /** * A list of listeners registered for <tt>ServerStoredGroupChangeEvent</tt>s. @@ -56,11 +53,6 @@ public class OperationSetPersistentPresenceDictImpl private ContactGroupDictImpl contactListRoot = null; /** - * The provider that created us. - */ - private ProtocolProviderServiceDictImpl parentProvider = null; - - /** * The currently active status message. */ private String statusMessage = "Default Status Message"; @@ -85,7 +77,8 @@ public class OperationSetPersistentPresenceDictImpl public OperationSetPersistentPresenceDictImpl( ProtocolProviderServiceDictImpl provider) { - this.parentProvider = provider; + super(provider); + contactListRoot = new ContactGroupDictImpl("RootGroup", provider); //add our unregistration listener @@ -141,82 +134,6 @@ public class OperationSetPersistentPresenceDictImpl } } - - /** - * 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(ContactDictImpl source, - ContactGroup parentGroup, - int eventID) - { - SubscriptionEvent evt = new SubscriptionEvent(source - , this.parentProvider - , parentGroup - , eventID); - - Iterator listeners = null; - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - 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 been moved.. - * @param oldParent the group where the contact was located before being - * moved. - * @param newParent the group where the contact has been moved. - */ - public void fireSubscriptionMovedEvent(Contact source, - ContactGroup oldParent, - ContactGroup newParent) - { - SubscriptionMovedEvent evt = new SubscriptionMovedEvent(source - , this.parentProvider - , oldParent - , newParent); - - Iterator listeners = null; - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - listener.subscriptionMoved(evt); - } - } - - /** * Notifies all registered listeners of the new event. * @@ -316,21 +233,6 @@ public class OperationSetPersistentPresenceDictImpl } /** - * Dict implementation of the corresponding ProtocolProviderService - * method. - * - * @param listener the SubscriptionListener to register - */ - public void addSubsciptionListener(SubscriptionListener listener) - { - synchronized(subscriptionListeners) - { - if (!subscriptionListeners.contains(listener)) - this.subscriptionListeners.add(listener); - } - } - - /** * Creates a group with the specified name and parent in the server * stored contact list. * @@ -756,19 +658,6 @@ public class OperationSetPersistentPresenceDictImpl } /** - * Removes the specified subscription listener. - * - * @param listener the listener to remove. - */ - public void removeSubscriptionListener(SubscriptionListener listener) - { - synchronized(subscriptionListeners) - { - this.subscriptionListeners.remove(listener); - } - } - - /** * Renames the specified group from the server stored contact list. * * @param group the group to rename. diff --git a/src/net/java/sip/communicator/impl/protocol/gibberish/OperationSetPersistentPresenceGibberishImpl.java b/src/net/java/sip/communicator/impl/protocol/gibberish/OperationSetPersistentPresenceGibberishImpl.java index 8c77a6f..81c132d 100644 --- a/src/net/java/sip/communicator/impl/protocol/gibberish/OperationSetPersistentPresenceGibberishImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/gibberish/OperationSetPersistentPresenceGibberishImpl.java @@ -23,14 +23,10 @@ import org.osgi.framework.*; * @author Emil Ivov */ public class OperationSetPersistentPresenceGibberishImpl - implements OperationSetPersistentPresence + extends AbstractOperationSetPersistentPresence<ProtocolProviderServiceGibberishImpl> { private static final Logger logger = Logger.getLogger(OperationSetPersistentPresenceGibberishImpl.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. @@ -55,11 +51,6 @@ public class OperationSetPersistentPresenceGibberishImpl private ContactGroupGibberishImpl contactListRoot = null; /** - * The provider that created us. - */ - private ProtocolProviderServiceGibberishImpl parentProvider = null; - - /** * The currently active status message. */ private String statusMessage = "Default Status Message"; @@ -84,7 +75,8 @@ public class OperationSetPersistentPresenceGibberishImpl public OperationSetPersistentPresenceGibberishImpl( ProtocolProviderServiceGibberishImpl provider) { - this.parentProvider = provider; + super(provider); + contactListRoot = new ContactGroupGibberishImpl("RootGroup", provider); //add our unregistration listener @@ -140,82 +132,6 @@ public class OperationSetPersistentPresenceGibberishImpl } } - - /** - * 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(ContactGibberishImpl source, - ContactGroup parentGroup, - int eventID) - { - SubscriptionEvent evt = new SubscriptionEvent(source - , this.parentProvider - , parentGroup - , eventID); - - Iterator listeners = null; - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - 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 been moved.. - * @param oldParent the group where the contact was located before being - * moved. - * @param newParent the group where the contact has been moved. - */ - public void fireSubscriptionMovedEvent(Contact source, - ContactGroup oldParent, - ContactGroup newParent) - { - SubscriptionMovedEvent evt = new SubscriptionMovedEvent(source - , this.parentProvider - , oldParent - , newParent); - - Iterator listeners = null; - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - listener.subscriptionMoved(evt); - } - } - - /** * Notifies all registered listeners of the new event. * @@ -315,21 +231,6 @@ public class OperationSetPersistentPresenceGibberishImpl } /** - * Gibberish implementation of the corresponding ProtocolProviderService - * method. - * - * @param listener the SubscriptionListener to register - */ - public void addSubsciptionListener(SubscriptionListener listener) - { - synchronized(subscriptionListeners) - { - if (!subscriptionListeners.contains(listener)) - this.subscriptionListeners.add(listener); - } - } - - /** * Creates a group with the specified name and parent in the server * stored contact list. * @@ -755,19 +656,6 @@ public class OperationSetPersistentPresenceGibberishImpl } /** - * Removes the specified subscription listener. - * - * @param listener the listener to remove. - */ - public void removeSubscriptionListener(SubscriptionListener listener) - { - synchronized(subscriptionListeners) - { - this.subscriptionListeners.remove(listener); - } - } - - /** * Renames the specified group from the server stored contact list. * * @param group the group to rename. diff --git a/src/net/java/sip/communicator/impl/protocol/icq/OperationSetPersistentPresenceIcqImpl.java b/src/net/java/sip/communicator/impl/protocol/icq/OperationSetPersistentPresenceIcqImpl.java index d11ec29..a6023a3 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/OperationSetPersistentPresenceIcqImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/icq/OperationSetPersistentPresenceIcqImpl.java @@ -12,7 +12,6 @@ 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.*; -import net.java.sip.communicator.service.protocol.AuthorizationResponse.*; import net.java.sip.communicator.util.*; import net.kano.joscar.*; import net.kano.joscar.flapcmd.*; @@ -40,29 +39,18 @@ import net.kano.joustsim.trust.*; * @author Emil Ivov */ public class OperationSetPersistentPresenceIcqImpl - implements OperationSetPersistentPresence + extends AbstractOperationSetPersistentPresence<ProtocolProviderServiceIcqImpl> { private static final Logger logger = Logger.getLogger(OperationSetPersistentPresenceIcqImpl.class); /** - * A callback to the ICQ provider that created us. - */ - private ProtocolProviderServiceIcqImpl icqProvider = null; - - /** * The list of presence status listeners interested in receiving presence * notifications of changes in status of contacts in our contact list. */ private Vector contactPresenceStatusListeners = new Vector(); /** - * The list of subscription listeners interested in receiving notifications - * whenever . - */ - private Vector subscriptionListeners = new Vector(); - - /** * The list of listeners interested in receiving changes in our local * presencestatus. */ @@ -202,12 +190,12 @@ public class OperationSetPersistentPresenceIcqImpl ProtocolProviderServiceIcqImpl icqProvider, String uin) { - this.icqProvider = icqProvider; + super(icqProvider); ssContactList = new ServerStoredContactListIcqImpl( this , icqProvider); //add a listener that'll follow the provider's state. - icqProvider.addRegistrationStateChangeListener( + parentProvider.addRegistrationStateChangeListener( registrationStateListener); } @@ -248,31 +236,6 @@ public class OperationSetPersistentPresenceIcqImpl } /** - * Registers a listener that would get notifications any time a new - * subscription was succesfully added, has failed or was removed. - * @param listener the SubscriptionListener to register - */ - public void addSubsciptionListener(SubscriptionListener listener) - { - synchronized(subscriptionListeners) - { - if(!subscriptionListeners.contains(listener)) - subscriptionListeners.add(listener); - } - } - - /** - * Removes the specified subscription listener. - * @param listener the listener to remove. - */ - public void removeSubscriptionListener(SubscriptionListener listener) - { - synchronized(subscriptionListeners){ - subscriptionListeners.remove(listener); - } - } - - /** * Get the PresenceStatus for a particular contact. This method is not meant * to be used by the user interface (which would simply register as a * presence listener and always follow contact status) but rather by other @@ -307,7 +270,7 @@ public class OperationSetPersistentPresenceIcqImpl GetInfoCmd getInfoCmd = new GetInfoCmd(GetInfoCmd.CMD_USER_INFO, contactIdentifier); - icqProvider.getAimConnection().getInfoService().getOscarConnection() + parentProvider.getAimConnection().getInfoService().getOscarConnection() .sendSnacRequest(getInfoCmd, responseRetriever); synchronized(responseRetriever) @@ -334,7 +297,7 @@ public class OperationSetPersistentPresenceIcqImpl */ private PresenceStatus statusLongToPresenceStatus(long icqStatus) { - if(icqProvider.USING_ICQ) + if(parentProvider.USING_ICQ) { // Fixed order of status checking // The order does matter, as the icqStatus consists of more than one @@ -413,7 +376,7 @@ public class OperationSetPersistentPresenceIcqImpl */ private long presenceStatusToStatusLong(PresenceStatus status) { - if(icqProvider.USING_ICQ) + if(parentProvider.USING_ICQ) return ((Long)scToIcqStatusMappings.get(status)).longValue(); else return ((Long)scToAimStatusMappings.get(status)).longValue(); @@ -624,9 +587,9 @@ public class OperationSetPersistentPresenceIcqImpl if(!contactIcqImpl.isPersistent()) { contactGroup.removeContact(contactIcqImpl); - fireSubscriptionEvent(SubscriptionEvent.SUBSCRIPTION_REMOVED, - contactIcqImpl, - contactGroup); + fireSubscriptionEvent(contactIcqImpl, + contactGroup, + SubscriptionEvent.SUBSCRIPTION_REMOVED); return; } @@ -701,9 +664,9 @@ public class OperationSetPersistentPresenceIcqImpl logger.debug("Will set status: " + status); MainBosService bosService - = icqProvider.getAimConnection().getBosService(); + = parentProvider.getAimConnection().getBosService(); - if(!icqProvider.USING_ICQ) + if(!parentProvider.USING_ICQ) { if(status.equals(AimStatusEnum.AWAY)) { @@ -741,7 +704,7 @@ public class OperationSetPersistentPresenceIcqImpl bosService.getOscarConnection().sendSnac(new SetExtraInfoCmd(icqStatus)); if(status.equals(IcqStatusEnum.AWAY)) - icqProvider.getAimConnection().getInfoService(). + parentProvider.getAimConnection().getInfoService(). setAwayMessage(statusMessage); else bosService.setStatusMessage(statusMessage); @@ -749,7 +712,7 @@ public class OperationSetPersistentPresenceIcqImpl //so that everyone sees the change. queryContactStatus( - icqProvider.getAimConnection().getScreenname().getFormatted()); + parentProvider.getAimConnection().getScreenname().getFormatted()); } /** @@ -928,7 +891,7 @@ public class OperationSetPersistentPresenceIcqImpl { if(supportedPresenceStatusSet.size() == 0) { - if(icqProvider.USING_ICQ) + if(parentProvider.USING_ICQ) { supportedPresenceStatusSet.add(IcqStatusEnum.ONLINE); supportedPresenceStatusSet.add(IcqStatusEnum.DO_NOT_DISTURB); @@ -969,7 +932,7 @@ public class OperationSetPersistentPresenceIcqImpl **/ this.authorizationHandler = handler; - icqProvider.getAimConnection().getSsiService(). + parentProvider.getAimConnection().getSsiService(). addBuddyAuthorizationListener(authListener); } @@ -1048,11 +1011,11 @@ public class OperationSetPersistentPresenceIcqImpl */ private void assertConnected() throws IllegalStateException { - if (icqProvider == null) + if (parentProvider == null) throw new IllegalStateException( "The icq provider must be non-null and signed on the ICQ " +"service before being able to communicate."); - if (!icqProvider.isRegistered()) + if (!parentProvider.isRegistered()) throw new IllegalStateException( "The icq provider must be signed on the ICQ service before " +"being able to communicate."); @@ -1141,7 +1104,7 @@ public class OperationSetPersistentPresenceIcqImpl ProviderPresenceStatusChangeEvent evt = new ProviderPresenceStatusChangeEvent( - icqProvider, oldStatus, newStatus); + parentProvider, oldStatus, newStatus); logger.debug("Dispatching Provider Status Change. Listeners=" + providerPresenceStatusListeners.size() @@ -1173,7 +1136,7 @@ public class OperationSetPersistentPresenceIcqImpl { PropertyChangeEvent evt = new PropertyChangeEvent( - icqProvider, ProviderPresenceStatusListener.STATUS_MESSAGE, + parentProvider, ProviderPresenceStatusListener.STATUS_MESSAGE, oldStatusMessage, newStatusMessage); logger.debug("Dispatching stat. msg change. Listeners=" @@ -1196,130 +1159,6 @@ public class OperationSetPersistentPresenceIcqImpl } /** - * Notify all subscription listeners of the corresponding event. - * - * @param eventID the int ID of the event to dispatch - * @param sourceContact the ContactIcqImpl instance that this event is - * pertaining to. - * @param parentGroup the ContactGroupIcqImpl under which the corresponding - * subscription is located. - */ - void fireSubscriptionEvent( int eventID, - ContactIcqImpl sourceContact, - ContactGroupIcqImpl parentGroup) - { - SubscriptionEvent evt = - new SubscriptionEvent(sourceContact, icqProvider, parentGroup, - eventID); - - logger.debug("Dispatching a Subscription Event to" - +subscriptionListeners.size() + " listeners. Evt="+evt); - - Iterator listeners = null; - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - if (evt.getEventID() == SubscriptionEvent.SUBSCRIPTION_CREATED) - { - listener.subscriptionCreated(evt); - } - else if (evt.getEventID() == SubscriptionEvent.SUBSCRIPTION_REMOVED) - { - listener.subscriptionRemoved(evt); - } - else if (evt.getEventID() == SubscriptionEvent.SUBSCRIPTION_FAILED) - { - listener.subscriptionFailed(evt); - } - } - } - - /** - * Notify all subscription listeners of the corresponding contact property - * change event. - * - * @param eventID the String ID of the event to dispatch - * @param sourceContact the ContactIcqImpl instance that this event is - * pertaining to. - * @param oldValue the value that the changed property had before the change - * occurred. - * @param newValue the value that the changed property currently has (after - * the change has occurred). - */ - void fireContactPropertyChangeEvent( String eventID, - ContactIcqImpl sourceContact, - Object oldValue, - Object newValue) - { - ContactPropertyChangeEvent evt = - new ContactPropertyChangeEvent(sourceContact, eventID - , oldValue, newValue); - - logger.debug("Dispatching a Contact Property Change Event to" - +subscriptionListeners.size() + " listeners. Evt="+evt); - - Iterator listeners = null; - - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - listener.contactModified(evt); - } - } - - - /** - * Notify all subscription listeners of the corresponding event. - * - * @param sourceContact the ContactIcqImpl instance that this event is - * pertaining to. - * @param oldParentGroup the group that was previously a parent of the - * source contact. - * @param newParentGroup the group under which the corresponding - * subscription is currently located. - */ - void fireSubscriptionMovedEvent( ContactIcqImpl sourceContact, - ContactGroupIcqImpl oldParentGroup, - ContactGroupIcqImpl newParentGroup) - { - SubscriptionMovedEvent evt = - new SubscriptionMovedEvent(sourceContact, icqProvider - , oldParentGroup, newParentGroup); - - logger.debug("Dispatching a Subscription Event to" - +subscriptionListeners.size() + " listeners. Evt="+evt); - - Iterator listeners = null; - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - listener.subscriptionMoved(evt); - } - } - - - /** * Notify all contact presence listeners of the corresponding event change * @param contact the contact that changed its status * @param oldStatus the status that the specified contact had so far @@ -1334,7 +1173,7 @@ public class OperationSetPersistentPresenceIcqImpl { ContactPresenceStatusChangeEvent evt = new ContactPresenceStatusChangeEvent( - contact, icqProvider, parentGroup, oldStatus, newStatus); + contact, parentProvider, parentGroup, oldStatus, newStatus); logger.debug("Dispatching Contact Status Change. Listeners=" + contactPresenceStatusListeners.size() @@ -1377,33 +1216,33 @@ public class OperationSetPersistentPresenceIcqImpl if(evt.getNewState() == RegistrationState.REGISTERED) { logger.debug("adding a Bos Service Listener"); - icqProvider.getAimConnection().getBosService() + parentProvider.getAimConnection().getBosService() .addMainBosServiceListener(joustSimBosListener); ssContactList.init( - icqProvider.getAimConnection().getSsiService()); + parentProvider.getAimConnection().getSsiService()); // /**@todo implement the following - icqProvider.getAimConnection().getBuddyService() + parentProvider.getAimConnection().getBuddyService() .addBuddyListener(joustSimBuddySerListener); // @todo we really need this for following the status of our // contacts and we really need it here ...*/ - icqProvider.getAimConnection().getBuddyInfoManager() + parentProvider.getAimConnection().getBuddyInfoManager() .addGlobalBuddyInfoListener(new GlobalBuddyInfoListener()); - icqProvider.getAimConnection().getExternalServiceManager(). + parentProvider.getAimConnection().getExternalServiceManager(). getIconServiceArbiter().addIconRequestListener( new IconUpdateListener()); - icqProvider.getAimConnection().getInfoService(). + parentProvider.getAimConnection().getInfoService(). addInfoListener(new AwayMessageListener()); - if(icqProvider.USING_ICQ) + if(parentProvider.USING_ICQ) { opSetExtendedAuthorizations = (OperationSetExtendedAuthorizationsIcqImpl) - icqProvider.getSupportedOperationSets() + parentProvider.getSupportedOperationSets() .get(OperationSetExtendedAuthorizations.class.getName()); if(presenceQueryTimer == null) @@ -1466,7 +1305,7 @@ public class OperationSetPersistentPresenceIcqImpl if(!oldContactStatus.isOnline()) continue; - if(icqProvider.USING_ICQ) + if(parentProvider.USING_ICQ) { contact.updatePresenceStatus(IcqStatusEnum.OFFLINE); @@ -1548,7 +1387,7 @@ public class OperationSetPersistentPresenceIcqImpl //update the last received field. long oldStatus = currentIcqStatus; - if(icqProvider.USING_ICQ) + if(parentProvider.USING_ICQ) { currentIcqStatus = userInfo.getIcqStatus(); @@ -1618,7 +1457,7 @@ public class OperationSetPersistentPresenceIcqImpl PresenceStatus newStatus = null; - if(!icqProvider.USING_ICQ) + if(!parentProvider.USING_ICQ) { Boolean awayStatus = info.getAwayStatus(); if(awayStatus == null || awayStatus.equals(Boolean.FALSE)) @@ -1677,7 +1516,7 @@ public class OperationSetPersistentPresenceIcqImpl = sourceContact.getPresenceStatus(); PresenceStatus newStatus = null; - if(icqProvider.USING_ICQ) + if(parentProvider.USING_ICQ) newStatus = IcqStatusEnum.OFFLINE; else newStatus = AimStatusEnum.OFFLINE; @@ -1769,7 +1608,7 @@ public class OperationSetPersistentPresenceIcqImpl if (authResponse.getResponseCode() == AuthorizationResponse.IGNORE) return; - icqProvider.getAimConnection().getSsiService(). + parentProvider.getAimConnection().getSsiService(). replyBuddyAuthorization( screenname, authResponse.getResponseCode() == AuthorizationResponse.ACCEPT, @@ -1836,10 +1675,10 @@ public class OperationSetPersistentPresenceIcqImpl if(authRequest == null) return false; - icqProvider.getAimConnection().getSsiService(). + parentProvider.getAimConnection().getSsiService(). sendFutureBuddyAuthorization(screenname, authRequest.getReason()); - icqProvider.getAimConnection().getSsiService(). + parentProvider.getAimConnection().getSsiService(). requestBuddyAuthorization(screenname, authRequest.getReason()); return true; diff --git a/src/net/java/sip/communicator/impl/protocol/icq/ServerStoredContactListIcqImpl.java b/src/net/java/sip/communicator/impl/protocol/icq/ServerStoredContactListIcqImpl.java index c1ca82a..4390e90 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/ServerStoredContactListIcqImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/icq/ServerStoredContactListIcqImpl.java @@ -243,7 +243,7 @@ public class ServerStoredContactListIcqImpl //dispatch parentOperationSet.fireSubscriptionEvent( - SubscriptionEvent.SUBSCRIPTION_CREATED, contact, parentGroup); + contact, parentGroup, SubscriptionEvent.SUBSCRIPTION_CREATED); } /** @@ -263,7 +263,7 @@ public class ServerStoredContactListIcqImpl //dispatch parentOperationSet.fireSubscriptionEvent( - SubscriptionEvent.SUBSCRIPTION_RESOLVED, contact, parentGroup); + contact, parentGroup, SubscriptionEvent.SUBSCRIPTION_RESOLVED); } @@ -310,7 +310,7 @@ public class ServerStoredContactListIcqImpl //dispatch parentOperationSet.fireSubscriptionEvent( - SubscriptionEvent.SUBSCRIPTION_REMOVED, contact, parentGroup); + contact, parentGroup, SubscriptionEvent.SUBSCRIPTION_REMOVED); } private void fireContactsReordered( ContactGroupIcqImpl parentGroup) @@ -589,9 +589,9 @@ public class ServerStoredContactListIcqImpl new Thread(){ public void run(){ parentOperationSet.fireSubscriptionEvent( - SubscriptionEvent.SUBSCRIPTION_CREATED, existingContact, - findContactGroup(existingContact)); + findContactGroup(existingContact), + SubscriptionEvent.SUBSCRIPTION_CREATED); } }.start(); return; diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java index f1bdc07..aba9237 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java @@ -29,17 +29,12 @@ import net.java.sip.communicator.impl.protocol.jabber.extensions.version.*; * @author Lubomir Marinov */ public class OperationSetPersistentPresenceJabberImpl - implements OperationSetPersistentPresence + extends AbstractOperationSetPersistentPresence<ProtocolProviderServiceJabberImpl> { private static final Logger logger = Logger.getLogger(OperationSetPersistentPresenceJabberImpl.class); /** - * A callback to the Jabber provider that created us. - */ - private ProtocolProviderServiceJabberImpl jabberProvider = null; - - /** * Contains our current status message. Note that this field would only * be changed once the server has confirmed the new status message and * not immediately upon setting a new one.. @@ -59,12 +54,6 @@ public class OperationSetPersistentPresenceJabberImpl private Vector providerPresenceStatusListeners = new Vector(); /** - * The list of subscription listeners interested in receiving notifications - * whenever . - */ - private Vector subscriptionListeners = new Vector(); - - /** * The list of presence status listeners interested in receiving presence * notifications of changes in status of contacts in our contact list. */ @@ -99,15 +88,15 @@ public class OperationSetPersistentPresenceJabberImpl public OperationSetPersistentPresenceJabberImpl( ProtocolProviderServiceJabberImpl provider) { - this.jabberProvider = provider; + super(provider); currentStatus = - this.jabberProvider.getJabberStatusEnum().getStatus( + parentProvider.getJabberStatusEnum().getStatus( JabberStatusEnum.OFFLINE); ssContactList = new ServerStoredContactListJabberImpl( this , provider); - this.jabberProvider.addRegistrationStateChangeListener( + parentProvider.addRegistrationStateChangeListener( new RegistrationStateListener()); } @@ -156,19 +145,6 @@ public class OperationSetPersistentPresenceJabberImpl } /** - * Registers a listener that would get notifications any time a new - * subscription was succesfully added, has failed or was removed. - * - * @param listener the SubscriptionListener to register - */ - public void addSubsciptionListener(SubscriptionListener listener) - { - synchronized(subscriptionListeners){ - subscriptionListeners.add(listener); - } - } - - /** * Creates a group with the specified name and parent in the server * stored contact list. * @@ -345,7 +321,7 @@ public class OperationSetPersistentPresenceJabberImpl */ public Iterator getSupportedStatusSet() { - return jabberProvider.getJabberStatusEnum().getSupportedStatusSet(); + return parentProvider.getJabberStatusEnum().getSupportedStatusSet(); } /** @@ -396,7 +372,7 @@ public class OperationSetPersistentPresenceJabberImpl assertConnected(); JabberStatusEnum jabberStatusEnum = - jabberProvider.getJabberStatusEnum(); + parentProvider.getJabberStatusEnum(); boolean isValidStatus = false; for (Iterator supportedStatusIter = jabberStatusEnum.getSupportedStatusSet(); supportedStatusIter @@ -416,7 +392,7 @@ public class OperationSetPersistentPresenceJabberImpl if (status.equals(jabberStatusEnum.getStatus(JabberStatusEnum.OFFLINE))) { presence = new Presence(Presence.Type.unavailable); - jabberProvider.unregister(); + parentProvider.unregister(); } else { @@ -426,7 +402,7 @@ public class OperationSetPersistentPresenceJabberImpl presence.setStatus(statusMessage); presence.addExtension(new Version()); - jabberProvider.getConnection().sendPacket(presence); + parentProvider.getConnection().sendPacket(presence); } fireProviderPresenceStatusChangeEvent(currentStatus, status); @@ -459,13 +435,13 @@ public class OperationSetPersistentPresenceJabberImpl IllegalArgumentException, IllegalStateException, OperationFailedException { - Presence presence = jabberProvider.getConnection().getRoster(). + Presence presence = parentProvider.getConnection().getRoster(). getPresence(contactIdentifier); if(presence != null) - return jabberStatusToPresenceStatus(presence, jabberProvider); + return jabberStatusToPresenceStatus(presence, parentProvider); else - return jabberProvider.getJabberStatusEnum().getStatus( + return parentProvider.getJabberStatusEnum().getStatus( JabberStatusEnum.OFFLINE); } @@ -526,18 +502,6 @@ public class OperationSetPersistentPresenceJabberImpl } /** - * Removes the specified subscription listener. - * - * @param listener the listener to remove. - */ - public void removeSubscriptionListener(SubscriptionListener listener) - { - synchronized(subscriptionListeners){ - subscriptionListeners.remove(listener); - } - } - - /** * Renames the specified group from the server stored contact list. * * @param group the group to rename. @@ -569,7 +533,7 @@ public class OperationSetPersistentPresenceJabberImpl subscribtionPacketListener = new JabberSubscriptionListener(); PacketFilter packetFilter = new PacketTypeFilter(Presence.class); - jabberProvider.getConnection(). + parentProvider.getConnection(). addPacketListener(subscribtionPacketListener, packetFilter); } @@ -724,11 +688,11 @@ public class OperationSetPersistentPresenceJabberImpl */ private void assertConnected() throws IllegalStateException { - if (jabberProvider == null) + if (parentProvider == null) throw new IllegalStateException( "The provider must be non-null and signed on the Jabber " +"service before being able to communicate."); - if (!jabberProvider.isRegistered()) + if (!parentProvider.isRegistered()) throw new IllegalStateException( "The provider must be signed on the Jabber service before " +"being able to communicate."); @@ -750,7 +714,7 @@ public class OperationSetPersistentPresenceJabberImpl ProviderPresenceStatusChangeEvent evt = new ProviderPresenceStatusChangeEvent( - jabberProvider, oldStatus, newStatus); + parentProvider, oldStatus, newStatus); currentStatus = newStatus; @@ -785,7 +749,7 @@ public class OperationSetPersistentPresenceJabberImpl { PropertyChangeEvent evt = new PropertyChangeEvent( - jabberProvider, ProviderPresenceStatusListener.STATUS_MESSAGE, + parentProvider, ProviderPresenceStatusListener.STATUS_MESSAGE, oldStatusMessage, newStatusMessage); logger.debug("Dispatching stat. msg change. Listeners=" @@ -829,11 +793,11 @@ public class OperationSetPersistentPresenceJabberImpl if(evt.getNewState() == RegistrationState.REGISTERED) { - jabberProvider.getConnection().getRoster().addRosterListener( + parentProvider.getConnection().getRoster().addRosterListener( new ContactChangesListener()); fireProviderPresenceStatusChangeEvent(currentStatus, - jabberProvider.getJabberStatusEnum().getStatus( + parentProvider.getJabberStatusEnum().getStatus( JabberStatusEnum.AVAILABLE)); // init ssList @@ -849,7 +813,7 @@ public class OperationSetPersistentPresenceJabberImpl //were online PresenceStatus oldStatus = currentStatus; PresenceStatus offlineStatus = - jabberProvider.getJabberStatusEnum().getStatus( + parentProvider.getJabberStatusEnum().getStatus( JabberStatusEnum.OFFLINE); currentStatus = offlineStatus; @@ -917,82 +881,6 @@ public class OperationSetPersistentPresenceJabberImpl } /** - * Notify all subscription listeners of the corresponding event. - * - * @param eventID the int ID of the event to dispatch - * @param sourceContact the ContactJabberImpl instance that this event is - * pertaining to. - * @param parentGroup the ContactGroupJabberImpl under which the corresponding - * subscription is located. - */ - void fireSubscriptionEvent( int eventID, - ContactJabberImpl sourceContact, - ContactGroup parentGroup) - { - SubscriptionEvent evt = - new SubscriptionEvent(sourceContact, jabberProvider, parentGroup, - eventID); - - logger.debug("Dispatching a Subscription Event to" - +subscriptionListeners.size() + " listeners. Evt="+evt); - - Iterator listeners = null; - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - if (evt.getEventID() == SubscriptionEvent.SUBSCRIPTION_CREATED) - listener.subscriptionCreated(evt); - else if (evt.getEventID() == SubscriptionEvent.SUBSCRIPTION_REMOVED) - listener.subscriptionRemoved(evt); - else if (evt.getEventID() == SubscriptionEvent.SUBSCRIPTION_FAILED) - listener.subscriptionFailed(evt); - } - } - - /** - * Notify all subscription listeners of the corresponding event. - * - * @param sourceContact the ContactJabberImpl instance that this event is - * pertaining to. - * @param oldParentGroup the group that was previously a parent of the - * source contact. - * @param newParentGroup the group under which the corresponding - * subscription is currently located. - */ - void fireSubscriptionMovedEvent( ContactJabberImpl sourceContact, - ContactGroup oldParentGroup, - ContactGroup newParentGroup) - { - SubscriptionMovedEvent evt = - new SubscriptionMovedEvent(sourceContact, jabberProvider - , oldParentGroup, newParentGroup); - - logger.debug("Dispatching a Subscription Event to" - +subscriptionListeners.size() + " listeners. Evt="+evt); - - Iterator listeners = null; - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - listener.subscriptionMoved(evt); - } - } - - /** * Notify all contact presence listeners of the corresponding event change * @param contact the contact that changed its status * @param oldStatus the status that the specified contact had so far @@ -1007,7 +895,7 @@ public class OperationSetPersistentPresenceJabberImpl { ContactPresenceStatusChangeEvent evt = new ContactPresenceStatusChangeEvent( - contact, jabberProvider, parentGroup, oldStatus, newStatus); + contact, parentProvider, parentGroup, oldStatus, newStatus); logger.debug("Dispatching Contact Status Change. Listeners=" @@ -1030,46 +918,6 @@ public class OperationSetPersistentPresenceJabberImpl } /** - * Notify all subscription listeners of the corresponding contact property - * change event. - * - * @param eventID the String ID of the event to dispatch - * @param sourceContact the ContactJabberImpl instance that this event is - * pertaining to. - * @param oldValue the value that the changed property had before the change - * occurred. - * @param newValue the value that the changed property currently has (after - * the change has occurred). - */ - void fireContactPropertyChangeEvent( String eventID, - ContactJabberImpl sourceContact, - Object oldValue, - Object newValue) - { - ContactPropertyChangeEvent evt = - new ContactPropertyChangeEvent(sourceContact, eventID - , oldValue, newValue); - - logger.debug("Dispatching a Contact Property Change Event to" - +subscriptionListeners.size() + " listeners. Evt="+evt); - - Iterator listeners = null; - - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - listener.contactModified(evt); - } - } - - /** * */ private class ContactChangesListener @@ -1107,7 +955,7 @@ public class OperationSetPersistentPresenceJabberImpl = sourceContact.getPresenceStatus(); PresenceStatus newStatus = - jabberStatusToPresenceStatus(presence, jabberProvider); + jabberStatusToPresenceStatus(presence, parentProvider); // when old and new status are the same do nothing // no change @@ -1160,14 +1008,14 @@ public class OperationSetPersistentPresenceJabberImpl Presence responsePacket = new Presence(Presence.Type.subscribed); responsePacket.setTo(fromID); logger.info("Sending Accepted Subscription"); - jabberProvider.getConnection().sendPacket(responsePacket); + parentProvider.getConnection().sendPacket(responsePacket); } else { Presence responsePacket = new Presence(Presence.Type.unsubscribed); responsePacket.setTo(fromID); logger.info("Sending Rejected Subscription"); - jabberProvider.getConnection().sendPacket(responsePacket); + parentProvider.getConnection().sendPacket(responsePacket); } } diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/ServerStoredContactListJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/ServerStoredContactListJabberImpl.java index 7a9ffb8..bde84a7 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/ServerStoredContactListJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/ServerStoredContactListJabberImpl.java @@ -182,9 +182,9 @@ public class ServerStoredContactListJabberImpl return; } - //dispatch - parentOperationSet.fireSubscriptionEvent( - SubscriptionEvent.SUBSCRIPTION_REMOVED, contact, parentGroup); + // dispatch + parentOperationSet.fireSubscriptionEvent(contact, parentGroup, + SubscriptionEvent.SUBSCRIPTION_REMOVED); } /** @@ -730,9 +730,9 @@ public class ServerStoredContactListJabberImpl return; } - //dispatch - parentOperationSet.fireSubscriptionEvent( - SubscriptionEvent.SUBSCRIPTION_CREATED, contact, parentGroup); + // dispatch + parentOperationSet.fireSubscriptionEvent(contact, parentGroup, + SubscriptionEvent.SUBSCRIPTION_CREATED); } /** @@ -750,9 +750,9 @@ public class ServerStoredContactListJabberImpl return; } - //dispatch - parentOperationSet.fireSubscriptionEvent( - SubscriptionEvent.SUBSCRIPTION_RESOLVED, contact, parentGroup); + // dispatch + parentOperationSet.fireSubscriptionEvent(contact, parentGroup, + SubscriptionEvent.SUBSCRIPTION_RESOLVED); } /** diff --git a/src/net/java/sip/communicator/impl/protocol/mock/MockPersistentPresenceOperationSet.java b/src/net/java/sip/communicator/impl/protocol/mock/MockPersistentPresenceOperationSet.java index 688d20d1..4e228f6 100644 --- a/src/net/java/sip/communicator/impl/protocol/mock/MockPersistentPresenceOperationSet.java +++ b/src/net/java/sip/communicator/impl/protocol/mock/MockPersistentPresenceOperationSet.java @@ -18,14 +18,10 @@ import net.java.sip.communicator.util.*; * @author Emil Ivov */ public class MockPersistentPresenceOperationSet - implements OperationSetPersistentPresence + extends AbstractOperationSetPersistentPresence<MockProvider> { 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. @@ -50,11 +46,6 @@ public class MockPersistentPresenceOperationSet private MockContactGroup contactListRoot = null; /** - * The provider that created us. - */ - private MockProvider parentProvider = null; - - /** * The currently active status message. */ private String statusMessage = "Default Status Message"; @@ -66,7 +57,8 @@ public class MockPersistentPresenceOperationSet public MockPersistentPresenceOperationSet(MockProvider provider) { - this.parentProvider = provider; + super(provider); + contactListRoot = new MockContactGroup("RootMockGroup", provider); } @@ -117,49 +109,6 @@ public class MockPersistentPresenceOperationSet } } - - /** - * 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); - - Iterator listeners = null; - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - 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. * @@ -258,20 +207,6 @@ public class MockPersistentPresenceOperationSet } /** - * Mock implementation of the corresponding ProtocolProviderService method. - * - * @param listener the SubscriptionListener to register - */ - public void addSubsciptionListener(SubscriptionListener listener) - { - synchronized(subscriptionListeners) - { - if (!subscriptionListeners.contains(listener)) - this.subscriptionListeners.add(listener); - } - } - - /** * Creates a group with the specified name and parent in the server * stored contact list. * @@ -585,19 +520,6 @@ public class MockPersistentPresenceOperationSet } /** - * Removes the specified subscription listener. - * - * @param listener the listener to remove. - */ - public void removeSubscriptionListener(SubscriptionListener listener) - { - synchronized(subscriptionListeners) - { - this.subscriptionListeners.remove(listener); - } - } - - /** * Renames the specified group from the server stored contact list. * * @param group the group to rename. diff --git a/src/net/java/sip/communicator/impl/protocol/msn/OperationSetPersistentPresenceMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/OperationSetPersistentPresenceMsnImpl.java index 6af04e1..7a2ef1f 100644 --- a/src/net/java/sip/communicator/impl/protocol/msn/OperationSetPersistentPresenceMsnImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/msn/OperationSetPersistentPresenceMsnImpl.java @@ -25,17 +25,12 @@ import net.sf.jml.event.*; * @author Damian Minkov */ public class OperationSetPersistentPresenceMsnImpl - implements OperationSetPersistentPresence + extends AbstractOperationSetPersistentPresence<ProtocolProviderServiceMsnImpl> { private static final Logger logger = Logger.getLogger(OperationSetPersistentPresenceMsnImpl.class); /** - * A callback to the Msn provider that created us. - */ - private ProtocolProviderServiceMsnImpl msnProvider = null; - - /** * Contains our current status message. Note that this field would only * be changed once the server has confirmed the new status message and * not immediately upon setting a new one.. @@ -55,12 +50,6 @@ public class OperationSetPersistentPresenceMsnImpl private Vector providerPresenceStatusListeners = new Vector(); /** - * The list of subscription listeners interested in receiving notifications - * whenever . - */ - private Vector subscriptionListeners = new Vector(); - - /** * The list of presence status listeners interested in receiving presence * notifications of changes in status of contacts in our contact list. */ @@ -124,11 +113,11 @@ public class OperationSetPersistentPresenceMsnImpl public OperationSetPersistentPresenceMsnImpl( ProtocolProviderServiceMsnImpl provider) { - this.msnProvider = provider; + super(provider); ssContactList = new ServerStoredContactListMsnImpl( this , provider); - this.msnProvider.addRegistrationStateChangeListener( + parentProvider.addRegistrationStateChangeListener( new RegistrationStateListener()); } @@ -177,19 +166,6 @@ public class OperationSetPersistentPresenceMsnImpl } /** - * Registers a listener that would get notifications any time a new - * subscription was successfully added, has failed or was removed. - * - * @param listener the SubscriptionListener to register - */ - public void addSubsciptionListener(SubscriptionListener listener) - { - synchronized(subscriptionListeners){ - subscriptionListeners.add(listener); - } - } - - /** * Creates a group with the specified name and parent in the server * stored contact list. * @@ -421,7 +397,7 @@ public class OperationSetPersistentPresenceMsnImpl if(status.equals(MsnStatusEnum.OFFLINE)) { - msnProvider.unregister(); + parentProvider.unregister(); return; } @@ -430,10 +406,10 @@ public class OperationSetPersistentPresenceMsnImpl //(as if set the status too early the server does not provide // any status information about the contacts in our list) if(ssContactList.isInitialized()) - msnProvider.getMessenger().getOwner(). + parentProvider.getMessenger().getOwner(). setStatus((MsnUserStatus)scToMsnModesMappings.get(status)); else - msnProvider.getMessenger().getOwner(). + parentProvider.getMessenger().getOwner(). setInitStatus((MsnUserStatus)scToMsnModesMappings.get(status)); } @@ -523,18 +499,6 @@ public class OperationSetPersistentPresenceMsnImpl } /** - * Removes the specified subscription listener. - * - * @param listener the listener to remove. - */ - public void removeSubscriptionListener(SubscriptionListener listener) - { - synchronized(subscriptionListeners){ - subscriptionListeners.remove(listener); - } - } - - /** * Renames the specified group from the server stored contact list. * * @param group the group to rename. @@ -681,11 +645,11 @@ public class OperationSetPersistentPresenceMsnImpl */ private void assertConnected() throws IllegalStateException { - if (msnProvider == null) + if (parentProvider == null) throw new IllegalStateException( "The provider must be non-null and signed on the msn " +"service before being able to communicate."); - if (!msnProvider.isRegistered()) + if (!parentProvider.isRegistered()) throw new IllegalStateException( "The provider must be signed on the msn service before " +"being able to communicate."); @@ -707,7 +671,7 @@ public class OperationSetPersistentPresenceMsnImpl ProviderPresenceStatusChangeEvent evt = new ProviderPresenceStatusChangeEvent( - msnProvider, oldStatus, newStatus); + parentProvider, oldStatus, newStatus); currentStatus = newStatus; @@ -742,7 +706,7 @@ public class OperationSetPersistentPresenceMsnImpl { PropertyChangeEvent evt = new PropertyChangeEvent( - msnProvider, ProviderPresenceStatusListener.STATUS_MESSAGE, + parentProvider, ProviderPresenceStatusListener.STATUS_MESSAGE, oldStatusMessage, newStatusMessage); logger.debug("Dispatching stat. msg change. Listeners=" @@ -786,7 +750,7 @@ public class OperationSetPersistentPresenceMsnImpl if(evt.getNewState() == RegistrationState.REGISTERED) { - msnProvider.getMessenger(). + parentProvider.getMessenger(). addContactListListener(new StatusChangedListener()); } else if(evt.getNewState() == RegistrationState.UNREGISTERED @@ -859,82 +823,6 @@ public class OperationSetPersistentPresenceMsnImpl } /** - * Notify all subscription listeners of the corresponding event. - * - * @param eventID the int ID of the event to dispatch - * @param sourceContact the ContactMsnImpl instance that this event is - * pertaining to. - * @param parentGroup the ContactGroupMsnImpl under which the corresponding - * subscription is located. - */ - void fireSubscriptionEvent( int eventID, - ContactMsnImpl sourceContact, - ContactGroup parentGroup) - { - SubscriptionEvent evt = - new SubscriptionEvent(sourceContact, msnProvider, parentGroup, - eventID); - - logger.debug("Dispatching a Subscription Event to" - +subscriptionListeners.size() + " listeners. Evt="+evt); - - Iterator listeners = null; - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - if (evt.getEventID() == SubscriptionEvent.SUBSCRIPTION_CREATED) - listener.subscriptionCreated(evt); - else if (evt.getEventID() == SubscriptionEvent.SUBSCRIPTION_REMOVED) - listener.subscriptionRemoved(evt); - else if (evt.getEventID() == SubscriptionEvent.SUBSCRIPTION_FAILED) - listener.subscriptionFailed(evt); - } - } - - /** - * Notify all subscription listeners of the corresponding event. - * - * @param sourceContact the ContactMsnImpl instance that this event is - * pertaining to. - * @param oldParentGroup the group that was previously a parent of the - * source contact. - * @param newParentGroup the group under which the corresponding - * subscription is currently located. - */ - void fireSubscriptionMovedEvent( ContactMsnImpl sourceContact, - ContactGroup oldParentGroup, - ContactGroup newParentGroup) - { - SubscriptionMovedEvent evt = - new SubscriptionMovedEvent(sourceContact, msnProvider - , oldParentGroup, newParentGroup); - - logger.debug("Dispatching a Subscription Event to" - +subscriptionListeners.size() + " listeners. Evt="+evt); - - Iterator listeners = null; - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - listener.subscriptionMoved(evt); - } - } - - /** * Notify all contact presence listeners of the corresponding event change * @param contact the contact that changed its status * @param oldStatus the status that the specified contact had so far @@ -949,7 +837,7 @@ public class OperationSetPersistentPresenceMsnImpl { ContactPresenceStatusChangeEvent evt = new ContactPresenceStatusChangeEvent( - contact, msnProvider, parentGroup, oldStatus, newStatus); + contact, parentProvider, parentGroup, oldStatus, newStatus); logger.debug("Dispatching Contact Status Change. Listeners=" @@ -970,46 +858,6 @@ public class OperationSetPersistentPresenceMsnImpl listener.contactPresenceStatusChanged(evt); } } - - /** - * Notify all subscription listeners of the corresponding contact property - * change event. - * - * @param eventID the String ID of the event to dispatch - * @param sourceContact the ContactJabberImpl instance that this event is - * pertaining to. - * @param oldValue the value that the changed property had before the change - * occurred. - * @param newValue the value that the changed property currently has (after - * the change has occurred). - */ - void fireContactPropertyChangeEvent( String eventID, - ContactMsnImpl sourceContact, - Object oldValue, - Object newValue) - { - ContactPropertyChangeEvent evt = - new ContactPropertyChangeEvent(sourceContact, eventID - , oldValue, newValue); - - logger.debug("Dispatching a Contact Property Change Event to" - +subscriptionListeners.size() + " listeners. Evt="+evt); - - Iterator listeners = null; - - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - listener.contactModified(evt); - } - } /** * Sets the messenger instance impl of the lib diff --git a/src/net/java/sip/communicator/impl/protocol/msn/ServerStoredContactListMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/ServerStoredContactListMsnImpl.java index d14132b..69dcd18 100644 --- a/src/net/java/sip/communicator/impl/protocol/msn/ServerStoredContactListMsnImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/msn/ServerStoredContactListMsnImpl.java @@ -210,7 +210,7 @@ public class ServerStoredContactListMsnImpl //dispatch parentOperationSet.fireSubscriptionEvent( - SubscriptionEvent.SUBSCRIPTION_REMOVED, contact, parentGroup); + contact, parentGroup, SubscriptionEvent.SUBSCRIPTION_REMOVED); } /** @@ -701,7 +701,7 @@ public class ServerStoredContactListMsnImpl //dispatch parentOperationSet.fireSubscriptionEvent( - SubscriptionEvent.SUBSCRIPTION_CREATED, contact, parentGroup); + contact, parentGroup, SubscriptionEvent.SUBSCRIPTION_CREATED); // sometimes when adding msn contact // status updates comes before event for adding contact and so @@ -750,7 +750,7 @@ public class ServerStoredContactListMsnImpl //dispatch parentOperationSet.fireSubscriptionEvent( - SubscriptionEvent.SUBSCRIPTION_RESOLVED, contact, parentGroup); + contact, parentGroup, SubscriptionEvent.SUBSCRIPTION_RESOLVED); } /** diff --git a/src/net/java/sip/communicator/impl/protocol/rss/OperationSetPersistentPresenceRssImpl.java b/src/net/java/sip/communicator/impl/protocol/rss/OperationSetPersistentPresenceRssImpl.java index d0c319a..46bd104 100644 --- a/src/net/java/sip/communicator/impl/protocol/rss/OperationSetPersistentPresenceRssImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/rss/OperationSetPersistentPresenceRssImpl.java @@ -25,17 +25,12 @@ import java.io.*; * @author Emil Ivov */ public class OperationSetPersistentPresenceRssImpl - implements OperationSetPersistentPresence + extends AbstractOperationSetPersistentPresence<ProtocolProviderServiceRssImpl> { private static final Logger logger = Logger.getLogger(OperationSetPersistentPresenceRssImpl.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(); @@ -58,11 +53,6 @@ public class OperationSetPersistentPresenceRssImpl private ContactGroupRssImpl contactListRoot = null; /** - * The provider that created us. - */ - private ProtocolProviderServiceRssImpl parentProvider = null; - - /** * The currently active status message. */ private String statusMessage = "Default Status Message"; @@ -87,7 +77,8 @@ public class OperationSetPersistentPresenceRssImpl public OperationSetPersistentPresenceRssImpl( ProtocolProviderServiceRssImpl provider) { - this.parentProvider = provider; + super(provider); + contactListRoot = new ContactGroupRssImpl("RootGroup", provider); // add our un-registration listener @@ -143,121 +134,6 @@ public class OperationSetPersistentPresenceRssImpl } } - /** - * Notify all subscription listeners of the corresponding contact property - * change event. - * - * @param eventID the String ID of the event to dispatch - * @param sourceContact the ContactRssImpl instance that this event is - * pertaining to. - * @param oldValue the value that the changed property had before the change - * occurred. - * @param newValue the value that the changed property currently has (after - * the change has occurred). - */ - void fireContactPropertyChangeEvent( String eventID, - ContactRssImpl sourceContact, - Object oldValue, - Object newValue) - { - ContactPropertyChangeEvent evt = - new ContactPropertyChangeEvent(sourceContact, eventID - , oldValue, newValue); - - logger.debug("Dispatching a Contact Property Change Event to " - +subscriptionListeners.size() + " listeners. Evt="+evt); - - Iterator listeners = null; - - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - listener.contactModified(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(ContactRssImpl source, - ContactGroup parentGroup, - int eventID) - { - SubscriptionEvent evt = new SubscriptionEvent(source - , this.parentProvider - , parentGroup - , eventID); - - Iterator listeners = null; - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - 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 been moved.. - * @param oldParent the group where the contact was located before being - * moved. - * @param newParent the group where the contact has been moved. - */ - public void fireSubscriptionMovedEvent(Contact source, - ContactGroup oldParent, - ContactGroup newParent) - { - SubscriptionMovedEvent evt = new SubscriptionMovedEvent(source - , this.parentProvider - , oldParent - , newParent); - - Iterator listeners = null; - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - listener.subscriptionMoved(evt); - } - } - - /** * Notifies all registered listeners of the new event. * @@ -357,21 +233,6 @@ public class OperationSetPersistentPresenceRssImpl } /** - * RSS implementation of the corresponding ProtocolProviderService - * method. - * - * @param listener the SubscriptionListener to register - */ - public void addSubsciptionListener(SubscriptionListener listener) - { - synchronized(subscriptionListeners) - { - if (!subscriptionListeners.contains(listener)) - this.subscriptionListeners.add(listener); - } - } - - /** * Creates a group with the specified name and parent in the server * stored contact list. * @@ -777,19 +638,6 @@ public class OperationSetPersistentPresenceRssImpl } /** - * Removes the specified subscription listener. - * - * @param listener the listener to remove. - */ - public void removeSubscriptionListener(SubscriptionListener listener) - { - synchronized(subscriptionListeners) - { - this.subscriptionListeners.remove(listener); - } - } - - /** * Renames the specified group from the server stored contact list. * * @param group the group to rename. diff --git a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetPresenceSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetPresenceSipImpl.java index cd20491..7b45ea9 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetPresenceSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetPresenceSipImpl.java @@ -37,14 +37,11 @@ import net.java.sip.communicator.util.xml.*; * @author Lubomir Marinov */ public class OperationSetPresenceSipImpl - implements OperationSetPersistentPresence, SipListener + extends AbstractOperationSetPersistentPresence<ProtocolProviderServiceSipImpl> + implements SipListener { private static final Logger logger = Logger.getLogger(OperationSetPresenceSipImpl.class); - /** - * A list of listeners registered for <tt>SubscriptionEvent</tt>s. - */ - private Vector subscriptionListeners = new Vector(); /** * A list of listeners registered for @@ -70,11 +67,6 @@ public class OperationSetPresenceSipImpl private ContactGroupSipImpl contactListRoot = null; /** - * The provider that created us. - */ - private ProtocolProviderServiceSipImpl parentProvider = null; - - /** * The currently active status message. */ private String statusMessage = "Default Status Message"; @@ -258,7 +250,8 @@ public class OperationSetPresenceSipImpl boolean isPresenceEnabled, boolean forceP2PMode, int pollingPeriod, int subscriptionExpiration) { - this.parentProvider = provider; + super(provider); + this.contactListRoot = new ContactGroupSipImpl("RootGroup", provider); //add our registration listener @@ -481,38 +474,6 @@ public class OperationSetPresenceSipImpl } /** - * Notifies all registered listeners of the new event. - * - * @param source the contact that has been moved.. - * @param oldParent the group where the contact was located before being - * moved. - * @param newParent the group where the contact has been moved. - */ - public void fireSubscriptionMovedEvent(Contact source, - ContactGroup oldParent, - ContactGroup newParent) - { - SubscriptionMovedEvent evt = new SubscriptionMovedEvent(source, - this.parentProvider, - oldParent, - newParent); - - Iterator listeners = null; - synchronized (this.subscriptionListeners) - { - listeners = new ArrayList(this.subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - listener.subscriptionMoved(evt); - } - } - - /** * Removes the specified group from the server stored contact list. * * @param group the group to remove. @@ -3232,32 +3193,6 @@ public class OperationSetPresenceSipImpl } /** - * Registers a listener that would get notifications any time a new - * subscription was successfully added, has failed or was removed. - * - * @param listener the SubscriptionListener to register - */ - public void addSubsciptionListener(SubscriptionListener listener) { - synchronized(this.subscriptionListeners) - { - if (!this.subscriptionListeners.contains(listener)) - this.subscriptionListeners.add(listener); - } - } - - /** - * Removes the specified subscription listener. - * - * @param listener the listener to remove. - */ - public void removeSubscriptionListener(SubscriptionListener listener) { - synchronized(this.subscriptionListeners) - { - this.subscriptionListeners.remove(listener); - } - } - - /** * Registers a listener that would receive events upon changes in server * stored groups. * @@ -3300,71 +3235,6 @@ public class OperationSetPresenceSipImpl } /** - * 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(ContactSipImpl source, - ContactGroup parentGroup, - int eventID) - { - fireSubscriptionEvent(source, parentGroup, eventID, - SubscriptionEvent.ERROR_UNSPECIFIED, null); - } - - /** - * 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(ContactSipImpl source, - ContactGroup parentGroup, - int eventID, - int errorCode, - String errorReason) - { - SubscriptionEvent evt = new SubscriptionEvent(source - , this.parentProvider - , parentGroup - , eventID - , errorCode - , errorReason); - - Iterator listeners = null; - synchronized (this.subscriptionListeners) - { - listeners = new ArrayList(this.subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - 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); - } - else if (eventID == SubscriptionEvent.SUBSCRIPTION_RESOLVED) - { - listener.subscriptionResolved(evt); - } - } - } - - /** * 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 diff --git a/src/net/java/sip/communicator/impl/protocol/ssh/OperationSetPersistentPresenceSSHImpl.java b/src/net/java/sip/communicator/impl/protocol/ssh/OperationSetPersistentPresenceSSHImpl.java index 263ac5a..50a834b 100644 --- a/src/net/java/sip/communicator/impl/protocol/ssh/OperationSetPersistentPresenceSSHImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/ssh/OperationSetPersistentPresenceSSHImpl.java @@ -29,14 +29,10 @@ import org.osgi.framework.*; * @author Shobhit Jindal */ public class OperationSetPersistentPresenceSSHImpl - implements OperationSetPersistentPresence + extends AbstractOperationSetPersistentPresence<ProtocolProviderServiceSSHImpl> { private static final Logger logger = Logger.getLogger(OperationSetPersistentPresenceSSHImpl.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. @@ -61,11 +57,6 @@ public class OperationSetPersistentPresenceSSHImpl private ContactGroupSSHImpl contactListRoot = null; /** - * The provider that created us. - */ - private ProtocolProviderServiceSSHImpl parentProvider = null; - - /** * The currently active status message. */ private String statusMessage = "Online"; @@ -84,7 +75,8 @@ public class OperationSetPersistentPresenceSSHImpl public OperationSetPersistentPresenceSSHImpl( ProtocolProviderServiceSSHImpl provider) { - this.parentProvider = provider; + super(provider); + contactListRoot = new ContactGroupSSHImpl("RootGroup", provider); //add our unregistration listener @@ -161,85 +153,7 @@ public class OperationSetPersistentPresenceSSHImpl 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( - ContactSSH source, - ContactGroup parentGroup, - int eventID) - { - SubscriptionEvent evt = new SubscriptionEvent(source - , this.parentProvider - , parentGroup - , eventID); - - Iterator listeners = null; - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - 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 been moved.. - * @param oldParent the group where the contact was located before being - * moved. - * @param newParent the group where the contact has been moved. - */ - public void fireSubscriptionMovedEvent( - Contact source, - ContactGroup oldParent, - ContactGroup newParent) - { - SubscriptionMovedEvent evt = new SubscriptionMovedEvent(source - , this.parentProvider - , oldParent - , newParent); - - Iterator listeners = null; - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - listener.subscriptionMoved(evt); - } - } - - + /** * Notifies all registered listeners of the new event. * @@ -342,23 +256,7 @@ public class OperationSetPersistentPresenceSSHImpl serverStoredGroupListeners.add(listener); } } - - /** - * SSH implementation of the corresponding ProtocolProviderService - * method. - * - * @param listener the SubscriptionListener to register - */ - public void addSubsciptionListener( - SubscriptionListener listener) - { - synchronized(subscriptionListeners) - { - if (!subscriptionListeners.contains(listener)) - this.subscriptionListeners.add(listener); - } - } - + /** * Creates a group with the specified name and parent in the server * stored contact list. @@ -789,21 +687,7 @@ public class OperationSetPersistentPresenceSSHImpl serverStoredGroupListeners.remove(listener); } } - - /** - * Removes the specified subscription listener. - * - * @param listener the listener to remove. - */ - public void removeSubscriptionListener( - SubscriptionListener listener) - { - synchronized(subscriptionListeners) - { - this.subscriptionListeners.remove(listener); - } - } - + /** * Renames the specified group from the server stored contact list. * diff --git a/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetPersistentPresenceYahooImpl.java b/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetPersistentPresenceYahooImpl.java index e58c350..b2ef619 100644 --- a/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetPersistentPresenceYahooImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetPersistentPresenceYahooImpl.java @@ -25,17 +25,12 @@ import ymsg.network.event.*; * @author Damian Minkov */ public class OperationSetPersistentPresenceYahooImpl - implements OperationSetPersistentPresence + extends AbstractOperationSetPersistentPresence<ProtocolProviderServiceYahooImpl> { private static final Logger logger = Logger.getLogger(OperationSetPersistentPresenceYahooImpl.class); /** - * A callback to the Yahoo provider that created us. - */ - private ProtocolProviderServiceYahooImpl yahooProvider = null; - - /** * Contains our current status message. Note that this field would only * be changed once the server has confirmed the new status message and * not immediately upon setting a new one.. @@ -55,12 +50,6 @@ public class OperationSetPersistentPresenceYahooImpl private Vector providerPresenceStatusListeners = new Vector(); /** - * The list of subscription listeners interested in receiving notifications - * whenever . - */ - private Vector subscriptionListeners = new Vector(); - - /** * The list of presence status listeners interested in receiving presence * notifications of changes in status of contacts in our contact list. */ @@ -143,11 +132,11 @@ public class OperationSetPersistentPresenceYahooImpl public OperationSetPersistentPresenceYahooImpl( ProtocolProviderServiceYahooImpl provider) { - this.yahooProvider = provider; + super(provider); ssContactList = new ServerStoredContactListYahooImpl( this , provider); - this.yahooProvider.addRegistrationStateChangeListener( + parentProvider.addRegistrationStateChangeListener( new RegistrationStateListener()); } @@ -196,19 +185,6 @@ public class OperationSetPersistentPresenceYahooImpl } /** - * Registers a listener that would get notifications any time a new - * subscription was succesfully added, has failed or was removed. - * - * @param listener the SubscriptionListener to register - */ - public void addSubsciptionListener(SubscriptionListener listener) - { - synchronized(subscriptionListeners){ - subscriptionListeners.add(listener); - } - } - - /** * Creates a group with the specified name and parent in the server * stored contact list. * @@ -440,7 +416,7 @@ public class OperationSetPersistentPresenceYahooImpl if(status.equals(YahooStatusEnum.OFFLINE)) { - yahooProvider.unregister(); + parentProvider.unregister(); return; } @@ -455,11 +431,11 @@ public class OperationSetPersistentPresenceYahooImpl // false - away // true - available - yahooProvider.getYahooSession(). + parentProvider.getYahooSession(). setStatus(statusMessage, isAvailable); } - yahooProvider.getYahooSession().setStatus( + parentProvider.getYahooSession().setStatus( ((Long)scToYahooModesMappings.get(status)).longValue()); fireProviderPresenceStatusChangeEvent(currentStatus, status); @@ -558,18 +534,6 @@ public class OperationSetPersistentPresenceYahooImpl } /** - * Removes the specified subscription listener. - * - * @param listener the listener to remove. - */ - public void removeSubscriptionListener(SubscriptionListener listener) - { - synchronized(subscriptionListeners){ - subscriptionListeners.remove(listener); - } - } - - /** * Renames the specified group from the server stored contact list. * * @param group the group to rename. @@ -730,11 +694,11 @@ public class OperationSetPersistentPresenceYahooImpl */ private void assertConnected() throws IllegalStateException { - if (yahooProvider == null) + if (parentProvider == null) throw new IllegalStateException( "The provider must be non-null and signed on the yahoo " +"service before being able to communicate."); - if (!yahooProvider.isRegistered()) + if (!parentProvider.isRegistered()) throw new IllegalStateException( "The provider must be signed on the yahoo service before " +"being able to communicate."); @@ -756,7 +720,7 @@ public class OperationSetPersistentPresenceYahooImpl ProviderPresenceStatusChangeEvent evt = new ProviderPresenceStatusChangeEvent( - yahooProvider, oldStatus, newStatus); + parentProvider, oldStatus, newStatus); currentStatus = newStatus; @@ -791,7 +755,7 @@ public class OperationSetPersistentPresenceYahooImpl { PropertyChangeEvent evt = new PropertyChangeEvent( - yahooProvider, ProviderPresenceStatusListener.STATUS_MESSAGE, + parentProvider, ProviderPresenceStatusListener.STATUS_MESSAGE, oldStatusMessage, newStatusMessage); logger.debug("Dispatching stat. msg change. Listeners=" @@ -819,7 +783,7 @@ public class OperationSetPersistentPresenceYahooImpl */ private void initContactStatuses() { - YahooGroup[] groups = yahooProvider.getYahooSession().getGroups(); + YahooGroup[] groups = parentProvider.getYahooSession().getGroups(); for (int i = 0; i < groups.length; i++) { @@ -860,10 +824,10 @@ public class OperationSetPersistentPresenceYahooImpl if(evt.getNewState() == RegistrationState.REGISTERED) { - yahooProvider.getYahooSession(). + parentProvider.getYahooSession(). addSessionListener(new StatusChangedListener()); - ssContactList.setYahooSession(yahooProvider.getYahooSession()); + ssContactList.setYahooSession(parentProvider.getYahooSession()); initContactStatuses(); @@ -922,82 +886,6 @@ public class OperationSetPersistentPresenceYahooImpl } /** - * Notify all subscription listeners of the corresponding event. - * - * @param eventID the int ID of the event to dispatch - * @param sourceContact the ContactYahooImpl instance that this event is - * pertaining to. - * @param parentGroup the ContactGroupYahooImpl under which the corresponding - * subscription is located. - */ - void fireSubscriptionEvent( int eventID, - ContactYahooImpl sourceContact, - ContactGroup parentGroup) - { - SubscriptionEvent evt = - new SubscriptionEvent(sourceContact, yahooProvider, parentGroup, - eventID); - - logger.debug("Dispatching a Subscription Event to" - +subscriptionListeners.size() + " listeners. Evt="+evt); - - Iterator listeners = null; - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - if (evt.getEventID() == SubscriptionEvent.SUBSCRIPTION_CREATED) - listener.subscriptionCreated(evt); - else if (evt.getEventID() == SubscriptionEvent.SUBSCRIPTION_REMOVED) - listener.subscriptionRemoved(evt); - else if (evt.getEventID() == SubscriptionEvent.SUBSCRIPTION_FAILED) - listener.subscriptionFailed(evt); - } - } - - /** - * Notify all subscription listeners of the corresponding event. - * - * @param sourceContact the ContactYahooImpl instance that this event is - * pertaining to. - * @param oldParentGroup the group that was previously a parent of the - * source contact. - * @param newParentGroup the group under which the corresponding - * subscription is currently located. - */ - void fireSubscriptionMovedEvent( ContactYahooImpl sourceContact, - ContactGroup oldParentGroup, - ContactGroup newParentGroup) - { - SubscriptionMovedEvent evt = - new SubscriptionMovedEvent(sourceContact, yahooProvider - , oldParentGroup, newParentGroup); - - logger.debug("Dispatching a Subscription Event to" - +subscriptionListeners.size() + " listeners. Evt="+evt); - - Iterator listeners = null; - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - listener.subscriptionMoved(evt); - } - } - - /** * Notify all contact presence listeners of the corresponding event change * @param contact the contact that changed its status * @param oldStatus the status that the specified contact had so far @@ -1012,7 +900,7 @@ public class OperationSetPersistentPresenceYahooImpl { ContactPresenceStatusChangeEvent evt = new ContactPresenceStatusChangeEvent( - contact, yahooProvider, parentGroup, oldStatus, newStatus); + contact, parentProvider, parentGroup, oldStatus, newStatus); logger.debug("Dispatching Contact Status Change. Listeners=" @@ -1033,46 +921,6 @@ public class OperationSetPersistentPresenceYahooImpl listener.contactPresenceStatusChanged(evt); } } - - /** - * Notify all subscription listeners of the corresponding contact property - * change event. - * - * @param eventID the String ID of the event to dispatch - * @param sourceContact the ContactJabberImpl instance that this event is - * pertaining to. - * @param oldValue the value that the changed property had before the change - * occurred. - * @param newValue the value that the changed property currently has (after - * the change has occurred). - */ - void fireContactPropertyChangeEvent( String eventID, - ContactYahooImpl sourceContact, - Object oldValue, - Object newValue) - { - ContactPropertyChangeEvent evt = - new ContactPropertyChangeEvent(sourceContact, eventID - , oldValue, newValue); - - logger.debug("Dispatching a Contact Property Change Event to" - +subscriptionListeners.size() + " listeners. Evt="+evt); - - Iterator listeners = null; - - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - listener.contactModified(evt); - } - } private void handleContactStatusChange(YahooUser yFriend) { @@ -1081,7 +929,7 @@ public class OperationSetPersistentPresenceYahooImpl if(sourceContact == null) { - if(yahooProvider.getAccountID().getUserID(). + if(parentProvider.getAccountID().getUserID(). equals(yFriend.getId())) { // thats my own status diff --git a/src/net/java/sip/communicator/impl/protocol/yahoo/ServerStoredContactListYahooImpl.java b/src/net/java/sip/communicator/impl/protocol/yahoo/ServerStoredContactListYahooImpl.java index 9a0acc9..d3e164e 100644 --- a/src/net/java/sip/communicator/impl/protocol/yahoo/ServerStoredContactListYahooImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/yahoo/ServerStoredContactListYahooImpl.java @@ -208,7 +208,7 @@ public class ServerStoredContactListYahooImpl //dispatch parentOperationSet.fireSubscriptionEvent( - SubscriptionEvent.SUBSCRIPTION_REMOVED, contact, parentGroup); + contact, parentGroup, SubscriptionEvent.SUBSCRIPTION_REMOVED); } /** @@ -698,7 +698,7 @@ public class ServerStoredContactListYahooImpl //dispatch parentOperationSet.fireSubscriptionEvent( - SubscriptionEvent.SUBSCRIPTION_CREATED, contact, parentGroup); + contact, parentGroup, SubscriptionEvent.SUBSCRIPTION_CREATED); } /** @@ -718,7 +718,7 @@ public class ServerStoredContactListYahooImpl //dispatch parentOperationSet.fireSubscriptionEvent( - SubscriptionEvent.SUBSCRIPTION_RESOLVED, contact, parentGroup); + contact, parentGroup, SubscriptionEvent.SUBSCRIPTION_RESOLVED); } /** diff --git a/src/net/java/sip/communicator/impl/protocol/zeroconf/OperationSetPersistentPresenceZeroconfImpl.java b/src/net/java/sip/communicator/impl/protocol/zeroconf/OperationSetPersistentPresenceZeroconfImpl.java index be0cc16..2fb12a4 100644 --- a/src/net/java/sip/communicator/impl/protocol/zeroconf/OperationSetPersistentPresenceZeroconfImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/zeroconf/OperationSetPersistentPresenceZeroconfImpl.java @@ -26,14 +26,10 @@ import org.osgi.framework.*; * @author Jonathan Martin */ public class OperationSetPersistentPresenceZeroconfImpl - implements OperationSetPersistentPresence + extends AbstractOperationSetPersistentPresence<ProtocolProviderServiceZeroconfImpl> { private static final Logger logger = Logger.getLogger(OperationSetPersistentPresenceZeroconfImpl.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. @@ -58,11 +54,6 @@ public class OperationSetPersistentPresenceZeroconfImpl private ContactGroupZeroconfImpl contactListRoot = null; /** - * The provider that created us. - */ - private ProtocolProviderServiceZeroconfImpl parentProvider = null; - - /** * The currently active status message. */ private String statusMessage = "The truth is out there..."; @@ -86,9 +77,9 @@ public class OperationSetPersistentPresenceZeroconfImpl */ public OperationSetPersistentPresenceZeroconfImpl( ProtocolProviderServiceZeroconfImpl provider) - { - - this.parentProvider = provider; + { + super(provider); + contactListRoot = new ContactGroupZeroconfImpl("RootGroup", provider); //add our unregistration listener @@ -143,83 +134,6 @@ public class OperationSetPersistentPresenceZeroconfImpl } } - - /** - * 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(ContactZeroconfImpl source, - ContactGroup parentGroup, - int eventID) - { - SubscriptionEvent evt = new SubscriptionEvent(source - , this.parentProvider - , parentGroup - , eventID); - - //logger.debug("ZEROCNF: Creation contact " + source.getAddress()); - Iterator listeners = null; - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - 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 been moved.. - * @param oldParent the group where the contact was located before being - * moved. - * @param newParent the group where the contact has been moved. - */ - public void fireSubscriptionMovedEvent(Contact source, - ContactGroup oldParent, - ContactGroup newParent) - { - SubscriptionMovedEvent evt = new SubscriptionMovedEvent(source - , this.parentProvider - , oldParent - , newParent); - - Iterator listeners = null; - synchronized (subscriptionListeners) - { - listeners = new ArrayList(subscriptionListeners).iterator(); - } - - while (listeners.hasNext()) - { - SubscriptionListener listener - = (SubscriptionListener) listeners.next(); - - listener.subscriptionMoved(evt); - } - } - - /** * Notifies all registered listeners of the new event. * @@ -321,21 +235,6 @@ public class OperationSetPersistentPresenceZeroconfImpl } /** - * Zeroconf implementation of the corresponding ProtocolProviderService - * method. - * - * @param listener the SubscriptionListener to register - */ - public void addSubsciptionListener(SubscriptionListener listener) - { - synchronized(subscriptionListeners) - { - if (!subscriptionListeners.contains(listener)) - this.subscriptionListeners.add(listener); - } - } - - /** * Creates a group with the specified name and parent in the server * stored contact list. * @@ -727,19 +626,6 @@ public class OperationSetPersistentPresenceZeroconfImpl } /** - * Removes the specified subscription listener. - * - * @param listener the listener to remove. - */ - public void removeSubscriptionListener(SubscriptionListener listener) - { - synchronized(subscriptionListeners) - { - this.subscriptionListeners.remove(listener); - } - } - - /** * Renames the specified group from the server stored contact list. * * @param group the group to rename. diff --git a/src/net/java/sip/communicator/service/protocol/AbstractOperationSetPersistentPresence.java b/src/net/java/sip/communicator/service/protocol/AbstractOperationSetPersistentPresence.java new file mode 100644 index 0000000..a2631e4 --- /dev/null +++ b/src/net/java/sip/communicator/service/protocol/AbstractOperationSetPersistentPresence.java @@ -0,0 +1,188 @@ +/* + * 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.service.protocol; + +import java.util.*; + +import net.java.sip.communicator.service.protocol.event.*; +import net.java.sip.communicator.util.*; + +/** + * Represents a default implementation of + * <tt>OperationSetPersistentPresence</tt> in order to make it easier for + * implementers to provide complete solutions while focusing on + * implementation-specific details. + * + * @author Lubomir Marinov + */ +public abstract class AbstractOperationSetPersistentPresence<T extends ProtocolProviderService> + implements OperationSetPersistentPresence +{ + private static final Logger logger = + Logger.getLogger(AbstractOperationSetPersistentPresence.class); + + /** + * The provider that created us. + */ + protected final T parentProvider; + + /** + * The list of listeners interested in <tt>SubscriptionEvent</tt>s. + */ + private final List<SubscriptionListener> subscriptionListeners = + new Vector<SubscriptionListener>(); + + /** + * Initializes a new <tt>AbstractOperationSetPersistentPresence</tt> + * instance created by a specific <tt>ProtocolProviderService</tt> . + * + * @param parentProvider the <tt>ProtocolProviderService</tt> which created + * the new instance + */ + protected AbstractOperationSetPersistentPresence(T parentProvider) + { + this.parentProvider = parentProvider; + } + + public void addSubsciptionListener(SubscriptionListener listener) + { + synchronized (subscriptionListeners) + { + if (!subscriptionListeners.contains(listener)) + subscriptionListeners.add(listener); + } + } + + /** + * Notify all subscription listeners of the corresponding contact property + * change event. + * + * @param eventID the String ID of the event to dispatch + * @param sourceContact the ContactJabberImpl instance that this event is + * pertaining to. + * @param oldValue the value that the changed property had before the change + * occurred. + * @param newValue the value that the changed property currently has (after + * the change has occurred). + */ + public void fireContactPropertyChangeEvent(String eventID, Contact source, + Object oldValue, Object newValue) + { + ContactPropertyChangeEvent evt = + new ContactPropertyChangeEvent(source, eventID, oldValue, newValue); + + List<SubscriptionListener> listeners; + synchronized (subscriptionListeners) + { + listeners = + new ArrayList<SubscriptionListener>(subscriptionListeners); + } + + logger.debug("Dispatching a Contact Property Change Event to" + + listeners.size() + " listeners. Evt=" + evt); + + for (Iterator<SubscriptionListener> listenerIt = listeners.iterator(); listenerIt + .hasNext();) + listenerIt.next().contactModified(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(Contact source, ContactGroup parentGroup, + int eventID) + { + fireSubscriptionEvent(source, parentGroup, eventID, + SubscriptionEvent.ERROR_UNSPECIFIED, null); + } + + public void fireSubscriptionEvent(Contact source, ContactGroup parentGroup, + int eventID, int errorCode, String errorReason) + { + SubscriptionEvent evt = + new SubscriptionEvent(source, parentProvider, parentGroup, eventID, + errorCode, errorReason); + + List<SubscriptionListener> listeners; + synchronized (subscriptionListeners) + { + listeners = + new ArrayList<SubscriptionListener>(subscriptionListeners); + } + + logger.debug("Dispatching a Subscription Event to" + listeners.size() + + " listeners. Evt=" + evt); + + for (Iterator<SubscriptionListener> listenerIt = listeners.iterator(); listenerIt + .hasNext();) + { + SubscriptionListener listener = listenerIt.next(); + + switch (eventID) + { + case SubscriptionEvent.SUBSCRIPTION_CREATED: + listener.subscriptionCreated(evt); + break; + case SubscriptionEvent.SUBSCRIPTION_FAILED: + listener.subscriptionFailed(evt); + break; + case SubscriptionEvent.SUBSCRIPTION_REMOVED: + listener.subscriptionRemoved(evt); + break; + case SubscriptionEvent.SUBSCRIPTION_RESOLVED: + listener.subscriptionResolved(evt); + break; + } + } + } + + /** + * Notifies all registered listeners of the new event. + * + * @param source the contact that has been moved.. + * @param oldParent the group where the contact was located before being + * moved. + * @param newParent the group where the contact has been moved. + */ + public void fireSubscriptionMovedEvent(Contact source, + ContactGroup oldParent, ContactGroup newParent) + { + SubscriptionMovedEvent evt = + new SubscriptionMovedEvent(source, parentProvider, oldParent, + newParent); + + List<SubscriptionListener> listeners; + synchronized (subscriptionListeners) + { + listeners = + new ArrayList<SubscriptionListener>(subscriptionListeners); + } + + logger.debug("Dispatching a Subscription Event to" + listeners.size() + + " listeners. Evt=" + evt); + + for (Iterator<SubscriptionListener> listenerIt = listeners.iterator(); listenerIt + .hasNext();) + listenerIt.next().subscriptionMoved(evt); + } + + /** + * Removes the specified subscription listener. + * + * @param listener the listener to remove. + */ + public void removeSubscriptionListener(SubscriptionListener listener) + { + synchronized (subscriptionListeners) + { + subscriptionListeners.remove(listener); + } + } +} |