summaryrefslogtreecommitdiffstats
blob: 423a4990b053f3a91e92e8d9cb8a4fa7bc49af61 (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
/*
 * Copyright (c) 2011 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.JingleDescription;
import com.isode.stroke.elements.JingleTransportPayload;
import java.util.Vector;

public class JingleContentPayload extends Payload {

	public enum Creator {
		UnknownCreator,
		InitiatorCreator,
		ResponderCreator
	};

	/*public enum Senders {
		NoSenders,
		InitiatorSender,
		ResponderSender,
		BothSenders,
	};*/

	private Creator creator;
	private String name = "";
	//private Senders senders;
	private Vector<JingleDescription> descriptions = new Vector<JingleDescription>();
	private Vector<JingleTransportPayload> transports = new Vector<JingleTransportPayload>();

	/**
	* Default Constructor.
	*/
	public JingleContentPayload() {
		this.creator = Creator.UnknownCreator;
	}

	/**
	* @return creator, Not Null.
	*/
	public Creator getCreator() {
		return creator;
	}

	/**
	* @param creator, Not Null.
	*/
	public void setCreator(Creator creator) {
		NotNull.exceptIfNull(creator, "creator");
		this.creator = creator;
	}

	/**
	* @return name, Not Null.
	*/
	public String getName() {
		return name;
	}

	/**
	* @param name, Not Null.
	*/
	public void setName(String name) {
		NotNull.exceptIfNull(name, "name");
		this.name = name;
	}

	/**
	* @return descriptions, Not Null.
	*/
	public Vector<JingleDescription> getDescriptions() {
		return descriptions;
	}

	/**
	* @param description, Not Null.
	*/
	public void addDescription(JingleDescription description) {
		NotNull.exceptIfNull(description, "description");
		descriptions.add(description);
	}

	/**
	* @return transports, Not Null.
	*/
	public Vector<JingleTransportPayload> getTransports() {
		return transports;
	}

	/**
	* @param transport, Not Null.
	*/
	public void addTransport(JingleTransportPayload transport) {
		NotNull.exceptIfNull(transport, "transport");		
		transports.add(transport);
	}

	/**
	 * Get the description of the given type.
	 * @param <T> type.
	 * @param type, not null.
	 * @return description of given type.
	 */
	public <T extends Payload> T getDescription(T type) {
        for (JingleDescription description : descriptions) {
            if (description.getClass().isAssignableFrom(type.getClass())) {
                return (T)description;
            }
        }
        return null;
	}

	/**
	 * Get the transport of the given type.
	 * @param <T> type.
	 * @param type, not null.
	 * @return transport of given type.
	 */
	public <T extends Payload> T getTransport(T type) {
        for (JingleTransportPayload transport : transports) {
            if (transport.getClass().isAssignableFrom(type.getClass())) {
                return (T)transport;
            }
        }
        return null;
	}
}