1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 20:12:07 +01:00

Use switch/case in 'IQ parse(XmlPullParser)'

This commit is contained in:
Florian Schmaus 2014-10-30 12:15:59 +01:00
parent b5daee3032
commit e88583d287

View file

@ -599,6 +599,8 @@ public class PacketParserUtils {
* @throws Exception if an exception occurs while parsing the packet.
*/
public static IQ parse(XmlPullParser parser, XMPPConnection connection) throws Exception {
ParserUtils.assertAtStartTag(parser);
final int initialDepth = parser.getDepth();
IQ iqPacket = null;
XMPPError error = null;
@ -607,25 +609,30 @@ public class PacketParserUtils {
final String from = parser.getAttributeValue("", "from");
final IQ.Type type = IQ.Type.fromString(parser.getAttributeValue("", "type"));
boolean done = false;
while (!done) {
outerloop: while (true) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
switch (eventType) {
case XmlPullParser.START_TAG:
String elementName = parser.getName();
String namespace = parser.getNamespace();
if (elementName.equals("error")) {
switch(elementName) {
case "error":
error = PacketParserUtils.parseError(parser);
}
else if (elementName.equals(RosterPacket.ELEMENT) && namespace.equals(RosterPacket.NAMESPACE)) {
break;
case RosterPacket.ELEMENT:
if (namespace.equals(RosterPacket.NAMESPACE)) {
iqPacket = parseRoster(parser);
break;
}
else if (elementName.equals(Bind.ELEMENT) && namespace.equals(Bind.NAMESPACE)) {
case Bind.ELEMENT:
if (namespace.equals(Bind.NAMESPACE)) {
iqPacket = parseResourceBinding(parser);
break;
}
// Otherwise, see if there is a registered provider for
// this element name and namespace.
else {
default:
IQProvider<IQ> provider = ProviderManager.getIQProvider(elementName, namespace);
if (provider != null) {
iqPacket = provider.parse(parser);
@ -645,12 +652,14 @@ public class PacketParserUtils {
iqPacket = new UnparsedResultIQ(parseElement(parser));
}
}
break;
}
break;
case XmlPullParser.END_TAG:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("iq")) {
done = true;
}
break;
}
}
// Decide what to do when an IQ packet was not understood