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

Rename PacketFilter (and implementing classes) and PacketExtension

to StanzaFilter and ExtensionElement.
This commit is contained in:
Florian Schmaus 2015-02-26 18:41:17 +01:00
parent 2250ac20ed
commit d4a6d8e653
233 changed files with 1175 additions and 895 deletions

View file

@ -20,7 +20,7 @@ package org.jivesoftware.smack;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.filter.StanzaTypeFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.test.SmackTestCase;
import org.jivesoftware.smackx.packet.Version;
@ -51,7 +51,7 @@ public class IQTest extends SmackTestCase {
};
PacketFilter filter = new AndFilter(new PacketIDFilter(iq.getStanzaId()),
new PacketTypeFilter(IQ.class));
new StanzaTypeFilter(IQ.class));
PacketCollector collector = getConnection(0).createPacketCollector(filter);
// Send the iq packet with an invalid namespace
getConnection(0).sendPacket(iq);

View file

@ -19,7 +19,7 @@ package org.jivesoftware.smack;
import org.jivesoftware.smack.filter.FromMatchesFilter;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.filter.StanzaTypeFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.test.SmackTestCase;
@ -143,7 +143,7 @@ public class PacketReaderTest extends SmackTestCase {
message.setBody("HELLO");
getConnection(1).sendPacket(message);
}
}, new PacketTypeFilter(Message.class));
}, new StanzaTypeFilter(Message.class));
// User0 listen for replies from user1
PacketCollector collector = getConnection(0).createPacketCollector(

View file

@ -21,9 +21,9 @@ import junit.framework.TestCase;
import org.jivesoftware.smack.packet.*;
/**
* Test cases for the PacketTypeFilter class.
* Test cases for the StanzaTypeFilter class.
*/
public class PacketTypeFilterTest extends TestCase {
public class StanzaTypeFilterTest extends TestCase {
private class InnerClassDummy {
public class DummyPacket extends Packet {
@ -48,20 +48,20 @@ public class PacketTypeFilterTest extends TestCase {
}
/**
* Test case for the constructor of PacketTypeFilter objects.
* Test case for the constructor of StanzaTypeFilter objects.
*/
public void testConstructor() {
// We dont need to test this since PacketTypeFilter(Class<? extends Packet> packetType) only excepts Packets
// We dont need to test this since StanzaTypeFilter(Class<? extends Packet> packetType) only excepts Packets
// Test a class that is not a subclass of Packet
// try {
// new PacketTypeFilter(Dummy.class);
// new StanzaTypeFilter(Dummy.class);
// fail("Parameter must be a subclass of Packet.");
// }
// catch (IllegalArgumentException e) {}
// Test a class that is a subclass of Packet
try {
new PacketTypeFilter(MockPacket.class);
new StanzaTypeFilter(MockPacket.class);
}
catch (IllegalArgumentException e) {
fail();
@ -69,7 +69,7 @@ public class PacketTypeFilterTest extends TestCase {
// Test another class which is a subclass of Packet
try {
new PacketTypeFilter(IQ.class);
new StanzaTypeFilter(IQ.class);
}
catch (IllegalArgumentException e) {
fail();
@ -77,7 +77,7 @@ public class PacketTypeFilterTest extends TestCase {
// Test an internal class which is a subclass of Packet
try {
new PacketTypeFilter(InnerClassDummy.DummyPacket.class);
new StanzaTypeFilter(InnerClassDummy.DummyPacket.class);
}
catch (IllegalArgumentException e) {
fail();
@ -85,7 +85,7 @@ public class PacketTypeFilterTest extends TestCase {
// Test an internal static class which is a static subclass of Packet
try {
new PacketTypeFilter(StaticInnerClassDummy.StaticDummyPacket.class);
new StanzaTypeFilter(StaticInnerClassDummy.StaticDummyPacket.class);
}
catch (IllegalArgumentException e) {
fail();
@ -93,19 +93,19 @@ public class PacketTypeFilterTest extends TestCase {
}
/**
* Test case to test the accept() method of PacketTypeFilter objects.
* Test case to test the accept() method of StanzaTypeFilter objects.
*/
public void testAccept() {
Packet packet = new MockPacket();
PacketTypeFilter filter = new PacketTypeFilter(MockPacket.class);
StanzaTypeFilter filter = new PacketTypeFilter(MockPacket.class);
assertTrue(filter.accept(packet));
packet = (new InnerClassDummy()).getInnerInstance();
filter = new PacketTypeFilter(InnerClassDummy.DummyPacket.class);
filter = new StanzaTypeFilter(InnerClassDummy.DummyPacket.class);
assertTrue(filter.accept(packet));
packet = StaticInnerClassDummy.getInnerInstance();
filter = new PacketTypeFilter(StaticInnerClassDummy.StaticDummyPacket.class);
filter = new StanzaTypeFilter(StaticInnerClassDummy.StaticDummyPacket.class);
assertTrue(filter.accept(packet));
}
}

View file

@ -56,7 +56,7 @@ import org.jivesoftware.smack.compress.packet.Compress;
import org.jivesoftware.smack.compression.XMPPInputOutputStream;
import org.jivesoftware.smack.debugger.SmackDebugger;
import org.jivesoftware.smack.filter.IQReplyFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.filter.StanzaIdFilter;
import org.jivesoftware.smack.iqrequest.IQRequestHandler;
import org.jivesoftware.smack.packet.Bind;
@ -64,7 +64,7 @@ import org.jivesoftware.smack.packet.ErrorIQ;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Mechanisms;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Session;
import org.jivesoftware.smack.packet.StartTls;
@ -72,7 +72,7 @@ import org.jivesoftware.smack.packet.PlainStreamElement;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
import org.jivesoftware.smack.parsing.UnparsablePacket;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.util.DNSUtil;
import org.jivesoftware.smack.util.Objects;
@ -154,7 +154,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
protected final Lock connectionLock = new ReentrantLock();
protected final Map<String, PacketExtension> streamFeatures = new HashMap<String, PacketExtension>();
protected final Map<String, ExtensionElement> streamFeatures = new HashMap<String, ExtensionElement>();
/**
* The full JID of the authenticated user, as returned by the resource binding response of the server.
@ -716,14 +716,14 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
@Override
public PacketCollector createPacketCollectorAndSend(IQ packet) throws NotConnectedException {
PacketFilter packetFilter = new IQReplyFilter(packet, this);
StanzaFilter packetFilter = new IQReplyFilter(packet, this);
// Create the packet collector before sending the packet
PacketCollector packetCollector = createPacketCollectorAndSend(packetFilter, packet);
return packetCollector;
}
@Override
public PacketCollector createPacketCollectorAndSend(PacketFilter packetFilter, Stanza packet)
public PacketCollector createPacketCollectorAndSend(StanzaFilter packetFilter, Stanza packet)
throws NotConnectedException {
// Create the packet collector before sending the packet
PacketCollector packetCollector = createPacketCollector(packetFilter);
@ -739,8 +739,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
}
@Override
public PacketCollector createPacketCollector(PacketFilter packetFilter) {
PacketCollector.Configuration configuration = PacketCollector.newConfiguration().setPacketFilter(packetFilter);
public PacketCollector createPacketCollector(StanzaFilter packetFilter) {
PacketCollector.Configuration configuration = PacketCollector.newConfiguration().setStanzaFilter(packetFilter);
return createPacketCollector(configuration);
}
@ -759,7 +759,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
@Override
@Deprecated
public void addPacketListener(PacketListener packetListener, PacketFilter packetFilter) {
public void addPacketListener(PacketListener packetListener, StanzaFilter packetFilter) {
addAsyncPacketListener(packetListener, packetFilter);
}
@ -770,7 +770,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
}
@Override
public void addSyncPacketListener(PacketListener packetListener, PacketFilter packetFilter) {
public void addSyncPacketListener(PacketListener packetListener, StanzaFilter packetFilter) {
if (packetListener == null) {
throw new NullPointerException("Packet listener is null.");
}
@ -788,7 +788,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
}
@Override
public void addAsyncPacketListener(PacketListener packetListener, PacketFilter packetFilter) {
public void addAsyncPacketListener(PacketListener packetListener, StanzaFilter packetFilter) {
if (packetListener == null) {
throw new NullPointerException("Packet listener is null.");
}
@ -806,7 +806,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
}
@Override
public void addPacketSendingListener(PacketListener packetListener, PacketFilter packetFilter) {
public void addPacketSendingListener(PacketListener packetListener, StanzaFilter packetFilter) {
if (packetListener == null) {
throw new NullPointerException("Packet listener is null.");
}
@ -862,7 +862,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
@Override
public void addPacketInterceptor(PacketListener packetInterceptor,
PacketFilter packetFilter) {
StanzaFilter packetFilter) {
if (packetInterceptor == null) {
throw new NullPointerException("Packet interceptor is null.");
}
@ -1244,7 +1244,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
protected static class ListenerWrapper {
private final PacketListener packetListener;
private final PacketFilter packetFilter;
private final StanzaFilter packetFilter;
/**
* Create a class which associates a packet filter with a listener.
@ -1252,7 +1252,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
* @param packetListener the packet listener.
* @param packetFilter the associated filter or null if it listen for all packets.
*/
public ListenerWrapper(PacketListener packetListener, PacketFilter packetFilter) {
public ListenerWrapper(PacketListener packetListener, StanzaFilter packetFilter) {
this.packetListener = packetListener;
this.packetFilter = packetFilter;
}
@ -1272,7 +1272,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
protected static class InterceptorWrapper {
private final PacketListener packetInterceptor;
private final PacketFilter packetFilter;
private final StanzaFilter packetFilter;
/**
* Create a class which associates a packet filter with an interceptor.
@ -1280,7 +1280,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
* @param packetInterceptor the interceptor.
* @param packetFilter the associated filter or null if it intercepts all packets.
*/
public InterceptorWrapper(PacketListener packetInterceptor, PacketFilter packetFilter) {
public InterceptorWrapper(PacketListener packetInterceptor, StanzaFilter packetFilter) {
this.packetInterceptor = packetInterceptor;
this.packetFilter = packetFilter;
}
@ -1339,7 +1339,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG && parser.getDepth() == initialDepth + 1) {
PacketExtension streamFeature = null;
ExtensionElement streamFeature = null;
String name = parser.getName();
String namespace = parser.getNamespace();
switch (name) {
@ -1359,7 +1359,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
streamFeature = PacketParserUtils.parseCompressionFeature(parser);
break;
default:
PacketExtensionProvider<PacketExtension> provider = ProviderManager.getStreamFeatureProvider(name, namespace);
ExtensionElementProvider<ExtensionElement> provider = ProviderManager.getStreamFeatureProvider(name, namespace);
if (provider != null) {
streamFeature = provider.parse(parser);
}
@ -1401,7 +1401,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
@SuppressWarnings("unchecked")
@Override
public <F extends PacketExtension> F getFeature(String element, String namespace) {
public <F extends ExtensionElement> F getFeature(String element, String namespace) {
return (F) streamFeatures.get(XmppStringUtils.generateKey(element, namespace));
}
@ -1410,19 +1410,19 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
return getFeature(element, namespace) != null;
}
private void addStreamFeature(PacketExtension feature) {
private void addStreamFeature(ExtensionElement feature) {
String key = XmppStringUtils.generateKey(feature.getElementName(), feature.getNamespace());
streamFeatures.put(key, feature);
}
@Override
public void sendStanzaWithResponseCallback(Stanza stanza, PacketFilter replyFilter,
public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter,
PacketListener callback) throws NotConnectedException {
sendStanzaWithResponseCallback(stanza, replyFilter, callback, null);
}
@Override
public void sendStanzaWithResponseCallback(Stanza stanza, PacketFilter replyFilter,
public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter,
PacketListener callback, ExceptionCallback exceptionCallback)
throws NotConnectedException {
sendStanzaWithResponseCallback(stanza, replyFilter, callback, exceptionCallback,
@ -1430,7 +1430,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
}
@Override
public void sendStanzaWithResponseCallback(Stanza stanza, final PacketFilter replyFilter,
public void sendStanzaWithResponseCallback(Stanza stanza, final StanzaFilter replyFilter,
final PacketListener callback, final ExceptionCallback exceptionCallback,
long timeout) throws NotConnectedException {
Objects.requireNonNull(stanza, "stanza must not be null");
@ -1487,12 +1487,12 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
public void sendIqWithResponseCallback(IQ iqRequest, final PacketListener callback,
final ExceptionCallback exceptionCallback, long timeout)
throws NotConnectedException {
PacketFilter replyFilter = new IQReplyFilter(iqRequest, this);
StanzaFilter replyFilter = new IQReplyFilter(iqRequest, this);
sendStanzaWithResponseCallback(iqRequest, replyFilter, callback, exceptionCallback, timeout);
}
@Override
public void addOneTimeSyncCallback(final PacketListener callback, final PacketFilter packetFilter) {
public void addOneTimeSyncCallback(final PacketListener callback, final StanzaFilter packetFilter) {
final PacketListener packetListener = new PacketListener() {
@Override
public void processPacket(Stanza packet) throws NotConnectedException {

View file

@ -24,7 +24,7 @@ import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.packet.Stanza;
/**
@ -38,14 +38,14 @@ import org.jivesoftware.smack.packet.Stanza;
* older packets are automatically dropped. The default number is retrieved by
* {@link SmackConfiguration#getPacketCollectorSize()}.
*
* @see XMPPConnection#createPacketCollector(PacketFilter)
* @see XMPPConnection#createPacketCollector(StanzaFilter)
* @author Matt Tucker
*/
public class PacketCollector {
private static final Logger LOGGER = Logger.getLogger(PacketCollector.class.getName());
private final PacketFilter packetFilter;
private final StanzaFilter packetFilter;
private final ArrayBlockingQueue<Stanza> resultQueue;
/**
@ -89,11 +89,23 @@ public class PacketCollector {
* filter is used to determine what packets are queued as results.
*
* @return the packet filter.
* @deprecated use {@link #getStanzaFilter()} instead.
*/
public PacketFilter getPacketFilter() {
return packetFilter;
@Deprecated
public StanzaFilter getPacketFilter() {
return getStanzaFilter();
}
/**
* Returns the stanza filter associated with this stanza collector. The stanza
* filter is used to determine what stanzas are queued as results.
*
* @return the stanza filter.
*/
public StanzaFilter getStanzaFilter() {
return packetFilter;
}
/**
* Polls to see if a packet is currently available and returns it, or
* immediately returns <tt>null</tt> if no packets are currently in the
@ -266,7 +278,7 @@ public class PacketCollector {
}
public static class Configuration {
private PacketFilter packetFilter;
private StanzaFilter packetFilter;
private int size = SmackConfiguration.getPacketCollectorSize();
private PacketCollector collectorToReset;
@ -279,9 +291,22 @@ public class PacketCollector {
*
* @param packetFilter
* @return a reference to this configuration.
* @deprecated use {@link #setStanzaFilter(StanzaFilter)} instead.
*/
public Configuration setPacketFilter(PacketFilter packetFilter) {
this.packetFilter = packetFilter;
@Deprecated
public Configuration setPacketFilter(StanzaFilter packetFilter) {
return setStanzaFilter(packetFilter);
}
/**
* Set the stanza filter used by this collector. If <code>null</code>, then all stanzas will
* get collected by this collector.
*
* @param stanzaFilter
* @return a reference to this configuration.
*/
public Configuration setStanzaFilter(StanzaFilter stanzaFilter) {
this.packetFilter = stanzaFilter;
return this;
}

View file

@ -30,10 +30,10 @@ import org.jivesoftware.smack.packet.Stanza;
* Additionally you are able to intercept Packets that are going to be send and
* make modifications to them. You can register a PacketListener as interceptor
* by using {@link XMPPConnection#addPacketInterceptor(PacketListener,
* org.jivesoftware.smack.filter.PacketFilter)}
* org.jivesoftware.smack.filter.StanzaFilter)}
* </p>
*
* @see XMPPConnection#addAsyncPacketListener(PacketListener, org.jivesoftware.smack.filter.PacketFilter)
* @see XMPPConnection#addAsyncPacketListener(PacketListener, org.jivesoftware.smack.filter.StanzaFilter)
* @author Matt Tucker
*/
public interface PacketListener {

View file

@ -19,7 +19,7 @@ package org.jivesoftware.smack;
import java.util.ArrayList;
import java.util.List;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.util.dns.HostAddress;
/**
@ -65,9 +65,9 @@ public class SmackException extends Exception {
*/
private static final long serialVersionUID = -6523363748984543636L;
private final PacketFilter filter;
private final StanzaFilter filter;
private NoResponseException(String message, PacketFilter filter) {
private NoResponseException(String message, StanzaFilter filter) {
super(message);
this.filter = filter;
}
@ -77,20 +77,20 @@ public class SmackException extends Exception {
*
* @return the used filter or <code>null</code>.
*/
public PacketFilter getFilter() {
public StanzaFilter getFilter() {
return filter;
}
public static NoResponseException newWith(XMPPConnection connection) {
return newWith(connection, (PacketFilter) null);
return newWith(connection, (StanzaFilter) null);
}
public static NoResponseException newWith(XMPPConnection connection,
PacketCollector collector) {
return newWith(connection, collector.getPacketFilter());
return newWith(connection, collector.getStanzaFilter());
}
public static NoResponseException newWith(XMPPConnection connection, PacketFilter filter) {
public static NoResponseException newWith(XMPPConnection connection, StanzaFilter filter) {
final long replyTimeout = connection.getPacketReplyTimeout();
final StringBuilder sb = new StringBuilder(256);
sb.append("No response received within reply timeout. Timeout was "

View file

@ -20,11 +20,11 @@ package org.jivesoftware.smack;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.filter.IQReplyFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.iqrequest.IQRequestHandler;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.PlainStreamElement;
/**
@ -211,7 +211,7 @@ public interface XMPPConnection {
* @param packet the packet to send right after the collector got created
* @return a new packet collector.
*/
public PacketCollector createPacketCollectorAndSend(PacketFilter packetFilter, Stanza packet)
public PacketCollector createPacketCollectorAndSend(StanzaFilter packetFilter, Stanza packet)
throws NotConnectedException;
/**
@ -222,7 +222,7 @@ public interface XMPPConnection {
* <p>
* <b>Note:</b> If you send a Packet right after using this method, then
* consider using
* {@link #createPacketCollectorAndSend(PacketFilter, Stanza)} instead.
* {@link #createPacketCollectorAndSend(StanzaFilter, Stanza)} instead.
* Otherwise make sure cancel the PacketCollector in every case, e.g. even
* if an exception is thrown, or otherwise you may leak the PacketCollector.
* </p>
@ -230,13 +230,13 @@ public interface XMPPConnection {
* @param packetFilter the packet filter to use.
* @return a new packet collector.
*/
public PacketCollector createPacketCollector(PacketFilter packetFilter);
public PacketCollector createPacketCollector(StanzaFilter packetFilter);
/**
* Create a new packet collector with the given packet collector configuration.
* <p>
* Please make sure to cancel the collector when it is no longer required. See also
* {@link #createPacketCollector(PacketFilter)}.
* {@link #createPacketCollector(StanzaFilter)}.
* </p>
*
* @param configuration the packet collector configuration.
@ -257,17 +257,17 @@ public interface XMPPConnection {
* <p>
* This method has been deprecated. It is important to differentiate between using an asynchronous packet listener
* (preferred where possible) and a synchronous packet lister. Refer
* {@link #addAsyncPacketListener(PacketListener, PacketFilter)} and
* {@link #addSyncPacketListener(PacketListener, PacketFilter)} for more information.
* {@link #addAsyncPacketListener(PacketListener, StanzaFilter)} and
* {@link #addSyncPacketListener(PacketListener, StanzaFilter)} for more information.
* </p>
*
* @param packetListener the packet listener to notify of new received packets.
* @param packetFilter the packet filter to use.
* @deprecated use {@link #addAsyncPacketListener(PacketListener, PacketFilter)} or
* {@link #addSyncPacketListener(PacketListener, PacketFilter)}.
* @deprecated use {@link #addAsyncPacketListener(PacketListener, StanzaFilter)} or
* {@link #addSyncPacketListener(PacketListener, StanzaFilter)}.
*/
@Deprecated
public void addPacketListener(PacketListener packetListener, PacketFilter packetFilter);
public void addPacketListener(PacketListener packetListener, StanzaFilter packetFilter);
/**
* Removes a packet listener for received packets from this connection.
@ -286,17 +286,17 @@ public interface XMPPConnection {
* <p>
* <b>Important:</b> This packet listeners will be called in the same <i>single</i> thread that processes all
* incoming stanzas. Only use this kind of packet filter if it does not perform any XMPP activity that waits for a
* response. Consider using {@link #addAsyncPacketListener(PacketListener, PacketFilter)} when possible, i.e. when
* response. Consider using {@link #addAsyncPacketListener(PacketListener, StanzaFilter)} when possible, i.e. when
* the invocation order doesn't have to be the same as the order of the arriving packets. If the order of the
* arriving packets, consider using a {@link PacketCollector} when possible.
* </p>
*
* @param packetListener the packet listener to notify of new received packets.
* @param packetFilter the packet filter to use.
* @see #addPacketInterceptor(PacketListener, PacketFilter)
* @see #addPacketInterceptor(PacketListener, StanzaFilter)
* @since 4.1
*/
public void addSyncPacketListener(PacketListener packetListener, PacketFilter packetFilter);
public void addSyncPacketListener(PacketListener packetListener, StanzaFilter packetFilter);
/**
* Removes a packet listener for received packets from this connection.
@ -312,17 +312,17 @@ public interface XMPPConnection {
* when an incoming packet is received. A packet filter determines which packets will be delivered to the listener.
* If the same packet listener is added again with a different filter, only the new filter will be used.
* <p>
* Unlike {@link #addAsyncPacketListener(PacketListener, PacketFilter)} packet listeners added with this method will be
* Unlike {@link #addAsyncPacketListener(PacketListener, StanzaFilter)} packet listeners added with this method will be
* invoked asynchronously in their own thread. Use this method if the order of the packet listeners must not depend
* on the order how the stanzas where received.
* </p>
*
* @param packetListener the packet listener to notify of new received packets.
* @param packetFilter the packet filter to use.
* @see #addPacketInterceptor(PacketListener, PacketFilter)
* @see #addPacketInterceptor(PacketListener, StanzaFilter)
* @since 4.1
*/
public void addAsyncPacketListener(PacketListener packetListener, PacketFilter packetFilter);
public void addAsyncPacketListener(PacketListener packetListener, StanzaFilter packetFilter);
/**
* Removes an <b>asynchronous</b> packet listener for received packets from this connection.
@ -344,7 +344,7 @@ public interface XMPPConnection {
* @param packetListener the packet listener to notify of sent packets.
* @param packetFilter the packet filter to use.
*/
public void addPacketSendingListener(PacketListener packetListener, PacketFilter packetFilter);
public void addPacketSendingListener(PacketListener packetListener, StanzaFilter packetFilter);
/**
* Removes a packet listener for sending packets from this connection.
@ -360,12 +360,12 @@ public interface XMPPConnection {
* will be delivered to the interceptor.
*
* <p>
* NOTE: For a similar functionality on incoming packets, see {@link #addAsyncPacketListener(PacketListener, PacketFilter)}.
* NOTE: For a similar functionality on incoming packets, see {@link #addAsyncPacketListener(PacketListener, StanzaFilter)}.
*
* @param packetInterceptor the packet interceptor to notify of packets about to be sent.
* @param packetFilter the packet filter to use.
*/
public void addPacketInterceptor(PacketListener packetInterceptor, PacketFilter packetFilter);
public void addPacketInterceptor(PacketListener packetInterceptor, StanzaFilter packetFilter);
/**
* Removes a packet interceptor.
@ -439,7 +439,7 @@ public interface XMPPConnection {
* @param namespace
* @return a packet extensions of the feature or <code>null</code>
*/
public <F extends PacketExtension> F getFeature(String element, String namespace);
public <F extends ExtensionElement> F getFeature(String element, String namespace);
/**
* Return true if the server supports the given stream feature.
@ -463,7 +463,7 @@ public interface XMPPConnection {
* @param callback the callback invoked if there is a response (required)
* @throws NotConnectedException
*/
public void sendStanzaWithResponseCallback(Stanza stanza, PacketFilter replyFilter,
public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter,
PacketListener callback) throws NotConnectedException;
/**
@ -480,7 +480,7 @@ public interface XMPPConnection {
* @param exceptionCallback the callback invoked if there is an exception (optional)
* @throws NotConnectedException
*/
public void sendStanzaWithResponseCallback(Stanza stanza, PacketFilter replyFilter, PacketListener callback,
public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter, PacketListener callback,
ExceptionCallback exceptionCallback) throws NotConnectedException;
/**
@ -498,7 +498,7 @@ public interface XMPPConnection {
* @param timeout the timeout in milliseconds to wait for a response
* @throws NotConnectedException
*/
public void sendStanzaWithResponseCallback(Stanza stanza, PacketFilter replyFilter,
public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter,
final PacketListener callback, final ExceptionCallback exceptionCallback,
long timeout) throws NotConnectedException;
@ -554,7 +554,7 @@ public interface XMPPConnection {
* @param callback the callback invoked once the packet filter matches a stanza.
* @param packetFilter the filter to match stanzas or null to match all.
*/
public void addOneTimeSyncCallback(PacketListener callback, PacketFilter packetFilter);
public void addOneTimeSyncCallback(PacketListener callback, StanzaFilter packetFilter);
/**
* Register an IQ request handler with this connection.

View file

@ -20,7 +20,7 @@ import java.util.Collections;
import java.util.List;
import org.jivesoftware.smack.packet.FullStreamElement;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.XmlStringBuilder;
public class Compress extends FullStreamElement {
@ -53,7 +53,7 @@ public class Compress extends FullStreamElement {
return xml;
}
public static class Feature implements PacketExtension {
public static class Feature implements ExtensionElement {
public static final String ELEMENT = "compression";
public final List<String> methods;

View file

@ -27,18 +27,18 @@ import org.jivesoftware.smack.util.Objects;
/**
*
*/
public abstract class AbstractListFilter implements PacketFilter {
public abstract class AbstractListFilter implements StanzaFilter {
/**
* The list of filters.
*/
protected final List<PacketFilter> filters;
protected final List<StanzaFilter> filters;
/**
* Creates an empty filter.
*/
protected AbstractListFilter() {
filters = new ArrayList<PacketFilter>();
filters = new ArrayList<StanzaFilter>();
}
/**
@ -46,12 +46,12 @@ public abstract class AbstractListFilter implements PacketFilter {
*
* @param filters the filters to add.
*/
protected AbstractListFilter(PacketFilter... filters) {
protected AbstractListFilter(StanzaFilter... filters) {
Objects.requireNonNull(filters, "Parameter must not be null.");
for(PacketFilter filter : filters) {
for(StanzaFilter filter : filters) {
Objects.requireNonNull(filter, "Parameter must not be null.");
}
this.filters = new ArrayList<PacketFilter>(Arrays.asList(filters));
this.filters = new ArrayList<StanzaFilter>(Arrays.asList(filters));
}
/**
@ -60,7 +60,7 @@ public abstract class AbstractListFilter implements PacketFilter {
*
* @param filter a filter to add to the filter list.
*/
public void addFilter(PacketFilter filter) {
public void addFilter(StanzaFilter filter) {
Objects.requireNonNull(filter, "Parameter must not be null.");
filters.add(filter);
}
@ -70,8 +70,8 @@ public abstract class AbstractListFilter implements PacketFilter {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(": (");
for (Iterator<PacketFilter> it = filters.iterator(); it.hasNext();) {
PacketFilter filter = it.next();
for (Iterator<StanzaFilter> it = filters.iterator(); it.hasNext();) {
StanzaFilter filter = it.next();
sb.append(filter.toString());
if (it.hasNext()) {
sb.append(", ");

View file

@ -25,11 +25,11 @@ import org.jivesoftware.smack.packet.Stanza;
*
* @author Matt Tucker
*/
public class AndFilter extends AbstractListFilter implements PacketFilter {
public class AndFilter extends AbstractListFilter implements StanzaFilter {
/**
* Creates an empty AND filter. Filters should be added using the
* {@link #addFilter(PacketFilter)} method.
* {@link #addFilter(StanzaFilter)} method.
*/
public AndFilter() {
super();
@ -40,12 +40,12 @@ public class AndFilter extends AbstractListFilter implements PacketFilter {
*
* @param filters the filters to add.
*/
public AndFilter(PacketFilter... filters) {
public AndFilter(StanzaFilter... filters) {
super(filters);
}
public boolean accept(Stanza packet) {
for (PacketFilter filter : filters) {
for (StanzaFilter filter : filters) {
if (!filter.accept(packet)) {
return false;
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2014 Florian Schmaus
* Copyright 2014-2015 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -23,39 +23,36 @@ import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.util.Objects;
/**
* Filters for packets of a particular type and allows a custom method to further filter the packets.
* Filters for stanzas of a particular type and allows a custom method to further filter the packets.
*
* @author Florian Schmaus
*/
public abstract class FlexiblePacketTypeFilter<P extends Stanza> implements PacketFilter {
public abstract class FlexibleStanzaTypeFilter<S extends Stanza> implements StanzaFilter {
protected final Class<P> packetType;
protected final Class<S> stanzaType;
public FlexiblePacketTypeFilter(Class<P> packetType) {
this.packetType = Objects.requireNonNull(packetType, "Type must not be null");
public FlexibleStanzaTypeFilter(Class<S> packetType) {
this.stanzaType = Objects.requireNonNull(packetType, "Type must not be null");
}
@SuppressWarnings("unchecked")
public FlexiblePacketTypeFilter() {
packetType = (Class<P>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
public FlexibleStanzaTypeFilter() {
stanzaType = (Class<S>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
}
@Override
@SuppressWarnings("unchecked")
public boolean accept(Stanza packet) {
if (packetType.isInstance(packet)) {
return acceptSpecific((P) packet);
public final boolean accept(Stanza packet) {
if (stanzaType.isInstance(packet)) {
return acceptSpecific((S) packet);
}
return false;
}
protected abstract boolean acceptSpecific(P packet);
protected abstract boolean acceptSpecific(S packet);
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" (" + packetType.toString() + ')');
return sb.toString();
return getClass().getSimpleName() + ": " + stanzaType.toString();
}
}

View file

@ -30,7 +30,7 @@ import org.jxmpp.util.XmppStringUtils;
*
* @author Gaston Dombiak
*/
public class FromMatchesFilter implements PacketFilter {
public class FromMatchesFilter implements StanzaFilter {
private final String address;

View file

@ -48,10 +48,10 @@ import org.jxmpp.util.XmppStringUtils;
* @author Lars Noschinski
*
*/
public class IQReplyFilter implements PacketFilter {
public class IQReplyFilter implements StanzaFilter {
private static final Logger LOGGER = Logger.getLogger(IQReplyFilter.class.getName());
private final PacketFilter iqAndIdFilter;
private final StanzaFilter iqAndIdFilter;
private final OrFilter fromFilter;
private final String to;
private final String local;
@ -98,8 +98,8 @@ public class IQReplyFilter implements PacketFilter {
server = conn.getServiceName().toLowerCase(Locale.US);
packetId = iqPacket.getStanzaId();
PacketFilter iqFilter = new OrFilter(IQTypeFilter.ERROR, IQTypeFilter.RESULT);
PacketFilter idFilter = new StanzaIdFilter(iqPacket);
StanzaFilter iqFilter = new OrFilter(IQTypeFilter.ERROR, IQTypeFilter.RESULT);
StanzaFilter idFilter = new StanzaIdFilter(iqPacket);
iqAndIdFilter = new AndFilter(iqFilter, idFilter);
fromFilter = new OrFilter();
fromFilter.addFilter(FromMatchesFilter.createFull(to));

View file

@ -27,13 +27,13 @@ import org.jivesoftware.smack.util.Objects;
* @author Alexander Wenckus
*
*/
public class IQTypeFilter extends FlexiblePacketTypeFilter<IQ> {
public class IQTypeFilter extends FlexibleStanzaTypeFilter<IQ> {
public static final PacketFilter GET = new IQTypeFilter(Type.get);
public static final PacketFilter SET = new IQTypeFilter(Type.set);
public static final PacketFilter RESULT = new IQTypeFilter(Type.result);
public static final PacketFilter ERROR = new IQTypeFilter(Type.error);
public static final PacketFilter GET_OR_SET = new OrFilter(GET, SET);
public static final StanzaFilter GET = new IQTypeFilter(Type.get);
public static final StanzaFilter SET = new IQTypeFilter(Type.set);
public static final StanzaFilter RESULT = new IQTypeFilter(Type.result);
public static final StanzaFilter ERROR = new IQTypeFilter(Type.error);
public static final StanzaFilter GET_OR_SET = new OrFilter(GET, SET);
private final IQ.Type type;

View file

@ -27,15 +27,15 @@ import org.jivesoftware.smack.packet.Message.Type;
* @see org.jivesoftware.smack.packet.Message.Type
* @author Ward Harold
*/
public class MessageTypeFilter extends FlexiblePacketTypeFilter<Message> {
public class MessageTypeFilter extends FlexibleStanzaTypeFilter<Message> {
public static final PacketFilter NORMAL = new MessageTypeFilter(Type.normal);
public static final PacketFilter CHAT = new MessageTypeFilter(Type.chat);
public static final PacketFilter GROUPCHAT = new MessageTypeFilter(Type.groupchat);
public static final PacketFilter HEADLINE = new MessageTypeFilter(Type.headline);
public static final PacketFilter ERROR = new MessageTypeFilter(Type.error);
public static final PacketFilter NORMAL_OR_CHAT = new OrFilter(NORMAL, CHAT);
public static final PacketFilter NORMAL_OR_CHAT_OR_HEADLINE = new OrFilter(NORMAL_OR_CHAT,
public static final StanzaFilter NORMAL = new MessageTypeFilter(Type.normal);
public static final StanzaFilter CHAT = new MessageTypeFilter(Type.chat);
public static final StanzaFilter GROUPCHAT = new MessageTypeFilter(Type.groupchat);
public static final StanzaFilter HEADLINE = new MessageTypeFilter(Type.headline);
public static final StanzaFilter ERROR = new MessageTypeFilter(Type.error);
public static final StanzaFilter NORMAL_OR_CHAT = new OrFilter(NORMAL, CHAT);
public static final StanzaFilter NORMAL_OR_CHAT_OR_HEADLINE = new OrFilter(NORMAL_OR_CHAT,
HEADLINE);
private final Message.Type type;

View file

@ -22,9 +22,9 @@ import org.jivesoftware.smack.packet.Message;
/**
* Filters message stanzas which have at least one body
*/
public class MessageWithBodiesFilter extends FlexiblePacketTypeFilter<Message> {
public class MessageWithBodiesFilter extends FlexibleStanzaTypeFilter<Message> {
public static final PacketFilter INSTANCE = new MessageWithBodiesFilter();
public static final StanzaFilter INSTANCE = new MessageWithBodiesFilter();
private MessageWithBodiesFilter() {
super(Message.class);

View file

@ -22,9 +22,9 @@ import org.jivesoftware.smack.packet.Message;
/**
* Filters message stanzas which have at least one body
*/
public class MessageWithSubjectFilter extends FlexiblePacketTypeFilter<Message> {
public class MessageWithSubjectFilter extends FlexibleStanzaTypeFilter<Message> {
public static final PacketFilter INSTANCE = new MessageWithSubjectFilter();
public static final StanzaFilter INSTANCE = new MessageWithSubjectFilter();
private MessageWithSubjectFilter() {
super(Message.class);

View file

@ -26,16 +26,16 @@ import org.jivesoftware.smack.util.Objects;
*
* @author Matt Tucker
*/
public class NotFilter implements PacketFilter {
public class NotFilter implements StanzaFilter {
private final PacketFilter filter;
private final StanzaFilter filter;
/**
* Creates a NOT filter using the specified filter.
*
* @param filter the filter.
*/
public NotFilter(PacketFilter filter) {
public NotFilter(StanzaFilter filter) {
this.filter = Objects.requireNonNull(filter, "Parameter must not be null.");
}

View file

@ -25,11 +25,11 @@ import org.jivesoftware.smack.packet.Stanza;
*
* @author Matt Tucker
*/
public class OrFilter extends AbstractListFilter implements PacketFilter {
public class OrFilter extends AbstractListFilter implements StanzaFilter {
/**
* Creates an empty OR filter. Filters should be added using the
* {@link #addFilter(PacketFilter)} method.
* {@link #addFilter(StanzaFilter)} method.
*/
public OrFilter() {
super();
@ -40,13 +40,13 @@ public class OrFilter extends AbstractListFilter implements PacketFilter {
*
* @param filters the filters to add.
*/
public OrFilter(PacketFilter... filters) {
public OrFilter(StanzaFilter... filters) {
super(filters);
}
@Override
public boolean accept(Stanza packet) {
for (PacketFilter filter : filters) {
for (StanzaFilter filter : filters) {
if (filter.accept(packet)) {
return true;
}

View file

@ -18,15 +18,17 @@
package org.jivesoftware.smack.filter;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.StringUtils;
/**
* Filters for packets with a particular type of packet extension.
*
* @author Matt Tucker
* @deprecated use {@link StanzaExtensionFilter} instead.
*/
public class PacketExtensionFilter implements PacketFilter {
@Deprecated
public class PacketExtensionFilter implements StanzaFilter {
private final String elementName;
private final String namespace;
@ -61,7 +63,7 @@ public class PacketExtensionFilter implements PacketFilter {
*
* @param packetExtension
*/
public PacketExtensionFilter(PacketExtension packetExtension) {
public PacketExtensionFilter(ExtensionElement packetExtension) {
this(packetExtension.getElementName(), packetExtension.getNamespace());
}

View file

@ -17,8 +17,6 @@
package org.jivesoftware.smack.filter;
import org.jivesoftware.smack.packet.Stanza;
/**
* Defines a way to filter packets for particular attributes. Packet filters are used when
* constructing packet listeners or collectors -- the filter defines what packets match the criteria
@ -45,14 +43,9 @@ import org.jivesoftware.smack.packet.Stanza;
* @see org.jivesoftware.smack.PacketCollector
* @see org.jivesoftware.smack.PacketListener
* @author Matt Tucker
* @deprecated use {@link StanzaFilter}
*/
public interface PacketFilter {
@Deprecated
public interface PacketFilter extends StanzaFilter {
/**
* Tests whether or not the specified packet should pass the filter.
*
* @param packet the packet to test.
* @return true if and only if <tt>packet</tt> passes the filter.
*/
public boolean accept(Stanza packet);
}

View file

@ -27,7 +27,7 @@ import org.jivesoftware.smack.util.StringUtils;
* @deprecated use {@link StanzaIdFilter} instead.
*/
@Deprecated
public class PacketIDFilter implements PacketFilter {
public class PacketIDFilter implements StanzaFilter {
private final String packetID;

View file

@ -31,8 +31,10 @@ import org.jivesoftware.smack.packet.Presence;
* </ul>
*
* @author Matt Tucker
* @deprecated use {@link StanzaTypeFilter} instead.
*/
public class PacketTypeFilter implements PacketFilter {
@Deprecated
public class PacketTypeFilter implements StanzaFilter {
public static final PacketTypeFilter PRESENCE = new PacketTypeFilter(Presence.class);
public static final PacketTypeFilter MESSAGE = new PacketTypeFilter(Message.class);

View file

@ -24,7 +24,7 @@ import org.jivesoftware.smack.util.Objects;
* A filter for Presence types. Returns true only if the stanza is an Presence packet and it matches the type provided in the
* constructor.
*/
public class PresenceTypeFilter extends FlexiblePacketTypeFilter<Presence> {
public class PresenceTypeFilter extends FlexibleStanzaTypeFilter<Presence> {
public static final PresenceTypeFilter AVAILABLE = new PresenceTypeFilter(Type.available);
public static final PresenceTypeFilter UNAVAILABLE = new PresenceTypeFilter(Type.unavailable);

View file

@ -0,0 +1,76 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smack.filter;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.StringUtils;
/**
* Filters for stanzas with a particular type of stanza extension.
*
* @author Matt Tucker
*/
public class StanzaExtensionFilter implements StanzaFilter {
private final String elementName;
private final String namespace;
/**
* Creates a new stanza extension filter. Stanzas will pass the filter if
* they have a stanza extension that matches the specified element name
* and namespace.
*
* @param elementName the XML element name of the stanza extension.
* @param namespace the XML namespace of the stanza extension.
*/
public StanzaExtensionFilter(String elementName, String namespace) {
StringUtils.requireNotNullOrEmpty(namespace, "namespace must not be null or empty");
this.elementName = elementName;
this.namespace = namespace;
}
/**
* Creates a new stanza extension filter. Stanzas will pass the filter if they have a stanza
* extension that matches the specified namespace.
*
* @param namespace the XML namespace of the stanza extension.
*/
public StanzaExtensionFilter(String namespace) {
this(null, namespace);
}
/**
* Creates a new stanza extension filter for the given stanza extension.
*
* @param packetExtension
*/
public StanzaExtensionFilter(ExtensionElement packetExtension) {
this(packetExtension.getElementName(), packetExtension.getNamespace());
}
public boolean accept(Stanza packet) {
return packet.hasExtension(elementName, namespace);
}
@Override
public String toString() {
return getClass().getSimpleName() + ": element=" + elementName + " namespace=" + namespace;
}
}

View file

@ -0,0 +1,58 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smack.filter;
import org.jivesoftware.smack.packet.Stanza;
/**
* Defines a way to filter stanzas for particular attributes. Stanza filters are used when
* constructing stanza listeners or collectors -- the filter defines what stanzas match the criteria
* of the collector or listener for further stanza processing.
* <p>
* Several simple filters are pre-defined. These filters can be logically combined for more complex
* stanza filtering by using the {@link org.jivesoftware.smack.filter.AndFilter AndFilter} and
* {@link org.jivesoftware.smack.filter.OrFilter OrFilter} filters. It's also possible to define
* your own filters by implementing this interface. The code example below creates a trivial filter
* for stanzas with a specific ID (real code should use {@link StanzaIdFilter} instead).
*
* <pre>
* // Use an anonymous inner class to define a stanza filter that returns
* // all stanzas that have a stanza ID of &quot;RS145&quot;.
* StanzaFilter myFilter = new StanzaFilter() {
* public boolean accept(Stanza stanza) {
* return &quot;RS145&quot;.equals(stanza.getStanzaId());
* }
* };
* // Create a new stanza collector using the filter we created.
* PacketCollector myCollector = connection.createPacketCollector(myFilter);
* </pre>
*
* @see org.jivesoftware.smack.PacketCollector
* @see org.jivesoftware.smack.PacketListener
* @author Matt Tucker
*/
public interface StanzaFilter {
/**
* Tests whether or not the specified stanza should pass the filter.
*
* @param stanza the packet to test.
* @return true if and only if <tt>stanza</tt> passes the filter.
*/
public boolean accept(Stanza stanza);
}

View file

@ -25,7 +25,7 @@ import org.jivesoftware.smack.util.StringUtils;
*
* @author Matt Tucker
*/
public class StanzaIdFilter implements PacketFilter {
public class StanzaIdFilter implements StanzaFilter {
private final String stanzaId;

View file

@ -0,0 +1,62 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smack.filter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.IQ;
/**
* Filters for Stanzas of a particular type. The type is given as a Class object, so
* example types would:
* <ul>
* <li><tt>Message.class</tt>
* <li><tt>IQ.class</tt>
* <li><tt>Presence.class</tt>
* </ul>
*
* @author Matt Tucker
*/
public final class StanzaTypeFilter implements StanzaFilter {
public static final StanzaTypeFilter PRESENCE = new StanzaTypeFilter(Presence.class);
public static final StanzaTypeFilter MESSAGE = new StanzaTypeFilter(Message.class);
public static final StanzaTypeFilter IQ = new StanzaTypeFilter(IQ.class);
private final Class<? extends Stanza> packetType;
/**
* Creates a new packet type filter that will filter for packets that are the
* same type as <tt>packetType</tt>.
*
* @param packetType the Class type.
*/
public StanzaTypeFilter(Class<? extends Stanza> packetType) {
this.packetType = packetType;
}
public boolean accept(Stanza packet) {
return packetType.isInstance(packet);
}
@Override
public String toString() {
return getClass().getSimpleName() + ": " + packetType.getName();
}
}

View file

@ -25,7 +25,7 @@ import org.jivesoftware.smack.util.StringUtils;
*
* @author Matt Tucker
*/
public class ThreadFilter extends FlexiblePacketTypeFilter<Message> implements PacketFilter {
public class ThreadFilter extends FlexibleStanzaTypeFilter<Message> implements StanzaFilter {
private final String thread;

View file

@ -20,7 +20,7 @@ import java.util.Locale;
import org.jivesoftware.smack.packet.Stanza;
public class ToFilter implements PacketFilter {
public class ToFilter implements StanzaFilter {
private final String to;

View file

@ -28,18 +28,18 @@ public class AbstractError {
private final String textNamespace;
protected final Map<String, String> descriptiveTexts;
private final List<PacketExtension> extensions;
private final List<ExtensionElement> extensions;
protected AbstractError(Map<String, String> descriptiveTexts) {
this(descriptiveTexts, null);
}
protected AbstractError(Map<String, String> descriptiveTexts, List<PacketExtension> extensions) {
protected AbstractError(Map<String, String> descriptiveTexts, List<ExtensionElement> extensions) {
this(descriptiveTexts, null, extensions);
}
protected AbstractError(Map<String, String> descriptiveTexts, String textNamespace, List<PacketExtension> extensions) {
protected AbstractError(Map<String, String> descriptiveTexts, String textNamespace, List<ExtensionElement> extensions) {
if (descriptiveTexts != null) {
this.descriptiveTexts = descriptiveTexts;
} else {
@ -91,7 +91,7 @@ public class AbstractError {
* @param namespace the XML element namespace of the packet extension.
* @return the extension, or <tt>null</tt> if it doesn't exist.
*/
public <PE extends PacketExtension> PE getExtension(String elementName, String namespace) {
public <PE extends ExtensionElement> PE getExtension(String elementName, String namespace) {
return PacketUtil.extensionElementFrom(extensions, elementName, namespace);
}
@ -104,7 +104,7 @@ public class AbstractError {
xml.escape(text);
xml.closeElement("text");
}
for (PacketExtension packetExtension : extensions) {
for (ExtensionElement packetExtension : extensions) {
xml.append(packetExtension.toXML());
}
}

View file

@ -68,7 +68,7 @@ public class Bind extends IQ {
return xml;
}
public static class Feature implements PacketExtension {
public static class Feature implements ExtensionElement {
public static final Feature INSTANCE = new Feature();

View file

@ -25,7 +25,7 @@ import java.util.Map;
import org.jivesoftware.smack.util.XmlStringBuilder;
/**
* Default implementation of the PacketExtension interface. Unless a PacketExtensionProvider
* Default implementation of the ExtensionElement interface. Unless a ExtensionElementProvider
* is registered with {@link org.jivesoftware.smack.provider.ProviderManager ProviderManager},
* instances of this class will be returned when getting packet extensions.<p>
*
@ -42,11 +42,11 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
* In this case, getValue("color") would return "blue", and getValue("food") would
* return "pizza". This parsing mechanism mechanism is very simplistic and will not work
* as desired in all cases (for example, if some of the elements have attributes. In those
* cases, a custom PacketExtensionProvider should be used.
* cases, a custom ExtensionElementProvider should be used.
*
* @author Matt Tucker
*/
public class DefaultPacketExtension implements PacketExtension {
public class DefaultExtensionElement implements ExtensionElement {
private String elementName;
private String namespace;
@ -58,7 +58,7 @@ public class DefaultPacketExtension implements PacketExtension {
* @param elementName the name of the element of the XML sub-document.
* @param namespace the namespace of the element.
*/
public DefaultPacketExtension(String elementName, String namespace) {
public DefaultExtensionElement(String elementName, String namespace) {
this.elementName = elementName;
this.namespace = namespace;
}

View file

@ -18,7 +18,7 @@
package org.jivesoftware.smack.packet;
/**
* Interface to represent a XML element. This is similar to {@link PacketExtension}, but does not
* Interface to represent a XML element. This is similar to {@link ExtensionElement}, but does not
* carry a namespace and is usually included as child element of an packet extension.
*/
public interface Element {

View file

@ -0,0 +1,46 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smack.packet;
/**
* Interface to represent extension elements.
* <p>
* An extension element is an XML subdocument
* with a root element name and namespace. Extension elements are used to provide
* extended functionality beyond what is in the base XMPP specification. Examples of
* extensions elements include message events, message properties, and extra presence data.
* IQ stanzas have limited support for extension elements.
* <p>
* This class is used primarily for extended content in XMPP Stanzas, to act as so called "extension elements". For more
* information see <a href="https://tools.ietf.org/html/rfc6120#section-8.4">RFC 6120 § 8.4 Extended Content</a>.
* </p>
*
* @see DefaultExtensionElement
* @see org.jivesoftware.smack.provider.ExtensionElementProvider
* @author Matt Tucker
*/
public interface ExtensionElement extends NamedElement {
/**
* Returns the root element XML namespace.
*
* @return the namespace.
*/
public String getNamespace();
}

View file

@ -23,6 +23,6 @@ package org.jivesoftware.smack.packet;
*
* @author Florian Schmaus
*/
public abstract class FullStreamElement implements PlainStreamElement, PacketExtension {
public abstract class FullStreamElement implements PlainStreamElement, ExtensionElement {
}

View file

@ -302,7 +302,7 @@ public abstract class IQ extends Stanza {
this(iq.getChildElementName(), iq.getChildElementNamespace());
}
public IQChildElementXmlStringBuilder(PacketExtension pe) {
public IQChildElementXmlStringBuilder(ExtensionElement pe) {
this(pe.getElementName(), pe.getNamespace());
}

View file

@ -23,7 +23,7 @@ import java.util.List;
import org.jivesoftware.smack.util.XmlStringBuilder;
public class Mechanisms implements PacketExtension {
public class Mechanisms implements ExtensionElement {
public static final String ELEMENT = "mechanisms";
public static final String NAMESPACE = "urn:ietf:params:xml:ns:xmpp-sasl";

View file

@ -18,7 +18,7 @@
package org.jivesoftware.smack.packet;
/**
* Interface to represent a XML element. This is similar to {@link PacketExtension}, but does not
* Interface to represent a XML element. This is similar to {@link ExtensionElement}, but does not
* carry a namespace and is usually included as child element of an packet extension.
*/
public interface NamedElement extends Element {

View file

@ -132,7 +132,7 @@ public interface Packet extends TopLevelStreamElement {
*
* @return the packet extensions.
*/
public List<PacketExtension> getExtensions();
public List<ExtensionElement> getExtensions();
/**
* Return a set of all extensions with the given element name <emph>and</emph> namespace.
@ -145,7 +145,7 @@ public interface Packet extends TopLevelStreamElement {
* @return a set of all matching extensions.
* @since 4.1
*/
public Set<PacketExtension> getExtensions(String elementName, String namespace);
public Set<ExtensionElement> getExtensions(String elementName, String namespace);
/**
* Returns the first extension of this packet that has the given namespace.
@ -156,7 +156,7 @@ public interface Packet extends TopLevelStreamElement {
* @param namespace the namespace of the extension that is desired.
* @return the packet extension with the given namespace.
*/
public PacketExtension getExtension(String namespace);
public ExtensionElement getExtension(String namespace);
/**
* Returns the first packet extension that matches the specified element name and
@ -173,20 +173,20 @@ public interface Packet extends TopLevelStreamElement {
* @param namespace the XML element namespace of the packet extension.
* @return the extension, or <tt>null</tt> if it doesn't exist.
*/
public <PE extends PacketExtension> PE getExtension(String elementName, String namespace);
public <PE extends ExtensionElement> PE getExtension(String elementName, String namespace);
/**
* Adds a packet extension to the packet. Does nothing if extension is null.
*
* @param extension a packet extension.
*/
public void addExtension(PacketExtension extension);
public void addExtension(ExtensionElement extension);
/**
* Adds a collection of packet extensions to the packet. Does nothing if extensions is null.
*
* @param extensions a collection of packet extensions
*/
public void addExtensions(Collection<PacketExtension> extensions);
public void addExtensions(Collection<ExtensionElement> extensions);
/**
* Check if a packet extension with the given element and namespace exists.
@ -215,7 +215,7 @@ public interface Packet extends TopLevelStreamElement {
* @param namespace
* @return the removed packet extension or null.
*/
public PacketExtension removeExtension(String elementName, String namespace);
public ExtensionElement removeExtension(String elementName, String namespace);
/**
* Removes a packet extension from the packet.
@ -223,7 +223,7 @@ public interface Packet extends TopLevelStreamElement {
* @param extension the packet extension to remove.
* @return the removed packet extension or null.
*/
public PacketExtension removeExtension(PacketExtension extension);
public ExtensionElement removeExtension(ExtensionElement extension);
@Override
// NOTE When Smack is using Java 8, then this method should be moved in Element as "Default Method".

View file

@ -18,27 +18,24 @@
package org.jivesoftware.smack.packet;
/**
* Interface to represent packet extensions. A packet extension is an XML subdocument
* with a root element name and namespace. Packet extensions are used to provide
* Interface to represent extension elements.
* <p>
* An extension element is an XML subdocument
* with a root element name and namespace. Extension elements are used to provide
* extended functionality beyond what is in the base XMPP specification. Examples of
* packet extensions include message events, message properties, and extra presence data.
* IQ packets cannot contain packet extensions.
* extensions elements include message events, message properties, and extra presence data.
* IQ stanzas have limited support for extension elements.
* <p>
* This class is used primarily for extended content in XMPP Stanzas, to act as so called "extension elements". For more
* information see <a href="https://tools.ietf.org/html/rfc6120#section-8.4">RFC 6120 § 8.4 Extended Content</a>.
* </p>
*
* @see DefaultPacketExtension
* @see org.jivesoftware.smack.provider.PacketExtensionProvider
* @see DefaultExtensionElement
* @see org.jivesoftware.smack.provider.ExtensionElementProvider
* @author Matt Tucker
* @deprecated use {@link ExtensionElement} instead.
*/
public interface PacketExtension extends NamedElement {
/**
* Returns the root element XML namespace.
*
* @return the namespace.
*/
public String getNamespace();
@Deprecated
public interface PacketExtension extends ExtensionElement {
}

View file

@ -42,7 +42,7 @@ public class Session extends SimpleIQ {
setType(IQ.Type.set);
}
public static class Feature implements PacketExtension {
public static class Feature implements ExtensionElement {
public static final String OPTIONAL_ELEMENT = "optional";

View file

@ -54,7 +54,7 @@ public abstract class Stanza implements TopLevelStreamElement, Packet {
protected static final String DEFAULT_LANGUAGE =
java.util.Locale.getDefault().getLanguage().toLowerCase(Locale.US);
private final MultiMap<String, PacketExtension> packetExtensions = new MultiMap<>();
private final MultiMap<String, ExtensionElement> packetExtensions = new MultiMap<>();
private String id = null;
private String to = null;
@ -88,7 +88,7 @@ public abstract class Stanza implements TopLevelStreamElement, Packet {
error = p.error;
// Copy extensions
for (PacketExtension pe : p.getExtensions()) {
for (ExtensionElement pe : p.getExtensions()) {
addExtension(pe);
}
}
@ -234,7 +234,7 @@ public abstract class Stanza implements TopLevelStreamElement, Packet {
*
* @return a list of all extension elements of this stanza.
*/
public List<PacketExtension> getExtensions() {
public List<ExtensionElement> getExtensions() {
synchronized (packetExtensions) {
// No need to create a new list, values() will already create a new one for us
return packetExtensions.values();
@ -252,7 +252,7 @@ public abstract class Stanza implements TopLevelStreamElement, Packet {
* @return a set of all matching extensions.
* @since 4.1
*/
public Set<PacketExtension> getExtensions(String elementName, String namespace) {
public Set<ExtensionElement> getExtensions(String elementName, String namespace) {
requireNotNullOrEmpty(elementName, "elementName must not be null or empty");
requireNotNullOrEmpty(namespace, "namespace must not be null or empty");
String key = XmppStringUtils.generateKey(elementName, namespace);
@ -268,32 +268,32 @@ public abstract class Stanza implements TopLevelStreamElement, Packet {
* @param namespace the namespace of the extension that is desired.
* @return the packet extension with the given namespace.
*/
public PacketExtension getExtension(String namespace) {
public ExtensionElement getExtension(String namespace) {
return PacketUtil.extensionElementFrom(getExtensions(), null, namespace);
}
/**
* Returns the first packet extension that matches the specified element name and
* Returns the first extension that matches the specified element name and
* namespace, or <tt>null</tt> if it doesn't exist. If the provided elementName is null,
* only the namespace is matched. Packet extensions are
* only the namespace is matched. Extensions are
* are arbitrary XML sub-documents in standard XMPP packets. By default, a
* DefaultPacketExtension instance will be returned for each extension. However,
* PacketExtensionProvider instances can be registered with the
* {@link DefaultExtensionElement} instance will be returned for each extension. However,
* ExtensionElementProvider instances can be registered with the
* {@link org.jivesoftware.smack.provider.ProviderManager ProviderManager}
* class to handle custom parsing. In that case, the type of the Object
* will be determined by the provider.
*
* @param elementName the XML element name of the packet extension. (May be null)
* @param namespace the XML element namespace of the packet extension.
* @param elementName the XML element name of the extension. (May be null)
* @param namespace the XML element namespace of the extension.
* @return the extension, or <tt>null</tt> if it doesn't exist.
*/
@SuppressWarnings("unchecked")
public <PE extends PacketExtension> PE getExtension(String elementName, String namespace) {
public <PE extends ExtensionElement> PE getExtension(String elementName, String namespace) {
if (namespace == null) {
return null;
}
String key = XmppStringUtils.generateKey(elementName, namespace);
PacketExtension packetExtension;
ExtensionElement packetExtension;
synchronized (packetExtensions) {
packetExtension = packetExtensions.getFirst(key);
}
@ -308,7 +308,7 @@ public abstract class Stanza implements TopLevelStreamElement, Packet {
*
* @param extension a packet extension.
*/
public void addExtension(PacketExtension extension) {
public void addExtension(ExtensionElement extension) {
if (extension == null) return;
String key = XmppStringUtils.generateKey(extension.getElementName(), extension.getNamespace());
synchronized (packetExtensions) {
@ -321,9 +321,9 @@ public abstract class Stanza implements TopLevelStreamElement, Packet {
*
* @param extensions a collection of packet extensions
*/
public void addExtensions(Collection<PacketExtension> extensions) {
public void addExtensions(Collection<ExtensionElement> extensions) {
if (extensions == null) return;
for (PacketExtension packetExtension : extensions) {
for (ExtensionElement packetExtension : extensions) {
addExtension(packetExtension);
}
}
@ -356,7 +356,7 @@ public abstract class Stanza implements TopLevelStreamElement, Packet {
*/
public boolean hasExtension(String namespace) {
synchronized (packetExtensions) {
for (PacketExtension packetExtension : packetExtensions.values()) {
for (ExtensionElement packetExtension : packetExtensions.values()) {
if (packetExtension.getNamespace().equals(namespace)) {
return true;
}
@ -372,7 +372,7 @@ public abstract class Stanza implements TopLevelStreamElement, Packet {
* @param namespace
* @return the removed packet extension or null.
*/
public PacketExtension removeExtension(String elementName, String namespace) {
public ExtensionElement removeExtension(String elementName, String namespace) {
String key = XmppStringUtils.generateKey(elementName, namespace);
synchronized (packetExtensions) {
return packetExtensions.remove(key);
@ -385,7 +385,7 @@ public abstract class Stanza implements TopLevelStreamElement, Packet {
* @param extension the packet extension to remove.
* @return the removed packet extension or null.
*/
public PacketExtension removeExtension(PacketExtension extension) {
public ExtensionElement removeExtension(ExtensionElement extension) {
return removeExtension(extension.getElementName(), extension.getNamespace());
}
@ -405,7 +405,7 @@ public abstract class Stanza implements TopLevelStreamElement, Packet {
protected final XmlStringBuilder getExtensionsXML() {
XmlStringBuilder xml = new XmlStringBuilder();
// Add in all standard extension sub-packets.
for (PacketExtension extension : getExtensions()) {
for (ExtensionElement extension : getExtensions()) {
xml.append(extension.toXML());
}
return xml;

View file

@ -104,7 +104,7 @@ public class StreamError extends AbstractError implements PlainStreamElement {
private final Condition condition;
private final String conditionText;
public StreamError(Condition condition, String conditionText, Map<String, String> descriptiveTexts, List<PacketExtension> extensions) {
public StreamError(Condition condition, String conditionText, Map<String, String> descriptiveTexts, List<ExtensionElement> extensions) {
super(descriptiveTexts, extensions);
// Some implementations may send the condition as non-empty element containing the empty string, that is
// <condition xmlns='foo'></condition>, in this case the parser may calls this constructor with the empty string

View file

@ -99,7 +99,7 @@ public class XMPPError extends AbstractError {
this(condition, null, null, null, null, null);
}
public XMPPError(Condition condition, PacketExtension applicationSpecificCondition) {
public XMPPError(Condition condition, ExtensionElement applicationSpecificCondition) {
this(condition, null, null, null, null, Arrays.asList(applicationSpecificCondition));
}
@ -115,7 +115,7 @@ public class XMPPError extends AbstractError {
* @param extensions list of packet extensions
*/
public XMPPError(Condition condition, String conditionText, String errorGenerator, Type type, Map<String, String> descriptiveTexts,
List<PacketExtension> extensions) {
List<ExtensionElement> extensions) {
super(descriptiveTexts, NAMESPACE, extensions);
this.condition = condition;
// Some implementations may send the condition as non-empty element containing the empty string, that is

View file

@ -23,7 +23,7 @@ import java.util.List;
import java.util.Map;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@ -61,7 +61,7 @@ import org.xmlpull.v1.XmlPullParserException;
* <tt>ItemsProvider</tt> extends {@link EmbeddedExtensionProvider}
* <tt>ItemProvider</tt> extends {@link EmbeddedExtensionProvider}
* and
* AtomProvider extends {@link PacketExtensionProvider}
* AtomProvider extends {@link ExtensionElementProvider}
*
* These classes are then registered in the meta-inf/smack.providers file
* as follows.
@ -81,7 +81,7 @@ import org.xmlpull.v1.XmlPullParserException;
*
* @author Robin Collier
*/
public abstract class EmbeddedExtensionProvider<PE extends PacketExtension> extends PacketExtensionProvider<PE> {
public abstract class EmbeddedExtensionProvider<PE extends ExtensionElement> extends ExtensionElementProvider<PE> {
@Override
public final PE parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException,
@ -95,13 +95,13 @@ public abstract class EmbeddedExtensionProvider<PE extends PacketExtension> exte
attMap.put(parser.getAttributeName(i), parser.getAttributeValue(i));
}
List<PacketExtension> extensions = new ArrayList<>();
List<ExtensionElement> extensions = new ArrayList<>();
int event;
do {
event = parser.next();
if (event == XmlPullParser.START_TAG)
PacketParserUtils.addPacketExtension(extensions, parser);
PacketParserUtils.addExtensionElement(extensions, parser);
}
while (!(event == XmlPullParser.END_TAG && parser.getDepth() == initialDepth));
@ -109,5 +109,5 @@ public abstract class EmbeddedExtensionProvider<PE extends PacketExtension> exte
}
protected abstract PE createReturnExtension(String currentElement, String currentNamespace,
Map<String, String> attributeMap, List<? extends PacketExtension> content);
Map<String, String> attributeMap, List<? extends ExtensionElement> content);
}

View file

@ -18,15 +18,15 @@
package org.jivesoftware.smack.provider;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.ExtensionElement;
/**
* An abstract class for parsing custom packets extensions. Each PacketExtensionProvider must
* An abstract class for parsing custom extensions elements. Each ExtensionElementProvider must
* be registered with the ProviderManager class for it to be used. Every implementation
* of this abstract class <b>must</b> have a public, no-argument constructor.
*
* @author Matt Tucker
*/
public abstract class PacketExtensionProvider<PE extends PacketExtension> extends Provider<PE> {
public abstract class ExtensionElementProvider<EE extends ExtensionElement> extends Provider<EE> {
}

View file

@ -16,7 +16,7 @@
*/
package org.jivesoftware.smack.provider;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.ExtensionElement;
/**
* Defines the information required to register a packet extension Provider with the {@link ProviderManager} when using the
@ -28,13 +28,13 @@ import org.jivesoftware.smack.packet.PacketExtension;
public final class ExtensionProviderInfo extends AbstractProviderInfo {
/**
* Defines an extension provider which implements the <code>PacketExtensionProvider</code> interface.
* Defines an extension provider which implements the <code>ExtensionElementProvider</code> interface.
*
* @param elementName Element that provider parses.
* @param namespace Namespace that provider parses.
* @param extProvider The provider implementation.
*/
public ExtensionProviderInfo(String elementName, String namespace, PacketExtensionProvider<PacketExtension> extProvider) {
public ExtensionProviderInfo(String elementName, String namespace, ExtensionElementProvider<ExtensionElement> extProvider) {
super(elementName, namespace, extProvider);
}

View file

@ -21,7 +21,7 @@ import java.lang.reflect.InvocationTargetException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.ParserUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@ -51,7 +51,7 @@ public class IntrospectionProvider{
}
}
public static abstract class PacketExtensionIntrospectionProvider<PE extends PacketExtension> extends PacketExtensionProvider<PE> {
public static abstract class PacketExtensionIntrospectionProvider<PE extends ExtensionElement> extends ExtensionElementProvider<PE> {
private final Class<PE> elementClass;
protected PacketExtensionIntrospectionProvider(Class<PE> elementClass) {

View file

@ -25,12 +25,12 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParser;
/**
* Loads the {@link IQProvider} and {@link PacketExtensionProvider} 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
@ -95,8 +95,8 @@ public class ProviderFileLoader implements ProviderLoader {
// a PacketExtension, add the class object itself and
// then we'll use reflection later to create instances
// of the class.
if (PacketExtensionProvider.class.isAssignableFrom(provider)) {
extProviders.add(new ExtensionProviderInfo(elementName, namespace, (PacketExtensionProvider<PacketExtension>) provider.newInstance()));
if (ExtensionElementProvider.class.isAssignableFrom(provider)) {
extProviders.add(new ExtensionProviderInfo(elementName, namespace, (ExtensionElementProvider<ExtensionElement>) provider.newInstance()));
}
else {
exceptions.add(new IllegalArgumentException(className
@ -106,7 +106,7 @@ public class ProviderFileLoader implements ProviderLoader {
case "streamFeatureProvider":
sfProviders.add(new StreamFeatureProviderInfo(elementName,
namespace,
(PacketExtensionProvider<PacketExtension>) provider.newInstance()));
(ExtensionElementProvider<ExtensionElement>) provider.newInstance()));
break;
default:
LOGGER.warning("Unknown provider type: " + typeName);

View file

@ -24,7 +24,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.StringUtils;
import org.jxmpp.util.XmppStringUtils;
@ -109,9 +109,9 @@ import org.jxmpp.util.XmppStringUtils;
*/
public final class ProviderManager {
private static final Map<String, PacketExtensionProvider<PacketExtension>> extensionProviders = new ConcurrentHashMap<String, PacketExtensionProvider<PacketExtension>>();
private static final Map<String, ExtensionElementProvider<ExtensionElement>> extensionProviders = new ConcurrentHashMap<String, ExtensionElementProvider<ExtensionElement>>();
private static final Map<String, IQProvider<IQ>> iqProviders = new ConcurrentHashMap<String, IQProvider<IQ>>();
private static final Map<String, PacketExtensionProvider<PacketExtension>> streamFeatureProviders = new ConcurrentHashMap<String, PacketExtensionProvider<PacketExtension>>();
private static final Map<String, ExtensionElementProvider<ExtensionElement>> streamFeatureProviders = new ConcurrentHashMap<String, ExtensionElementProvider<ExtensionElement>>();
static {
// Ensure that Smack is initialized by calling getVersion, so that user
@ -138,7 +138,7 @@ public final class ProviderManager {
if (loader.getStreamFeatureProviderInfo() != null) {
for (StreamFeatureProviderInfo info : loader.getStreamFeatureProviderInfo()) {
addStreamFeatureProvider(info.getElementName(), info.getNamespace(),
(PacketExtensionProvider<PacketExtension>) info.getProvider());
(ExtensionElementProvider<ExtensionElement>) info.getProvider());
}
}
}
@ -238,7 +238,7 @@ public final class ProviderManager {
* @param namespace namespace associated with extension provider.
* @return the extenion provider.
*/
public static PacketExtensionProvider<PacketExtension> getExtensionProvider(String elementName, String namespace) {
public static ExtensionElementProvider<ExtensionElement> getExtensionProvider(String elementName, String namespace) {
String key = getKey(elementName, namespace);
return extensionProviders.get(key);
}
@ -259,8 +259,8 @@ public final class ProviderManager {
validate(elementName, namespace);
// First remove existing providers
String key = removeExtensionProvider(elementName, namespace);
if (provider instanceof PacketExtensionProvider) {
extensionProviders.put(key, (PacketExtensionProvider<PacketExtension>) provider);
if (provider instanceof ExtensionElementProvider) {
extensionProviders.put(key, (ExtensionElementProvider<ExtensionElement>) provider);
} else {
throw new IllegalArgumentException("Provider must be a PacketExtensionProvider");
}
@ -288,18 +288,18 @@ public final class ProviderManager {
*
* @return all PacketExtensionProvider instances.
*/
public static List<PacketExtensionProvider<PacketExtension>> getExtensionProviders() {
List<PacketExtensionProvider<PacketExtension>> providers = new ArrayList<>(extensionProviders.size());
public static List<ExtensionElementProvider<ExtensionElement>> getExtensionProviders() {
List<ExtensionElementProvider<ExtensionElement>> providers = new ArrayList<>(extensionProviders.size());
providers.addAll(extensionProviders.values());
return providers;
}
public static PacketExtensionProvider<PacketExtension> getStreamFeatureProvider(String elementName, String namespace) {
public static ExtensionElementProvider<ExtensionElement> getStreamFeatureProvider(String elementName, String namespace) {
String key = getKey(elementName, namespace);
return streamFeatureProviders.get(key);
}
public static void addStreamFeatureProvider(String elementName, String namespace, PacketExtensionProvider<PacketExtension> provider) {
public static void addStreamFeatureProvider(String elementName, String namespace, ExtensionElementProvider<ExtensionElement> provider) {
validate(elementName, namespace);
String key = getKey(elementName, namespace);
streamFeatureProviders.put(key, provider);

View file

@ -16,7 +16,7 @@
*/
package org.jivesoftware.smack.provider;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.ExtensionElement;
/**
*
@ -31,7 +31,7 @@ public final class StreamFeatureProviderInfo extends AbstractProviderInfo {
* @param extProvider The provider implementation.
*/
public StreamFeatureProviderInfo(String elementName, String namespace,
PacketExtensionProvider<PacketExtension> extProvider) {
ExtensionElementProvider<ExtensionElement> extProvider) {
super(elementName, namespace, extProvider);
}

View file

@ -30,13 +30,13 @@ import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.compress.packet.Compress;
import org.jivesoftware.smack.packet.DefaultPacketExtension;
import org.jivesoftware.smack.packet.DefaultExtensionElement;
import org.jivesoftware.smack.packet.EmptyResultIQ;
import org.jivesoftware.smack.packet.ErrorIQ;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Session;
import org.jivesoftware.smack.packet.StartTls;
@ -44,7 +44,7 @@ import org.jivesoftware.smack.packet.StreamError;
import org.jivesoftware.smack.packet.UnparsedIQ;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.sasl.packet.SaslStreamElements.SASLFailure;
import org.xmlpull.v1.XmlPullParser;
@ -284,7 +284,7 @@ public class PacketParserUtils {
message.setError(parseError(parser));
break;
default:
PacketParserUtils.addPacketExtension(message, parser, elementName, namespace);
PacketParserUtils.addExtensionElement(message, parser, elementName, namespace);
break;
}
break;
@ -574,7 +574,7 @@ public class PacketParserUtils {
// Be extra robust: Skip PacketExtensions that cause Exceptions, instead of
// failing completely here. See SMACK-390 for more information.
try {
PacketParserUtils.addPacketExtension(presence, parser, elementName, namespace);
PacketParserUtils.addExtensionElement(presence, parser, elementName, namespace);
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Failed to parse extension packet in Presence packet.", e);
}
@ -797,7 +797,7 @@ public class PacketParserUtils {
public static StreamError parseStreamError(XmlPullParser parser) throws IOException, XmlPullParserException,
SmackException {
final int initialDepth = parser.getDepth();
List<PacketExtension> extensions = new ArrayList<PacketExtension>();
List<ExtensionElement> extensions = new ArrayList<ExtensionElement>();
Map<String, String> descriptiveTexts = null;
StreamError.Condition condition = null;
String conditionText = null;
@ -824,7 +824,7 @@ public class PacketParserUtils {
}
break;
default:
PacketParserUtils.addPacketExtension(extensions, parser, name, namespace);
PacketParserUtils.addExtensionElement(extensions, parser, name, namespace);
break;
}
break;
@ -853,7 +853,7 @@ public class PacketParserUtils {
Map<String, String> descriptiveTexts = null;
XMPPError.Condition condition = null;
String conditionText = null;
List<PacketExtension> extensions = new ArrayList<PacketExtension>();
List<ExtensionElement> extensions = new ArrayList<ExtensionElement>();
// Parse the error header
XMPPError.Type errorType = XMPPError.Type.fromString(parser.getAttributeValue("", "type"));
@ -880,7 +880,7 @@ public class PacketParserUtils {
}
break;
default:
PacketParserUtils.addPacketExtension(extensions, parser, name, namespace);
PacketParserUtils.addExtensionElement(extensions, parser, name, namespace);
}
break;
case XmlPullParser.END_TAG:
@ -893,26 +893,36 @@ public class PacketParserUtils {
}
/**
* Parses a packet extension sub-packet.
* @deprecated use {@link #parseExtensionElement(String, String, XmlPullParser)} instead.
*/
@Deprecated
public static ExtensionElement parsePacketExtension(String elementName, String namespace,
XmlPullParser parser) throws XmlPullParserException,
IOException, SmackException {
return parseExtensionElement(elementName, namespace, parser);
}
/**
* Parses an extension element.
*
* @param elementName the XML element name of the packet extension.
* @param elementName the XML element name of the extension element.
* @param namespace the XML namespace of the packet extension.
* @param parser the XML parser, positioned at the starting element of the extension.
* @return a PacketExtension.
* @return an extension element.
*/
public static PacketExtension parsePacketExtension(String elementName, String namespace,
public static ExtensionElement parseExtensionElement(String elementName, String namespace,
XmlPullParser parser) throws XmlPullParserException,
IOException, SmackException {
ParserUtils.assertAtStartTag(parser);
// See if a provider is registered to handle the extension.
PacketExtensionProvider<PacketExtension> provider = ProviderManager.getExtensionProvider(elementName, namespace);
ExtensionElementProvider<ExtensionElement> provider = ProviderManager.getExtensionProvider(elementName, namespace);
if (provider != null) {
return provider.parse(parser);
}
final int initialDepth = parser.getDepth();
// No providers registered, so use a default extension.
DefaultPacketExtension extension = new DefaultPacketExtension(elementName, namespace);
DefaultExtensionElement extension = new DefaultExtensionElement(elementName, namespace);
outerloop: while (true) {
int eventType = parser.next();
switch (eventType) {
@ -1005,27 +1015,53 @@ public class PacketParserUtils {
return null;
}
@Deprecated
public static void addPacketExtension(Stanza packet, XmlPullParser parser) throws XmlPullParserException,
IOException, SmackException {
ParserUtils.assertAtStartTag(parser);
addPacketExtension(packet, parser, parser.getName(), parser.getNamespace());
addExtensionElement(packet, parser);
}
@Deprecated
public static void addPacketExtension(Stanza packet, XmlPullParser parser, String elementName, String namespace)
throws XmlPullParserException, IOException, SmackException {
PacketExtension packetExtension = parsePacketExtension(elementName, namespace, parser);
addExtensionElement(packet, parser, elementName, namespace);
}
@Deprecated
public static void addPacketExtension(Collection<ExtensionElement> collection, XmlPullParser parser)
throws XmlPullParserException, IOException, SmackException {
addExtensionElement(collection, parser, parser.getName(), parser.getNamespace());
}
@Deprecated
public static void addPacketExtension(Collection<ExtensionElement> collection, XmlPullParser parser,
String elementName, String namespace) throws XmlPullParserException, IOException, SmackException {
addExtensionElement(collection, parser, elementName, namespace);
}
public static void addExtensionElement(Stanza packet, XmlPullParser parser)
throws XmlPullParserException, IOException, SmackException {
ParserUtils.assertAtStartTag(parser);
addExtensionElement(packet, parser, parser.getName(), parser.getNamespace());
}
public static void addExtensionElement(Stanza packet, XmlPullParser parser, String elementName,
String namespace) throws XmlPullParserException, IOException, SmackException {
ExtensionElement packetExtension = parseExtensionElement(elementName, namespace, parser);
packet.addExtension(packetExtension);
}
public static void addPacketExtension(Collection<PacketExtension> collection, XmlPullParser parser)
throws XmlPullParserException, IOException, SmackException {
addPacketExtension(collection, parser, parser.getName(), parser.getNamespace());
public static void addExtensionElement(Collection<ExtensionElement> collection,
XmlPullParser parser) throws XmlPullParserException, IOException,
SmackException {
addExtensionElement(collection, parser, parser.getName(), parser.getNamespace());
}
public static void addPacketExtension(Collection<PacketExtension> collection, XmlPullParser parser,
String elementName, String namespace) throws XmlPullParserException, IOException, SmackException {
PacketExtension packetExtension = parsePacketExtension(elementName, namespace, parser);
public static void addExtensionElement(Collection<ExtensionElement> collection,
XmlPullParser parser, String elementName, String namespace)
throws XmlPullParserException, IOException, SmackException {
ExtensionElement packetExtension = parseExtensionElement(elementName, namespace, parser);
collection.add(packetExtension);
}
}

View file

@ -18,7 +18,7 @@ package org.jivesoftware.smack.util;
import java.util.Collection;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.ExtensionElement;
public class PacketUtil {
@ -32,8 +32,8 @@ public class PacketUtil {
* @deprecated use {@link #extensionElementFrom(Collection, String, String)} instead
*/
@Deprecated
public static <PE extends PacketExtension> PE packetExtensionfromCollection(
Collection<PacketExtension> collection, String element,
public static <PE extends ExtensionElement> PE packetExtensionfromCollection(
Collection<ExtensionElement> collection, String element,
String namespace) {
return extensionElementFrom(collection, element, namespace);
}
@ -47,9 +47,9 @@ public class PacketUtil {
* @return the extension element
*/
@SuppressWarnings("unchecked")
public static <PE extends PacketExtension> PE extensionElementFrom(Collection<PacketExtension> collection,
public static <PE extends ExtensionElement> PE extensionElementFrom(Collection<ExtensionElement> collection,
String element, String namespace) {
for (PacketExtension packetExtension : collection) {
for (ExtensionElement packetExtension : collection) {
if ((element == null || packetExtension.getElementName().equals(
element))
&& packetExtension.getNamespace().equals(namespace)) {

View file

@ -20,7 +20,7 @@ import java.util.Collection;
import org.jivesoftware.smack.packet.Element;
import org.jivesoftware.smack.packet.NamedElement;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.ExtensionElement;
public class XmlStringBuilder implements Appendable, CharSequence {
public static final String RIGHT_ANGLE_BRACKET = Character.toString('>');
@ -31,7 +31,7 @@ public class XmlStringBuilder implements Appendable, CharSequence {
sb = new LazyStringBuilder();
}
public XmlStringBuilder(PacketExtension pe) {
public XmlStringBuilder(ExtensionElement pe) {
this();
prelude(pe);
}
@ -244,7 +244,7 @@ public class XmlStringBuilder implements Appendable, CharSequence {
return this;
}
public XmlStringBuilder prelude(PacketExtension pe) {
public XmlStringBuilder prelude(ExtensionElement pe) {
return prelude(pe.getElementName(), pe.getNamespace());
}

View file

@ -19,7 +19,7 @@ package org.jivesoftware.smack;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.packet.Stanza;
import org.junit.Test;
@ -175,7 +175,7 @@ public class PacketCollectorTest
assertNull(collector.pollResult());
}
class OKEverything implements PacketFilter
class OKEverything implements StanzaFilter
{
@Override
public boolean accept(Stanza packet)
@ -187,9 +187,9 @@ public class PacketCollectorTest
class TestPacketCollector extends PacketCollector
{
protected TestPacketCollector(XMPPConnection conection, PacketFilter packetFilter, int size)
protected TestPacketCollector(XMPPConnection conection, StanzaFilter packetFilter, int size)
{
super(conection, PacketCollector.newConfiguration().setPacketFilter(packetFilter).setSize(size));
super(conection, PacketCollector.newConfiguration().setStanzaFilter(packetFilter).setSize(size));
}
}

View file

@ -99,7 +99,7 @@ public class StreamErrorTest {
assertNotNull(error);
assertEquals(Condition.conflict, error.getCondition());
assertEquals("Replaced by new connection", error.getDescriptiveText());
PacketExtension appSpecificElement = error.getExtension("appSpecificElement", "myns");
ExtensionElement appSpecificElement = error.getExtension("appSpecificElement", "myns");
assertNotNull(appSpecificElement);
}

View file

@ -20,8 +20,8 @@ import static org.junit.Assert.assertThat;
import static org.jivesoftware.smack.test.util.CharsequenceEquals.equalsCharSequence;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smack.util.PacketParserUtils;
@ -72,12 +72,12 @@ public class ParsingExceptionTest {
assertThat(MESSAGE_EXCEPTION_ELEMENT + EXTENSION2 + "</message>", equalsCharSequence(content));
}
static class ThrowException extends PacketExtensionProvider<PacketExtension> {
static class ThrowException extends ExtensionElementProvider<ExtensionElement> {
public static final String ELEMENT = "exception";
public static final String NAMESPACE = "http://smack.jivesoftware.org/exception";
@Override
public PacketExtension parse(XmlPullParser parser, int initialDepth) throws SmackException {
public ExtensionElement parse(XmlPullParser parser, int initialDepth) throws SmackException {
throw new SmackException("Test Exception");
}