1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-29 15:32:06 +01:00

Add PacketExtensionFilter(PacketExtension) constructor

and PacketExtensionFilter(Class<? extends PacketExtension).
This commit is contained in:
Florian Schmaus 2014-06-10 18:52:46 +02:00
parent b083449cc3
commit 1b2231be0b

View file

@ -18,6 +18,7 @@
package org.jivesoftware.smack.filter; package org.jivesoftware.smack.filter;
import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
/** /**
* Filters for packets with a particular type of packet extension. * Filters for packets with a particular type of packet extension.
@ -26,8 +27,8 @@ import org.jivesoftware.smack.packet.Packet;
*/ */
public class PacketExtensionFilter implements PacketFilter { public class PacketExtensionFilter implements PacketFilter {
private String elementName; private final String elementName;
private String namespace; private final String namespace;
/** /**
* Creates a new packet extension filter. Packets will pass the filter if * Creates a new packet extension filter. Packets will pass the filter if
@ -52,6 +53,14 @@ public class PacketExtensionFilter implements PacketFilter {
this(null, namespace); this(null, namespace);
} }
public PacketExtensionFilter(PacketExtension packetExtension) {
this(packetExtension.getElementName(), packetExtension.getNamespace());
}
public PacketExtensionFilter(Class<? extends PacketExtension> packetExtensionClass) throws InstantiationException, IllegalAccessException {
this(packetExtensionClass.newInstance());
}
public boolean accept(Packet packet) { public boolean accept(Packet packet) {
return packet.getExtension(elementName, namespace) != null; return packet.getExtension(elementName, namespace) != null;
} }