mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-12-09 06:31:08 +01:00
Create alternative-session JingleReason
This commit is contained in:
parent
acc98b4b2f
commit
a604266336
2 changed files with 89 additions and 22 deletions
|
|
@ -20,6 +20,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
import org.jivesoftware.smack.packet.NamedElement;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
/**
|
||||
|
|
@ -32,6 +33,27 @@ public class JingleReason implements NamedElement {
|
|||
|
||||
public static final String ELEMENT = "reason";
|
||||
|
||||
public static AlternativeSession AlternativeSession(String sessionId) {
|
||||
return new AlternativeSession(sessionId);
|
||||
}
|
||||
|
||||
public static final JingleReason Busy = new JingleReason(Reason.busy);
|
||||
public static final JingleReason Cancel = new JingleReason(Reason.cancel);
|
||||
public static final JingleReason ConnectivityError = new JingleReason(Reason.connectivity_error);
|
||||
public static final JingleReason Decline = new JingleReason(Reason.decline);
|
||||
public static final JingleReason Expired = new JingleReason(Reason.expired);
|
||||
public static final JingleReason FailedApplication = new JingleReason(Reason.failed_application);
|
||||
public static final JingleReason FailedTransport = new JingleReason(Reason.failed_transport);
|
||||
public static final JingleReason GeneralError = new JingleReason(Reason.general_error);
|
||||
public static final JingleReason Gone = new JingleReason(Reason.gone);
|
||||
public static final JingleReason IncompatibleParameters = new JingleReason(Reason.incompatible_parameters);
|
||||
public static final JingleReason MediaError = new JingleReason(Reason.media_error);
|
||||
public static final JingleReason SecurityError = new JingleReason(Reason.security_error);
|
||||
public static final JingleReason Success = new JingleReason(Reason.success);
|
||||
public static final JingleReason Timeout = new JingleReason(Reason.timeout);
|
||||
public static final JingleReason UnsupportedApplications = new JingleReason(Reason.unsupported_applications);
|
||||
public static final JingleReason UnsupportedTransports = new JingleReason(Reason.unsupported_transports);
|
||||
|
||||
public enum Reason {
|
||||
alternative_session,
|
||||
busy,
|
||||
|
|
@ -52,7 +74,7 @@ public class JingleReason implements NamedElement {
|
|||
unsupported_transports,
|
||||
;
|
||||
|
||||
private static final Map<String, Reason> LUT = new HashMap<>(Reason.values().length);
|
||||
protected static final Map<String, Reason> LUT = new HashMap<>(Reason.values().length);
|
||||
|
||||
static {
|
||||
for (Reason reason : Reason.values()) {
|
||||
|
|
@ -60,9 +82,9 @@ public class JingleReason implements NamedElement {
|
|||
}
|
||||
}
|
||||
|
||||
private final String asString;
|
||||
protected final String asString;
|
||||
|
||||
private Reason() {
|
||||
Reason() {
|
||||
asString = name().replace('_', '-');
|
||||
}
|
||||
|
||||
|
|
@ -80,9 +102,9 @@ public class JingleReason implements NamedElement {
|
|||
}
|
||||
}
|
||||
|
||||
private final Reason reason;
|
||||
protected final Reason reason;
|
||||
|
||||
public JingleReason(Reason reason) {
|
||||
protected JingleReason(Reason reason) {
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
|
|
@ -102,4 +124,33 @@ public class JingleReason implements NamedElement {
|
|||
return xml;
|
||||
}
|
||||
|
||||
|
||||
public static class AlternativeSession extends JingleReason {
|
||||
|
||||
public static final String SID = "sid";
|
||||
private final String sessionId;
|
||||
|
||||
public AlternativeSession(String sessionId) {
|
||||
super(Reason.alternative_session);
|
||||
if (StringUtils.isNullOrEmpty(sessionId)) {
|
||||
throw new NullPointerException("SessionID must not be null or empty.");
|
||||
}
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlStringBuilder toXML() {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
xml.rightAngleBracket();
|
||||
|
||||
xml.openElement(reason.asString);
|
||||
xml.openElement(SID);
|
||||
xml.append(sessionId);
|
||||
xml.closeElement(SID);
|
||||
xml.closeElement(reason.asString);
|
||||
|
||||
xml.closeElement(this);
|
||||
return xml;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue