001package jmri.jmrit.logixng.actions.configurexml;
002
003import jmri.*;
004import jmri.configurexml.JmriConfigureXmlException;
005import jmri.jmrit.logixng.DigitalActionManager;
006import jmri.jmrit.logixng.actions.ActionClock;
007import jmri.jmrit.logixng.util.configurexml.LogixNG_SelectEnumXml;
008import jmri.jmrit.logixng.util.configurexml.LogixNG_SelectIntegerXml;
009
010import org.jdom2.Element;
011
012/**
013 * Handle XML configuration for ActionClock 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 ActionClockXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML {
020
021    public ActionClockXml() {
022    }
023
024    /**
025     * Default implementation for storing the contents of a clock action.
026     *
027     * @param o Object to store, of type ActionClock
028     * @return Element containing the complete info
029     */
030    @Override
031    public Element store(Object o) {
032        ActionClock p = (ActionClock) o;
033
034        var selectEnumXml = new LogixNG_SelectEnumXml<ActionClock.ClockState>();
035        var selectTimeXml = new LogixNG_SelectIntegerXml();
036
037        Element element = new Element("ActionClock");
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(selectTimeXml.store(p.getSelectTime(), "time"));
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        ActionClock h = new ActionClock(sys, uname);
054
055        var selectEnumXml = new LogixNG_SelectEnumXml<ActionClock.ClockState>();
056        var selectTimeXml = new LogixNG_SelectIntegerXml();
057
058        loadCommon(h, shared);
059
060        selectEnumXml.load(shared.getChild("state"), h.getSelectEnum());
061        selectEnumXml.loadLegacy(
062                shared, h.getSelectEnum(),
063                null,
064                "clockState",
065                null,
066                null,
067                null);
068
069        selectTimeXml.load(shared.getChild("time"), h.getSelectTime());
070        selectTimeXml.loadLegacy(
071                shared, h.getSelectTime(),
072                null,
073                "setTime",
074                null,
075                null,
076                null);
077
078        InstanceManager.getDefault(DigitalActionManager.class).registerAction(h);
079        return true;
080    }
081
082//    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ActionClockXml.class);
083}