001package jmri.jmrit.logixng.actions.configurexml;
002
003import jmri.InstanceManager;
004import jmri.configurexml.JmriConfigureXmlException;
005import jmri.jmrit.logixng.*;
006import jmri.jmrit.logixng.actions.ActionShutDownTask;
007
008import org.jdom2.Element;
009
010/**
011 * Handle XML configuration for ActionShutDownTask objects.
012 *
013 * @author Bob Jacobsen      Copyright: Copyright (c) 2004, 2008, 2010
014 * @author Daniel Bergqvist  Copyright (C) 2022
015 */
016public class ActionShutDownTaskXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML {
017
018    public ActionShutDownTaskXml() {
019    }
020
021    /**
022     * Default implementation for storing the contents of a SE8cSignalHead
023     *
024     * @param o Object to store, of type TripleLightSignalHead
025     * @return Element containing the complete info
026     */
027    @Override
028    public Element store(Object o) {
029        ActionShutDownTask p = (ActionShutDownTask) o;
030
031        Element element = new Element("ActionShutDownTask");
032        element.setAttribute("class", this.getClass().getName());
033        element.addContent(new Element("systemName").addContent(p.getSystemName()));
034
035        storeCommon(p, element);
036
037        Element callSocketElement = new Element("CallSocket");
038        callSocketElement.addContent(new Element("socketName").addContent(p.getCallSocket().getName()));
039        MaleSocket callSocket = p.getCallSocket().getConnectedSocket();
040        String callSocketSystemName;
041        if (callSocket != null) {
042            callSocketSystemName = callSocket.getSystemName();
043        } else {
044            callSocketSystemName = p.getCallSocketSystemName();
045        }
046        if (callSocketSystemName != null) {
047            callSocketElement.addContent(new Element("systemName").addContent(callSocketSystemName));
048        }
049        element.addContent(callSocketElement);
050
051        Element runSocketElement = new Element("RunSocket");
052        runSocketElement.addContent(new Element("socketName").addContent(p.getRunSocket().getName()));
053        MaleSocket runSocket = p.getRunSocket().getConnectedSocket();
054        String runSocketSystemName;
055        if (runSocket != null) {
056            runSocketSystemName = runSocket.getSystemName();
057        } else {
058            runSocketSystemName = p.getRunSocketSystemName();
059        }
060        if (runSocketSystemName != null) {
061            runSocketElement.addContent(new Element("systemName").addContent(runSocketSystemName));
062        }
063        element.addContent(runSocketElement);
064
065        return element;
066    }
067
068    @Override
069    public boolean load(Element shared, Element perNode) throws JmriConfigureXmlException {
070
071        Element callSocketNameElement = shared.getChild("CallSocket").getChild("socketName");
072        String callSocketName = callSocketNameElement.getTextTrim();
073        Element callSocketSystemNameElement = shared.getChild("CallSocket").getChild("systemName");
074        String callSocketSystemName = null;
075        if (callSocketSystemNameElement != null) {
076            callSocketSystemName = callSocketSystemNameElement.getTextTrim();
077        }
078
079        Element runSocketNameElement = shared.getChild("RunSocket").getChild("socketName");
080        String runSocketName = runSocketNameElement.getTextTrim();
081        Element runSocketSystemNameElement = shared.getChild("RunSocket").getChild("systemName");
082        String runSocketSystemName = null;
083        if (runSocketSystemNameElement != null) {
084            runSocketSystemName = runSocketSystemNameElement.getTextTrim();
085        }
086
087        String sys = getSystemName(shared);
088        String uname = getUserName(shared);
089        ActionShutDownTask h = new ActionShutDownTask(sys, uname);
090
091        loadCommon(h, shared);
092
093        h.getCallSocket().setName(callSocketName);
094        h.setCallSocketSystemName(callSocketSystemName);
095
096        h.getRunSocket().setName(runSocketName);
097        h.setRunSocketSystemName(runSocketSystemName);
098
099        InstanceManager.getDefault(DigitalActionManager.class).registerAction(h);
100        return true;
101    }
102
103//    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ActionShutDownTaskXml.class);
104}