summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2015-06-17 07:33:03 (GMT)
committerTarun Gupta <tarun1995gupta@gmail.com>2015-06-18 20:18:56 (GMT)
commitf9c7be7adde21ab29b5e268a726506bb06510ead (patch)
treeb1e2f276c7015eb74e955b856bdf944c8f4f4041 /src/com/isode/stroke/elements/JinglePayload.java
parent4addb6419080db814094ab501d69111adffeb5be (diff)
downloadstroke-f9c7be7adde21ab29b5e268a726506bb06510ead.zip
stroke-f9c7be7adde21ab29b5e268a726506bb06510ead.tar.bz2
Adds Jingle Elements.
Adds: JinglePayload, its Parser and Serializer and JingleReasonParser. JingleContentPayload Element, its Parser and Serializer. JingleDesciption Element. JingleFileTransferDescription Element, its Parser and Serializer. JingleFileTransferFileInfo Element, its Parser and Serializer. JingleFileTransferHash Element, its Parser and Serializer. JingleIBBTransportPayload Element, its Parser and Serializer. JingleS5BTransportPayload Element, its Parser and Serializer. JingleTransportPayload Element and HashElement. Updates HostAddress access specifier for getInetAddress(). License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Tests added for: JingleParser JingleContentPayload Parser and Serializer. JingleFileTransferHash Parser and Serializer. JingleFileTranferFileInfo Parser and Serializer. JingleFileTransferDescription Parser and Serializer. JingleIBBTransportPayload Parser and Serializer. JingleS5BTransportPayload Parser and Serializer. All tests passes. Change-Id: Ife1b7fef00efc57d8d0d4290f3280327439abbb6
Diffstat (limited to 'src/com/isode/stroke/elements/JinglePayload.java')
-rw-r--r--src/com/isode/stroke/elements/JinglePayload.java265
1 files changed, 265 insertions, 0 deletions
diff --git a/src/com/isode/stroke/elements/JinglePayload.java b/src/com/isode/stroke/elements/JinglePayload.java
new file mode 100644
index 0000000..c90e802
--- /dev/null
+++ b/src/com/isode/stroke/elements/JinglePayload.java
@@ -0,0 +1,265 @@
+/*
+ * Copyright (c) 2011-2014 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.elements;
+
+import com.isode.stroke.base.NotNull;
+import com.isode.stroke.elements.Payload;
+import com.isode.stroke.elements.JingleContentPayload;
+import com.isode.stroke.jid.JID;
+import java.util.Vector;
+
+public class JinglePayload extends Payload {
+
+ public static class Reason extends Payload {
+
+ public enum Type {
+ UnknownType,
+ AlternativeSession,
+ Busy,
+ Cancel,
+ ConnectivityError,
+ Decline,
+ Expired,
+ FailedApplication,
+ FailedTransport,
+ GeneralError,
+ Gone,
+ IncompatibleParameters,
+ MediaError,
+ SecurityError,
+ Success,
+ Timeout,
+ UnsupportedApplications,
+ UnsupportedTransports
+ };
+
+ public Type type;
+ public String text = "";
+
+ public Reason() {
+ this(Type.UnknownType, "");
+ }
+
+ public Reason(Type type) {
+ this(type, "");
+ }
+
+ public Reason(Type type, String text) {
+ NotNull.exceptIfNull(type, "type");
+ NotNull.exceptIfNull(text, "text");
+ this.type = type;
+ this.text = text;
+ }
+
+ /**
+ * @return Type, NotNull.
+ */
+ public Type getType() {
+ return this.type;
+ }
+
+ /**
+ * @param Type, NotNull.
+ */
+ public void setType(Type type) {
+ NotNull.exceptIfNull(type, "type");
+ this.type = type;
+ }
+
+ /**
+ * @return Text, NotNull.
+ */
+ public String getText() {
+ return this.text;
+ }
+
+ /**
+ * @param Text, NotNull.
+ */
+ public void setText(String text) {
+ NotNull.exceptIfNull(text, "text");
+ this.text = text;
+ }
+ }
+
+ public enum Action {
+ UnknownAction,
+ ContentAccept,
+ ContentAdd,
+ ContentModify,
+ ContentReject,
+ ContentRemove,
+ DescriptionInfo,
+ SecurityInfo,
+ SessionAccept,
+ SessionInfo,
+ SessionInitiate,
+ SessionTerminate,
+ TransportAccept,
+ TransportInfo,
+ TransportReject,
+ TransportReplace
+ };
+
+ private Action action;
+ private JID initiator = new JID();
+ private JID responder = new JID();
+ private String sessionID = "";
+ private Vector<Payload> payloads = new Vector<Payload>();
+ private Reason reason = null;
+
+ public JinglePayload() {
+ this(Action.SessionTerminate, "");
+ }
+
+ public JinglePayload(Action action, String sessionID) {
+ NotNull.exceptIfNull(action, "action");
+ NotNull.exceptIfNull(sessionID, "sessionID");
+ this.action = action;
+ this.sessionID = sessionID;
+ }
+
+ /**
+ * @param action, NotNull.
+ */
+ public void setAction(Action action) {
+ NotNull.exceptIfNull(action, "action");
+ this.action = action;
+ }
+
+ /**
+ * @return action, NotNull.
+ */
+ public Action getAction() {
+ return action;
+ }
+
+ /**
+ * @param initiator, NotNull.
+ */
+ public void setInitiator(JID initiator) {
+ NotNull.exceptIfNull(initiator, "initiator");
+ this.initiator = initiator;
+ }
+
+ /**
+ * @return initiator, NotNull.
+ */
+ public JID getInitiator() {
+ return initiator;
+ }
+
+ /**
+ * @param responder, NotNull.
+ */
+ public void setResponder(JID responder) {
+ NotNull.exceptIfNull(responder, "responder");
+ this.responder = responder;
+ }
+
+ /**
+ * @return responder, NotNull.
+ */
+ public JID getResponder() {
+ return responder;
+ }
+
+ /**
+ * @param sessionID, NotNull.
+ */
+ public void setSessionID(String id) {
+ NotNull.exceptIfNull(id, "sessionID");
+ sessionID = id;
+ }
+
+ /**
+ * @return sessionID, NotNull.
+ */
+ public String getSessionID() {
+ return sessionID;
+ }
+
+ /**
+ * @param content.
+ */
+ public void addContent(JingleContentPayload content) {
+ this.payloads.add(content);
+ }
+
+ /**
+ * @param payload.
+ */
+ public void addPayload(Payload payload) {
+ this.payloads.add(payload);
+ }
+
+ /**
+ * @return payloads, of type JingleContentPayload.
+ */
+ public Vector<JingleContentPayload> getContents() {
+ return getPayloads(new JingleContentPayload());
+ }
+
+ /**
+ * @return payloads.
+ */
+ public Vector<Payload> getPayloads() {
+ return payloads;
+ }
+
+ /**
+ * Get the payload of the given type from the stanza
+ * @param <T> payload type
+ * @param type payload type object instance, not null
+ * @return payload of given type, can be null
+ */
+ @SuppressWarnings("unchecked")
+ public <T extends Payload> T getPayload(T type) {
+ for (Payload payload : payloads) {
+ if (payload.getClass().isAssignableFrom(type.getClass())) {
+ return (T)payload;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get the payloads of the given type from the stanza
+ * @param <T> payload type
+ * @param type payload type object instance, not null
+ * @return list of payloads of given type, not null but can be empty
+ */
+ @SuppressWarnings("unchecked")
+ public <T extends Payload> Vector<T> getPayloads(T type) {
+ Vector<T> matched_payloads = new Vector<T>();
+ for (Payload payload : payloads) {
+ if (payload.getClass().isAssignableFrom(type.getClass())) {
+ matched_payloads.add((T)payload);
+ }
+ }
+ return matched_payloads;
+ }
+
+ /**
+ * @param reason.
+ */
+ public void setReason(Reason reason) {
+ this.reason = reason;
+ }
+
+ /**
+ * @return reason.
+ */
+ public Reason getReason() {
+ return reason;
+ }
+} \ No newline at end of file