diff options
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/xmpp/XepRegistry.java')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/xmpp/XepRegistry.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/XepRegistry.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/XepRegistry.java new file mode 100644 index 00000000..89174c70 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/XepRegistry.java @@ -0,0 +1,51 @@ +package de.thedevstack.conversationsplus.xmpp; + +import java.util.Hashtable; + +import de.thedevstack.conversationsplus.xmpp.disco.FeatureRegistry; +import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacketReceiver; + +/** + */ +public class XepRegistry { + private final Hashtable<String, Xep> xeps = new Hashtable<>(); + private static final XepRegistry INSTANCE = new XepRegistry(); + + public static void enable(String shortName) { + if (INSTANCE.xeps.containsKey(shortName)) { + Xep xep = INSTANCE.xeps.get(shortName); + xep.enable(); + FeatureRegistry.remove(xep); + IqPacketReceiver.getInstance().registerIqPacketHandler(xep); + } + } + + public static void disable(String shortName) { + if (INSTANCE.xeps.containsKey(shortName)) { + Xep xep = INSTANCE.xeps.get(shortName); + xep.disable(); + FeatureRegistry.remove(xep); + IqPacketReceiver.getInstance().unregisterIqPacketHandler(xep); + } + } + + public static void add(Xep xep) { + INSTANCE.xeps.put(xep.shortName(), xep); + if (xep.isEnabled()) { + FeatureRegistry.add(xep); + IqPacketReceiver.getInstance().registerIqPacketHandler(xep); + } + } + + public static void remove(Xep xep) { + INSTANCE.xeps.remove(xep.shortName()); + FeatureRegistry.remove(xep); + IqPacketReceiver.getInstance().unregisterIqPacketHandler(xep); + } + + public static XepRegistry getInstance() { + return INSTANCE; + } + + private XepRegistry() {} +} |