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