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