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

Replace legacy IQProvider with IqProvider

This commit is contained in:
Ingo Bauersachs 2022-04-01 22:06:18 +02:00
parent 78ffcae880
commit 4efa707028
94 changed files with 354 additions and 261 deletions

View file

@ -19,6 +19,7 @@ package org.jivesoftware.smack.provider;
import java.io.IOException;
import org.jivesoftware.smack.packet.Bind;
import org.jivesoftware.smack.packet.IqData;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
@ -27,10 +28,10 @@ import org.jxmpp.jid.EntityFullJid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.jid.parts.Resourcepart;
public class BindIQProvider extends IQProvider<Bind> {
public class BindIQProvider extends IqProvider<Bind> {
@Override
public Bind parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
public Bind parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
String name;
Bind bind = null;
outerloop: while (true) {

View file

@ -28,7 +28,7 @@ import org.jivesoftware.smack.packet.IQ;
public final class IQProviderInfo extends AbstractProviderInfo {
/**
* Defines an IQ provider which implements the <code>IQProvider</code> interface.
* Defines an IQ provider which implements the {@link IqProvider} interface.
*
* @param elementName Element that provider parses.
* @param namespace Namespace that provider parses.

View file

@ -21,6 +21,7 @@ import java.lang.reflect.InvocationTargetException;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IqData;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
@ -42,7 +43,7 @@ public class IntrospectionProvider{
*/
// TODO: Remove in Smack 4.6.
@Deprecated
public abstract static class IQIntrospectionProvider<I extends IQ> extends IQProvider<I> {
public abstract static class IQIntrospectionProvider<I extends IQ> extends IqProvider<I> {
private final Class<I> elementClass;
protected IQIntrospectionProvider(Class<I> elementClass) {
@ -51,7 +52,7 @@ public class IntrospectionProvider{
@SuppressWarnings("unchecked")
@Override
public I parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
public I parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
try {
return (I) parseWithIntrospection(elementClass, parser, initialDepth);
}

View file

@ -23,9 +23,17 @@ import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IqData;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
/**
* An abstract class for parsing custom {@link IQ} packets. Each IqProvider must be registered with the {@link
* ProviderManager} for it to be used. Every implementation of this abstract class <b>must</b> have a public,
* no-argument constructor.
*
* @param <I> the {@link IQ} that is parsed by implementations.
*/
public abstract class IqProvider<I extends IQ> extends AbstractProvider<I> {
public final I parse(XmlPullParser parser, IqData iqCommon)
@ -40,6 +48,8 @@ public abstract class IqProvider<I extends IQ> extends AbstractProvider<I> {
I i = wrapExceptions(() -> parse(parser, initialDepth, iqData, xmlEnvironment));
// Parser should be at end tag of the consumed/parsed element
ParserUtils.forwardToEndTagOfDepth(parser, initialDepth);
return i;
}

View file

@ -37,8 +37,11 @@ import org.jivesoftware.smack.xml.XmlPullParserException;
* abstract class <b>must</b> have a public, no-argument constructor.
*
* @author Matt Tucker
* @deprecated Use {@link IqProvider} instead
*/
public abstract class IQProvider<I extends IQ> extends IqProvider<I> {
@Deprecated
// TODO: Remove in Smack 4.6.
public abstract class LegacyIQProvider<I extends IQ> extends IqProvider<I> {
public final I parse(XmlPullParser parser) throws IOException, XmlPullParserException, SmackParsingException {
return parse(parser, (XmlEnvironment) null);

View file

@ -30,7 +30,7 @@ import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
/**
* Loads the {@link IQProvider} and {@link ExtensionElementProvider} information from a standard provider file in preparation
* Loads the {@link IqProvider} and {@link ExtensionElementProvider} information from a standard provider file in preparation
* for loading into the {@link ProviderManager}.
*
* @author Robin Collier
@ -76,7 +76,7 @@ public class ProviderFileLoader implements ProviderLoader {
switch (typeName) {
case "iqProvider":
// Attempt to load the provider class and then create
// a new instance if it's an IQProvider. Otherwise, if it's
// a new instance if it's an IqProvider. Otherwise, if it's
// an IQ class, add the class object itself, then we'll use
// reflection later to create instances of the class.
// Add the provider to the map.
@ -85,7 +85,7 @@ public class ProviderFileLoader implements ProviderLoader {
iqProviders.add(new IQProviderInfo(elementName, namespace, iqProvider));
}
else {
exceptions.add(new IllegalArgumentException(className + " is not a IQProvider"));
exceptions.add(new IllegalArgumentException(className + " is not a IqProvider"));
}
break;
case "extensionProvider":

View file

@ -34,11 +34,11 @@ import org.jivesoftware.smack.util.XmppElementUtil;
/**
* Manages providers for parsing custom XML sub-documents of XMPP packets. Two types of
* providers exist:<ul>
* <li>IQProvider -- parses IQ requests into Java objects.
* <li>IqProvider -- parses IQ requests into Java objects.
* <li>PacketExtension -- parses XML sub-documents attached to packets into
* PacketExtension instances.</ul>
*
* <b>IQProvider</b><p>
* <b>IqProvider</b><p>
*
* By default, Smack only knows how to process IQ packets with sub-packets that
* are in a few namespaces such as:<ul>
@ -63,8 +63,8 @@ import org.jivesoftware.smack.util.XmppElementUtil;
*
* Each IQ provider is associated with an element name and a namespace. If multiple provider
* entries attempt to register to handle the same namespace, the first entry loaded from the
* classpath will take precedence. The IQ provider class can either implement the IQProvider
* interface, or extend the IQ class. In the former case, each IQProvider is responsible for
* classpath will take precedence. The IQ provider class can either implement the IqProvider
* interface, or extend the IQ class. In the former case, each IqProvider is responsible for
* parsing the raw XML stream to create an IQ instance. In the latter case, bean introspection
* is used to try to automatically set properties of the IQ instance using the values found
* in the IQ stanza XML. For example, an XMPP time stanza resembles the following:
@ -173,11 +173,11 @@ public final class ProviderManager {
}
/**
* Returns an unmodifiable collection of all IQProvider instances. Each object
* in the collection will either be an IQProvider instance, or a Class object
* that implements the IQProvider interface.
* Returns an unmodifiable collection of all IqProvider instances. Each object
* in the collection will either be an IqProvider instance, or a Class object
* that implements the IqProvider interface.
*
* @return all IQProvider instances.
* @return all IqProvider instances.
*/
public static List<IqProvider<IQ>> getIQProviders() {
List<IqProvider<IQ>> providers = new ArrayList<>(iqProviders.size());
@ -186,7 +186,7 @@ public final class ProviderManager {
}
/**
* Adds an IQ provider (must be an instance of IQProvider or Class object that is an IQ)
* Adds an IQ provider (must be an instance of IqProvider or Class object that is an IQ)
* with the specified element name and name space. The provider will override any providers
* loaded through the classpath.
*

View file

@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.Collection;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IqData;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.util.FileUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
@ -60,10 +61,10 @@ public class ProviderConfigTest {
Assert.assertNotNull(ProviderManager.getIQProvider("provider", "test:file_provider"));
}
public static class TestIQProvider extends IQProvider<IQ> {
public static class TestIQProvider extends IqProvider<IQ> {
@Override
public IQ parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) {
public IQ parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment) {
return null;
}

View file

@ -20,6 +20,7 @@ import static org.junit.Assert.assertTrue;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IqData;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.xml.XmlPullParser;
@ -37,10 +38,10 @@ public class ProviderManagerTest {
assertTrue(SmackConfiguration.isSmackInitialized());
}
public static class TestIQProvider extends IQProvider<IQ> {
public static class TestIQProvider extends IqProvider<IQ> {
@Override
public IQ parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) {
public IQ parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment) {
return null;
}