Propose.java

 1package eu.siacs.conversations.xmpp.jingle.stanzas;
 2
 3import com.google.common.base.Preconditions;
 4import com.google.common.collect.ImmutableList;
 5
 6import java.util.List;
 7
 8import eu.siacs.conversations.xml.Element;
 9import eu.siacs.conversations.xml.Namespace;
10
11public class Propose extends Element {
12    private Propose() {
13        super("propose", Namespace.JINGLE_MESSAGE);
14    }
15
16    public List<GenericDescription> getDescriptions() {
17        final ImmutableList.Builder<GenericDescription> builder = new ImmutableList.Builder<>();
18        for (final Element child : this.children) {
19            if ("description".equals(child.getName())) {
20                final String namespace = child.getNamespace();
21                if (Namespace.JINGLE_APPS_FILE_TRANSFER.equals(namespace)) {
22                    builder.add(FileTransferDescription.upgrade(child));
23                } else if (Namespace.JINGLE_APPS_RTP.equals(namespace)) {
24                    builder.add(RtpDescription.upgrade(child));
25                } else {
26                    builder.add(GenericDescription.upgrade(child));
27                }
28            }
29        }
30        return builder.build();
31    }
32
33    public static Propose upgrade(final Element element) {
34        Preconditions.checkArgument("propose".equals(element.getName()));
35        Preconditions.checkArgument(Namespace.JINGLE_MESSAGE.equals(element.getNamespace()));
36        final Propose propose = new Propose();
37        propose.setAttributes(element.getAttributes());
38        propose.setChildren(element.getChildren());
39        return propose;
40    }
41}