001package jmri.jmrix.loconet.logixng.configurexml;
002
003import java.util.*;
004
005import jmri.*;
006import jmri.configurexml.JmriConfigureXmlException;
007import jmri.jmrit.logixng.DigitalActionManager;
008import jmri.jmrix.loconet.LocoNetSystemConnectionMemo;
009import jmri.jmrix.loconet.logixng.SetSpeedZero;
010
011import org.jdom2.Element;
012
013/**
014 * Handle XML configuration for ExpressionSlotUsage objects.
015 *
016 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010
017 * @author Daniel Bergqvist Copyright (C) 2022
018 */
019public class SetSpeedZeroXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML {
020
021    public SetSpeedZeroXml() {
022    }
023
024    /**
025     * Default implementation for storing the contents of a ExpressionSlotUsage
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        SetSpeedZero p = (SetSpeedZero) o;
033
034        Element element = new Element("ActionLoconetSetSpeedZero");
035        element.setAttribute("class", this.getClass().getName());
036        element.addContent(new Element("systemName").addContent(p.getSystemName()));
037
038        storeCommon(p, element);
039
040        if (p.getMemo() != null) {
041            element.addContent(new Element("systemConnection")
042                    .addContent(p.getMemo().getSystemPrefix()));
043        }
044
045        return element;
046    }
047
048    @Override
049    public boolean load(Element shared, Element perNode) throws JmriConfigureXmlException {     // Test class that inherits this class throws exception
050        String sys = getSystemName(shared);
051        String uname = getUserName(shared);
052        SetSpeedZero h = new SetSpeedZero(sys, uname, null);
053
054        loadCommon(h, shared);
055
056        Element systemConnection = shared.getChild("systemConnection");
057        if (systemConnection != null) {
058            String systemConnectionName = systemConnection.getTextTrim();
059            List<LocoNetSystemConnectionMemo> systemConnections =
060                    jmri.InstanceManager.getList(LocoNetSystemConnectionMemo.class);
061
062            for (LocoNetSystemConnectionMemo memo : systemConnections) {
063                if (memo.getSystemPrefix().equals(systemConnectionName)) {
064                    h.setMemo(memo);
065                    break;
066                }
067            }
068        }
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(SetSpeedZeroXml.class);
075}