1package eu.siacs.conversations.xmpp.stanzas.jingle;
2
3import eu.siacs.conversations.xml.Element;
4import eu.siacs.conversations.xmpp.stanzas.IqPacket;
5
6public class JinglePacket extends IqPacket {
7 Content content = null;
8 Reason reason = null;
9
10 @Override
11 public Element addChild(Element child) {
12 if ("jingle".equals(child.getName())) {
13 Element contentElement = child.findChild("content");
14 if (contentElement!=null) {
15 this.content = new Content();
16 this.content.setChildren(contentElement.getChildren());
17 this.content.setAttributes(contentElement.getAttributes());
18 }
19 Element reasonElement = child.findChild("reason");
20 if (reasonElement!=null) {
21 this.reason = new Reason();
22 this.reason.setChildren(reasonElement.getChildren());
23 this.reason.setAttributes(reasonElement.getAttributes());
24 }
25 this.build();
26 this.findChild("jingle").setAttributes(child.getAttributes());
27 }
28 return child;
29 }
30
31 public JinglePacket setContent(Content content) {
32 this.content = content;
33 this.build();
34 return this;
35 }
36
37 public JinglePacket setReason(Reason reason) {
38 this.reason = reason;
39 this.build();
40 return this;
41 }
42
43 private void build() {
44 this.children.clear();
45 Element jingle = addChild("jingle", "urn:xmpp:jingle:1");
46 if (this.content!=null) {
47 jingle.addChild(this.content);
48 }
49 if (this.reason != null) {
50 jingle.addChild(this.reason);
51 }
52 this.children.add(jingle);
53 }
54}