aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/service/protocol
diff options
context:
space:
mode:
authorDamian Minkov <damencho@jitsi.org>2011-07-04 15:39:10 +0000
committerDamian Minkov <damencho@jitsi.org>2011-07-04 15:39:10 +0000
commit2e78f26000b30f35d464e5c21f842c67e1f54691 (patch)
tree25c3d6c76d197fcc963e021c310dec916f734b1b /src/net/java/sip/communicator/service/protocol
parentc8b23f022b1e482133a8a5549c452d3440dca0bc (diff)
downloadjitsi-2e78f26000b30f35d464e5c21f842c67e1f54691.zip
jitsi-2e78f26000b30f35d464e5c21f842c67e1f54691.tar.gz
jitsi-2e78f26000b30f35d464e5c21f842c67e1f54691.tar.bz2
Adds listener for notifying for server stored account details.
SIP protocol gets its account display name from the OK responses to its register requests.
Diffstat (limited to 'src/net/java/sip/communicator/service/protocol')
-rw-r--r--src/net/java/sip/communicator/service/protocol/AbstractOperationSetServerStoredAccountInfo.java103
-rw-r--r--src/net/java/sip/communicator/service/protocol/OperationSetServerStoredAccountInfo.java21
-rw-r--r--src/net/java/sip/communicator/service/protocol/event/ServerStoredDetailsChangeEvent.java106
-rw-r--r--src/net/java/sip/communicator/service/protocol/event/ServerStoredDetailsChangeListener.java18
4 files changed, 248 insertions, 0 deletions
diff --git a/src/net/java/sip/communicator/service/protocol/AbstractOperationSetServerStoredAccountInfo.java b/src/net/java/sip/communicator/service/protocol/AbstractOperationSetServerStoredAccountInfo.java
new file mode 100644
index 0000000..d457a43
--- /dev/null
+++ b/src/net/java/sip/communicator/service/protocol/AbstractOperationSetServerStoredAccountInfo.java
@@ -0,0 +1,103 @@
+package net.java.sip.communicator.service.protocol;
+
+import net.java.sip.communicator.service.protocol.event.*;
+import net.java.sip.communicator.util.*;
+
+import java.util.*;
+
+/**
+ * Represents a default implementation of
+ * {@link OperationSetServerStoredAccountInfo} in order to make it easier for
+ * implementers to provide complete solutions while focusing on
+ * implementation-specific details.
+ *
+ * @author Damian Minkov
+ */
+public abstract class AbstractOperationSetServerStoredAccountInfo
+ implements OperationSetServerStoredAccountInfo
+{
+ /**
+ * The <tt>Logger</tt> used by the
+ * <tt>AbstractOperationSetPersistentPresence</tt> class and its instances
+ * for logging output.
+ */
+ private static final Logger logger =
+ Logger.getLogger(AbstractOperationSetServerStoredAccountInfo.class);
+
+ /**
+ * A list of listeners registered for
+ * <tt>ServerStoredDetailsChangeListener</tt>s.
+ */
+ private final List<ServerStoredDetailsChangeListener>
+ serverStoredDetailsListeners
+ = new ArrayList<ServerStoredDetailsChangeListener>();
+
+ /**
+ * Registers a ServerStoredDetailsChangeListener with this operation set so
+ * that it gets notifications of details change.
+ *
+ * @param listener the <tt>ServerStoredDetailsChangeListener</tt>
+ * to register.
+ */
+ public void addServerStoredDetailsChangeListener(
+ ServerStoredDetailsChangeListener listener)
+ {
+ synchronized (serverStoredDetailsListeners)
+ {
+ if (!serverStoredDetailsListeners.contains(listener))
+ serverStoredDetailsListeners.add(listener);
+ }
+ }
+
+ /**
+ * Unregisters <tt>listener</tt> so that it won't receive any further
+ * notifications upon details change.
+ *
+ * @param listener the <tt>ServerStoredDetailsChangeListener</tt>
+ * to unregister.
+ */
+ public void removeServerStoredDetailsChangeListener(
+ ServerStoredDetailsChangeListener listener)
+ {
+ synchronized (serverStoredDetailsListeners)
+ {
+ serverStoredDetailsListeners.remove(listener);
+ }
+ }
+
+ /**
+ * Notify all listeners of the corresponding account detail
+ * change event.
+ *
+ * @param eventID the int ID of the event to dispatch
+ * @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 fireServerStoredDetailsChangeEvent(
+ ProtocolProviderService source,
+ int eventID, Object oldValue, Object newValue)
+ {
+ ServerStoredDetailsChangeEvent evt
+ = new ServerStoredDetailsChangeEvent(
+ source,
+ eventID,
+ oldValue,
+ newValue);
+
+ Collection<ServerStoredDetailsChangeListener> listeners;
+ synchronized (serverStoredDetailsListeners)
+ {
+ listeners = new ArrayList<ServerStoredDetailsChangeListener>(
+ serverStoredDetailsListeners);
+ }
+
+ if (logger.isDebugEnabled())
+ logger.debug("Dispatching a Contact Property Change Event to"
+ + listeners.size() + " listeners. Evt=" + evt);
+
+ for (ServerStoredDetailsChangeListener listener : listeners)
+ listener.serverStoredDetailsChanged(evt);
+ }
+}
diff --git a/src/net/java/sip/communicator/service/protocol/OperationSetServerStoredAccountInfo.java b/src/net/java/sip/communicator/service/protocol/OperationSetServerStoredAccountInfo.java
index 140e812..206aa88 100644
--- a/src/net/java/sip/communicator/service/protocol/OperationSetServerStoredAccountInfo.java
+++ b/src/net/java/sip/communicator/service/protocol/OperationSetServerStoredAccountInfo.java
@@ -9,6 +9,7 @@ package net.java.sip.communicator.service.protocol;
import java.util.*;
import net.java.sip.communicator.service.protocol.ServerStoredDetails.*;
+import net.java.sip.communicator.service.protocol.event.*;
/**
* The Account Info Operation set is a means of accessing and modifying detailed
@@ -184,4 +185,24 @@ public interface OperationSetServerStoredAccountInfo
ServerStoredDetails.GenericDetail currentDetailValue,
ServerStoredDetails.GenericDetail newDetailValue)
throws ClassCastException, OperationFailedException;
+
+ /**
+ * Registers a ServerStoredDetailsChangeListener with this operation set so
+ * that it gets notifications of details change.
+ *
+ * @param listener the <tt>ServerStoredDetailsChangeListener</tt>
+ * to register.
+ */
+ public void addServerStoredDetailsChangeListener(
+ ServerStoredDetailsChangeListener listener);
+
+ /**
+ * Unregisters <tt>listener</tt> so that it won't receive any further
+ * notifications upon details change.
+ *
+ * @param listener the <tt>ServerStoredDetailsChangeListener</tt>
+ * to unregister.
+ */
+ public void removeServerStoredDetailsChangeListener(
+ ServerStoredDetailsChangeListener listener);
}
diff --git a/src/net/java/sip/communicator/service/protocol/event/ServerStoredDetailsChangeEvent.java b/src/net/java/sip/communicator/service/protocol/event/ServerStoredDetailsChangeEvent.java
new file mode 100644
index 0000000..51a24f5
--- /dev/null
+++ b/src/net/java/sip/communicator/service/protocol/event/ServerStoredDetailsChangeEvent.java
@@ -0,0 +1,106 @@
+package net.java.sip.communicator.service.protocol.event;
+
+import net.java.sip.communicator.service.protocol.*;
+
+import java.util.*;
+
+/**
+ * Instances of this class represent a change in the server stored details
+ * change that triggered them.
+ *
+ * @author Damian Minkov
+ */
+public class ServerStoredDetailsChangeEvent
+ extends EventObject
+{
+ /**
+ * Indicates that the ServerStoredDetailsChangeEvent instance was triggered
+ * by adding a new detail.
+ */
+ public static final int DETAIL_ADDED = 1;
+
+ /**
+ * Indicates that the ServerStoredDetailsChangeEvent instance was triggered
+ * by the removal of an existing detail.
+ */
+ public static final int DETAIL_REMOVED = 2;
+
+ /**
+ * Indicates that the ServerStoredDetailsChangeEvent instance was triggered
+ * by the fact a detail was replaced with new value.
+ */
+ public static final int DETAIL_REPLACED = 3;
+
+ /**
+ * The event type id.
+ */
+ private final int eventID;
+
+ /**
+ * New value for property. May be null if not known.
+ * @serial
+ */
+ private Object newValue;
+
+ /**
+ * Previous value for property. May be null if not known.
+ * @serial
+ */
+ private Object oldValue;
+
+ /**
+ * Constructs a ServerStoredDetailsChangeEvent.
+ *
+ * @param source The object on which the Event initially occurred.
+ * @throws IllegalArgumentException if source is null.
+ */
+ public ServerStoredDetailsChangeEvent(
+ ProtocolProviderService source,
+ int eventID,
+ Object oldValue,
+ Object newValue)
+ {
+ super(source);
+
+ this.eventID = eventID;
+ this.oldValue = oldValue;
+ this.newValue = newValue;
+ }
+
+ /**
+ * Returns the provider that has generated this event
+ * @return the provider that generated the event.
+ */
+ public ProtocolProviderService getProvider()
+ {
+ return (ProtocolProviderService)getSource();
+ }
+
+ /**
+ * Gets the new value for the event, expressed as an Object.
+ *
+ * @return The new value for the event, expressed as an Object.
+ */
+ public Object getNewValue()
+ {
+ return newValue;
+ }
+
+ /**
+ * Gets the old value for the event, expressed as an Object.
+ *
+ * @return The old value for the event, expressed as an Object.
+ */
+ public Object getOldValue()
+ {
+ return oldValue;
+ }
+
+ /**
+ * The event type id.
+ */
+ public int getEventID()
+ {
+ return eventID;
+ }
+}
diff --git a/src/net/java/sip/communicator/service/protocol/event/ServerStoredDetailsChangeListener.java b/src/net/java/sip/communicator/service/protocol/event/ServerStoredDetailsChangeListener.java
new file mode 100644
index 0000000..5d763fd
--- /dev/null
+++ b/src/net/java/sip/communicator/service/protocol/event/ServerStoredDetailsChangeListener.java
@@ -0,0 +1,18 @@
+package net.java.sip.communicator.service.protocol.event;
+
+/**
+ * Listener that is informed when a change has been made to some server
+ * stored detail.
+ *
+ * @author Damian Minkov
+ */
+public interface ServerStoredDetailsChangeListener
+{
+ /**
+ * The method is called by a ProtocolProvider implementation whenever
+ * a change in the server stored detail occurred.
+ * @param evt ServerStoredDetailsChangeEvent the event describing the detail
+ * change.
+ */
+ public void serverStoredDetailsChanged(ServerStoredDetailsChangeEvent evt);
+}