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