001package jmri.jmrit.logixng.actions.configurexml;
002
003import jmri.*;
004import jmri.configurexml.JmriConfigureXmlException;
005import jmri.jmrit.logixng.DigitalActionManager;
006import jmri.jmrit.logixng.actions.EnableLogix;
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) 2021
016 */
017public class EnableLogixXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML {
018
019    public EnableLogixXml() {
020    }
021
022    /**
023     * Default implementation for storing the contents of a EnableLogix
024     *
025     * @param o Object to store, of type EnableLogix
026     * @return Element containing the complete info
027     */
028    @Override
029    public Element store(Object o) {
030        EnableLogix p = (EnableLogix) o;
031
032        Element element = new Element("EnableLogix");
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<Logix>();
039        var selectEnumXml = new LogixNG_SelectEnumXml<EnableLogix.Operation>();
040
041        element.addContent(selectNamedBeanXml.store(p.getSelectNamedBean(), "namedBean"));
042        element.addContent(selectEnumXml.store(p.getSelectEnum(), "operation"));
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        EnableLogix h = new EnableLogix(sys, uname);
052
053        loadCommon(h, shared);
054
055        var selectNamedBeanXml = new LogixNG_SelectNamedBeanXml<Logix>();
056        var selectEnumXml = new LogixNG_SelectEnumXml<EnableLogix.Operation>();
057
058        selectNamedBeanXml.load(shared.getChild("namedBean"), h.getSelectNamedBean());
059        selectNamedBeanXml.loadLegacy(shared, h.getSelectNamedBean(), "logix");
060
061        selectEnumXml.load(shared.getChild("operation"), h.getSelectEnum());
062        selectEnumXml.loadLegacy(
063                shared, h.getSelectEnum(),
064                "operationAddressing",
065                "operationDirect",
066                "operationReference",
067                "operationLocalVariable",
068                "operationFormula");
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(EnableLogixXml.class);
075}