001package jmri.jmrix.mqtt.logixng;
002
003import java.util.AbstractMap;
004import java.util.HashSet;
005import java.util.Map;
006import java.util.Set;
007
008import jmri.jmrit.logixng.Category;
009import jmri.jmrit.logixng.DigitalActionFactory;
010import jmri.jmrit.logixng.DigitalActionBean;
011
012import org.openide.util.lookup.ServiceProvider;
013
014/**
015 * The factory for LogixNG MQTT classes.
016 */
017@ServiceProvider(service = DigitalActionFactory.class)
018public class ActionFactory implements DigitalActionFactory {
019
020    @Override
021    public void init() {
022        CategoryMqtt.registerCategory();
023    }
024
025    @Override
026    public Set<Map.Entry<Category, Class<? extends DigitalActionBean>>> getActionClasses() {
027        Set<Map.Entry<Category, Class<? extends DigitalActionBean>>> actionClasses = new HashSet<>();
028
029        // We don't want to add these classes if we don't have a MQTT connection
030        if (CategoryMqtt.hasMQTT()) {
031            actionClasses.add(new AbstractMap.SimpleEntry<>(CategoryMqtt.MQTT, Publish.class));
032            actionClasses.add(new AbstractMap.SimpleEntry<>(CategoryMqtt.MQTT, Subscribe.class));
033        }
034
035        return actionClasses;
036    }
037
038}