1package eu.siacs.conversations.xmpp.jingle.stanzas;
2
3import com.google.common.base.Preconditions;
4
5import java.util.Collection;
6import java.util.List;
7
8import eu.siacs.conversations.xml.Element;
9import eu.siacs.conversations.xml.Namespace;
10import eu.siacs.conversations.xmpp.jingle.JingleCandidate;
11
12public class S5BTransportInfo extends GenericTransportInfo {
13
14 private S5BTransportInfo(final String name, final String xmlns) {
15 super(name, xmlns);
16 }
17
18 public String getTransportId() {
19 return this.getAttribute("sid");
20 }
21
22 public S5BTransportInfo(final String transportId, final Collection<JingleCandidate> candidates) {
23 super("transport", Namespace.JINGLE_TRANSPORTS_S5B);
24 Preconditions.checkNotNull(transportId,"transport id must not be null");
25 for(JingleCandidate candidate : candidates) {
26 this.addChild(candidate.toElement());
27 }
28 this.setAttribute("sid", transportId);
29 }
30
31 public S5BTransportInfo(final String transportId, final Element child) {
32 super("transport", Namespace.JINGLE_TRANSPORTS_S5B);
33 Preconditions.checkNotNull(transportId,"transport id must not be null");
34 this.addChild(child);
35 this.setAttribute("sid", transportId);
36 }
37
38 public List<JingleCandidate> getCandidates() {
39 return JingleCandidate.parse(this.getChildren());
40 }
41
42 public static S5BTransportInfo upgrade(final Element element) {
43 Preconditions.checkArgument("transport".equals(element.getName()), "Name of provided element is not transport");
44 Preconditions.checkArgument(Namespace.JINGLE_TRANSPORTS_S5B.equals(element.getNamespace()), "Element does not match s5b transport namespace");
45 final S5BTransportInfo transportInfo = new S5BTransportInfo("transport", Namespace.JINGLE_TRANSPORTS_S5B);
46 transportInfo.setAttributes(element.getAttributes());
47 transportInfo.setChildren(element.getChildren());
48 return transportInfo;
49 }
50}