001package jmri.jmrit.logixng.actions.configurexml;
002
003import jmri.*;
004import jmri.configurexml.JmriConfigureXmlException;
005import jmri.jmrit.logixng.DigitalActionManager;
006import jmri.jmrit.logixng.actions.ActionClockRate;
007import jmri.jmrit.logixng.util.configurexml.LogixNG_SelectEnumXml;
008import jmri.jmrit.logixng.util.configurexml.LogixNG_SelectDoubleXml;
009
010import org.jdom2.Element;
011
012/**
013 * Handle XML configuration for ActionClockRate objects.
014 *
015 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010
016 * @author Daniel Bergqvist Copyright (C) 2021
017 * @author Dave Sand Copyright (C) 2021
018 */
019public class ActionClockRateXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML {
020
021    public ActionClockRateXml() {
022    }
023
024    /**
025     * Default implementation for storing the contents of a clock action.
026     *
027     * @param o Object to store, of type ActionClockRate
028     * @return Element containing the complete info
029     */
030    @Override
031    public Element store(Object o) {
032        ActionClockRate p = (ActionClockRate) o;
033
034        var selectEnumXml = new LogixNG_SelectEnumXml<ActionClockRate.ClockState>();
035        var selectSpeedXml = new LogixNG_SelectDoubleXml();
036
037        Element element = new Element("ActionClockRate");
038        element.setAttribute("class", this.getClass().getName());
039        element.addContent(new Element("systemName").addContent(p.getSystemName()));
040
041        storeCommon(p, element);
042
043        element.addContent(selectEnumXml.store(p.getSelectEnum(), "state"));
044        element.addContent(selectSpeedXml.store(p.getSelectSpeed(), "rate"));
045
046        return element;
047    }
048
049    @Override
050    public boolean load(Element shared, Element perNode) throws JmriConfigureXmlException {
051        String sys = getSystemName(shared);
052        String uname = getUserName(shared);
053        ActionClockRate h = new ActionClockRate(sys, uname);
054
055        var selectEnumXml = new LogixNG_SelectEnumXml<ActionClockRate.ClockState>();
056        var selectRateXml = new LogixNG_SelectDoubleXml();
057
058        loadCommon(h, shared);
059
060        selectEnumXml.load(shared.getChild("state"), h.getSelectEnum());
061
062        selectRateXml.load(shared.getChild("rate"), h.getSelectSpeed());
063
064        InstanceManager.getDefault(DigitalActionManager.class).registerAction(h);
065        return true;
066    }
067
068//    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ActionClockRateXml.class);
069}