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 = addChild("query");
43		}
44		return query;
45	}
46	
47	public Element query(String xmlns) {
48		Element query = query();
49		query.setAttribute("xmlns", xmlns);
50		return query();
51	}
52	
53	public int getType() {
54		String type = getAttribute("type");
55		if ("error".equals(type)) {
56			return TYPE_ERROR;
57		} else if ("result".equals(type)) {
58			return TYPE_RESULT;
59		} else if ("set".equals(type)) {
60			return TYPE_SET;
61		} else if ("get".equals(type)) {
62			return TYPE_GET;
63		} else {
64			return 1000;
65		}
66	}
67
68}