001package jmri.jmrit.logixng.actions.configurexml;
002
003import jmri.InstanceManager;
004import jmri.jmrit.logixng.DigitalActionManager;
005import jmri.jmrit.logixng.MaleSocket;
006import jmri.jmrit.logixng.actions.RunOnce;
007
008import org.jdom2.Element;
009
010
011/**
012 * Handle XML configuration for RunOnce objects.
013 *
014 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010
015 * @author Daniel Bergqvist Copyright (C) 2022
016 */
017public class RunOnceXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML {
018
019    /**
020     * Default implementation for storing the contents of a SE8cSignalHead
021     *
022     * @param o Object to store, of type TripleTurnoutSignalHead
023     * @return Element containing the complete info
024     */
025    @Override
026    public Element store(Object o) {
027        RunOnce p = (RunOnce) o;
028
029        Element element = new Element("RunOnce");
030        element.setAttribute("class", this.getClass().getName());
031        element.addContent(new Element("systemName").addContent(p.getSystemName()));
032
033        storeCommon(p, element);
034
035        String socketSystemName;
036        Element e = new Element("Socket");
037        e.addContent(new Element("socketName").addContent(p.getSocket().getName()));
038        MaleSocket socket = p.getSocket().getConnectedSocket();
039        if (socket != null) {
040            socketSystemName = socket.getSystemName();
041        } else {
042            socketSystemName = p.getSocketSystemName();
043        }
044        if (socketSystemName != null) {
045            e.addContent(new Element("systemName").addContent(socketSystemName));
046        }
047        element.addContent(e);
048
049        return element;
050    }
051
052    @Override
053    public boolean load(Element shared, Element perNode) {
054
055        String sys = getSystemName(shared);
056        String uname = getUserName(shared);
057
058        String socketName = null;
059        String socketSystemName = null;
060
061        if (shared.getChild("Socket") != null) {
062            socketName = shared.getChild("Socket").getChild("socketName").getTextTrim();
063            Element socketSystemNameElement = shared.getChild("Socket").getChild("systemName");
064            if (socketSystemNameElement != null) {
065                socketSystemName = socketSystemNameElement.getTextTrim();
066            }
067        }
068
069        RunOnce h = new RunOnce(sys, uname, socketName, socketSystemName);
070
071        loadCommon(h, shared);
072
073        InstanceManager.getDefault(DigitalActionManager.class).registerAction(h);
074        return true;
075    }
076
077//    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(RunOnceXml.class);
078}