1package eu.siacs.conversations.xmpp.jingle.stanzas;
2
3import com.google.common.base.Preconditions;
4
5import eu.siacs.conversations.xml.Element;
6import eu.siacs.conversations.xml.Namespace;
7
8public class IbbTransportInfo extends GenericTransportInfo {
9
10 private IbbTransportInfo(final String name, final String xmlns) {
11 super(name, xmlns);
12 }
13
14 public IbbTransportInfo(final String transportId, final int blockSize) {
15 super("transport", Namespace.JINGLE_TRANSPORTS_IBB);
16 Preconditions.checkNotNull(transportId, "Transport ID can not be null");
17 Preconditions.checkArgument(blockSize > 0, "Block size must be larger than 0");
18 this.setAttribute("block-size", blockSize);
19 this.setAttribute("sid", transportId);
20 }
21
22 public String getTransportId() {
23 return this.getAttribute("sid");
24 }
25
26 public int getBlockSize() {
27 final String blockSize = this.getAttribute("block-size");
28 if (blockSize == null) {
29 return 0;
30 }
31 try {
32 return Integer.parseInt(blockSize);
33 } catch (NumberFormatException e) {
34 return 0;
35 }
36 }
37
38 public static IbbTransportInfo upgrade(final Element element) {
39 Preconditions.checkArgument("transport".equals(element.getName()), "Name of provided element is not transport");
40 Preconditions.checkArgument(Namespace.JINGLE_TRANSPORTS_IBB.equals(element.getNamespace()), "Element does not match ibb transport namespace");
41 final IbbTransportInfo transportInfo = new IbbTransportInfo("transport", Namespace.JINGLE_TRANSPORTS_IBB);
42 transportInfo.setAttributes(element.getAttributes());
43 transportInfo.setChildren(element.getChildren());
44 return transportInfo;
45 }
46}