anotherim/src/main/java/eu/siacs/conversations/xmpp/stanzas/IqPacket.java

78 lines
1.5 KiB
Java
Raw Normal View History

2014-10-22 16:38:44 +00:00
package eu.siacs.conversations.xmpp.stanzas;
import eu.siacs.conversations.xml.Element;
public class IqPacket extends AbstractStanza {
public static final int TYPE_ERROR = -1;
public static final int TYPE_SET = 0;
public static final int TYPE_RESULT = 1;
public static final int TYPE_GET = 2;
private IqPacket(final String name) {
2014-10-22 16:38:44 +00:00
super(name);
}
public IqPacket(final int type) {
2014-10-22 16:38:44 +00:00
super("iq");
switch (type) {
case TYPE_SET:
this.setAttribute("type", "set");
break;
case TYPE_GET:
this.setAttribute("type", "get");
break;
case TYPE_RESULT:
this.setAttribute("type", "result");
break;
case TYPE_ERROR:
this.setAttribute("type", "error");
break;
default:
break;
2014-10-22 16:38:44 +00:00
}
}
public IqPacket() {
super("iq");
}
public Element query() {
Element query = findChild("query");
if (query == null) {
query = addChild("query");
}
return query;
}
public Element query(final String xmlns) {
final Element query = query();
2014-10-22 16:38:44 +00:00
query.setAttribute("xmlns", xmlns);
return query();
}
public int getType() {
final String type = getAttribute("type");
switch (type) {
case "error":
return TYPE_ERROR;
case "result":
return TYPE_RESULT;
case "set":
return TYPE_SET;
case "get":
return TYPE_GET;
default:
return 1000;
2014-10-22 16:38:44 +00:00
}
}
public IqPacket generateRespone(final int type) {
final IqPacket packet = new IqPacket(type);
2014-10-22 16:38:44 +00:00
packet.setTo(this.getFrom());
packet.setId(this.getId());
return packet;
}
}