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 {
// resource binding and session establishment (to client sessions only)
waitingCompressionACK = true;
}
} else if(isStreamManagementStanza(doc)) {
switch(tag) {
case "enable":
session.enableStreamMangement(doc);
break;
case "r":
session.getStreamManager().sendServerAcknowledgement();
break;
case "a":
session.getStreamManager().processClientAcknowledgement(doc);
break;
default:
process(doc);
break;
}
} else if (isStreamManagementStanza(doc)) {
session.getStreamManager().process( doc, session.getAddress() );
}
else {
process(doc);
......
......@@ -453,28 +453,6 @@ public abstract class LocalSession implements Session {
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
public final Locale getLanguage() {
return language;
......
......@@ -96,7 +96,43 @@ public class StreamManager {
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
*/
public void sendServerAcknowledgement() {
......
......@@ -57,21 +57,8 @@ public class StreamManagementPacketRouter extends SessionPacketRouter {
@Override
public void route(Element wrappedElement) throws UnknownStanzaException {
String tag = wrappedElement.getName();
if (StreamManager.NAMESPACE_V3.equals(wrappedElement.getNamespace().getStringValue())) {
switch(tag) {
case "enable":
session.enableStreamMangement(wrappedElement);
break;
case "r":
session.getStreamManager().sendServerAcknowledgement();
break;
case "a":
session.getStreamManager().processClientAcknowledgement(wrappedElement);
break;
default:
session.getStreamManager().sendUnexpectedError();
}
session.getStreamManager().process( wrappedElement, session.getAddress() );
} else {
super.route(wrappedElement);
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