IqPacket.java

 1package eu.siacs.conversations.xmpp.stanzas;
 2
 3import android.graphics.YuvImage;
 4import eu.siacs.conversations.xml.Element;
 5
 6
 7public class IqPacket extends AbstractStanza {
 8	
 9	public static final int TYPE_ERROR = -1;
10	public static final int TYPE_SET = 0;
11	public static final int TYPE_RESULT = 1;
12	public static final int TYPE_GET = 2;
13
14	private IqPacket(String name) {
15		super(name);
16	}
17
18	public IqPacket(int type) {
19		super("iq");
20		switch (type) {
21		case TYPE_SET:
22			this.setAttribute("type", "set");
23			break;
24		case TYPE_GET:
25			this.setAttribute("type", "get");
26			break;
27		case TYPE_RESULT:
28			this.setAttribute("type", "result");
29			break;
30		default:
31			break;
32		}
33	}
34	
35	public IqPacket() {
36		super("iq");
37	}
38	
39	public Element query() {
40		Element query = findChild("query");
41		if (query==null) {
42			query = new Element("query");
43			addChild(query);
44		}
45		return query;
46	}
47	
48	public Element query(String xmlns) {
49		Element query = query();
50		query.setAttribute("xmlns", xmlns);
51		return query();
52	}
53	
54	public int getType() {
55		String type = getAttribute("type");
56		if ("error".equals(type)) {
57			return TYPE_ERROR;
58		} else if ("result".equals(type)) {
59			return TYPE_RESULT;
60		} else if ("set".equals(type)) {
61			return TYPE_SET;
62		} else if ("get".equals(type)) {
63			return TYPE_GET;
64		} else {
65			return 1000;
66		}
67	}
68
69}