mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 06:12:05 +01:00
Add PacketExtensionFilter(PacketExtension) constructor
and PacketExtensionFilter(Class<? extends PacketExtension).
This commit is contained in:
parent
b083449cc3
commit
1b2231be0b
1 changed files with 11 additions and 2 deletions
|
@ -18,6 +18,7 @@
|
|||
package org.jivesoftware.smack.filter;
|
||||
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
|
||||
private String elementName;
|
||||
private String namespace;
|
||||
private final String elementName;
|
||||
private final String namespace;
|
||||
|
||||
/**
|
||||
* Creates a new packet extension filter. Packets will pass the filter if
|
||||
|
@ -52,6 +53,14 @@ public class PacketExtensionFilter implements PacketFilter {
|
|||
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) {
|
||||
return packet.getExtension(elementName, namespace) != null;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue