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.Logix;
007
008import org.jdom2.Attribute;
009import org.jdom2.Element;
010
011/**
012 * Handle XML configuration for ActionLightXml objects.
013 *
014 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010
015 * @author Daniel Bergqvist Copyright (C) 2019
016 */
017public class LogixXml 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 TripleLightSignalHead
023     * @return Element containing the complete info
024     */
025    @Override
026    public Element store(Object o) {
027        Logix p = (Logix) o;
028
029        Element element = new Element("Logix");
030        element.setAttribute("class", this.getClass().getName());
031        element.addContent(new Element("systemName").addContent(p.getSystemName()));
032
033        storeCommon(p, element);
034
035        element.setAttribute("executeType", p.getExecuteType().name());
036
037        Element e2 = new Element("ExpressionSocket");
038        e2.addContent(new Element("socketName").addContent(p.getChild(0).getName()));
039        MaleSocket socket = p.getExpressionSocket().getConnectedSocket();
040        String socketSystemName;
041        if (socket != null) {
042            socketSystemName = socket.getSystemName();
043        } else {
044            socketSystemName = p.getExpressionSocketSystemName();
045        }
046        if (socketSystemName != null) {
047            e2.addContent(new Element("systemName").addContent(socketSystemName));
048        }
049        element.addContent(e2);
050
051        e2 = new Element("ActionSocket");
052        e2.addContent(new Element("socketName").addContent(p.getChild(1).getName()));
053        socket = p.getActionSocket().getConnectedSocket();
054        if (socket != null) {
055            socketSystemName = socket.getSystemName();
056        } else {
057            socketSystemName = p.getActionSocketSystemName();
058        }
059        if (socketSystemName != null) {
060            e2.addContent(new Element("systemName").addContent(socketSystemName));
061        }
062        element.addContent(e2);
063
064        return element;
065    }
066
067    @Override
068    public boolean load(Element shared, Element perNode) {
069        String sys = getSystemName(shared);
070        String uname = getUserName(shared);
071        Logix h = new Logix(sys, uname);
072
073        loadCommon(h, shared);
074
075        Attribute typeAttr = shared.getAttribute("executeType");
076        if (typeAttr != null) {
077            String typeStr = typeAttr.getValue();
078            h.setExecuteType(Logix.ExecuteType.valueOf(typeStr));
079        }
080
081        Element socketName = shared.getChild("ExpressionSocket").getChild("socketName");
082        h.getChild(0).setName(socketName.getTextTrim());
083        Element socketSystemName = shared.getChild("ExpressionSocket").getChild("systemName");
084        if (socketSystemName != null) {
085            h.setExpressionSocketSystemName(socketSystemName.getTextTrim());
086        }
087
088        socketName = shared.getChild("ActionSocket").getChild("socketName");
089        h.getChild(1).setName(socketName.getTextTrim());
090        socketSystemName = shared.getChild("ActionSocket").getChild("systemName");
091        if (socketSystemName != null) {
092            h.setActionSocketSystemName(socketSystemName.getTextTrim());
093        }
094
095        InstanceManager.getDefault(DigitalActionManager.class).registerAction(h);
096        return true;
097    }
098
099//    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ActionLightXml.class);
100}