Commit e62c04d9 authored by Guus der Kinderen's avatar Guus der Kinderen

OF-1028: Reduce duplicate code

By moving the processing of Stream Management elements into the
StreamManager implementation, duplicated code can be removed.
parent 8e06f9dc
...@@ -190,21 +190,8 @@ public abstract class StanzaHandler { ...@@ -190,21 +190,8 @@ public abstract class StanzaHandler {
// resource binding and session establishment (to client sessions only) // resource binding and session establishment (to client sessions only)
waitingCompressionACK = true; waitingCompressionACK = true;
} }
} else if(isStreamManagementStanza(doc)) { } else if (isStreamManagementStanza(doc)) {
switch(tag) { session.getStreamManager().process( doc, session.getAddress() );
case "enable":
session.enableStreamMangement(doc);
break;
case "r":
session.getStreamManager().sendServerAcknowledgement();
break;
case "a":
session.getStreamManager().processClientAcknowledgement(doc);
break;
default:
process(doc);
break;
}
} }
else { else {
process(doc); process(doc);
......
...@@ -453,28 +453,6 @@ public abstract class LocalSession implements Session { ...@@ -453,28 +453,6 @@ public abstract class LocalSession implements Session {
return "NONE"; return "NONE";
} }
/**
* Enables stream management for session
* @param enable XEP-0198 <enable/> element
*/
public void enableStreamMangement(Element enable) {
// Do nothing if already enabled
if(streamManager.isEnabled()) {
return;
}
streamManager.setNamespace(enable.getNamespace().getStringValue());
// Ensure that resource binding has occurred
if(getAddress().getResource() == null) {
streamManager.sendUnexpectedError();
return;
}
streamManager.setEnabled(true);
}
@Override @Override
public final Locale getLanguage() { public final Locale getLanguage() {
return language; return language;
......
...@@ -96,6 +96,42 @@ public class StreamManager { ...@@ -96,6 +96,42 @@ public class StreamManager {
this.connection = connection; this.connection = connection;
} }
/**
* Processes a stream management element.
*
* @param element The stream management element to be processed.
* @param onBehalfOf The (full) JID of the entity for which the element is processed.
*/
public void process( Element element, JID onBehalfOf )
{
switch(element.getName()) {
case "enable":
// Do nothing if already enabled
if(isEnabled()) {
return;
}
// Ensure that resource binding has occurred
if( onBehalfOf.getResource() == null ) {
sendUnexpectedError();
return;
}
setNamespace( element.getNamespace().getStringValue() );
setEnabled(true);
break;
case "r":
sendServerAcknowledgement();
break;
case "a":
processClientAcknowledgement( element);
break;
default:
sendUnexpectedError();
}
}
/** /**
* Sends XEP-0198 acknowledgement <a /> to client from server * Sends XEP-0198 acknowledgement <a /> to client from server
*/ */
......
...@@ -57,21 +57,8 @@ public class StreamManagementPacketRouter extends SessionPacketRouter { ...@@ -57,21 +57,8 @@ public class StreamManagementPacketRouter extends SessionPacketRouter {
@Override @Override
public void route(Element wrappedElement) throws UnknownStanzaException { public void route(Element wrappedElement) throws UnknownStanzaException {
String tag = wrappedElement.getName();
if (StreamManager.NAMESPACE_V3.equals(wrappedElement.getNamespace().getStringValue())) { if (StreamManager.NAMESPACE_V3.equals(wrappedElement.getNamespace().getStringValue())) {
switch(tag) { session.getStreamManager().process( wrappedElement, session.getAddress() );
case "enable":
session.enableStreamMangement(wrappedElement);
break;
case "r":
session.getStreamManager().sendServerAcknowledgement();
break;
case "a":
session.getStreamManager().processClientAcknowledgement(wrappedElement);
break;
default:
session.getStreamManager().sendUnexpectedError();
}
} else { } else {
super.route(wrappedElement); super.route(wrappedElement);
if (isUnsolicitedAckExpected()) { if (isUnsolicitedAckExpected()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment