2014-03-10 18:22:13 +00:00
|
|
|
package eu.siacs.conversations.xmpp.stanzas;
|
2014-01-30 15:42:35 +00:00
|
|
|
|
2014-03-13 16:29:22 +00:00
|
|
|
import eu.siacs.conversations.xml.Element;
|
|
|
|
|
2014-01-30 15:42:35 +00:00
|
|
|
|
2014-03-10 18:22:13 +00:00
|
|
|
public class IqPacket extends AbstractStanza {
|
2014-01-30 15:42:35 +00:00
|
|
|
|
2014-03-13 16:29:22 +00:00
|
|
|
public static final int TYPE_ERROR = -1;
|
2014-01-30 15:42:35 +00:00
|
|
|
public static final int TYPE_SET = 0;
|
|
|
|
public static final int TYPE_RESULT = 1;
|
2014-01-30 23:33:01 +00:00
|
|
|
public static final int TYPE_GET = 2;
|
2014-01-30 15:42:35 +00:00
|
|
|
|
|
|
|
private IqPacket(String name) {
|
|
|
|
super(name);
|
|
|
|
}
|
|
|
|
|
2014-02-01 00:25:56 +00:00
|
|
|
public IqPacket(int type) {
|
2014-01-30 15:42:35 +00:00
|
|
|
super("iq");
|
|
|
|
switch (type) {
|
|
|
|
case TYPE_SET:
|
|
|
|
this.setAttribute("type", "set");
|
|
|
|
break;
|
2014-01-30 23:33:01 +00:00
|
|
|
case TYPE_GET:
|
|
|
|
this.setAttribute("type", "get");
|
|
|
|
break;
|
|
|
|
case TYPE_RESULT:
|
|
|
|
this.setAttribute("type", "result");
|
|
|
|
break;
|
2014-01-30 15:42:35 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-01-30 23:33:01 +00:00
|
|
|
|
|
|
|
public IqPacket() {
|
|
|
|
super("iq");
|
|
|
|
}
|
2014-03-13 16:29:22 +00:00
|
|
|
|
|
|
|
public Element query() {
|
|
|
|
Element query = findChild("query");
|
|
|
|
if (query==null) {
|
2014-03-20 14:49:53 +00:00
|
|
|
query = addChild("query");
|
2014-03-13 16:29:22 +00:00
|
|
|
}
|
|
|
|
return query;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Element query(String xmlns) {
|
|
|
|
Element query = query();
|
|
|
|
query.setAttribute("xmlns", xmlns);
|
|
|
|
return query();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getType() {
|
|
|
|
String type = getAttribute("type");
|
|
|
|
if ("error".equals(type)) {
|
|
|
|
return TYPE_ERROR;
|
|
|
|
} else if ("result".equals(type)) {
|
|
|
|
return TYPE_RESULT;
|
|
|
|
} else if ("set".equals(type)) {
|
|
|
|
return TYPE_SET;
|
|
|
|
} else if ("get".equals(type)) {
|
|
|
|
return TYPE_GET;
|
|
|
|
} else {
|
|
|
|
return 1000;
|
|
|
|
}
|
|
|
|
}
|
2014-01-30 15:42:35 +00:00
|
|
|
|
|
|
|
}
|