aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/xmpp/XepRegistry.java
blob: 89174c7067f5720c250fe9a8d46aeacf1d8301f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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() {}
}