summaryrefslogtreecommitdiffstats
blob: c90e8021a694c1552360b8677dbe3aa0a982d535 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
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;
	}
}