001package jmri.jmrit.logixng.actions.configurexml;
002
003import jmri.*;
004import jmri.configurexml.JmriConfigureXmlException;
005import jmri.jmrit.logixng.DigitalActionManager;
006import jmri.jmrit.logixng.actions.ActionTurnoutLock;
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 ActionLightXml objects.
013 *
014 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010
015 * @author Daniel Bergqvist Copyright (C) 2019
016 */
017public class ActionTurnoutLockXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML {
018
019    public ActionTurnoutLockXml() {
020    }
021
022    /**
023     * Default implementation for storing the contents of a ActionTurnoutLock
024     *
025     * @param o Object to store, of type TripleTurnoutSignalHead
026     * @return Element containing the complete info
027     */
028    @Override
029    public Element store(Object o) {
030        ActionTurnoutLock p = (ActionTurnoutLock) o;
031
032        Element element = new Element("ActionTurnoutLock");
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<Turnout>();
039        var selectEnumXml = new LogixNG_SelectEnumXml<ActionTurnoutLock.TurnoutLock>();
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 {     // Test class that inherits this class throws exception
049        String sys = getSystemName(shared);
050        String uname = getUserName(shared);
051        ActionTurnoutLock h = new ActionTurnoutLock(sys, uname);
052
053        loadCommon(h, shared);
054
055        var selectNamedBeanXml = new LogixNG_SelectNamedBeanXml<Turnout>();
056        var selectEnumXml = new LogixNG_SelectEnumXml<ActionTurnoutLock.TurnoutLock>();
057
058        selectNamedBeanXml.load(shared.getChild("namedBean"), h.getSelectNamedBean());
059
060        selectEnumXml.load(shared.getChild("state"), h.getSelectEnum());
061
062        InstanceManager.getDefault(DigitalActionManager.class).registerAction(h);
063        return true;
064    }
065
066//    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ActionTurnoutLockXml.class);
067}