1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 09:39:39 +02:00

Rework Smack Provider design

this is the first stop towards fixing "SMACK-65: parsing should look for
depth", by providing the initial parsing depth to the provider. Some
methods (.e.g parseMessage) now use the depth as abort condition,
instead of a unclean String equals check.

parseIQ() and parseExtension() where both renamed to parse.

This also restricts the Exceptions thrown by the parse method, to just
XmlPullParserException, IOException and SmackException (not really a big
victory, but nevertheless a slight improvement).

StreamFeatureProvider is now gone, we simply use PacketExtensionProvider
for stream features.
This commit is contained in:
Florian Schmaus 2014-10-07 21:15:20 +02:00
parent d04517cd08
commit 6980c8e63d
137 changed files with 1101 additions and 841 deletions

View file

@ -327,7 +327,7 @@ public class RosterTest {
.append("</query>")
.append("</iq>");
final XmlPullParser parser = TestUtils.getIQParser(sb.toString());
final IQ rosterPush = PacketParserUtils.parseIQ(parser, connection);
final IQ rosterPush = PacketParserUtils.parse(parser, connection);
initRoster(connection, roster);
rosterListener.reset();
@ -460,7 +460,7 @@ public class RosterTest {
.append("</query>")
.append("</iq>");
final XmlPullParser parser = TestUtils.getIQParser(sb.toString());
final IQ rosterPush = PacketParserUtils.parseIQ(parser, connection);
final IQ rosterPush = PacketParserUtils.parse(parser, connection);
initRoster(connection, roster);
rosterListener.reset();

View file

@ -72,12 +72,12 @@ public class ParsingExceptionTest {
assertThat(MESSAGE_EXCEPTION_ELEMENT + EXTENSION2 + "</message>", equalsCharSequence(content));
}
static class ThrowException implements PacketExtensionProvider {
static class ThrowException extends PacketExtensionProvider<PacketExtension> {
public static final String ELEMENT = "exception";
public static final String NAMESPACE = "http://smack.jivesoftware.org/exception";
@Override
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
public PacketExtension parse(XmlPullParser parser, int initialDepth) throws SmackException {
throw new SmackException("Test Exception");
}

View file

@ -59,10 +59,10 @@ public class ProviderConfigTest {
Assert.assertNotNull(ProviderManager.getIQProvider("provider", "test:file_provider"));
}
public static class TestIQProvider implements IQProvider {
public static class TestIQProvider extends IQProvider<IQ> {
@Override
public IQ parseIQ(XmlPullParser parser) throws Exception {
public IQ parse(XmlPullParser parser, int initialDepth) {
return null;
}

View file

@ -34,10 +34,10 @@ public class ProviderManagerTest {
assertTrue(SmackConfiguration.isSmackInitialized());
}
public static class TestIQProvider implements IQProvider {
public static class TestIQProvider extends IQProvider<IQ> {
@Override
public IQ parseIQ(XmlPullParser parser) throws Exception {
public IQ parse(XmlPullParser parser, int initialDepth) {
return null;
}