summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGurmeen Bindra <gurmeen.bindra@isode.com>2012-04-23 15:06:39 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-04-27 11:06:27 (GMT)
commit19340ddc7dc929aad094eed3f6a3cd7f84d86a4b (patch)
treeb2c7f71c8e32b15c267b7d62b64f77fb5945d3b7 /src/com/isode/stroke/client
parente2f24c6930603dbd016a6530f7d12b08c97ea900 (diff)
downloadstroke-19340ddc7dc929aad094eed3f6a3cd7f84d86a4b.zip
stroke-19340ddc7dc929aad094eed3f6a3cd7f84d86a4b.tar.bz2
MUC Administration related classes
This change ports the MUC Administration related classes from Swiften to stroke. Also includes the MUC initialisation code in the CoreClient. Test-information: tested the ported unit tests
Diffstat (limited to 'src/com/isode/stroke/client')
-rw-r--r--src/com/isode/stroke/client/Client.java73
-rw-r--r--src/com/isode/stroke/client/DummyStanzaChannel.java115
2 files changed, 188 insertions, 0 deletions
diff --git a/src/com/isode/stroke/client/Client.java b/src/com/isode/stroke/client/Client.java
new file mode 100644
index 0000000..69c893f
--- /dev/null
+++ b/src/com/isode/stroke/client/Client.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2012, Isode Limited, London, England.
+ * All rights reserved.
+ */
+/*
+ * Copyright (c) 2010, Remko Tronçon.
+ * All rights reserved.
+ */
+package com.isode.stroke.client;
+
+import com.isode.stroke.eventloop.EventLoop;
+import com.isode.stroke.jid.JID;
+import com.isode.stroke.muc.MUCManager;
+import com.isode.stroke.muc.MUCRegistry;
+import com.isode.stroke.network.NetworkFactories;
+import com.isode.stroke.presence.DirectedPresenceSender;
+import com.isode.stroke.presence.StanzaChannelPresenceSender;
+
+/**
+ * Provides the core functionality for writing XMPP client software.
+ *
+ * Besides connecting to an XMPP server, this class also provides interfaces for
+ * performing most tasks on the XMPP network.
+ */
+
+public class Client extends CoreClient {
+
+ private MUCManager mucManager;
+ private MUCRegistry mucRegistry;
+ private DirectedPresenceSender directedPresenceSender;
+ private StanzaChannelPresenceSender stanzaChannelPresenceSender;
+
+ /**
+ * Constructor.
+ *
+ * @param eventLoop Event loop used by the class, must not be null. The
+ * Client creates threads to do certain tasks. However, it
+ * posts events that it expects to be done in the application's
+ * main thread to this eventLoop. The application should
+ * use an appropriate EventLoop implementation for the application type. This
+ * EventLoop is just a way for the Client to pass these
+ * events back to the main thread, and should not be used by the
+ * application for its own purposes.
+ * @param jid User JID used to connect to the server, must not be null
+ * @param password User password to use, must not be null
+ * @param networkFactories An implementation of network interaction, must
+ * not be null.
+ */
+ public Client(EventLoop eventLoop, JID jid, String password, NetworkFactories networkFactories) {
+ super(eventLoop,jid, password, networkFactories);
+ stanzaChannelPresenceSender = new StanzaChannelPresenceSender(getStanzaChannel());
+ directedPresenceSender = new DirectedPresenceSender(stanzaChannelPresenceSender);
+
+ mucRegistry = new MUCRegistry();
+ mucManager = new MUCManager(getStanzaChannel(), getIQRouter(), directedPresenceSender, mucRegistry);
+ }
+
+ /**
+ * Get the manager for multi user chat rooms
+ * @return MUC manager, not null
+ */
+ public MUCManager getMUCManager() {
+ return mucManager;
+ }
+
+ /**
+ * Get the registry for multi user chat rooms
+ * @return MUC registry, not null
+ */
+ public MUCRegistry getMUCRegistry() {
+ return mucRegistry;
+ }
+}
diff --git a/src/com/isode/stroke/client/DummyStanzaChannel.java b/src/com/isode/stroke/client/DummyStanzaChannel.java
new file mode 100644
index 0000000..25fb817
--- /dev/null
+++ b/src/com/isode/stroke/client/DummyStanzaChannel.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2012, Isode Limited, London, England.
+ * All rights reserved.
+ */
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * All rights reserved.
+ */
+package com.isode.stroke.client;
+
+import java.util.Vector;
+
+import com.isode.stroke.elements.IQ;
+import com.isode.stroke.elements.Message;
+import com.isode.stroke.elements.Payload;
+import com.isode.stroke.elements.Presence;
+import com.isode.stroke.elements.Stanza;
+import com.isode.stroke.jid.JID;
+
+/**
+ * Dummy Stanza Channel for Unit Testing
+ *
+ */
+public class DummyStanzaChannel extends StanzaChannel {
+
+ public Vector<Stanza> sentStanzas = new Vector<Stanza>();
+ public boolean available_;
+
+ public DummyStanzaChannel() {
+ available_ = true;
+ }
+
+ public void sendStanza(Stanza stanza) {
+ sentStanzas.add(stanza);
+ }
+
+ public void setAvailable(boolean available) {
+ available_ = available;
+ onAvailableChanged.emit(available);
+ }
+
+ public void sendIQ(IQ iq) {
+ sentStanzas.add(iq);
+ }
+
+ public void sendMessage(Message message) {
+ sentStanzas.add(message);
+ }
+
+ public void sendPresence(Presence presence) {
+ sentStanzas.add(presence);
+ }
+
+ public String getNewIQID() {
+ return "test-id";
+ }
+
+ public boolean isAvailable() {
+ return available_;
+ }
+
+ public boolean getStreamManagementEnabled() {
+ return false;
+ }
+
+ public <T extends Payload> boolean isRequestAtIndex(int index, JID jid, IQ.Type type, T plType) {
+ if (index >= sentStanzas.size()) {
+ return false;
+ }
+ Stanza stanza = (sentStanzas.get(index));
+ IQ iqStanza = null;
+ if(stanza instanceof IQ) {
+ iqStanza = (IQ)(sentStanzas.get(index));
+ }
+ return iqStanza != null && iqStanza.getType() == type && iqStanza.getTo().equals(jid)
+ && iqStanza.getPayload(plType) != null;
+ }
+
+ public boolean isResultAtIndex(int index, String id) {
+ if (index >= sentStanzas.size()) {
+ return false;
+ }
+ Stanza stanza = (sentStanzas.get(index));
+ IQ iqStanza = null;
+ if(stanza instanceof IQ) {
+ iqStanza = (IQ)(sentStanzas.get(index));
+ }
+ return iqStanza != null && iqStanza.getType() == IQ.Type.Result && iqStanza.getID().equals(id) ;
+}
+
+
+ public boolean isErrorAtIndex(int index, String id) {
+ if (index >= sentStanzas.size()) {
+ return false;
+ }
+ Stanza stanza = (sentStanzas.get(index));
+ IQ iqStanza = null;
+ if(stanza instanceof IQ) {
+ iqStanza = (IQ)(sentStanzas.get(index));
+ }
+ return iqStanza != null && iqStanza.getType() == IQ.Type.Error && iqStanza.getID().equals(id);
+ }
+
+ public <T> T getStanzaAtIndex(T object,int index) {
+ if (sentStanzas.size() <= index) {
+ return null;
+ }
+ Stanza stanza = sentStanzas.get(index);
+ T obj = null;
+ if(object.getClass().isAssignableFrom(stanza.getClass())) {
+ return (T)(sentStanzas.get(index));
+ }
+ return null;
+ }
+}