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