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