001package jmri.jmrit.logixng.expressions.configurexml;
002
003import java.util.ResourceBundle;
004import jmri.*;
005import jmri.configurexml.JmriConfigureXmlException;
006import jmri.Transit;
007import jmri.jmrit.logixng.*;
008import jmri.jmrit.logixng.expressions.ExpressionTransit;
009import jmri.jmrit.logixng.util.configurexml.LogixNG_SelectNamedBeanXml;
010import jmri.jmrit.logixng.util.configurexml.LogixNG_SelectEnumXml;
011import org.jdom2.Element;
012
013/**
014 * Handle XML configuration for ExpressionTransitXml objects.
015 *
016 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010
017 * @author Daniel Bergqvist Copyright 2021
018 * @author Dave Sand Copyright (C) 2023
019 */
020public class ExpressionTransitXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML {
021
022    static final ResourceBundle rb = ResourceBundle.getBundle("jmri.jmrit.logixng.actions.ActionBundle");
023
024    public ExpressionTransitXml() {
025    }
026
027    /**
028     * Default implementation for storing the contents of a ExpressionTransit
029     *
030     * @param o Object to store, of type ExpressionTransit
031     * @return Element containing the complete info
032     */
033    @Override
034    public Element store(Object o) {
035        ExpressionTransit p = (ExpressionTransit) o;
036
037        Element element = new Element("ExpressionTransit");
038        element.setAttribute("class", this.getClass().getName());
039        element.addContent(new Element("systemName").addContent(p.getSystemName()));
040
041        storeCommon(p, element);
042
043        var selectNamedBeanXml = new LogixNG_SelectNamedBeanXml<Transit>();
044        var selectEnumXml = new LogixNG_SelectEnumXml<ExpressionTransit.TransitState>();
045
046        element.addContent(selectNamedBeanXml.store(p.getSelectNamedBean(), "namedBean"));
047
048        element.addContent(new Element("is_isNot").addContent(p.get_Is_IsNot().name()));
049
050        element.addContent(selectEnumXml.store(p.getSelectEnum(), "transitStateData"));
051
052        return element;
053    }
054
055    @Override
056    public boolean load(Element shared, Element perNode) throws JmriConfigureXmlException {
057        String sys = getSystemName(shared);
058        String uname = getUserName(shared);
059        ExpressionTransit h = new ExpressionTransit(sys, uname);
060
061        loadCommon(h, shared);
062
063        var selectNamedBeanXml = new LogixNG_SelectNamedBeanXml<Transit>();
064        var selectEnumXml = new LogixNG_SelectEnumXml<ExpressionTransit.TransitState>();
065
066        selectNamedBeanXml.load(shared.getChild("namedBean"), h.getSelectNamedBean());
067        selectNamedBeanXml.loadLegacy(shared, h.getSelectNamedBean(), "transit");
068
069        Element is_IsNot = shared.getChild("is_isNot");
070        if (is_IsNot != null) {
071            h.set_Is_IsNot(Is_IsNot_Enum.valueOf(is_IsNot.getTextTrim()));
072        }
073
074        selectEnumXml.load(shared.getChild("transitStateData"), h.getSelectEnum());
075        selectEnumXml.loadLegacy(
076                shared,
077                h.getSelectEnum(),
078                "stateAddressing",
079                "transitState",
080                "stateReference",
081                "stateLocalVariable",
082                "stateFormula");
083
084        InstanceManager.getDefault(DigitalExpressionManager.class).registerExpression(h);
085        return true;
086    }
087
088//    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ExpressionTransitXml.class);
089}