1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-29 17:52:06 +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:
if (namespace.equals(RosterPacket.NAMESPACE)) {
iqPacket = parseRoster(parser); 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); 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;
case XmlPullParser.END_TAG:
if (parser.getDepth() == initialDepth) {
break outerloop;
} }
else if (eventType == XmlPullParser.END_TAG) { break;
if (parser.getName().equals("iq")) {
done = true;
}
} }
} }
// Decide what to do when an IQ packet was not understood // Decide what to do when an IQ packet was not understood